From 82e79f3944b87cd46bdf9f37d2d2475882a53db7 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 31 May 2023 14:32:58 +0200 Subject: [PATCH 1/2] Update plugin for flake8 >v3 --- .github/workflows/makefile.yml | 26 ++++++++++ .pylintrc | 7 +-- .travis.yml | 11 ---- CHANGELOG.rst | 27 +++++++++- Makefile | 20 ++++++-- requirements-test.txt | 11 ++-- requirements.txt | 3 +- setup.py | 44 ++++++++-------- st2flake8/__init__.py | 3 +- st2flake8/license_rules.py | 51 ++++++++----------- .../module_with_apache_license.py | 2 - .../license_check/module_with_gnu_license.py | 2 - .../module_with_proprietary_license.py | 2 - .../module_without_license_header.py | 3 -- st2flake8/tests/fixtures/loader.py | 3 +- st2flake8/tests/unit/base.py | 11 ++-- st2flake8/tests/unit/test_license_checker.py | 38 ++++++-------- tox.ini | 11 ++-- 18 files changed, 143 insertions(+), 132 deletions(-) create mode 100644 .github/workflows/makefile.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 0000000..84f0c1e --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,26 @@ +name: Makefile CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + + - name: Install dependencies + run: make build + + - name: Test + run: make tests + + - name: Package + run: make package diff --git a/.pylintrc b/.pylintrc index 8e2d3c5..2ac0894 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,14 +1,9 @@ [MESSAGES CONTROL] # C0111 Missing docstring # I0011 Warning locally suppressed using disable-msg -# I0012 Warning locally suppressed using disable-msg -# W0704 Except doesn't do anything Used when an except clause does nothing but "pass" and there is no "else" clause -# W0142 Used * or * magic* Used when a function or method is called using *args or **kwargs to dispatch arguments. # W0212 Access to a protected member %s of a client class -# W0232 Class has no __init__ method Used when a class has no __init__ method, neither its parent classes. # W0613 Unused argument %r Used when a function or method argument is not used. # W0702 No exception's type specified Used when an except clause doesn't specify exceptions type to catch. -# R0201 Method could be a function # W0614 Unused import XYZ from wildcard import # R0914 Too many local variables # R0912 Too many branches @@ -16,7 +11,7 @@ # R0913 Too many arguments # R0904 Too many public methods # E0211: Method has no argument -disable=C0103,C0111,I0011,I0012,W0704,W0142,W0212,W0232,W0613,W0702,R0201,W0614,R0914,R0912,R0915,R0913,R0904,R0801 +disable=C0103,C0111,I0011,W0212,W0613,W0702,W0614,R0914,R0912,R0915,R0913,R0904,R0801 [TYPECHECK] # Note: This modules are manipulated during the runtime so we can't detect all the properties during diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 23eb7a7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: python - -python: - - 2.7 - - 3.6 - -install: - - pip install tox-travis - -script: - - tox diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a5693d9..a320175 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,2 +1,27 @@ Changelog -========= +======================================================================== + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +[0.2.1] Unreleased +------------------------------------------------------------------------ + +Added +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + - add support for flake8 v6 + +Deleted +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + - drop support for python 2.x + - drop compatibility with flake8 <3.x + - drop useless/unknown pylint options: I0012, W0704, W0142, W0232, R0201 + +Changed +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + - updated extension code from ``L`` to ``LIC001``. diff --git a/Makefile b/Makefile index 2a017cd..fdee375 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +# Copyright 2023 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +14,7 @@ # limitations under the License. PY3 := /usr/bin/python3 -VER := $(shell cat ./st2flake8/__init__.py | grep -Po "__version__ = '\K[^']*") +VER := $(shell awk -F'"' '/__version__ =/ {print $2}' ./st2flake8/__init__.py) # Virtual Environment VENV_DIR ?= .venv @@ -34,13 +35,22 @@ clean: rm -rf *.egg-info rm -f coverage.xml +.PHONY: tox +tox: + $(VENV_DIR)/bin/tox + +.PHONY: tests +tests: + echo "Running tests" + $(VENV_DIR)/bin/pytest + .PHONY: venv venv: - test -d $(VENV_DIR) || virtualenv --no-site-packages $(VENV_DIR) + test -d $(VENV_DIR) || $(PY3) -m venv $(VENV_DIR) -.PHONY: reqs -reqs: venv - $(VENV_DIR)/bin/pip install --upgrade "pip>=19.0,<20.0" +.PHONY: build +build: venv + $(VENV_DIR)/bin/pip install --upgrade pip $(VENV_DIR)/bin/pip install -r requirements.txt $(VENV_DIR)/bin/pip install -r requirements-test.txt $(VENV_DIR)/bin/python setup.py develop diff --git a/requirements-test.txt b/requirements-test.txt index 3c05909..358cfa9 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,5 +1,6 @@ -flake8==3.7.7 -nose -nosexcover -pep8>=1.6.0,<1.7 -pylint>=1.4.3,<1.5 +coverage==7.2.7 +flake8==6.0.0 +pep8==1.7.1 +pylint==2.17.2 +pytest==7.3.1 +tox==3.23.0 diff --git a/requirements.txt b/requirements.txt index c6dc781..96457c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -flake8-copyright==0.2.2 -flake8-polyfill==1.0.2 +flake8-copyright==0.2.4 diff --git a/setup.py b/setup.py index 088e92c..78a3aa8 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 +# Copyright 2023 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +22,7 @@ PKG_ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) -PKG_REQ_FILE = '%s/requirements.txt' % PKG_ROOT_DIR +PKG_REQ_FILE = "%s/requirements.txt" % PKG_ROOT_DIR os.chdir(PKG_ROOT_DIR) @@ -29,6 +30,7 @@ def get_version_string(): version = None sys.path.insert(0, PKG_ROOT_DIR) from st2flake8 import __version__ + version = __version__ sys.path.pop(0) return version @@ -39,34 +41,34 @@ def get_requirements(): required = f.read().splitlines() # Ignore comments in the requirements file - required = [line for line in required if not line.startswith('#')] + required = [line for line in required if not line.startswith("#")] return required setup( - name='st2flake8', + name="st2flake8", version=get_version_string(), - author='StackStorm', - author_email='info@stackstorm.com', - url='https://www.stackstorm.com', + author="StackStorm", + author_email="info@stackstorm.com", + url="https://www.stackstorm.com", packages=find_packages(exclude=[]), install_requires=get_requirements(), - license='Apache License (2.0)', + license="Apache License (2.0)", classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Information Technology', - 'Intended Audience :: System Administrators', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6' + "Development Status :: 4 - Beta", + "Intended Audience :: Information Technology", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: Apache Software License", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", ], entry_points={ - 'flake8.extension': [ - 'L = st2flake8.license_rules:LicenseChecker', + "flake8.extension": [ + "LIC001 = st2flake8.license_rules:LicenseChecker", ] - } + }, ) diff --git a/st2flake8/__init__.py b/st2flake8/__init__.py index 2302731..86efa82 100644 --- a/st2flake8/__init__.py +++ b/st2flake8/__init__.py @@ -1,3 +1,4 @@ +# Copyright 2023 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.1.0' +__version__ = "0.1.0" diff --git a/st2flake8/license_rules.py b/st2flake8/license_rules.py index 9125be7..dc50122 100644 --- a/st2flake8/license_rules.py +++ b/st2flake8/license_rules.py @@ -1,3 +1,4 @@ +# Copyright 2023 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,13 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import - import st2flake8 -from flake8_polyfill import options - - PROPRIETARY_LICENSE = """ # Unauthorized copying of this file, via any medium is strictly # prohibited. Proprietary and confidential. See the LICENSE file @@ -39,22 +35,19 @@ # limitations under the License. """ -PROPRIETARY_LICENSE = PROPRIETARY_LICENSE.strip('\n') -APACHE_20_LICENSE = APACHE_20_LICENSE.strip('\n') +PROPRIETARY_LICENSE = PROPRIETARY_LICENSE.strip("\n") +APACHE_20_LICENSE = APACHE_20_LICENSE.strip("\n") -LICENSE_TYPES = { - 'proprietary': PROPRIETARY_LICENSE, - 'apache': APACHE_20_LICENSE -} +LICENSE_TYPES = {"proprietary": PROPRIETARY_LICENSE, "apache": APACHE_20_LICENSE} ERROR_MESSAGES = { - 'proprietary': 'L101 Proprietary license header not found', - 'apache': 'L102 Apache 2.0 license header not found' + "proprietary": "L101 Proprietary license header not found", + "apache": "L102 Apache 2.0 license header not found", } class LicenseChecker(object): - name = 'st2flake8_license' + name = "st2flake8_license" version = st2flake8.__version__ off_by_default = True @@ -64,25 +57,21 @@ def __init__(self, tree, filename): @classmethod def add_options(cls, parser): - options.register( - parser, - '--license-type', - type='choice', - choices=['proprietary', 'apache'], - default='apache', - action='store', - parse_from_config=True, - help='Checks for specific type of license header.' + parser.add_option( + "--license-type", + type="choice", + choices=["proprietary", "apache"], + default="apache", + action="store", + help="Checks for specific type of license header.", ) - options.register( - parser, - '--license-min-file-size', - type='int', + parser.add_option( + "--license-min-file-size", + type="int", default=1, - action='store', - parse_from_config=True, - help='Minimum number of characters in a file before requiring a license header.' + action="store", + help="Minimum number of characters in a file before requiring a license header.", ) @classmethod @@ -95,7 +84,7 @@ def run(self): L101 Proprietary license header not found L102 Apache 2.0 license header not found """ - with open(self.filename, 'r') as f: + with open(self.filename, "r") as f: content = f.read() if len(content) >= self.min_file_size and LICENSE_TYPES[self.license_type] not in content: diff --git a/st2flake8/tests/fixtures/license_check/module_with_apache_license.py b/st2flake8/tests/fixtures/license_check/module_with_apache_license.py index cec701a..6184830 100644 --- a/st2flake8/tests/fixtures/license_check/module_with_apache_license.py +++ b/st2flake8/tests/fixtures/license_check/module_with_apache_license.py @@ -10,8 +10,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import - def MockClass(object): pass diff --git a/st2flake8/tests/fixtures/license_check/module_with_gnu_license.py b/st2flake8/tests/fixtures/license_check/module_with_gnu_license.py index d935f4e..cabfedd 100644 --- a/st2flake8/tests/fixtures/license_check/module_with_gnu_license.py +++ b/st2flake8/tests/fixtures/license_check/module_with_gnu_license.py @@ -11,8 +11,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import absolute_import - def MockClass(object): pass diff --git a/st2flake8/tests/fixtures/license_check/module_with_proprietary_license.py b/st2flake8/tests/fixtures/license_check/module_with_proprietary_license.py index aff3253..54333a2 100644 --- a/st2flake8/tests/fixtures/license_check/module_with_proprietary_license.py +++ b/st2flake8/tests/fixtures/license_check/module_with_proprietary_license.py @@ -2,8 +2,6 @@ # prohibited. Proprietary and confidential. See the LICENSE file # included with this work for details. -from __future__ import absolute_import - def MockClass(object): pass diff --git a/st2flake8/tests/fixtures/license_check/module_without_license_header.py b/st2flake8/tests/fixtures/license_check/module_without_license_header.py index 096227f..a7b5e1d 100644 --- a/st2flake8/tests/fixtures/license_check/module_without_license_header.py +++ b/st2flake8/tests/fixtures/license_check/module_without_license_header.py @@ -1,5 +1,2 @@ -from __future__ import absolute_import - - def MockClass(object): pass diff --git a/st2flake8/tests/fixtures/loader.py b/st2flake8/tests/fixtures/loader.py index 2ee4059..8bf8ee6 100644 --- a/st2flake8/tests/fixtures/loader.py +++ b/st2flake8/tests/fixtures/loader.py @@ -1,3 +1,4 @@ +# Copyright 2023 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import - import os diff --git a/st2flake8/tests/unit/base.py b/st2flake8/tests/unit/base.py index 30ca234..e45d939 100644 --- a/st2flake8/tests/unit/base.py +++ b/st2flake8/tests/unit/base.py @@ -1,3 +1,4 @@ +# Copyright 2023 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,23 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import - import os import optparse -import six import unittest from st2flake8.tests.fixtures import loader as fixture_loader class Flake8PluginTest(unittest.TestCase): - def get_fixture_path(self, fixture): return os.path.join(fixture_loader.get_fixtures_base_path(), fixture) def get_fixture_content(self, filename): - with open(filename, 'r') as f: + with open(filename, "r") as f: content = f.read() return content @@ -42,8 +39,8 @@ def configure_options(self, instance, **kwargs): # Setup the args to pass into the checker. cli_args = [] - for k, v in six.iteritems(kwargs): - arg_name = '--' + k.replace('_', '-') + for k, v in kwargs.items(): + arg_name = "--" + k.replace("_", "-") cli_args.extend([arg_name, str(v)]) (options, args) = parser.parse_args(cli_args) diff --git a/st2flake8/tests/unit/test_license_checker.py b/st2flake8/tests/unit/test_license_checker.py index a8b7926..553d572 100644 --- a/st2flake8/tests/unit/test_license_checker.py +++ b/st2flake8/tests/unit/test_license_checker.py @@ -1,3 +1,4 @@ +# Copyright 2023 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import - import ast from st2flake8 import license_rules @@ -21,7 +20,6 @@ class LicenseCheckerTest(base.Flake8PluginTest): - def get_plugin_instance(self, fixture, **options): filename = self.get_fixture_path(fixture) tree = ast.parse(self.get_fixture_content(filename)) @@ -30,9 +28,7 @@ def get_plugin_instance(self, fixture, **options): return instance def test_module_with_default_license(self): - instance = self.get_plugin_instance( - 'license_check/module_with_apache_license.py' - ) + instance = self.get_plugin_instance("license_check/module_with_apache_license.py") expected_error = [] @@ -40,8 +36,7 @@ def test_module_with_default_license(self): def test_module_with_proprietary_license(self): instance = self.get_plugin_instance( - 'license_check/module_with_proprietary_license.py', - license_type='proprietary' + "license_check/module_with_proprietary_license.py", license_type="proprietary" ) expected_error = [] @@ -50,18 +45,16 @@ def test_module_with_proprietary_license(self): def test_module_with_wrong_proprietary_license(self): instance = self.get_plugin_instance( - 'license_check/module_with_gnu_license.py', - license_type='proprietary' + "license_check/module_with_gnu_license.py", license_type="proprietary" ) - expected_error = [(1, 1, 'L101 Proprietary license header not found', type(instance))] + expected_error = [(1, 1, "L101 Proprietary license header not found", type(instance))] self.assertListEqual(list(instance.run()), expected_error) def test_module_with_apache_license(self): instance = self.get_plugin_instance( - 'license_check/module_with_apache_license.py', - license_type='apache' + "license_check/module_with_apache_license.py", license_type="apache" ) expected_error = [] @@ -70,30 +63,29 @@ def test_module_with_apache_license(self): def test_module_with_wrong_apache_license(self): instance = self.get_plugin_instance( - 'license_check/module_with_gnu_license.py', - license_type='apache' + "license_check/module_with_gnu_license.py", license_type="apache" ) - expected_error = [(1, 1, 'L102 Apache 2.0 license header not found', type(instance))] + expected_error = [(1, 1, "L102 Apache 2.0 license header not found", type(instance))] self.assertListEqual(list(instance.run()), expected_error) def test_empty_module_with_license_check_on_zero_file_size(self): instance = self.get_plugin_instance( - 'license_check/module_with_no_content.py', - license_type='proprietary', - license_min_file_size=0 + "license_check/module_with_no_content.py", + license_type="proprietary", + license_min_file_size=0, ) - expected_error = [(1, 1, 'L101 Proprietary license header not found', type(instance))] + expected_error = [(1, 1, "L101 Proprietary license header not found", type(instance))] self.assertListEqual(list(instance.run()), expected_error) def test_empty_module_with_license_check_on_min_file_size(self): instance = self.get_plugin_instance( - 'license_check/module_with_no_content.py', - license_type='proprietary', - license_min_file_size=1 + "license_check/module_with_no_content.py", + license_type="proprietary", + license_min_file_size=1, ) expected_error = [] diff --git a/tox.ini b/tox.ini index 5c0ad55..f7600b0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,8 @@ [tox] -envlist = py36,py27,pep8 +envlist = py38,py39,py310,py311,pep8 minversion = 1.6 skipsdist = True -[travis] -python = - 2.7: py27, pep8 - 3.6: py36, pep8 - [testenv] setenv = VIRTUAL_ENV = {envdir} usedevelop = True @@ -16,11 +11,11 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements-test.txt commands = - nosetests -sv --with-xcoverage --cover-package=st2flake8 st2flake8.tests + coverage run -m pytest st2flake8/tests [testenv:pep8] setenv = VIRTUALENV_DIR = {envdir} -basepython = python2.7 +basepython = python3.10 deps = -r{toxinidir}/requirements-test.txt commands = From 6c7ea3dfbd7afe1192fae64a578493043d0b419f Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 28 Mar 2024 22:15:34 +0100 Subject: [PATCH 2/2] Fixes to use flake8 7.0.0 --- .flake8 | 3 ++- .github/workflows/makefile.yml | 4 +-- CHANGELOG.rst | 2 +- Makefile | 48 ++++++++++++++++++++++------------ requirements-test.txt | 10 ++++--- setup.py | 4 +-- st2flake8/license_rules.py | 3 +-- st2flake8/tests/unit/base.py | 15 ++++++++--- 8 files changed, 57 insertions(+), 32 deletions(-) diff --git a/.flake8 b/.flake8 index b493b98..4d14d25 100644 --- a/.flake8 +++ b/.flake8 @@ -5,8 +5,9 @@ ignore = E402 exclude=*.egg/* # Configuration for flake8-copyright extension -copyright-check = True +flake8_copyright = True copyright-min-file-size = 1 + # NOTE: This requires flake8 >= 3.0.0 to work correctly. # If old version is used (< 3.0.0), it will select all the errors and it wont ignore ones # listed above as part of ignore list diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index 84f0c1e..7ddad3c 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -17,10 +17,10 @@ jobs: - uses: actions/checkout@v3 - name: Install dependencies - run: make build + run: make setup_virtualenv - name: Test run: make tests - name: Package - run: make package + run: make build_package diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a320175..ed3c4af 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Added ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - add support for flake8 v6 + - add support for flake8 v7.0.0 Deleted ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Makefile b/Makefile index fdee375..2be0103 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright 2023 StackStorm contributors. +# Copyright 2020-2024 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,8 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -PY3 := /usr/bin/python3 -VER := $(shell awk -F'"' '/__version__ =/ {print $2}' ./st2flake8/__init__.py) +PY3 := python3 +SYS_PY3 := $(shell which $(PY3)) +PIP_VERSION = 24.0 +VER := $(shell grep __version__ ./st2flake8/__init__.py | cut -d= -f2 | tr -d '" ') # Virtual Environment VENV_DIR ?= .venv @@ -26,6 +28,10 @@ TOX_DIR ?= .tox PKGDISTDIR = dist PKGBUILDDIR = build + +.PHONY: all +all: tox + .PHONY: clean clean: rm -rf $(VENV_DIR) @@ -36,27 +42,37 @@ clean: rm -f coverage.xml .PHONY: tox -tox: +tox: setup_virtualenv check_virtualenv $(VENV_DIR)/bin/tox .PHONY: tests -tests: - echo "Running tests" +tests: check_virtualenv $(VENV_DIR)/bin/pytest -.PHONY: venv -venv: - test -d $(VENV_DIR) || $(PY3) -m venv $(VENV_DIR) +.PHONY: create_virtualenv +create_virtualenv: + test -d $(VENV_DIR) || $(SYS_PY3) -m venv $(VENV_DIR) -.PHONY: build -build: venv - $(VENV_DIR)/bin/pip install --upgrade pip +.PHONY: install_requirements +install_requirements: create_virtualenv + $(VENV_DIR)/bin/pip install --upgrade pip==$(PIP_VERSION) $(VENV_DIR)/bin/pip install -r requirements.txt $(VENV_DIR)/bin/pip install -r requirements-test.txt - $(VENV_DIR)/bin/python setup.py develop -.PHONY: package -package: +.PHONY: setup_virtualenv +setup_virtualenv: install_requirements + +.PHONY: check_virtualenv +check_virtualenv: + test -d $(VENV_DIR) || echo "Missing virtual environment, try running make setup_virtualenv." + test -d $(VENV_DIR) || exit 1 + +.PHONY: build_application +build_application: check_virtualenv + $(VENV_DIR)/bin/$(PY3) setup.py develop + +.PHONY: build_package +build_package: check_virtualenv rm -rf $(PKGDISTDIR) rm -rf $(PKGBUILDDIR) - $(PY3) setup.py sdist bdist_wheel + $(VENV_DIR)/bin/$(PY3) setup.py sdist bdist_wheel diff --git a/requirements-test.txt b/requirements-test.txt index 358cfa9..b040484 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,6 +1,8 @@ +# 202404: Align all requirements with st2 test-requirements coverage==7.2.7 -flake8==6.0.0 +flake8==7.0.0 pep8==1.7.1 -pylint==2.17.2 -pytest==7.3.1 -tox==3.23.0 +pylint==3.1.0 +pytest==6.2.5 +tox==4.5.2 +wheel diff --git a/setup.py b/setup.py index 78a3aa8..4938208 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2023 StackStorm contributors. +# Copyright 2020-2024 StackStorm contributors. # Copyright 2019 Extreme Networks, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -46,7 +46,7 @@ def get_requirements(): setup( - name="st2flake8", + name="st2-flake8", version=get_version_string(), author="StackStorm", author_email="info@stackstorm.com", diff --git a/st2flake8/license_rules.py b/st2flake8/license_rules.py index dc50122..9e7dd36 100644 --- a/st2flake8/license_rules.py +++ b/st2flake8/license_rules.py @@ -59,7 +59,6 @@ def __init__(self, tree, filename): def add_options(cls, parser): parser.add_option( "--license-type", - type="choice", choices=["proprietary", "apache"], default="apache", action="store", @@ -68,7 +67,7 @@ def add_options(cls, parser): parser.add_option( "--license-min-file-size", - type="int", + type=int, default=1, action="store", help="Minimum number of characters in a file before requiring a license header.", diff --git a/st2flake8/tests/unit/base.py b/st2flake8/tests/unit/base.py index e45d939..d67ce9a 100644 --- a/st2flake8/tests/unit/base.py +++ b/st2flake8/tests/unit/base.py @@ -14,10 +14,12 @@ # limitations under the License. import os -import optparse +from flake8 import __version__ as flake8_version +from flake8.options.manager import OptionManager import unittest from st2flake8.tests.fixtures import loader as fixture_loader +from st2flake8 import __version__ as st2flake8_version class Flake8PluginTest(unittest.TestCase): @@ -32,8 +34,13 @@ def get_fixture_content(self, filename): def configure_options(self, instance, **kwargs): # Set up the args parser. - parser = optparse.OptionParser() - parser.config_options = [] + parser = OptionManager( + version=flake8_version, + plugin_versions=st2flake8_version, + parents=[], + formatter_names=[], + ) + instance.add_options(parser) # Setup the args to pass into the checker. @@ -43,7 +50,7 @@ def configure_options(self, instance, **kwargs): arg_name = "--" + k.replace("_", "-") cli_args.extend([arg_name, str(v)]) - (options, args) = parser.parse_args(cli_args) + options = parser.parse_args(cli_args) # Apply the options to the plugin instance. instance.parse_options(options)