Skip to content

Commit

Permalink
Merge bda5ae6 into 3692145
Browse files Browse the repository at this point in the history
  • Loading branch information
netromdk committed Jun 25, 2023
2 parents 3692145 + bda5ae6 commit 587f075
Show file tree
Hide file tree
Showing 37 changed files with 930 additions and 1,014 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analyze.yml
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snyk-schedule.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
requirements: [misc, analysis, coverage]
requirements: [analysis, coverage]

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snyk.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
requirements: [misc, analysis, coverage]
requirements: [analysis, coverage]

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
Expand Down
27 changes: 21 additions & 6 deletions .github/workflows/test.yml
Expand Up @@ -14,8 +14,10 @@ jobs:
strategy:
matrix:
# Start Linux jobs last since they are fastest to start and complete, and start 3.11 first,
# since it pairs wiht macOS+Windows jobs.
python-version: ['3.11', '3.10', 3.7, 3.8, 3.9, 2.7]
# since it pairs wiht macOS+Windows jobs, and 3.5 and 3.6 last since they only run tests and
# don't use venv. 3.4 is not supported on GitHub anymore and 3.5 and 3.6 for x64 isn't
# produced for ubuntu 22.04.
python-version: ['3.11', '3.10', 3.7, 3.8, 3.9, 3.5, 3.6]
os: [windows-latest, macos-latest, ubuntu-latest]

# Choose test script depending on OS.
Expand All @@ -27,10 +29,13 @@ jobs:
- os: windows-latest
test_script_name: ./misc/actions/test.ps1

# Only test on macOS and Windows with Python 3.11.
exclude:
- os: macos-latest
python-version: 2.7
# Only test on macOS and Windows with Python 3.11.
# But do test 3.5 and 3.6 on macOS because they aren't compiled for x64 on Ubuntu 22.04.
# - os: macos-latest
# python-version: 3.5
# - os: macos-latest
# python-version: 3.6
- os: macos-latest
python-version: 3.7
- os: macos-latest
Expand All @@ -39,8 +44,11 @@ jobs:
python-version: 3.9
- os: macos-latest
python-version: '3.10'

- os: windows-latest
python-version: 3.5
- os: windows-latest
python-version: 2.7
python-version: 3.6
- os: windows-latest
python-version: 3.7
- os: windows-latest
Expand All @@ -50,6 +58,13 @@ jobs:
- os: windows-latest
python-version: '3.10'

# Ignore 3.5 and 3.6 on Linux because it isn't compiled for x64 on Ubuntu 22.04.
# Test on macOS instead.
- os: ubuntu-latest
python-version: 3.5
- os: ubuntu-latest
python-version: 3.6

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- name: Set up Python ${{ matrix.python-version }}
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -2,7 +2,8 @@
Contributions are very welcome, especially adding and updating detection rules of modules,
functions, classes etc. to cover as many Python versions as possible.

Note that code must remain valid and working on Python v2.7+ and v3+.
Note that code must remain valid and Vermin be able to run via Python v3+ but still include
detection of v2.x functionality.

## Dependencies
Install development and analysis dependencies via `make setup`. It will setup a `virtualenv` in
Expand Down
14 changes: 4 additions & 10 deletions Makefile
Expand Up @@ -5,7 +5,7 @@ MODULES=vermin tests
TOP_LEVEL_FILES=${MODULES} vermin.py runtests.py ${OTHER_FILES}

self-test:
./vermin.py --violations -q -t=2.7 -t=3 ${VERMIN_FILES}
./vermin.py --violations -q -t=3 ${VERMIN_FILES}

test: self-test
./runtests.py
Expand All @@ -23,16 +23,13 @@ count:
setup-venv: clean-venv
virtualenv -p python3 .venv

setup-misc: clean
pip install -r misc/.misc-requirements.txt

setup-coverage: clean
pip install -r misc/.coverage-requirements.txt

setup-analysis: clean
pip install -r misc/.analysis-requirements.txt

setup: setup-venv setup-misc setup-coverage setup-analysis
setup: setup-venv setup-analysis

install-deps:
python -m pip install --upgrade pip virtualenv
Expand All @@ -55,9 +52,6 @@ dist-clean: clean clean-venv clean-pypi
pypi-dist: clean-pypi
python setup.py bdist_wheel --universal

update-misc-requirements: setup-venv setup-misc
pip freeze > misc/.misc-requirements.txt

update-coverage-requirements: setup-venv setup-coverage
pip freeze > misc/.coverage-requirements.txt

Expand All @@ -77,7 +71,7 @@ security-check:
bandit -r -s B101 ${MODULES}

