Skip to content

Commit

Permalink
New option: --allow-non-packages
Browse files Browse the repository at this point in the history
I can finally use this on my Vim plugins like
https://github.com/mgedmin/taghelper.vim
  • Loading branch information
mgedmin committed Oct 10, 2024
1 parent b405485 commit 6ce29ff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Changelog
=========

0.22.2 (unreleased)
0.23.0 (unreleased)
-------------------

- Nothing changed yet.
- New option ``--allow-non-packages`` so you can automate tox.ini or GitHub
workflow updates in projects that are not Python packages.


0.22.1 (2024-10-09)
Expand Down
14 changes: 11 additions & 3 deletions src/check_python_versions/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ def _main() -> None:
parser.add_argument('--skip-non-packages', action='store_true',
help='skip arguments that are not Python packages'
' without warning about them')
parser.add_argument('--allow-non-packages', action='store_true',
help='try to work on directories that are not Python'
' packages but have a tox.ini'
' or .github/workflows')
parser.add_argument('--only', metavar='FILES',
help='check only the specified files'
' (comma-separated list, e.g.'
Expand Down Expand Up @@ -399,6 +403,9 @@ def _main() -> None:
parser.error("argument --add: not allowed with argument --update")
if args.update and args.drop:
parser.error("argument --drop: not allowed with argument --update")
if args.skip_non_packages and args.allow_non_packages:
parser.error("use either --skip-non-packages or --allow-non-packages,"
" not both")
if args.diff and not (args.update or args.add or args.drop):
parser.error(
"argument --diff: not allowed without --update/--add/--drop")
Expand Down Expand Up @@ -431,9 +438,10 @@ def _main() -> None:
if n:
print("\n")
print(f"{path}:\n")
if not check_package(path):
mismatches.append(path)
continue
if not args.allow_non_packages:
if not check_package(path):
mismatches.append(path)
continue
replacements = {}
if args.add or args.drop or args.update:
replacements = update_versions(
Expand Down
28 changes: 28 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,34 @@ def test_main_skip_non_packages(monkeypatch, capsys, tmp_path):
assert capsys.readouterr().out == ''


def test_main_allow_non_packages(monkeypatch, capsys, tmp_path):
monkeypatch.setattr(sys, 'argv', [
'check-python-versions', '--allow-non-packages', str(tmp_path),
])
with pytest.raises(SystemExit) as exc_info:
cpv.main()
assert (
capsys.readouterr().out + str(exc_info.value) + '\n'
).replace(str(tmp_path), 'tmp') == textwrap.dedent("""\
no file with version information found
mismatch!
""")


def test_main_conflicting_non_packages_options(monkeypatch, capsys, tmp_path):
monkeypatch.setattr(sys, 'argv', [
'check-python-versions', '--skip-non-packages', '--allow-non-packages',
str(tmp_path),
])
with pytest.raises(SystemExit):
cpv.main()
assert (
'use either --skip-non-packages or --allow-non-packages, not both'
in capsys.readouterr().err
)


def test_main_single(monkeypatch, capsys, tmp_path):
monkeypatch.setattr(sys, 'argv', [
'check-python-versions',
Expand Down

0 comments on commit 6ce29ff

Please sign in to comment.