From a6bc27c0b6a927b6abb4cd67f3540393b367c410 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Thu, 4 Apr 2024 13:56:06 +0200 Subject: [PATCH] Moving stuff around in the linters, and adding ruff (#73) --- .github/workflows/_tests.yml | 43 ++++++++++++++++++++----------- README.rst | 3 ++- setup.py | 49 ++++++++++++++++++++++++------------ 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/.github/workflows/_tests.yml b/.github/workflows/_tests.yml index 95653ce..c05e89a 100644 --- a/.github/workflows/_tests.yml +++ b/.github/workflows/_tests.yml @@ -11,6 +11,7 @@ jobs: prepare-matrix: name: Prepare Python/Django matrix runs-on: ubuntu-latest + continue-on-error: true outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: @@ -20,6 +21,10 @@ jobs: - uses: actions/setup-python@v5 with: python-version: 3.12 + - name: Install the linters + run: | + pip install --upgrade setuptools + python setup.py install_linters - name: Generate matrix from setup.py id: set-matrix run: | @@ -53,6 +58,24 @@ jobs: print(f'::error ::{product} v{version}: EOL was {eol}') elif eol_date - today < WARNING_DAYS: print(f'::warning ::{product} v{version}: EOL is coming up on the {eol}')" + - name: iSort check + if: always() + run: isort --check . + - name: Black check + if: always() + run: black --config .black --check . + - name: Flake8 check + if: always() + run: flake8 . + - name: Ruff check + if: always() + run: ruff check . + - name: rst check + if: always() + run: rst-lint . + - name: Continue + if: always() + run: exit 0 tests: runs-on: ubuntu-latest @@ -84,17 +107,9 @@ jobs: run: pip install -e '.[test]' - name: Run tests run: pytest --cov django_squash --cov-report=xml --cov-report=term - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - fail_ci_if_error: true - token: ${{ secrets.CODECOV_TOKEN }} - env_vars: OS,RUST - - name: Flake8 check - run: flake8 - - name: iSort check - run: isort --check . - - name: Black check - run: black --config .black --check . - - name: rst check - run: rst-lint . + # - name: Upload coverage to Codecov + # uses: codecov/codecov-action@v4 + # with: + # fail_ci_if_error: true + # token: ${{ secrets.CODECOV_TOKEN }} + # env_vars: OS,RUST diff --git a/README.rst b/README.rst index 4488cde..1279970 100644 --- a/README.rst +++ b/README.rst @@ -60,7 +60,7 @@ Developing .. code-block:: shell - docker run --rm -it -v .:/app -v django-squash-pip-cache:/root/.cache/pip -e PYTHONDONTWRITEBYTECODE=1 python:3.12 bash -c "cd app; pip install -e .[test]; echo \"alias linters=\\\"echo '> isort'; isort .; echo '> black'; black --config .black .; echo '> flake8'; flake8 .; echo '> rst-lint'; rst-lint README.rst docs/*\\\"\" >> ~/.bash_profile; printf '\n\n\nrun **pytest** to run tests, **linters** to run linters\n\n'; exec bash --init-file ~/.bash_profile" + docker run --rm -it -v .:/app -v django-squash-pip-cache:/root/.cache/pip -e PYTHONDONTWRITEBYTECODE=1 python:3.12 bash -c "cd app; pip install -e .[test,lint]; echo \"alias linters=\\\"echo '> isort'; isort .; echo '> black'; black --config .black .; echo '> ruff'; ruff check .;echo '> flake8'; flake8 .; echo '> rst-lint'; rst-lint README.rst docs/*\\\"\" >> ~/.bash_profile; printf '\n\n\nrun **pytest** to run tests, **linters** to run linters\n\n'; exec bash --init-file ~/.bash_profile" Alternatively, you can also create a virtual environment and run @@ -89,6 +89,7 @@ Alternatively, you can also create a virtual environment and run isort . black --config .black . flake8 . + ruff check . rst-lint . .. _Django: http://djangoproject.com diff --git a/setup.py b/setup.py index 463f91d..b4f4a12 100755 --- a/setup.py +++ b/setup.py @@ -25,12 +25,44 @@ if __name__ == "__main__": from setuptools import find_packages, setup + from setuptools.command.build_py import build_py as Command + + extras_require = { + "lint": [ + "black", + "flake8", + "flake8-tidy-imports", + "isort", + "pygments", + "restructuredtext-lint", + "ruff", + ], + "test": [ + "black", # tests need black also. + "build", + "ipdb", + "libcst", + "psycopg2-binary", + "pytest-cov", + "pytest-django", + ], + } + + class InstallLintersCommand(Command): + """Custom build command to install ONLY the liners.""" + + def run(self): + req = " ".join(extras_require["lint"]) + os.system(f"pip install {req}") setup( name="django_squash", version="0.0.11", description="A migration squasher that doesn't care how Humpty Dumpty was put together.", long_description=README, + cmdclass={ + "install_linters": InstallLintersCommand, + }, classifiers=[ # See https://pypi.org/pypi?%3Aaction=list_classifiers "Development Status :: 5 - Production/Stable", @@ -64,20 +96,5 @@ f"django>={MIN_DJANGO_VERSION}", ], tests_require=[], - extras_require={ - "test": [ - "black", - "build", - "flake8", - "flake8-tidy-imports", - "ipdb", - "isort", - "libcst", - "psycopg2-binary", - "pytest-cov", - "pytest-django", - "restructuredtext-lint", - "setuptools", - ], - }, + extras_require=extras_require, )