diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index b0d819b6..a2377f97 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,5 +7,6 @@ Here are some things you should check for submitting your pull request: - If applicable, add an entry in the changelog. - If applicable, add documentation to all new items and extend the guide. - If applicable, add tests for all new or fixed functions + - If you changed any python code, run `black .`. You can install black with `pip install black`) You might want to run `tox` (`pip install tox`) locally to check compatibility with all supported python versions. If you're using linux or mac you might find the Makefile helpful for testing. diff --git a/.travis.yml b/.travis.yml index ba3d73d7..6a09e398 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ matrix: python: "3.7" # Keep this synced up with build.rs and ensure that the nightly version does have clippy available # https://static.rust-lang.org/dist/YYYY-MM-DD/clippy-nightly-x86_64-unknown-linux-gnu.tar.gz exists - env: TRAVIS_RUST_VERSION=nightly-2019-07-19 + env: TRAVIS_RUST_VERSION=nightly-2019-07-19 - name: PyPy3.5 7.0 # Tested via anaconda PyPy (since travis's PyPy version is too old) python: "3.7" env: FEATURES="pypy" PATH="$PATH:/opt/anaconda/envs/pypy3/bin" diff --git a/Makefile b/Makefile index b10d7dc0..dd37438f 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ test_py3: fmt: cargo fmt --all -- --check + black . --check clippy: @touch src/lib.rs # Touching file to ensure that cargo clippy will re-check the project diff --git a/ci/travis/test.sh b/ci/travis/test.sh index 6def36b0..5298e588 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -11,6 +11,7 @@ else fi if [ "$TRAVIS_JOB_NAME" = "Minimum nightly" ]; then + pip install --pre black==19.3b0 make lint fi diff --git a/examples/rustapi_module/setup.py b/examples/rustapi_module/setup.py index 2dbaebb0..9be64a75 100644 --- a/examples/rustapi_module/setup.py +++ b/examples/rustapi_module/setup.py @@ -38,20 +38,21 @@ class CargoModifiedSdist(SdistCommand): super().make_release_tree(base_dir, files) import toml + # Cargo.toml is now staged and ready to be modified - cargo_loc = os.path.join(base_dir, 'Cargo.toml') + cargo_loc = os.path.join(base_dir, "Cargo.toml") assert os.path.exists(cargo_loc) - with open(cargo_loc, 'r') as f: + with open(cargo_loc, "r") as f: cargo_toml = toml.load(f) - rel_pyo3_path = cargo_toml['dependencies']['pyo3']['path'] + rel_pyo3_path = cargo_toml["dependencies"]["pyo3"]["path"] base_path = os.path.dirname(__file__) abs_pyo3_path = os.path.abspath(os.path.join(base_path, rel_pyo3_path)) - cargo_toml['dependencies']['pyo3']['path'] = abs_pyo3_path + cargo_toml["dependencies"]["pyo3"]["path"] = abs_pyo3_path - with open(cargo_loc, 'w') as f: + with open(cargo_loc, "w") as f: toml.dump(cargo_toml, f) @@ -98,17 +99,12 @@ setup( rustc_flags=get_py_version_cfgs(), ), RustExtension( - "rustapi_module.test_dict", - "Cargo.toml", - rustc_flags=get_py_version_cfgs(), + "rustapi_module.test_dict", "Cargo.toml", rustc_flags=get_py_version_cfgs() ), ], install_requires=install_requires, tests_require=tests_require, include_package_data=True, zip_safe=False, - cmdclass={ - 'test': PyTest, - 'sdist': CargoModifiedSdist, - }, + cmdclass={"test": PyTest, "sdist": CargoModifiedSdist}, ) diff --git a/examples/rustapi_module/tests/test_datetime.py b/examples/rustapi_module/tests/test_datetime.py index 71f8c553..017f45e3 100644 --- a/examples/rustapi_module/tests/test_datetime.py +++ b/examples/rustapi_module/tests/test_datetime.py @@ -40,8 +40,8 @@ MIN_DAYS = pdt.timedelta.min // pdt.timedelta(days=1) MAX_MICROSECONDS = int(pdt.timedelta.max.total_seconds() * 1e6) MIN_MICROSECONDS = int(pdt.timedelta.min.total_seconds() * 1e6) -IS_X86 = platform.architecture()[0] == '32bit' -IS_WINDOWS = sys.platform == 'win32' +IS_X86 = platform.architecture()[0] == "32bit" +IS_WINDOWS = sys.platform == "win32" if IS_WINDOWS: MIN_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(86400) if IS_X86: @@ -85,8 +85,9 @@ def test_invalid_date_fails(): rdt.make_date(2017, 2, 30) -@given(d=st.dates(MIN_DATETIME_FROM_TIMESTAMP.date(), - MAX_DATETIME_FROM_TIMESTAMP.date())) +@given( + d=st.dates(MIN_DATETIME_FROM_TIMESTAMP.date(), MAX_DATETIME_FROM_TIMESTAMP.date()) +) def test_date_from_timestamp(d): if PYPY and d < pdt.date(1900, 1, 1): pytest.xfail("pdt.datetime.timestamp will raise on PyPy with dates before 1900") @@ -225,8 +226,7 @@ def test_datetime_typeerror(): rdt.make_datetime("2011", 1, 1, 0, 0, 0, 0) -@given(dt=st.datetimes(MIN_DATETIME_FROM_TIMESTAMP, - MAX_DATETIME_FROM_TIMESTAMP)) +@given(dt=st.datetimes(MIN_DATETIME_FROM_TIMESTAMP, MAX_DATETIME_FROM_TIMESTAMP)) @example(dt=pdt.datetime(1970, 1, 2, 0, 0)) def test_datetime_from_timestamp(dt): if PYPY and dt < pdt.datetime(1900, 1, 1): diff --git a/examples/rustapi_module/tests/test_dict_iter.py b/examples/rustapi_module/tests/test_dict_iter.py index d5592fa4..21c97883 100644 --- a/examples/rustapi_module/tests/test_dict_iter.py +++ b/examples/rustapi_module/tests/test_dict_iter.py @@ -1,10 +1,8 @@ import pytest from rustapi_module.test_dict import DictSize -@pytest.mark.parametrize( - "size", - [64, 128, 256], -) + +@pytest.mark.parametrize("size", [64, 128, 256]) def test_size(size): d = {} for i in range(size): diff --git a/examples/rustapi_module/tests/test_subclassing.py b/examples/rustapi_module/tests/test_subclassing.py index 062710f6..497b2318 100644 --- a/examples/rustapi_module/tests/test_subclassing.py +++ b/examples/rustapi_module/tests/test_subclassing.py @@ -2,7 +2,8 @@ import platform from rustapi_module.subclassing import Subclassable -PYPY = platform.python_implementation() == 'PyPy' +PYPY = platform.python_implementation() == "PyPy" + class SomeSubClass(Subclassable): pass @@ -10,4 +11,4 @@ class SomeSubClass(Subclassable): if not PYPY: a = SomeSubClass() - _b = str(a) + repr(a) \ No newline at end of file + _b = str(a) + repr(a) diff --git a/examples/word-count/setup.py b/examples/word-count/setup.py index 153637f7..42e5852a 100644 --- a/examples/word-count/setup.py +++ b/examples/word-count/setup.py @@ -36,20 +36,21 @@ class CargoModifiedSdist(SdistCommand): super().make_release_tree(base_dir, files) import toml + # Cargo.toml is now staged and ready to be modified - cargo_loc = os.path.join(base_dir, 'Cargo.toml') + cargo_loc = os.path.join(base_dir, "Cargo.toml") assert os.path.exists(cargo_loc) - with open(cargo_loc, 'r') as f: + with open(cargo_loc, "r") as f: cargo_toml = toml.load(f) - rel_pyo3_path = cargo_toml['dependencies']['pyo3']['path'] + rel_pyo3_path = cargo_toml["dependencies"]["pyo3"]["path"] base_path = os.path.dirname(__file__) abs_pyo3_path = os.path.abspath(os.path.join(base_path, rel_pyo3_path)) - cargo_toml['dependencies']['pyo3']['path'] = abs_pyo3_path + cargo_toml["dependencies"]["pyo3"]["path"] = abs_pyo3_path - with open(cargo_loc, 'w') as f: + with open(cargo_loc, "w") as f: toml.dump(cargo_toml, f) @@ -87,8 +88,5 @@ setup( setup_requires=setup_requires, include_package_data=True, zip_safe=False, - cmdclass={ - 'test': PyTest, - 'sdist': CargoModifiedSdist, - }, + cmdclass={"test": PyTest, "sdist": CargoModifiedSdist}, ) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..7822c2a7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[tool.black] +target_version = ['py35'] +include = '\.pyi?$' +exclude = ''' + +( + /( + \.eggs # exclude a few common directories in the + | \.git # root of the project + | \.mypy_cache + | \.tox + | \.venv + | venv + | target + | dist + )/ +) +''' \ No newline at end of file