From 9e0f04ec4f54628247c931b4ced098d8d0e046b3 Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Fri, 15 Nov 2024 17:04:43 -0500 Subject: [PATCH 1/4] build: migrate setup.py to pyproject.toml --- pyproject.toml | 134 +++++++++++++++++++++++++++++++++++++++++++ setup.py | 152 ------------------------------------------------- 2 files changed, 134 insertions(+), 152 deletions(-) delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml index 62669ad88..6877bdafb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,137 @@ +[project] +name = "craft-parts" +dynamic = ["version"] +description = "Craft parts tooling" +readme = "README.md" +requires-python = ">=3.10" +authors = [ + { name = "Canonical Ltd.", email = "snapcraft@lists.snapcraft.io" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", + "Natural Language :: English", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] +dependencies = [ + "overrides!=7.6.0", + "pydantic>=2.0.0", + "pyxdg", + "PyYAML", + "requests-unixsocket2>=0.4.0", + "requests>=2.32,<3.0", +] + +[project.optional-dependencies] +apt = [ + "python-apt>=2.4.0;sys_platform=='linux'" +] +docs = [ + "sphinx", + "sphinx-autodoc-typehints", + "sphinx-lint", + "sphinx-pydantic", + "sphinx-rtd-theme", + "sphinxcontrib-details-directive==0.1.0", +] + +[tool.uv] +constraint-dependencies = [ + # Basic constraints to allow --resolution=lowest + "build>=0.7.0", + "iniconfig>=1.1.0", + "lxml>=5.0", + "pyparsing>=3.0.0", + "pyproject-hooks>=1.0.0", + "pyyaml>=5.0", + "markdown>=3.0", + "markupsafe>=2.0", + "pyyaml>5.0", + "regex>=2021.11.10", + "sphinx-basic-ng>=1.0.0b1", + "tornado>=4.0", + "webencodings>=0.4.0", +] +dev-dependencies = [ + # Inherited from starbase + "build", + "coverage[toml]~=7.4", + "pytest~=8.0", + "pytest-cov~=5.0", + "pytest-mock~=3.12", + "yamllint~=1.34", + "mypy[reports]~=1.11.0", + "pyright==1.1.388", + "types-Pygments", + "types-colorama", + "types-setuptools", + + # Project-specific linting + "autoflake", + "black", + "codespell", + "pydocstyle", + + # Testing + "hypothesis", + "jsonschema", + "pytest-check", + "pytest-subprocess", + "requests-mock", + + # Type checking + "types-colorama", + "types-docutils", + "types-jsonschema", + "types-Pillow", + "types-Pygments", + "types-pytz", + "types-PyYAML", + "types-requests", + "types-setuptools", +] + + +[project.scripts] +craftctl = "craft_parts.ctl:main" + +[project.urls] +Homepage = "https://github.com/canonical/craft-parts" + +[build-system] +requires = [ + "setuptools>=69.0", + "setuptools_scm[toml]>=7.1" +] +build-backend = "setuptools.build_meta" + +[tool.setuptools.package-dir] +"craft_parts_docs" = "docs/common" + + +[tool.setuptools.dynamic] +readme = {file = "README.rst"} + +[tool.setuptools_scm] +write_to = "craft_parts/_version.py" +# the version comes from the latest annotated git tag formatted as 'X.Y.Z' +# version scheme: +# - X.Y.Z.post+g.d<%Y%m%d> +# parts of scheme: +# - X.Y.Z - most recent git tag +# - post+g - present when current commit is not tagged +# - .d<%Y%m%d> - present when working dir is dirty +# version scheme when no tags exist: +# - 0.0.post+g +version_scheme = "post-release" +# deviations from the default 'git describe' command: +# - only match annotated tags +# - only match tags formatted as 'X.Y.Z' +git_describe_command = "git describe --dirty --long --match '[0-9]*.[0-9]*.[0-9]*' --exclude '*[^0-9.]*'" + [tool.black] target-version = ["py310"] diff --git a/setup.py b/setup.py deleted file mode 100644 index cd4de414d..000000000 --- a/setup.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2021-2022 Canonical Ltd. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License version 3 as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program. If not, see . - -"""The setup script.""" - -import os -import re - -from setuptools import find_packages, setup - -VERSION = "2.1.2" - -with open("README.md") as readme_file: - readme = readme_file.read() - - -def is_ubuntu() -> bool: - """Verify if running on Ubuntu.""" - try: - with open("/etc/os-release") as release_file: - os_release = release_file.read() - if re.search(r"^ID(?:_LIKE)?=.*\bubuntu\b.*$", os_release, re.MULTILINE): - return True - except FileNotFoundError: - return False - else: - return False - - -def is_rtd() -> bool: - """Verify if running on ReadTheDocs.""" - return "READTHEDOCS" in os.environ - - -install_requires = [ - # see https://github.com/mkorpela/overrides/issues/121 - "overrides!=7.6.0", - "PyYAML", - "pydantic>=2.0.0", - "pyxdg", - "requests>=2.32,<3.0", - "requests-unixsocket2>=0.4.0", -] - -dev_requires = [ - "autoflake", - "twine", -] - -docs_require = [ - "sphinx", - "sphinx-autodoc-typehints", - "sphinx-lint", - "sphinx-pydantic", - "sphinx-rtd-theme", - "sphinxcontrib-details-directive==0.1.0", -] - -types_requires = [ - "mypy[reports]>=1.4.1,<2.0", - "types-colorama", - "types-docutils", - "types-jsonschema", - "types-Pillow", - "types-Pygments", - "types-pytz", - "types-PyYAML", - "types-requests", - "types-setuptools", -] - -test_requires = [ - "black", - "codespell", - "coverage", - "hypothesis", - "jsonschema", - "pydocstyle", - "pyright==1.1.385", - "pytest", - "pytest-check", - "pytest-cov", - "pytest-mock", - "pytest-subprocess", - "requests-mock", - "tox", - "yamllint==1.35.1", -] - -extras_requires = { - "dev": dev_requires + docs_require + test_requires + types_requires, - "docs": docs_require, - "test": test_requires + types_requires, - "types": types_requires, - # Generic "apt" extra for handling any apt-based platforms (e.g. Debian, Ubuntu) - "apt": ["python-apt>=2.0.0"], -} - - -setup( - name="craft-parts", - version=VERSION, - description="Craft parts tooling", - long_description=readme, - long_description_content_type="text/markdown", - author="Canonical Ltd.", - author_email="snapcraft@lists.snapcraft.io", - url="https://github.com/canonical/craft-parts", - license="GNU General Public License v3", - python_requires=">=3.10", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", - "Natural Language :: English", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - ], - entry_points={ - "console_scripts": [ - "craftctl=craft_parts.ctl:main", - ], - }, - install_requires=install_requires, - extras_require=extras_requires, - packages=[ - *find_packages(include=["craft_parts", "craft_parts.*"]), - "craft_parts_docs", - ], - # todo: can we make the docs optional? - package_dir={"craft_parts_docs": "docs/common"}, - package_data={ - "craft_parts": ["py.typed"], - "craft_parts_docs": ["**"], - }, - include_package_data=True, - zip_safe=False, -) From 5154f19b6a7554bd7bdb2f6e89b507593080d526 Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Fri, 15 Nov 2024 17:09:46 -0500 Subject: [PATCH 2/4] build: move setup.cfg to pyproject.toml --- pyproject.toml | 12 +++++++++++- setup.cfg | 20 -------------------- 2 files changed, 11 insertions(+), 21 deletions(-) delete mode 100644 setup.cfg diff --git a/pyproject.toml b/pyproject.toml index 6877bdafb..53c95ff20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -141,7 +141,6 @@ skip = ".tox,.git,build,.*_cache,__pycache__,*.tar,*.snap,*.png,./node_modules,. quiet-level = 3 check-filenames = true - [tool.mypy] python_version = "3.10" exclude = [ @@ -171,6 +170,17 @@ no_implicit_optional = true module = ["tests.*"] strict = false +[tool.pydocstyle] +ignore = [ + "D105", # Missing docstring in magic method (reason: magic methods already have definitions) + "D107", # Missing docstring in __init__ (reason: documented in class docstring) + "D203", # 1 blank line required before class docstring (reason: pep257 default) + "D204", + "D213", # Multi-line docstring summary should start at the second line (reason: pep257 default) + "D215", # Section underline is over-indented (reason: pep257 default) +] + + [tool.ruff] line-length = 88 target-version = "py310" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c881bfb25..000000000 --- a/setup.cfg +++ /dev/null @@ -1,20 +0,0 @@ -[bdist_wheel] -universal = 0 - -[flake8] -exclude = docs venv .venv .mypy_cache .direnv .git __pycache__ -max-line-length = 88 -# E203 whitespace before ':' -# E501 line too long -extend-ignore = E203, E501 - -[pydocstyle] -# D105 Missing docstring in magic method (reason: magic methods already have definitions) -# D107 Missing docstring in __init__ (reason: documented in class docstring) -# D203 1 blank line required before class docstring (reason: pep257 default) -# D213 Multi-line docstring summary should start at the second line (reason: pep257 default) -# D215 Section underline is over-indented (reason: pep257 default) -ignore = D105, D107, D203, D204, D213, D215 - -[aliases] -test = pytest From 88920a124a312d3a81d84c788415ef1eb855657a Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Fri, 15 Nov 2024 17:15:42 -0500 Subject: [PATCH 3/4] build: non-uv ci compatibility --- pyproject.toml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 53c95ff20..3820609fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,45 @@ docs = [ "sphinx-rtd-theme", "sphinxcontrib-details-directive==0.1.0", ] +dev = [ # TODO: Remove this once we've switched CI to uv + # Inherited from starbase + "build", + "coverage[toml]~=7.4", + "pytest~=8.0", + "pytest-cov~=5.0", + "pytest-mock~=3.12", + "yamllint~=1.34", + "mypy[reports]~=1.11.0", + "pyright==1.1.388", + "types-Pygments", + "types-colorama", + "types-setuptools", + + # Project-specific linting + "autoflake", + "black", + "codespell", + "pydocstyle", + "tox", + + # Testing + "hypothesis", + "jsonschema", + "pytest-check", + "pytest-subprocess", + "requests-mock", + + # Type checking + "types-colorama", + "types-docutils", + "types-jsonschema", + "types-Pillow", + "types-Pygments", + "types-pytz", + "types-PyYAML", + "types-requests", + "types-setuptools", +] [tool.uv] constraint-dependencies = [ From e214035d9acd7dfbaf7431e856755fc912c0479e Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Fri, 15 Nov 2024 17:46:10 -0500 Subject: [PATCH 4/4] fix: doc builds --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3820609fe..398a752f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,12 +30,13 @@ apt = [ "python-apt>=2.4.0;sys_platform=='linux'" ] docs = [ + "canonical-sphinx", "sphinx", "sphinx-autodoc-typehints", "sphinx-lint", "sphinx-pydantic", "sphinx-rtd-theme", - "sphinxcontrib-details-directive==0.1.0", + "sphinxcontrib-details-directive", ] dev = [ # TODO: Remove this once we've switched CI to uv # Inherited from starbase