Format examples with black (#590)
This commit is contained in:
parent
88b0a03dcd
commit
73947d84b4
|
@ -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.
|
||||
|
|
1
Makefile
1
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
|
||||
|
|
|
@ -11,6 +11,7 @@ else
|
|||
fi
|
||||
|
||||
if [ "$TRAVIS_JOB_NAME" = "Minimum nightly" ]; then
|
||||
pip install --pre black==19.3b0
|
||||
make lint
|
||||
fi
|
||||
|
||||
|
|
|
@ -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},
|
||||
)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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},
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)/
|
||||
)
|
||||
'''
|
Loading…
Reference in New Issue