Skip to content

Commit

Permalink
Merge pull request #10 from nzlosh/master
Browse files Browse the repository at this point in the history
Update plugin for flake8 >v3
  • Loading branch information
cognifloyd authored Apr 3, 2024
2 parents 7a6ff0d + 6c7ea3d commit c33f500
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 144 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -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 setup_virtualenv

- name: Test
run: make tests

- name: Package
run: make build_package
7 changes: 1 addition & 6 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
[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
# R0915 Too many statements
# 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
Expand Down
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

27 changes: 26 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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 v7.0.0

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``.
50 changes: 38 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2020-2024 StackStorm contributors.
# Copyright 2019 Extreme Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,8 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

PY3 := /usr/bin/python3
VER := $(shell cat ./st2flake8/__init__.py | grep -Po "__version__ = '\K[^']*")
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
Expand All @@ -25,6 +28,10 @@ TOX_DIR ?= .tox
PKGDISTDIR = dist
PKGBUILDDIR = build


.PHONY: all
all: tox

.PHONY: clean
clean:
rm -rf $(VENV_DIR)
Expand All @@ -34,19 +41,38 @@ clean:
rm -rf *.egg-info
rm -f coverage.xml

.PHONY: venv
venv:
test -d $(VENV_DIR) || virtualenv --no-site-packages $(VENV_DIR)
.PHONY: tox
tox: setup_virtualenv check_virtualenv
$(VENV_DIR)/bin/tox

.PHONY: tests
tests: check_virtualenv
$(VENV_DIR)/bin/pytest

.PHONY: create_virtualenv
create_virtualenv:
test -d $(VENV_DIR) || $(SYS_PY3) -m venv $(VENV_DIR)

.PHONY: reqs
reqs: venv
$(VENV_DIR)/bin/pip install --upgrade "pip>=19.0,<20.0"
.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
13 changes: 8 additions & 5 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
flake8==3.7.7
nose
nosexcover
pep8>=1.6.0,<1.7
pylint>=1.4.3,<1.5
# 202404: Align all requirements with st2 test-requirements
coverage==7.2.7
flake8==7.0.0
pep8==1.7.1
pylint==3.1.0
pytest==6.2.5
tox==4.5.2
wheel
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
flake8-copyright==0.2.2
flake8-polyfill==1.0.2
flake8-copyright==0.2.4
44 changes: 23 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3

# Copyright 2020-2024 StackStorm contributors.
# Copyright 2019 Extreme Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,14 +22,15 @@


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)


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
Expand All @@ -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="st2-flake8",
version=get_version_string(),
author='StackStorm',
author_email='[email protected]',
url='https://www.stackstorm.com',
author="StackStorm",
author_email="[email protected]",
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",
]
}
},
)
3 changes: 2 additions & 1 deletion st2flake8/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2023 StackStorm contributors.
# Copyright 2019 Extreme Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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"
50 changes: 19 additions & 31 deletions st2flake8/license_rules.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2023 StackStorm contributors.
# Copyright 2019 Extreme Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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
Expand All @@ -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

Expand All @@ -64,25 +57,20 @@ 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",
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
Expand All @@ -95,7 +83,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit c33f500

Please sign in to comment.