lint:
pylint -j 0 --disable=C,W0201,W0311,W0621,W0703,W0707,R0801,R0902,R0903,R0904,R0911,R0913,R0914,R0915,R0916,R1702,R1725,E0611,E1136\
pylint -j 0 --disable=C0103,C0114,C0115,C0116,C0209,C0302,W0201,W0311,W0621,W0703,R0801,R0902,R0903,R0904,R0911,R0912,R0913,R0914,R0915,R0916,R1702,E1136\
${TOP_LEVEL_FILES}

check-pypi:
Expand All @@ -90,7 +84,7 @@ check-all: check security-check

test-coverage:
coverage run --source=vermin,tests runtests.py
coverage run --append --source=vermin ./vermin.py -v -t=2.7 -t=3 vermin.py vermin
coverage run --append --source=vermin ./vermin.py -v -t=3 vermin.py vermin

coverage-report:
coverage report -m
32 changes: 16 additions & 16 deletions README.rst
Expand Up @@ -30,11 +30,8 @@ Vermin
******

Concurrently detect the minimum Python versions needed to run code. Additionally, since the code is
vanilla Python, and it doesn't have any external dependencies, it works with v2.7+ and v3+.

*Note: Vermin 1.6 will end support for running via Python 2.7* which has been `sunset
<https://www.python.org/doc/sunset-python-2/>`__ since January 1, 2020. Python 3.x is going to be
required but detection of 2.x functionality will remain functional.
vanilla Python, and it doesn't have any external dependencies, it can be run with v3+ but still
includes detection of v2.x functionality.

It functions by parsing Python code into an abstract syntax tree (AST), which it traverses and
matches against internal dictionaries with **3676** rules, covering v2.0-2.7 and v3.0-3.11, divided
Expand Down Expand Up @@ -149,10 +146,10 @@ bytearray, ``with`` statement, asynchronous ``with`` statement, multiple context
``with`` statement, multiple context expressions in a ``with`` statement grouped with parenthesis,
unpacking assignment, generalized unpacking, ellipsis literal (``...``) out of slices, dictionary
union (``{..} | {..}``), dictionary union merge (``a = {..}; a |= {..}``), builtin generic type
annotations (``list[str]``), function decorators, class decorators, relaxed decorators, pattern
matching with ``match``, and union types written as ``X | Y``. It tries to detect and ignore
user-defined functions, classes, arguments, and variables with names that clash with library-defined
symbols.
annotations (``list[str]``), function decorators, class decorators, relaxed decorators,
``metaclass`` class keyword, pattern matching with ``match``, and union types written as ``X | Y``.
It tries to detect and ignore user-defined functions, classes, arguments, and variables with names
that clash with library-defined symbols.

Caveats
=======
Expand Down Expand Up @@ -210,16 +207,19 @@ Examples
.. code-block:: console
% ./vermin.py vermin
Minimum required versions: 2.7, 3.0
Minimum required versions: 3.0
Incompatible versions: 2
% ./vermin.py -t=2.7 -t=3.3 vermin
Minimum required versions: 2.7, 3.0
Target versions not met: 2.7, 3.3
% ./vermin.py -t=3.3 vermin
Minimum required versions: 3.0
Incompatible versions: 2
Target versions not met: 3.3
% echo $?
1
% ./vermin.py --versions vermin
Minimum required versions: 2.7, 3.0
Minimum required versions: 3.0
Incompatible versions: 2
Version range: 2.0, 2.6, 2.7, 3.0
% ./vermin.py -v examples
Expand Down Expand Up @@ -435,5 +435,5 @@ Contributing
============

Contributions are very welcome, especially adding and updating detection rules of modules,
functions, classes etc. to cover as many Python versions as possible. See
`CONTRIBUTING.md <CONTRIBUTING.md>`__ for more information.
functions, classes etc. to cover as many Python versions as possible. See `CONTRIBUTING.md
<CONTRIBUTING.md>`__ for more information.
62 changes: 40 additions & 22 deletions misc/.analysis-requirements.txt
@@ -1,22 +1,40 @@
astroid==2.5.0
bandit==1.6.2
docutils==0.16
flake8==3.8.4
gitdb==4.0.5
GitPython==3.1.30
isort==5.6.4
lazy-object-proxy==1.4.3
mccabe==0.6.1
pbr==5.5.1
pycodestyle==2.6.0
pyflakes==2.2.0
Pygments==2.7.4
pylint==2.7.0
pyroma==2.6
PyYAML==5.4
six==1.15.0
smmap==3.0.4
stevedore==3.2.2
toml==0.10.1
vulture==2.1
wrapt==1.12.1
astroid==2.15.5
bandit==1.7.5
build==0.10.0
certifi==2023.5.7
charset-normalizer==3.1.0
dill==0.3.6
docutils==0.20.1
flake8==6.0.0
gitdb==4.0.10
GitPython==3.1.31
idna==3.4
isort==5.12.0
lazy-object-proxy==1.9.0
markdown-it-py==3.0.0
mccabe==0.7.0
mdurl==0.1.2
packaging==23.1
pbr==5.11.1
pep517==0.13.0
platformdirs==3.5.3
pycodestyle==2.10.0
pyflakes==3.0.1
Pygments==2.15.1
pylint==2.17.4
pyparsing==3.0.9
pyproject_hooks==1.0.0
pyroma==4.2
PyYAML==6.0
requests==2.31.0
rich==13.4.2
six==1.16.0
smmap==5.0.0
stevedore==5.1.0
toml==0.10.2
tomli==2.0.1
tomlkit==0.11.8
trove-classifiers==2023.5.24
urllib3==2.0.3
vulture==2.7
wrapt==1.15.0
20 changes: 0 additions & 20 deletions misc/.misc-requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions misc/actions/test.ps1
@@ -1,6 +1,6 @@
$PYTHON_VERSION = python -c "import sys;v=sys.version_info;print('{}.{}'.format(v[0],v[1]))"

