From: Cooper Lees Date: Fri, 8 May 2020 15:50:50 +0000 (-0700) Subject: Refactor black into packages in src/ dir (#1376) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/2082a325fdd14f0aabd88f7f12a20f9fb085c538?ds=sidebyside Refactor black into packages in src/ dir (#1376) - 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 ``` --- diff --git a/.appveyor.yml b/.appveyor.yml index d29cca2..06a15bc 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -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 diff --git a/.coveragerc b/.coveragerc index d006038..32a8da5 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,5 @@ [report] omit = - blib2to3/* + src/blib2to3/* tests/data/* */site-packages/* diff --git a/.gitignore b/.gitignore index b76c149..509797e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ black.egg-info build/ dist/ pip-wheel-metadata/ -_black_version.py +src/_black_version.py .idea .eggs .dmypy.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1959390..bbd034d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/.travis.yml b/.travis.yml index 4e086bd..b2b127c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/setup.py b/setup.py index b953b96..3d14fd4 100644 --- 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, diff --git a/black.py b/src/black/__init__.py similarity index 100% rename from black.py rename to src/black/__init__.py diff --git a/blackd.py b/src/blackd/__init__.py similarity index 100% rename from blackd.py rename to src/blackd/__init__.py diff --git a/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt similarity index 100% rename from blib2to3/Grammar.txt rename to src/blib2to3/Grammar.txt diff --git a/blib2to3/LICENSE b/src/blib2to3/LICENSE similarity index 100% rename from blib2to3/LICENSE rename to src/blib2to3/LICENSE diff --git a/blib2to3/PatternGrammar.txt b/src/blib2to3/PatternGrammar.txt similarity index 100% rename from blib2to3/PatternGrammar.txt rename to src/blib2to3/PatternGrammar.txt diff --git a/blib2to3/README b/src/blib2to3/README similarity index 100% rename from blib2to3/README rename to src/blib2to3/README diff --git a/blib2to3/__init__.py b/src/blib2to3/__init__.py similarity index 100% rename from blib2to3/__init__.py rename to src/blib2to3/__init__.py diff --git a/blib2to3/pgen2/__init__.py b/src/blib2to3/pgen2/__init__.py similarity index 100% rename from blib2to3/pgen2/__init__.py rename to src/blib2to3/pgen2/__init__.py diff --git a/blib2to3/pgen2/conv.py b/src/blib2to3/pgen2/conv.py similarity index 100% rename from blib2to3/pgen2/conv.py rename to src/blib2to3/pgen2/conv.py diff --git a/blib2to3/pgen2/driver.py b/src/blib2to3/pgen2/driver.py similarity index 100% rename from blib2to3/pgen2/driver.py rename to src/blib2to3/pgen2/driver.py diff --git a/blib2to3/pgen2/grammar.py b/src/blib2to3/pgen2/grammar.py similarity index 100% rename from blib2to3/pgen2/grammar.py rename to src/blib2to3/pgen2/grammar.py diff --git a/blib2to3/pgen2/literals.py b/src/blib2to3/pgen2/literals.py similarity index 100% rename from blib2to3/pgen2/literals.py rename to src/blib2to3/pgen2/literals.py diff --git a/blib2to3/pgen2/parse.py b/src/blib2to3/pgen2/parse.py similarity index 100% rename from blib2to3/pgen2/parse.py rename to src/blib2to3/pgen2/parse.py diff --git a/blib2to3/pgen2/pgen.py b/src/blib2to3/pgen2/pgen.py similarity index 100% rename from blib2to3/pgen2/pgen.py rename to src/blib2to3/pgen2/pgen.py diff --git a/blib2to3/pgen2/token.py b/src/blib2to3/pgen2/token.py similarity index 100% rename from blib2to3/pgen2/token.py rename to src/blib2to3/pgen2/token.py diff --git a/blib2to3/pgen2/tokenize.py b/src/blib2to3/pgen2/tokenize.py similarity index 100% rename from blib2to3/pgen2/tokenize.py rename to src/blib2to3/pgen2/tokenize.py diff --git a/blib2to3/pygram.py b/src/blib2to3/pygram.py similarity index 100% rename from blib2to3/pygram.py rename to src/blib2to3/pygram.py diff --git a/blib2to3/pytree.py b/src/blib2to3/pytree.py similarity index 100% rename from blib2to3/pytree.py rename to src/blib2to3/pytree.py diff --git a/tests/test_black.py b/tests/test_black.py index 6fb01f7..1b574c0 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -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)