diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d145dd197..fb2bed7309 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -161,12 +161,11 @@ jobs: python-version: ${{ matrix.python }} - name: Install dependencies run: | - python -m pip install mypy - - name: Static type checking with mypy - uses: liskin/gh-problem-matcher-wrap@v3 - with: - linters: mypy - run: mypy --install-types --non-interactive --config mypy.ini faker + python -m pip install tox + - name: Run mypy + run: tox + env: + TOXENV: mypy test_ubuntu: runs-on: ubuntu-latest diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index bd47b86f67..008beacce8 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -30,6 +30,7 @@ Making Changes the new branch with ``git checkout fix/master/my_contribution``. Please avoid working directly on the ``master`` branch. - Make commits of logical units. +- Install the development requirements: ``python -m pip install -e .[dev]`` - Follow our `coding style`_. You can run ``make lint`` to format your code. - Check for unnecessary whitespace with ``git diff --check`` before committing. diff --git a/Makefile b/Makefile index 1e6a94421f..c3d6c0d357 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,16 @@ mypy: mypy --install-types --non-interactive --config mypy.ini faker black: - black --line-length 120 . + black . isort: isort --atomic . -generate-stubs: - python3.10 generate_stubs.py +generate-stubs: + python3.11 generate_stubs.py + black faker/proxy.pyi + isort faker/proxy.pyi + lint: generate-stubs isort black mypy flake8 diff --git a/docs/coding_style.rst b/docs/coding_style.rst index de611d6b78..46d71f6190 100644 --- a/docs/coding_style.rst +++ b/docs/coding_style.rst @@ -5,7 +5,7 @@ We use the black code style with a line length of 120 characters and trailing co You can format the code with:: - black --line-length 120 + black . Please include `type hints`_ for every provider method you write. An overview of generic types is included below. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..55ec8d784c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +line-length = 120 diff --git a/setup.py b/setup.py index 9425a09f5d..505adb9f41 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,26 @@ except AttributeError: zip_safe = False +extra_test = [ + "coverage>=5.2", + "freezegun", + "pytest>=6.0.1", + "ukpostcodeparser>=1.1.1", + "validators>=0.13.0", + "sphinx>=2.4,<3.0", + "Pillow", + "xmltodict", +] +extra_flake8 = ["flake8>=4.0.0", "flake8-comprehensions"] +extra_check_manifest = ["check-manifest"] +extra_isort = ["isort"] +extra_mypy = ["mypy==1.14.1"] +extra_black = ["black==24.4.0"] +extra_doc8 = ["doc8"] +extra_dev = list( + set(extra_test + extra_flake8 + extra_check_manifest + extra_isort + extra_mypy + extra_black + extra_doc8) +) + setup( name="Faker", version=VERSION, @@ -71,4 +91,14 @@ install_requires=[ "python-dateutil>=2.4", ], + extras_require={ + "test": extra_test, + "flake8": extra_flake8, + "check-manifest": extra_check_manifest, + "isort": extra_isort, + "mypy": extra_mypy, + "black": extra_black, + "doc8": extra_doc8, + "dev": extra_dev, + }, ) diff --git a/tox.ini b/tox.ini index 550cd35d00..bcaa6b9079 100644 --- a/tox.ini +++ b/tox.ini @@ -3,15 +3,7 @@ envlist=py{39,310,311,312,313,py3},alpine,flake8,checkmanifest,isort,mypy,doc8 skip_missing_interpreters = true [testenv] -deps = - coverage>=5.2 - freezegun - pytest>=6.0.1 - ukpostcodeparser>=1.1.1 - validators>=0.13.0 - sphinx>=2.4,<3.0 - Pillow - xmltodict +extras = test commands = coverage run --source=faker -m pytest {posargs} coverage run --source=faker -a -m pytest --exclusive-faker-session tests/pytest/session_overrides {posargs} @@ -19,39 +11,34 @@ commands = [testenv:flake8] basepython = python -deps = - flake8>=4.0.0 - flake8-comprehensions +extras = flake8 commands = flake8 --extend-ignore=E203 faker tests [testenv:checkmanifest] basepython = python -deps = - check-manifest +extras = check-manifest commands = check-manifest [testenv:isort] -deps = - isort +extras = isort commands = {envpython} -m isort --check-only --diff . [testenv:mypy] basepython = python -deps = - mypy==1.15.0 +extras = mypy commands = - mypy --install-types --non-interactive --config mypy.ini faker + {envpython} -m mypy --install-types --non-interactive --config mypy.ini faker [testenv:black] -deps = black==24.4.0 +extras = black commands = - {envpython} -m black --check --line-length 120 . + {envpython} -m black --check . [testenv:doc8] -deps = doc8 +extras = doc8 commands = {envpython} -m doc8