if ( $PYTHON_VERSION -eq "2.7" -or $PYTHON_VERSION -eq "3.4" -or $PYTHON_VERSION -eq "3.5" -or $PYTHON_VERSION -eq "3.6") {
if ( $PYTHON_VERSION -eq "3.4" -or $PYTHON_VERSION -eq "3.5" -or $PYTHON_VERSION -eq "3.6") {
make test
}
else {
Expand All @@ -23,7 +23,7 @@ else {
$Host.SetShouldExit(1) # This is necessary in order to fail the GitHub job.
exit 1
}
coverage run --append --source=vermin ./vermin.py -v -t="2.7" -t=3 vermin.py vermin
coverage run --append --source=vermin ./vermin.py -v -t=3 vermin.py vermin
if (!$?) {
$Host.SetShouldExit(1)
exit 1
Expand Down
3 changes: 1 addition & 2 deletions misc/actions/test.sh
Expand Up @@ -3,8 +3,7 @@ set -x

PYTHON_VERSION=$(python -c "import sys;v=sys.version_info;print('{}.{}'.format(v[0],v[1]))")

if [[ $PYTHON_VERSION = 2.7 ||
$PYTHON_VERSION = 3.4 ||
if [[ $PYTHON_VERSION = 3.4 ||
$PYTHON_VERSION = 3.5 ||
$PYTHON_VERSION = 3.6 ]];
then
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Expand Up @@ -31,9 +31,7 @@
"Intended Audience :: Developers",

"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.0",

"License :: OSI Approved :: MIT License",

Expand All @@ -45,7 +43,7 @@

packages=find_packages(exclude=["tests"]),

python_requires=">=2.7",
python_requires=">=3.0",

entry_points={
"console_scripts": [
Expand Down
10 changes: 8 additions & 2 deletions tests/annotation.py
@@ -1,11 +1,9 @@
from .testutils import VerminTest

class VerminModuleTests(VerminTest):
@VerminTest.skipUnlessVersion(3)
def test_return_annotation(self):
self.assertOnlyIn((3, 0), self.detect("def foo() -> str:\n\treturn ''"))

@VerminTest.skipUnlessVersion(3)
def test_arg_annotation(self):
self.assertOnlyIn((3, 0), self.detect("def foo(bar: int):\n\tpass"))

Expand Down Expand Up @@ -47,3 +45,11 @@ def test_Literal_annotation(self):
visitor = self.visit("def foo(x: L[1], y: L[1], z: Literal[4]):\n\treturn z")
self.assertTrue(visitor.literal_annotations())
self.assertOnlyIn((3, 8), visitor.minimum_versions())

@VerminTest.skipUnlessVersion(3, 6)
def test_maybe_Literal_annotation(self):
self.config.set_eval_annotations(False)
visitor = self.visit("def only_four(x: Literal[4]):\n\treturn x")
self.assertFalse(visitor.literal_annotations())
self.assertTrue(visitor.maybe_annotations())
self.assertOnlyIn((3, 0), visitor.minimum_versions())
3 changes: 1 addition & 2 deletions tests/arguments.py
Expand Up @@ -3,7 +3,6 @@
from shutil import rmtree

from vermin import Backports, Features, DEFAULT_PROCESSES, CONFIG_FILE_NAMES
from vermin.utility import open_wrapper
import vermin.formats

from .testutils import VerminTest, ScopedTemporaryFile
Expand Down Expand Up @@ -418,7 +417,7 @@ def test_config_file(self):
def test_no_config_file(self):
tmp_fld = mkdtemp()
path = os.path.join(tmp_fld, CONFIG_FILE_NAMES[0])
with open_wrapper(path, mode="w+", encoding="utf-8") as fp:
with open(path, mode="w+", encoding="utf-8") as fp:
fp.write("""[vermin]
pessimistic = yes
""")
Expand Down

0 comments on commit 587f075

Please sign in to comment.