]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Refactor black into packages in src/ dir (#1376)
authorCooper Lees <cooper@fb.com>
Fri, 8 May 2020 15:50:50 +0000 (08:50 -0700)
committerGitHub <noreply@github.com>
Fri, 8 May 2020 15:50:50 +0000 (08:50 -0700)
- Move black.py to src/black/__init__.py
- Have setuptools_scm make src/_black_version.py and exclude from git
- Move blackd.py to src/blackd/__init__.py
- Move blib2to3/ to src/
- Update `setup.py`
- Update unittests to pass
  - Mostly path fixing + resolving
- Update CI
  - pre-commit config
  - appveyor + travis

Tested on my mac with python 3.7.5 via:
```
python3 -m venv /tmp/tb3
/tmp/tb3/bin/pip install --upgrade setuptools pip coverage pre-commit
/tmp/tb2/bin/pip install ~/repos/black/
cd ~/repos/black/
/tmp/tb2/bin/coverage run tests/test_black.py
/tmp/tb3/bin/pre-commit run -a
/tmp/tb3/bin/black --help
/tmp/tb3/bin/black ~/repos/ptr/ptr.py
```

25 files changed:
.appveyor.yml
.coveragerc
.gitignore
.pre-commit-config.yaml
.travis.yml
setup.py
src/black/__init__.py [moved from black.py with 100% similarity]
src/blackd/__init__.py [moved from blackd.py with 100% similarity]
src/blib2to3/Grammar.txt [moved from blib2to3/Grammar.txt with 100% similarity]
src/blib2to3/LICENSE [moved from blib2to3/LICENSE with 100% similarity]
src/blib2to3/PatternGrammar.txt [moved from blib2to3/PatternGrammar.txt with 100% similarity]
src/blib2to3/README [moved from blib2to3/README with 100% similarity]
src/blib2to3/__init__.py [moved from blib2to3/__init__.py with 100% similarity]
src/blib2to3/pgen2/__init__.py [moved from blib2to3/pgen2/__init__.py with 100% similarity]
src/blib2to3/pgen2/conv.py [moved from blib2to3/pgen2/conv.py with 100% similarity]
src/blib2to3/pgen2/driver.py [moved from blib2to3/pgen2/driver.py with 100% similarity]
src/blib2to3/pgen2/grammar.py [moved from blib2to3/pgen2/grammar.py with 100% similarity]
src/blib2to3/pgen2/literals.py [moved from blib2to3/pgen2/literals.py with 100% similarity]
src/blib2to3/pgen2/parse.py [moved from blib2to3/pgen2/parse.py with 100% similarity]
src/blib2to3/pgen2/pgen.py [moved from blib2to3/pgen2/pgen.py with 100% similarity]
src/blib2to3/pgen2/token.py [moved from blib2to3/pgen2/token.py with 100% similarity]
src/blib2to3/pgen2/tokenize.py [moved from blib2to3/pgen2/tokenize.py with 100% similarity]
src/blib2to3/pygram.py [moved from blib2to3/pygram.py with 100% similarity]
src/blib2to3/pytree.py [moved from blib2to3/pytree.py with 100% similarity]
tests/test_black.py

index d29cca24c01089f734c5c89720aaa8ddd22e6d25..06a15bc96fc4a3014b1bcd59a2a251e7c9679035 100644 (file)
@@ -7,12 +7,12 @@ build: off
 
 test_script:
   - C:\Python36\python.exe tests/test_black.py
-  - C:\Python36\python.exe -m mypy black.py blackd.py tests/test_black.py blib2to3
+  - C:\Python36\python.exe -m mypy src/black src/blackd tests/test_black.py src/blib2to3
 
 after_test:
   - C:\Python36\python.exe -m pip install pyinstaller
   - "%CMD_IN_ENV% C:\\Python36\\python.exe -m PyInstaller --clean -F --add-data
-    blib2to3/;blib2to3 black.py"
+    src/blib2to3/;blib2to3 src/black/__init__.py"
 
 artifacts:
   - path: dist/black.exe
index d006038342d35312c6bf4ee0d463e7cc85793845..32a8da521ba3e72be3e327cdcca85dc716ac455e 100644 (file)
@@ -1,5 +1,5 @@
 [report]
 omit =
-  blib2to3/*
+  src/blib2to3/*
   tests/data/*
   */site-packages/*
index b76c149ce0505c770315b2c481ad90c3b47564f4..509797e65c4df34f6099182ad57be103b4fa536d 100644 (file)
@@ -9,7 +9,7 @@ black.egg-info
 build/
 dist/
 pip-wheel-metadata/
-_black_version.py
+src/_black_version.py
 .idea
 .eggs
 .dmypy.json
index 195939015c516506e4b67791db1be1bddbde327f..bbd034dc0c21f61b667e9051ffbf6bc22abbc71b 100644 (file)
@@ -1,6 +1,6 @@
 # Note: don't use this config for your own repositories. Instead, see
 # "Version control integration" in README.md.
-exclude: ^(blib2to3/|profiling/|tests/data/)
+exclude: ^(src/blib2to3/|profiling/|tests/data/)
 repos:
   - repo: local
     hooks:
index 4e086bd38f47b8afce0c59fbc8cec24758e3b9b3..b2b127cfeb07880831512c902a93d64d5c50fba6 100644 (file)
@@ -33,7 +33,7 @@ matrix:
     - python: 3.9-dev
 before_deploy:
   - pip install pyinstaller
-  - pyinstaller --clean -F --add-data blib2to3/:blib2to3 black.py
+  - pyinstaller --clean -F --add-data src/blib2to3/:blib2to3 src/black/__init__.py
 deploy:
   provider: releases
   api_key:
index b953b96ac9deec3921e04615873e20e1c6f8a708..3d14fd425fbbbc7ff5c2b3828f31d3482254922d 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018 Łukasz Langa
+# Copyright (C) 2020 Łukasz Langa
 from setuptools import setup
 import sys
 import os
@@ -28,14 +28,14 @@ if os.getenv("BLACK_USE_MYPYC", None) == "1":
 
 if USE_MYPYC:
     mypyc_targets = [
-        "black.py",
-        "blib2to3/pytree.py",
-        "blib2to3/pygram.py",
-        "blib2to3/pgen2/parse.py",
-        "blib2to3/pgen2/grammar.py",
-        "blib2to3/pgen2/token.py",
-        "blib2to3/pgen2/driver.py",
-        "blib2to3/pgen2/pgen.py",
+        "src/black/__init__.py",
+        "src/blib2to3/pytree.py",
+        "src/blib2to3/pygram.py",
+        "src/blib2to3/pgen2/parse.py",
+        "src/blib2to3/pgen2/grammar.py",
+        "src/blib2to3/pgen2/token.py",
+        "src/blib2to3/pgen2/driver.py",
+        "src/blib2to3/pgen2/pgen.py",
     ]
 
     from mypyc.build import mypycify
@@ -48,7 +48,7 @@ else:
 setup(
     name="black",
     use_scm_version={
-        "write_to": "_black_version.py",
+        "write_to": "src/_black_version.py",
         "write_to_template": 'version = "{version}"\n',
     },
     description="The uncompromising code formatter.",
@@ -60,9 +60,10 @@ setup(
     url="https://github.com/psf/black",
     project_urls={"Changelog": "https://github.com/psf/black/blob/master/CHANGES.md"},
     license="MIT",
-    py_modules=["black", "blackd", "_black_version"],
+    py_modules=["_black_version"],
     ext_modules=ext_modules,
-    packages=["blib2to3", "blib2to3.pgen2"],
+    packages=["blackd", "black", "blib2to3", "blib2to3.pgen2"],
+    package_dir={"": "src"},
     package_data={"blib2to3": ["*.txt"]},
     python_requires=">=3.6",
     zip_safe=False,
similarity index 100%
rename from black.py
rename to src/black/__init__.py
similarity index 100%
rename from blackd.py
rename to src/blackd/__init__.py
similarity index 100%
rename from blib2to3/LICENSE
rename to src/blib2to3/LICENSE
similarity index 100%
rename from blib2to3/README
rename to src/blib2to3/README
similarity index 100%
rename from blib2to3/pygram.py
rename to src/blib2to3/pygram.py
similarity index 100%
rename from blib2to3/pytree.py
rename to src/blib2to3/pytree.py
index 6fb01f73d28c5e962a8b2081c00a0472f5b0cea0..1b574c012edfcd963535c349af271d2e06299959 100644 (file)
@@ -35,6 +35,7 @@ ff = partial(black.format_file_in_place, mode=black.FileMode(), fast=True)
 fs = partial(black.format_str, mode=black.FileMode())
 THIS_FILE = Path(__file__)
 THIS_DIR = THIS_FILE.parent
+PROJECT_ROOT = THIS_DIR.parent
 DETERMINISTIC_HEADER = "[Deterministic header]"
 EMPTY_LINE = "# EMPTY LINE WITH WHITESPACE" + " (this comment will be removed)"
 PY36_ARGS = [
@@ -54,7 +55,7 @@ def read_data(name: str, data: bool = True) -> Tuple[str, str]:
         name += ".py"
     _input: List[str] = []
     _output: List[str] = []
-    base_dir = THIS_DIR / "data" if data else THIS_DIR
+    base_dir = THIS_DIR / "data" if data else PROJECT_ROOT
     with open(base_dir / name, "r", encoding="utf8") as test:
         lines = test.readlines()
     result = _input
@@ -202,43 +203,43 @@ class BlackTestCase(unittest.TestCase):
         self.checkSourceFile("tests/test_black.py")
 
     def test_black(self) -> None:
-        self.checkSourceFile("black.py")
+        self.checkSourceFile("src/black/__init__.py")
 
     def test_pygram(self) -> None:
-        self.checkSourceFile("blib2to3/pygram.py")
+        self.checkSourceFile("src/blib2to3/pygram.py")
 
     def test_pytree(self) -> None:
-        self.checkSourceFile("blib2to3/pytree.py")
+        self.checkSourceFile("src/blib2to3/pytree.py")
 
     def test_conv(self) -> None:
-        self.checkSourceFile("blib2to3/pgen2/conv.py")
+        self.checkSourceFile("src/blib2to3/pgen2/conv.py")
 
     def test_driver(self) -> None:
-        self.checkSourceFile("blib2to3/pgen2/driver.py")
+        self.checkSourceFile("src/blib2to3/pgen2/driver.py")
 
     def test_grammar(self) -> None:
-        self.checkSourceFile("blib2to3/pgen2/grammar.py")
+        self.checkSourceFile("src/blib2to3/pgen2/grammar.py")
 
     def test_literals(self) -> None:
-        self.checkSourceFile("blib2to3/pgen2/literals.py")
+        self.checkSourceFile("src/blib2to3/pgen2/literals.py")
 
     def test_parse(self) -> None:
-        self.checkSourceFile("blib2to3/pgen2/parse.py")
+        self.checkSourceFile("src/blib2to3/pgen2/parse.py")
 
     def test_pgen(self) -> None:
-        self.checkSourceFile("blib2to3/pgen2/pgen.py")
+        self.checkSourceFile("src/blib2to3/pgen2/pgen.py")
 
     def test_tokenize(self) -> None:
-        self.checkSourceFile("blib2to3/pgen2/tokenize.py")
+        self.checkSourceFile("src/blib2to3/pgen2/tokenize.py")
 
     def test_token(self) -> None:
-        self.checkSourceFile("blib2to3/pgen2/token.py")
+        self.checkSourceFile("src/blib2to3/pgen2/token.py")
 
     def test_setup(self) -> None:
         self.checkSourceFile("setup.py")
 
     def test_piping(self) -> None:
-        source, expected = read_data("../black", data=False)
+        source, expected = read_data("src/black/__init__", data=False)
         result = BlackRunner().invoke(
             black.main,
             ["-", "--fast", f"--line-length={black.DEFAULT_LINE_LENGTH}"],
@@ -1663,7 +1664,7 @@ class BlackTestCase(unittest.TestCase):
 
     def test_symlink_out_of_root_directory(self) -> None:
         path = MagicMock()
-        root = THIS_DIR
+        root = THIS_DIR.resolve()
         child = MagicMock()
         include = re.compile(black.DEFAULT_INCLUDES)
         exclude = re.compile(black.DEFAULT_EXCLUDES)