From e4a56cf64f1d9e088577f1480158e2b57d3c72ca Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Fri, 23 Aug 2024 02:14:57 +0200 Subject: [PATCH] Switch to pyproject.toml and hatchling build backend --- .github/utils/check_version.py | 11 +++--- .github/workflows/pypi.yml | 2 -- .gitignore | 1 + CHANGES.rst | 1 + flask_multipass/__init__.py | 17 ++++++++- pyproject.toml | 51 ++++++++++++++++++++++++++ setup.cfg | 66 ---------------------------------- setup.py | 10 ------ tox.ini | 2 +- 9 files changed, 74 insertions(+), 87 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.github/utils/check_version.py b/.github/utils/check_version.py index 2172dd4..f30dc23 100644 --- a/.github/utils/check_version.py +++ b/.github/utils/check_version.py @@ -1,13 +1,10 @@ -import os import sys -from importlib.util import find_spec +import tomllib +from pathlib import Path -from setuptools.config.expand import StaticModule - -package = 'flask_multipass' -sys.path.insert(0, os.getcwd()) -version = StaticModule(package, find_spec(package)).__version__ +data = tomllib.loads(Path('pyproject.toml').read_text()) +version = data['project']['version'] tag_version = sys.argv[1] if tag_version != version: diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 298f985..e65072e 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -22,8 +22,6 @@ jobs: run: >- python -m build - --sdist - --wheel --outdir dist/ . - uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index 62ba2db..08d74c5 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ htmlcov/ .coverage example/example.cfg +.python-version diff --git a/CHANGES.rst b/CHANGES.rst index 486c4af..3c1ea89 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Version 0.5.5 ------------- - Ensure only valid schemas (http and https) can be used when validating the ``next`` URL +- Deprecate the ``flask_multipass.__version__`` attribute Version 0.5.4 ------------- diff --git a/flask_multipass/__init__.py b/flask_multipass/__init__.py index f04f735..dbcc3f9 100644 --- a/flask_multipass/__init__.py +++ b/flask_multipass/__init__.py @@ -13,7 +13,22 @@ from .identity import IdentityProvider -__version__ = '0.5.5' __all__ = ('Multipass', 'AuthProvider', 'IdentityProvider', 'AuthInfo', 'IdentityInfo', 'Group', 'MultipassException', 'AuthenticationFailed', 'IdentityRetrievalFailed', 'GroupRetrievalFailed', 'NoSuchUser', 'InvalidCredentials') + + +def __getattr__(name): + if name == '__version__': + import importlib.metadata + import warnings + + warnings.warn( + 'The `__version__` attribute is deprecated. Use feature detection or' + " `importlib.metadata.version('flask-multipass')` instead.", + DeprecationWarning, + stacklevel=2, + ) + return importlib.metadata.version('flask-multipass') + + raise AttributeError(name) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ad0584c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,51 @@ +[project] +name = 'Flask-Multipass' +version = '0.5.5' +description = 'A pluggable solution for multi-backend authentication with Flask' +readme = 'README.rst' +license = 'BSD-3-Clause' +authors = [{ name = 'Indico Team', email = 'indico-team@cern.ch' }] +classifiers = [ + 'Environment :: Web Environment', + 'Framework :: Flask', + 'License :: OSI Approved :: BSD License', + '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', +] +requires-python = '~=3.8' +dependencies = ['flask', 'blinker'] + +[project.optional-dependencies] +dev = ['pytest', 'pytest-cov', 'pytest-mock'] +authlib = ['authlib>=0.14.1', 'requests'] +ldap = ['flask-wtf', 'python-ldap>=3.3.1,<4.0'] +saml = ['python3-saml>=1.10.1,<1.11'] +sqlalchemy = ['sqlalchemy', 'flask-wtf'] + +[project.urls] +GitHub = 'https://github.com/indico/flask-multipass' + +[project.entry-points.'flask_multipass.auth_providers'] +ldap = 'flask_multipass.providers.ldap:LDAPAuthProvider' +authlib = 'flask_multipass.providers.authlib:AuthlibAuthProvider' +saml = 'flask_multipass.providers.saml:SAMLAuthProvider' +shibboleth = 'flask_multipass.providers.shibboleth:ShibbolethAuthProvider' +static = 'flask_multipass.providers.static:StaticAuthProvider' + +[project.entry-points.'flask_multipass.identity_providers'] +ldap = 'flask_multipass.providers.ldap:LDAPIdentityProvider' +ldap_or_authinfo = 'flask_multipass.providers.ldap:AuthFallbackLDAPIdentityProvider' +authlib = 'flask_multipass.providers.authlib:AuthlibIdentityProvider' +saml = 'flask_multipass.providers.saml:SAMLIdentityProvider' +shibboleth = 'flask_multipass.providers.shibboleth:ShibbolethIdentityProvider' +static = 'flask_multipass.providers.static:StaticIdentityProvider' + +[build-system] +requires = ['hatchling==1.25.0'] +build-backend = 'hatchling.build' + +[tool.hatch.build] +exclude = ['docs/_build', '.github', '.python-version'] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 6b253ff..0000000 --- a/setup.cfg +++ /dev/null @@ -1,66 +0,0 @@ -[metadata] -name = Flask-Multipass -version = attr: flask_multipass.__version__ -description = A pluggable solution for multi-backend authentication with Flask -long_description = file: README.rst -long_description_content_type = text/x-rst -url = https://github.com/indico/flask-multipass -license = BSD -license_file = LICENSE -author = Indico Team -author_email = indico-team@cern.ch -classifiers = - Environment :: Web Environment - Framework :: Flask - License :: OSI Approved :: BSD License - 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 - -[options] -packages = find: -zip_safe = false -include_package_data = true -python_requires = ~=3.8 -install_requires = - flask - blinker - -[options.extras_require] -dev = - pytest - pytest-cov - pytest-mock -authlib = - authlib>=0.14.1 - requests -ldap = - flask-wtf - python-ldap>=3.3.1,<4.0 -saml = - python3-saml>=1.10.1,<1.11 -sqlalchemy = - sqlalchemy - flask-wtf - -[options.packages.find] -include = - flask_multipass - flask_multipass.* - -[options.entry_points] -flask_multipass.auth_providers = - ldap = flask_multipass.providers.ldap:LDAPAuthProvider - authlib = flask_multipass.providers.authlib:AuthlibAuthProvider - saml = flask_multipass.providers.saml:SAMLAuthProvider - shibboleth = flask_multipass.providers.shibboleth:ShibbolethAuthProvider - static = flask_multipass.providers.static:StaticAuthProvider -flask_multipass.identity_providers = - ldap = flask_multipass.providers.ldap:LDAPIdentityProvider - ldap_or_authinfo = flask_multipass.providers.ldap:AuthFallbackLDAPIdentityProvider - authlib = flask_multipass.providers.authlib:AuthlibIdentityProvider - saml = flask_multipass.providers.saml:SAMLIdentityProvider - shibboleth = flask_multipass.providers.shibboleth:ShibbolethIdentityProvider - static = flask_multipass.providers.static:StaticIdentityProvider diff --git a/setup.py b/setup.py deleted file mode 100644 index bae42f0..0000000 --- a/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -# This file is part of Flask-Multipass. -# Copyright (C) 2015 - 2021 CERN -# -# Flask-Multipass is free software; you can redistribute it -# and/or modify it under the terms of the Revised BSD License. - -from setuptools import setup - - -setup() diff --git a/tox.ini b/tox.ini index de0b939..014e161 100644 --- a/tox.ini +++ b/tox.ini @@ -15,4 +15,4 @@ extras = [testenv:style] skip_install = true deps = flake8 -commands = flake8 setup.py example flask_multipass +commands = flake8 example flask_multipass