Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active python versions #40

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@
'check-python-versions = check_python_versions.cli:main',
],
},
install_requires=['pyyaml'],
install_requires=['pyyaml', 'python-active-versions>=1.3.0'],
zip_safe=False,
)
15 changes: 15 additions & 0 deletions src/check_python_versions/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
from io import StringIO
from typing import Callable, Collection, Dict, List, Optional, Tuple

from python_active_versions.python_active_versions import (
get_active_python_versions,
)

from . import __version__
from .sources.all import ALL_SOURCES
from .sources.base import SourceFile
Expand Down Expand Up @@ -370,6 +374,9 @@ 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('--python-versions', action='store_true',
default=False,
help='show active python versions')
parser.add_argument('--only', metavar='FILES',
help='check only the specified files'
' (comma-separated list, e.g.'
Expand Down Expand Up @@ -457,6 +464,14 @@ def _main() -> None:
elif multiple:
print("\n\nall ok!")

if args.python_versions and not (args.add or args.drop or args.update):
_python_versions = get_active_python_versions(docker_images=False,
log_level='WARNING')
print('\n\nActive Python versions:')
for _version in _python_versions:
print(f"version: {_version['version']} - "
f"latest software: {_version['latest_sw']}")


def main() -> None:
"""The main function.
Expand Down
39 changes: 39 additions & 0 deletions tests/test_cli_python_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
import textwrap

from unittest.mock import Mock, patch


@patch('check_python_versions.cli.get_active_python_versions',
Mock(return_value=[{'version': '3.10', 'latest_sw': '3.10.5'},
{'version': '3.11', 'latest_sw': '3.11.1'}])
)
def test_main_show_python(monkeypatch, tmp_path, capsys):
monkeypatch.setattr(sys, 'argv', [
'check-python-versions',
str(tmp_path),
'--python-versions',
'--only', 'setup.py',
])
setup_py = tmp_path / "setup.py"
setup_py.write_text(textwrap.dedent("""\
from setuptools import setup
setup(
name='foo',
classifiers=[
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
],
)
"""))
import check_python_versions.cli as cpv

cpv.main()
assert capsys.readouterr().out == textwrap.dedent("""\
setup.py says: 2.7, 3.6


Active Python versions:
version: 3.10 - latest software: 3.10.5
version: 3.11 - latest software: 3.11.1
""")
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ skip_install = true
deps =
mypy
types-pyyaml
python_active_versions
commands =
mypy src setup.py {posargs}
# not checking tests/ because I don't want strict mode there, and mypy
Expand Down