From 7658b88022ed144c3cf4f8349c74ce520d62f903 Mon Sep 17 00:00:00 2001 From: Victorien <65306057+Viicos@users.noreply.github.com> Date: Sun, 23 Jun 2024 10:18:50 +0200 Subject: [PATCH] Switch to `pyproject.toml` (#408) * Switch to `pyproject.toml` Keep setuptools, remove Poetry. Remove references to pycodestyle, flake8 already runs it Make lint configurations consistent with each other Run black in CI Remove travis CI Remove pylint config, it is not enforced (can be added later) * Drop support for Python 3.6, update actions * Add black to dev deps * Fix deps specification --- .flake8 | 4 + .github/workflows/python-package.yml | 29 +++-- .travis.yml | 28 ----- MANIFEST.in | 6 - Makefile | 14 ++- pyproject.toml | 174 +++++++-------------------- setup.cfg | 4 - setup.py | 51 -------- tests/pylint.rc | 75 ------------ 9 files changed, 68 insertions(+), 317 deletions(-) create mode 100644 .flake8 delete mode 100644 .travis.yml delete mode 100644 MANIFEST.in delete mode 100644 setup.cfg delete mode 100644 setup.py delete mode 100644 tests/pylint.rc diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..55adb71a --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +ignore = E731,W504,E501 +max-complexity = 50 +max-line-length = 200 diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 01b65b57..5a7c8365 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -13,12 +13,11 @@ on: jobs: test_py3: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: python-version: - - "3.6" - "3.7" - "3.8" - "3.9" @@ -26,52 +25,52 @@ jobs: - "3.11" - "3.12" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - uses: actions/cache@v2 + - uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} restore-keys: | ${{ runner.os }}-pip- - name: Install dependencies run: | pip install -U setuptools sudo apt-get update -qq - sudo apt-get install -qq swig python-dev libxml2-dev libxmlsec1-dev + sudo apt-get install -qq swig libxml2-dev libxmlsec1-dev make install-req make install-test - name: Test run: make pytest lint: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 environment: CI steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: "3.12" - - uses: actions/cache@v2 + - uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} restore-keys: | ${{ runner.os }}-pip- - name: Install dependencies run: | pip install -U setuptools sudo apt-get update -qq - sudo apt-get install -qq swig python-dev libxml2-dev libxmlsec1-dev + sudo apt-get install -qq swig libxml2-dev libxmlsec1-dev pip install --force-reinstall --no-binary lxml lxml make install-req - make install-test + make install-lint - name: Run linters run: | - make pycodestyle make flake8 + make black - name: Run coveralls env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6313f31b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: python -python: - - '2.7' - - '3.5' - - '3.6' - - '3.7' - - '3.8' - - '3.9' - - '3.10' - -matrix: - include: - - python: '3.7' - dist: xenial # required for Python >= 3.7 (travis-ci/travis-ci#9069) - -install: - - sudo apt-get update -qq - - sudo apt-get install -qq swig python-dev libxml2-dev libxmlsec1-dev - - 'travis_retry pip install --force-reinstall --no-binary lxml lxml' - - 'travis_retry pip install .' - - 'travis_retry pip install -e ".[test]"' - -script: - - 'coverage run --source=src/onelogin/saml2 --rcfile=tests/coverage.rc setup.py test' - - 'coverage report -m --rcfile=tests/coverage.rc' -# - 'pylint src/onelogin/saml2 --rcfile=tests/pylint.rc' -# - 'flake8 --toml-config pyproject.toml' - - 'flake8 --ignore E226,E302,E41,E731,E501,C901,W504' diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 9b0be815..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,6 +0,0 @@ -include README.md -include LICENSE -recursive-include src *.py -recursive-include src *.xsd -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] diff --git a/Makefile b/Makefile index 95848867..89ea36f4 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,9 @@ PIP=pip +BLACK=black FLAKE8=flake8 PYTEST=pytest -PYCODESTYLE=pycodestyle COVERAGE=coverage COVERAGE_CONFIG=tests/coverage.rc -PEP8_CONFIG=tests/pep8.rc MAIN_SOURCE=src/onelogin/saml2 DEMOS=demo-django demo-flask demo-tornado demo_pyramid TESTS=tests/src/OneLogin/saml2_tests @@ -14,19 +13,22 @@ install-req: $(PIP) install . install-test: - $(PIP) install -e ".[test]" + $(PIP) install -e ".[test]" + +install-lint: + $(PIP) install -e ".[lint]" pytest: $(COVERAGE) run --source $(MAIN_SOURCE) --rcfile=$(COVERAGE_CONFIG) -m pytest $(COVERAGE) report -m --rcfile=$(COVERAGE_CONFIG) -pycodestyle: - $(PYCODESTYLE) --ignore=E501,E731,W504 $(SOURCES) --config=$(PEP8_CONFIG) +black: + $(BLACK) $(SOURCES) flake8: $(FLAKE8) $(SOURCES) -clean: +clean: rm -rf .pytest_cache/ rm -rf .eggs/ find . -type d -name "__pycache__" -exec rm -r {} + diff --git a/pyproject.toml b/pyproject.toml index d59ef2fb..83c7383f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,19 @@ -[tool.poetry] +[build-system] +requires = ["setuptools>=61.0.0"] +build-backend = "setuptools.build_meta" + +[project] name = "python3-saml" version = "1.16.0" description = "Saml Python Toolkit. Add SAML support to your Python software using this library" -license = "Apache-2.0" -authors = ["SAML-Toolkits "] -maintainers = ["Sixto Martin "] +license = {file = "LICENSE"} +authors = [ + {name = "SAML-Toolkits", email = "contact@iamdigitalservices.com"} +] +maintainers = [ + {name = "Sixto Martin", email = "sixto.martin.garcia@gmail.com"} +] readme = "README.md" -homepage = "https://saml.info" -repository = "https://github.com/SAML-Toolkits/python3-saml" keywords = [ "saml", "saml2", @@ -17,71 +23,42 @@ keywords = [ "identity", ] classifiers = [ - "Topic :: Software Development :: Build Tools", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Software Development :: Libraries :: Python Modules", ] -packages = [ - { include = "onelogin", from = "src" }, - { include = "onelogin/saml2", from = "src" }, +dependencies = [ + "lxml>=4.6.5,!=4.7.0", + "xmlsec>=1.3.9", + "isodate>=0.6.1", ] +requires-python = ">=3.7" -include = [ - { path = "src/onelogin/saml2/schemas"}, - { path = "tests", format = "sdist" } -] - -[tool.poetry.urls] +[project.urls] +Homepage = "https://saml.info" +Source = "https://github.com/SAML-Toolkits/python3-saml" "Bug Tracker" = "https://github.com/SAML-Toolkits/python3-saml/issues" +Changelog = "https://github.com/SAML-Toolkits/python3-saml/blob/master/changelog.md" -[tool.poetry.dependencies] -python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" -lxml = ">=4.6.5, !=4.7.0" -xmlsec = ">=1.3.9" -isodate = ">=0.6.1" - -#[tool.poetry.group.dev] -#optional = true - -#[tool.poetry.group.dev.dependencies] -#black = "*" -#isort = {version = "^5.10.1", extras = ["pyproject"]} -flake8 = { version = ">=3.6.0, <=5.0.0", optional = true} -#Flake8-pyproject = "^1.1.0.post0" -#flake8-bugbear = "^22.8.23" -#flake8-logging-format = "^0.7.5" -#ipdb = "^0.13.9" - -#[tool.poetry.group.test.dependencies] -pytest = { version = ">=4.6.11", optional = true} -coverage = { version = ">=4.5.2", optional = true} -#pylint = ">=1.9.4" - -[tool.poetry.extras] -test = ["flake8", "pytest", "coverage"] - -#[tool.poetry.group.test] -#optional = true - -#[tool.poetry.group.coverage] -#optional = true - -#[tool.poetry.group.coverage.dependencies] -#coverage = ">=4.5.2" -#pytest-cov = "*" - -#[tool.poetry.group.docs] -#optional = true +[project.optional-dependencies] +test = [ + "coverage>=4.5.2", + "pytest>=4.6", +] +lint = [ + "black==24.4.2", + "flake8>=3.6.0, <=5.0.0", +] -#[tool.poetry.group.docs.dependencies] -#sphinx = "*" +[tool.setuptools] +package-dir = {"" = "src"} -[build-system] -requires = [ - "poetry>=1.1.15", - "setuptools >= 40.1.0", - "wheel" -] -build-backend = "poetry.core.masonry.api" +[tool.setuptools.package-data] +"onelogin.saml2.schemas" = ["*.xsd"] [tool.pytest.ini_options] minversion = "4.6.11" @@ -93,75 +70,11 @@ pythonpath = [ "tests", ] -[tool.coverage.run] -branch = true -source = ["src/onelogin/saml2"] - -[tool.coverage.report] -exclude_lines = [ - "pragma: no cover", - "def __repr__", - "def __str__", - "raise AssertionError", - "raise NotImplementedError", - "if __name__ == .__main__.:", - "if TYPE_CHECKING:", - "if typing.TYPE_CHECKING:", -] -ignore_errors = true - -[tool.coverage.html] -directory = "cov_html" - -[tool.flake8] -max-line-length = 210 -max-complexity = 22 -count = true -show-source = true -statistics = true -disable-noqa = false -# 'ignore' defaults to: E121,E123,E126,E226,E24,E704,W503,W504 -extend-ignore = [ - 'B904', - 'B006', - 'B950', - 'B017', - 'C901', - 'E501', - 'E731', -] -per-file-ignores = [ - '__init__.py:F401', -] -# 'select' defaults to: E,F,W,C90 -extend-select = [ - # * Default warnings reported by flake8-bugbear (B) - - # https://github.com/PyCQA/flake8-bugbear#list-of-warnings - 'B', - # * The B950 flake8-bugbear opinionated warnings - - # https://github.com/PyCQA/flake8-bugbear#opinionated-warnings - 'B9', -] -extend-exclude = [ - '.github', '.gitlab', - '.Python', '.*.pyc', '.*.pyo', '.*.pyd', '.*.py.class', '*.egg-info', - 'venv*', '.venv*', '.*_cache', - 'lib', 'lib64', '.*.so', - 'build', 'dist', 'sdist', 'wheels', -] - [tool.black] line-length = 200 -extend-exclude = ''' -# A regex preceded with ^/ will apply only to files and directories -# in the root of the project. -( - \.pytest_cache -) -''' [tool.isort] -profile = 'black' +profile = "black" # The 'black' profile means: # multi_line_output = 3 # include_trailing_comma = true @@ -179,7 +92,4 @@ honor_noqa = true atomic = true ignore_comments = true skip_gitignore = true -src_paths = [ - 'src', - 'tests', -] +src_paths = ['src'] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 63f212dd..00000000 --- a/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -ignore = E731,W504,E501 -max-complexity = 48 -max-line-length = 1900 diff --git a/setup.py b/setup.py deleted file mode 100644 index fc187da3..00000000 --- a/setup.py +++ /dev/null @@ -1,51 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -from setuptools import setup - - -setup( - name='python3-saml', - version='1.16.0', - description='Saml Python Toolkit. Add SAML support to your Python software using this library', - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'Intended Audience :: System Administrators', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - ], - python_requires='>=3.6', - license='MIT', - url='https://github.com/SAML-Toolkits/python3-saml', - packages=['onelogin', 'onelogin/saml2'], - include_package_data=True, - package_data={ - 'onelogin/saml2/schemas': ['*.xsd'], - }, - package_dir={ - '': 'src', - }, - test_suite='tests', - install_requires=[ - 'lxml>=4.6.5, !=4.7.0', - 'isodate>=0.6.1', - 'xmlsec>=1.3.9' - ], - dependency_links=['http://github.com/mehcode/python-xmlsec/tarball/master'], - extras_require={ - 'test': ( - 'coverage>=4.5.2', - # 'pylint>=1.9.4', - 'flake8>=3.6.0, <=5.0.0', - 'pytest>=4.6', - ), - }, - keywords='saml saml2 sso xmlsec federation identity', -) diff --git a/tests/pylint.rc b/tests/pylint.rc deleted file mode 100644 index e5dd9bb9..00000000 --- a/tests/pylint.rc +++ /dev/null @@ -1,75 +0,0 @@ -[MASTER] -profile=no -persistent=yes -ignore= -cache-size=500 - -[REPORTS] -output-format=text -files-output=no -reports=yes - -[BASIC] -no-docstring-rgx=__.*__|_.* -class-rgx=[A-Z_][a-zA-Z0-9_]+$ -function-rgx=[a-zA_][a-zA-Z0-9_]{2,70}$ -method-rgx=[a-z_][a-zA-Z0-9_]{2,70}$ -const-rgx=(([A-Z_][A-Z0-9_]*)|([a-z_][a-z0-9_]*)|(__.*__)|register|urlpatterns)$ -good-names=_,i,j,k,e,qs,pk,setUp,tearDown,el,ns,fd,js,nb,na,sp,SAML_SINGLE_LOGOUT_NOT_SUPPORTED,SAML_SINGLE_LOGOUT_NOT_SUPPORTED,NAMEID_WINDOWS_DOMAIN_QUALIFIED_NAME -docstring-min-length=1 - -disable=E0611,W0703,W0511,W1401,F0401,W0102,E1103,W0212,I0011 - -[TYPECHECK] - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus extisting member attributes cannot be deduced by static analysis -ignored-modules= - -# List of classes names for which member attributes should not be checked -# (useful for classes with attributes dynamically set). -ignored-classes=SQLObject,WSGIRequest - -# When zope mode is activated, add a predefined set of Zope acquired attributes -# to generated-members. -zope=no - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E0201 when accessed. -generated-members=objects,DoesNotExist,id,pk,_meta,base_fields,context,views,save - -# List of method names used to declare (i.e. assign) instance attributes -defining-attr-methods=__init__,__new__,setUp - -[VARIABLES] -init-import=no -dummy-variables-rgx=_|dummy - -[SIMILARITIES] -min-similarity-lines=6 -ignore-comments=yes -ignore-docstrings=yes -[MISCELLANEOUS] -notes=FIXME,XXX,TODO - -[FORMAT] -max-line-length=200 -max-module-lines=1200 -indent-string=' ' -indent-after-paren=4 - -[DESIGN] -max-args=10 -max-locals=40 -max-returns=6 -max-branches=50 -max-statements=120 -max-parents=10 -max-attributes=10 -min-public-methods=0 -max-public-methods=100