From 23d82c82944a3de4068666ed3bf16e50eb335ae8 Mon Sep 17 00:00:00 2001 From: Johannes Maron Date: Mon, 11 Jul 2022 12:09:29 +0200 Subject: [PATCH 1/3] Add argument to fail for warnings --- relint.py | 12 +++++++++--- test_relint.py | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/relint.py b/relint.py index 9870f62..f22aeeb 100644 --- a/relint.py +++ b/relint.py @@ -52,10 +52,16 @@ def parse_args(args): action='store_true', help='Analyze content from git diff.' ) + parser.add_argument( + '-W', + '--fail-warnings', + action='store_true', + help='Fail for warnings.' + ) return parser.parse_args(args=args) -def load_config(path): +def load_config(path, fail_warnings): with open(path) as fs: for test in yaml.safe_load(fs): filename = test.get('filename') @@ -76,7 +82,7 @@ def load_config(path): hint=test.get('hint'), file_pattern=file_pattern, filename=filename, - error=test.get('error', True) + error=test.get('error', True) or fail_warnings ) @@ -217,7 +223,7 @@ def main(args=sys.argv[1:]): for path in glob.iglob(glob.escape(file), recursive=True) } - tests = list(load_config(args.config)) + tests = list(load_config(args.config, args.fail_warnings)) matches = chain.from_iterable( lint_file(path, tests) diff --git a/test_relint.py b/test_relint.py index a7b5f12..36f67bf 100644 --- a/test_relint.py +++ b/test_relint.py @@ -16,6 +16,13 @@ def test_main_execution(self, mocker, filename): assert exc_info.value.code == 0 + @pytest.mark.parametrize('filename', ['test_relint.py', '[a-b].py', '[b-a].py']) + def test_main_execution(self, mocker, filename): + with pytest.raises(SystemExit) as exc_info: + main(['relint.py', '-W', filename]) + + assert exc_info.value.code != 0 + def test_main_execution_with_diff(self, capsys, mocker, tmpdir): tmpdir.join('.relint.yml').write(open('.relint.yml').read()) tmpdir.join('dummy.py').write("# TODO do something") From 307a7d8d0b1b74f6c8257a5cfd925a8e23378d96 Mon Sep 17 00:00:00 2001 From: Johannes Maron Date: Mon, 11 Jul 2022 12:11:10 +0200 Subject: [PATCH 2/3] Fail for warnings in pre-commit to promote incremental changes --- relint-pre-commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relint-pre-commit.sh b/relint-pre-commit.sh index 1541bfd..096216a 100755 --- a/relint-pre-commit.sh +++ b/relint-pre-commit.sh @@ -1,4 +1,4 @@ #!/usr/bin/env sh set -eo pipefail -git diff --staged | relint --diff "${@:1}" +git diff --staged | relint --diff -W "${@:1}" From 7282ddad4ef77a94d9e5a08c32fe4970ea56a2b2 Mon Sep 17 00:00:00 2001 From: Johannes Maron Date: Mon, 11 Jul 2022 13:28:19 +0200 Subject: [PATCH 3/3] Update package and ci actions --- .github/dependabot.yml | 10 ++++++++++ .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/release.yml | 23 ++++++++++++----------- .github/workflows/tests.yml | 26 -------------------------- setup.cfg | 13 +++++++------ 5 files changed, 58 insertions(+), 43 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7df6849 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: +- package-ecosystem: pip + directory: "/" + schedule: + interval: weekly +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: weekly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d3b2464 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +jobs: + + PyTest: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + - "3.8" + - "3.9" + - "3.10" + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - run: python -m pip install --upgrade pip setuptools codecov + - run: python -m pip install -e .[test] + - run: relint ** + - run: py.test --cov=. + - uses: codecov/codecov-action@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f93cf2f..9beacc4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,20 +1,21 @@ -name: PyPi Release +name: Release -on: [release] +on: + release: + types: [published] jobs: - build: + PyPi: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - - name: Install dependencies - run: python -m pip install --upgrade pip setuptools wheel twine - - name: Build dist packages - run: python setup.py sdist bdist_wheel - - name: Upload packages - run: python -m twine upload dist/* + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - run: python -m pip install --upgrade pip build wheel twine + - run: python -m build --sdist --wheel + - run: python -m twine upload dist/* env: TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 1c97a30..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Tests - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - max-parallel: 4 - matrix: - python-version: [3.5, 3.6, 3.7] - - steps: - - uses: actions/checkout@v1 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - run: python -m pip install --upgrade pip setuptools codecov - - run: python setup.py develop - - run: relint ** - - run: coverage run --source=relint setup.py test - - run: codecov - env: - CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} diff --git a/setup.cfg b/setup.cfg index 79f9000..af1573f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,14 +1,14 @@ [metadata] name = relint -author = Johannes Hoppe -author_email = info@johanneshoppe.com +author = Johannes Maron +author_email = johannes@maron.family description = Write your own linting rules using regular expressions long_description = file: README.rst url = https://github.com/codingjoe/relint license = MIT license_file = LICENSE classifier = - Development Status :: 4 - Beta + Development Status :: 5 - Production/Stable Environment :: Console Intended Audience :: Developers License :: OSI Approved :: MIT License @@ -25,12 +25,13 @@ keywords = install_requires = PyYAML setup_requires = setuptools_scm - pytest-runner -tests_require = +py_modules = relint + +[options.extras_require] +test = pytest pytest-cov pytest-mock -py_modules = relint [options.entry_points] console_scripts =