From fd7f947de8f7d2be66b3cbe004b139bb3e30aede Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Fri, 15 Nov 2024 17:04:43 -0500 Subject: [PATCH 1/7] build: migrate setup.py to pyproject.toml --- pyproject.toml | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 3c7c70aaa..9c003ebfb 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.35", + "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"] From c8fc0dfd01afadc222e612fa3437b03852f0573c Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Fri, 15 Nov 2024 17:09:46 -0500 Subject: [PATCH 2/7] 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 9c003ebfb..17749213b 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 7b504630b34adb9f5490e6624b5b3c47609ad71f Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Fri, 15 Nov 2024 17:15:42 -0500 Subject: [PATCH 3/7] build: non-uv ci compatibility --- pyproject.toml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 17749213b..d92720c9a 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 11a484edd598b7e53c6bb75f6804547ebe7d3296 Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Fri, 15 Nov 2024 17:46:10 -0500 Subject: [PATCH 4/7] fix: doc builds --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d92720c9a..341f49a71 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 From 42c9522d03d8546e9c60aa0dc1169c3883682e75 Mon Sep 17 00:00:00 2001 From: Sergio Schvezov Date: Mon, 25 Nov 2024 17:06:10 -0300 Subject: [PATCH 5/7] Update pyproject.toml --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 341f49a71..9f822fbbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -149,6 +149,7 @@ requires = [ build-backend = "setuptools.build_meta" [tool.setuptools.package-dir] +"craft_parts" = "craft_parts" "craft_parts_docs" = "docs/common" From 7be57c966b4d669da5bf5056a30b0362149017a1 Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Mon, 9 Dec 2024 09:21:28 -0500 Subject: [PATCH 6/7] fix: remove bumpversion --- .bumpversion.cfg | 12 ------------ craft_parts/__init__.py | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index f4b312956..000000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,12 +0,0 @@ -[bumpversion] -current_version = 2.1.4 -commit = True -tag = True - -[bumpversion:file:setup.py] -search = VERSION = "{current_version}" -replace = VERSION = "{new_version}" - -[bumpversion:file:craft_parts/__init__.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" diff --git a/craft_parts/__init__.py b/craft_parts/__init__.py index cf1a6852a..ec505aaa2 100644 --- a/craft_parts/__init__.py +++ b/craft_parts/__init__.py @@ -16,8 +16,6 @@ """Craft a project from several parts.""" -__version__ = "2.1.4" - from . import plugins from .actions import Action, ActionProperties, ActionType from .dirs import ProjectDirs @@ -35,7 +33,20 @@ ) from .steps import Step + +try: + from ._version import __version__ +except ImportError: # pragma: no cover + from importlib.metadata import version, PackageNotFoundError + + try: + __version__ = version("craft_parts") + except PackageNotFoundError: + __version__ = "dev" + + __all__ = [ + "__version__", "Features", "Action", "ActionProperties", From 43c3b413cdffd5d11d0388f6950041cda94c3b8a Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Mon, 9 Dec 2024 09:27:41 -0500 Subject: [PATCH 7/7] fix: re-remove setup.py after rebase --- setup.py | 152 ------------------------------------------------------- 1 file changed, 152 deletions(-) delete mode 100644 setup.py diff --git a/setup.py b/setup.py deleted file mode 100644 index 1fa86918c..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.4" - -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, -)