From c399c012570c51ae806fdb5bb940d7ab1bd1c3d2 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Sat, 29 Jun 2024 12:18:13 +0530 Subject: [PATCH] project: Switch to pyproject Starting with PEP 621, `pyproject.toml` is the standard way of specifying project metadata. Also switch to using the version from `pyproject.toml` instead of having a west.version python module. Adjust documentation for the same. Update MAINTAINERS.rst to use build for dist building. Signed-off-by: Ayush Singh --- MAINTAINERS.rst | 11 ++++++---- pyproject.toml | 46 +++++++++++++++++++++++++++++++++++++++ setup.py | 53 --------------------------------------------- src/west/version.py | 4 +++- 4 files changed, 56 insertions(+), 58 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/MAINTAINERS.rst b/MAINTAINERS.rst index a79fce1a..b6877b3b 100644 --- a/MAINTAINERS.rst +++ b/MAINTAINERS.rst @@ -66,8 +66,8 @@ Pre-release test plan 7. Assuming that all went well (if it didn't, go fix it and repeat): - - update __version__ to 'X.Y.Z' (i.e. drop the 'aN' suffix that denotes - alpha N) + - update version in pyproject.toml to 'X.Y.Z' (i.e. drop the 'aN' suffix + that denotes alpha N) - tag the release on GitHub (see "Tagging the release" for a procedure) @@ -88,12 +88,15 @@ Building and uploading the release wheels You need the zephyr-project PyPI credentials for the 'twine upload' command. :: git clean -ffdx - python3 setup.py sdist bdist_wheel + pip3 install --upgrade build twine + pyproject-build twine upload -u zephyr-project dist/* The 'git clean' step is important. We've anecdotally observed broken wheels being generated from dirty repositories. +Check out [packaging.python.org](https://packaging.python.org/en/latest/tutorials/packaging-projects/#generating-distribution-archives) for more detailed instructions. + Tagging the release ------------------- @@ -158,7 +161,7 @@ Summary of what happens: 3. In vX.Y-branch, in src/west/version.py, set __version__ to X.Y.0a1. Push this to origin/vX.Y-branch. You don't need a PR for this. -4. In the main branch, set __version__ to X.Y.99. +4. In the main branch, set version in pyproject.toml to X.Y.99. Push this to origin/main. You don't need a PR for this. 5. Create an annotated tag vX.Y.99 which points to the main branch commit you diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..03a2053c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,46 @@ +[build-system] +requires = ["setuptools>=61.2"] +build-backend = "setuptools.build_meta" + +[project] +name = "west" +version = "1.2.99" +authors = [{name = "Zephyr Project", email = "devel@lists.zephyrproject.org"}] +description = "Zephyr RTOS Project meta-tool" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache Software License", + "Operating System :: POSIX :: Linux", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", +] +requires-python = ">=3.8" +dependencies = [ + "colorama", + "PyYAML>=5.1", + "pykwalify", + "setuptools", + "packaging", +] + +[project.license] +file = "LICENSE" + +[project.readme] +file = "README.rst" +content-type = "text/x-rst" + +[project.urls] +Homepage = "https://github.com/zephyrproject-rtos/west" + +[project.scripts] +west = "west.app.main:main" + +[tool.setuptools] +package-dir = {"" = "src"} +zip-safe = false +include-package-data = true + +[tool.setuptools.packages.find] +where = ["src"] +namespaces = false diff --git a/setup.py b/setup.py deleted file mode 100644 index 1d68190d..00000000 --- a/setup.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2018 Open Source Foundries Limited. -# Copyright (c) 2020, Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -import os - -import setuptools - -SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) -os.chdir(SCRIPT_DIR) - -with open('README.rst', 'r') as f: - long_description = f.read() - -with open('src/west/version.py', 'r') as f: - __version__ = None - exec(f.read()) - assert __version__ is not None - -version = os.environ.get('WEST_VERSION', __version__) - -setuptools.setup( - name='west', - version=version, - author='Zephyr Project', - author_email='devel@lists.zephyrproject.org', - description='Zephyr RTOS Project meta-tool', - long_description=long_description, - # http://docutils.sourceforge.net/FAQ.html#what-s-the-official-mime-type-for-restructuredtext-data - long_description_content_type="text/x-rst", - url='https://github.com/zephyrproject-rtos/west', - packages=setuptools.find_packages(where='src'), - package_dir={'': 'src'}, - include_package_data=True, - classifiers=[ - 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: POSIX :: Linux', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: Microsoft :: Windows', - ], - install_requires=[ - 'colorama', - 'PyYAML>=5.1', - 'pykwalify', - 'setuptools', - 'packaging', - ], - python_requires='>=3.8', - entry_points={'console_scripts': ('west = west.app.main:main',)}, - zip_safe=False -) diff --git a/src/west/version.py b/src/west/version.py index 4a167787..b6ddd081 100644 --- a/src/west/version.py +++ b/src/west/version.py @@ -5,7 +5,9 @@ # This is the Python 3 version of option 3 in: # https://packaging.python.org/guides/single-sourcing-package-version/#single-sourcing-the-version -__version__ = '1.2.99' +import importlib.metadata + +__version__ = importlib.metadata.version("west") # # MAINTAINERS: #