From 15eafeb80a665f454b087d2079deeea6fae34e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 14 Apr 2023 16:40:01 +0200 Subject: [PATCH] build: Migrate from setup.py to pyproject.toml Using `setup.py` is deprecated and the new recommanded way is to declare a `pyproject.toml` file (see PEP 517 [^1]). This commit proposes to use setuptools to achieve that, because setuptools is already used by yamllint, is standard and referenced by the official Python packaging documentation [^2], and seems to be the most lightweight solution. An alternative could have been to use Poetry, see the dedicated pull request and discussion [^3]. For some period, the `setup.py` file will be kept (although almost empty), to allow old tools versions to keep working. Closes https://github.com/adrienverge/yamllint/issues/509. [^1]: https://peps.python.org/pep-0517/ [^2]: https://packaging.python.org/en/latest/tutorials/installing-packages/ [^3]: https://github.com/adrienverge/yamllint/pull/557 --- .flake8 | 4 +++ .github/workflows/ci.yaml | 11 +++---- MANIFEST.in | 4 --- docs/quickstart.rst | 2 +- pyproject.toml | 54 +++++++++++++++++++++++++++++++++ setup.cfg | 63 --------------------------------------- setup.py | 15 ++-------- 7 files changed, 68 insertions(+), 85 deletions(-) create mode 100644 .flake8 delete mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 setup.cfg diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..2b7958b8 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +import-order-style = pep8 +application-import-names = yamllint +ignore = W503,W504 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1f0b62d7..8c1b616e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,9 +21,8 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 - run: - python -m pip install flake8 flake8-import-order sphinx - rstcheck[sphinx] doc8 - - run: python -m pip install . + pip install flake8 flake8-import-order sphinx rstcheck[sphinx] doc8 + - run: pip install . - run: flake8 . - run: doc8 $(git ls-files '*.rst') - run: rstcheck --ignore-directives automodule $(git ls-files '*.rst') @@ -53,8 +52,10 @@ jobs: python-version: ${{ matrix.python-version }} - name: Append GitHub Actions system path run: echo "$HOME/.local/bin" >> $GITHUB_PATH - - run: pip install coveralls + - run: pip install coverage - run: pip install . - - run: coverage run --source=yamllint -m unittest discover + # https://github.com/AndreMiras/coveralls-python-action/issues/18 + - run: echo -e "[run]\nrelative_files = True" > .coveragerc + - run: coverage run -m unittest discover - name: Coveralls uses: AndreMiras/coveralls-python-action@develop diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 792a6720..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,4 +0,0 @@ -include LICENSE -include README.rst -include docs/* -include tests/*.py tests/rules/*.py tests/yaml-1.2-spec-examples/* diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 1502084c..9828dd62 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -45,7 +45,7 @@ If you prefer installing from source, you can run, from the source directory: .. code:: bash - python setup.py sdist + python -m build pip install --user dist/yamllint-*.tar.gz Running yamllint diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..7851dd76 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +[project] +name = "yamllint" +description = "A linter for YAML files." +readme = {file = "README.rst", content-type = "text/x-rst"} +requires-python = ">=3.7" +license = {text = "GPL-3.0-only"} +authors = [{name = "Adrien Vergé"}] +keywords = ["yaml", "lint", "linter", "syntax", "checker"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Programming Language :: Python", + "Topic :: Software Development", + "Topic :: Software Development :: Debuggers", + "Topic :: Software Development :: Quality Assurance", + "Topic :: Software Development :: Testing", +] +dependencies = [ + "pathspec >= 0.5.3", + "pyyaml", +] +dynamic = ["version"] + +[project.optional-dependencies] +dev = [ + "doc8", + "flake8", + "flake8-import-order", + "rstcheck[sphinx]", + "sphinx", +] + +[project.scripts] +yamllint = "yamllint.cli:run" + +[project.urls] +homepage = "https://github.com/adrienverge/yamllint" +repository = "https://github.com/adrienverge/yamllint" +documentation = "https://yamllint.readthedocs.io" + +[build-system] +build-backend = "setuptools.build_meta" +requires = ["setuptools >= 61"] + +[tool.setuptools] +packages = ["yamllint", "yamllint.conf", "yamllint.rules"] + +[tool.setuptools.package-data] +yamllint = ["conf/*.yaml"] + +[tool.setuptools.dynamic] +version = {attr = "yamllint.__version__"} diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 501fc04a..00000000 --- a/setup.cfg +++ /dev/null @@ -1,63 +0,0 @@ -[flake8] -import-order-style = pep8 -application-import-names = yamllint -ignore = W503,W504 - -[metadata] -keywords = - yaml - lint - linter - syntax - checker - -url = https://github.com/adrienverge/yamllint -classifiers = - Development Status :: 5 - Production/Stable - Environment :: Console - Intended Audience :: Developers - License :: OSI Approved :: GNU General Public License v3 (GPLv3) - Programming Language :: Python :: 3 - 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 - Topic :: Software Development - Topic :: Software Development :: Debuggers - Topic :: Software Development :: Quality Assurance - Topic :: Software Development :: Testing - -project_urls = - Documentation = https://yamllint.readthedocs.io - Download = https://pypi.org/project/yamllint/#files - Bug Tracker = https://github.com/adrienverge/yamllint/issues - Source Code = https://github.com/adrienverge/yamllint - -[options] -packages = find: - -python_requires = >=3.7 - -include_package_data = True -install_requires = - pathspec >= 0.5.3 - pyyaml - setuptools - -test_suite = tests - -[options.packages.find] -exclude = - tests - tests.* - -[options.package_data] -yamllint = conf/*.yaml - -[options.entry_points] -console_scripts = - yamllint = yamllint.cli:run - -[coverage:run] -relative_files = True diff --git a/setup.py b/setup.py index 25e04229..ca785969 100644 --- a/setup.py +++ b/setup.py @@ -15,15 +15,6 @@ from setuptools import setup -from yamllint import (__author__, __license__, - APP_NAME, APP_VERSION, APP_DESCRIPTION) - - -setup( - name=APP_NAME, - version=APP_VERSION, - author=__author__, - description=APP_DESCRIPTION.split('\n')[0], - long_description=APP_DESCRIPTION, - license=__license__, -) +# This is only kept for backward-compatibility with older versions that don't +# support new packaging standards (e.g. PEP 517 or PEP 660): +setup()