From 9d06be36427508f676ca1d7364084dbaea2df17d Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 6 Jul 2023 10:41:55 -0700 Subject: [PATCH] Replace setup.py with pyproject.toml (#244) --- .github/workflows/ci.yml | 22 ++++---- .gitignore | 6 +- wpiformat/{LICENSE => LICENSE.txt} | 0 wpiformat/pyproject.toml | 51 +++++++++++++++++ wpiformat/setup.cfg | 2 - wpiformat/setup.py | 89 ------------------------------ wpiformat/tox.ini | 11 ++++ wpiformat/wpiformat/version.py | 27 +++++++++ 8 files changed, 102 insertions(+), 106 deletions(-) rename wpiformat/{LICENSE => LICENSE.txt} (100%) create mode 100644 wpiformat/pyproject.toml delete mode 100644 wpiformat/setup.cfg delete mode 100644 wpiformat/setup.py create mode 100644 wpiformat/tox.ini create mode 100644 wpiformat/wpiformat/version.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5664928..8bf7b918 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,27 +25,25 @@ jobs: with: python-version: ${{ matrix.python-version }} + - name: Install Python dependencies + run: pip install build + - name: Install wpiformat run: | cd wpiformat - pip install -e . + python -m build --wheel + pip install dist/*.whl + shell: bash - name: Install test dependencies - shell: bash - run: | - if [ "$RUNNER_OS" == "Windows" ]; then - # This pytest dependency is installed manually with bash because the - # installation prints to stderr. Prints to stderr cause Powershell to - # report a nonzero return code and cause the tests to fail. - pip install wheel iniconfig - fi + run: pip install tox - name: Run unit tests run: | git config --global user.email "you@example.com" git config --global user.name "Your Name" cd wpiformat - python setup.py test + tox - name: wpiformat - whole repo run: | @@ -127,10 +125,10 @@ jobs: python-version: '3.10' - name: Install Python dependencies - run: pip install wheel + run: pip install build - name: Build package - run: python setup.py bdist_wheel + run: python -m build working-directory: wpiformat - name: Upload package to PyPi diff --git a/.gitignore b/.gitignore index 5ab844da..8e2bf757 100644 --- a/.gitignore +++ b/.gitignore @@ -137,13 +137,13 @@ local.properties .loadpath ### Python ### +*.egg-info/ .eggs/ .pytest_cache/ +.tox/ +__pycache__/ build/ dist/ -__pycache__ -*.egg-info/ -version.py # External tool builders .externalToolBuilders/ diff --git a/wpiformat/LICENSE b/wpiformat/LICENSE.txt similarity index 100% rename from wpiformat/LICENSE rename to wpiformat/LICENSE.txt diff --git a/wpiformat/pyproject.toml b/wpiformat/pyproject.toml new file mode 100644 index 00000000..303652e2 --- /dev/null +++ b/wpiformat/pyproject.toml @@ -0,0 +1,51 @@ +[project] +name = "wpiformat" +description = "Linters and formatters for ensuring WPILib's source code conforms to its style guide" +dynamic = [ "version" ] +readme = "README.rst" +dependencies = [ + "regex==2022.9.13", + "black==23.3.0", + "clang-format==16.0.4", + "clang-tidy==15.0.2.1" +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Intended Audience :: Education", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering", + "Programming Language :: Python :: 3" +] + + [project.license] + text = "BSD-3-Clause" + + [[project.maintainers]] + name = "Tyler Veness" + email = "calcmogul@gmail.com" + + [project.urls] + Homepage = "https://github.com/wpilibsuite/styleguide" + +[project.scripts] +wpiformat = "wpiformat:main" + +[build-system] +requires = [ + "clang-format==16.0.4", + "clang-tidy==15.0.2.1", + "regex==2022.9.13", + "setuptools>=61.0", + "setuptools-git-versioning" +] +build-backend = "setuptools.build_meta" + +[tool.setuptools-git-versioning] +enabled = true +version_callback = "wpiformat.version:get_version" + +[tool.pytest.ini_options] +minversion = "6.0" +testpaths = [ "wpiformat/test" ] diff --git a/wpiformat/setup.cfg b/wpiformat/setup.cfg deleted file mode 100644 index b7e47898..00000000 --- a/wpiformat/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[aliases] -test=pytest diff --git a/wpiformat/setup.py b/wpiformat/setup.py deleted file mode 100644 index 09c31be1..00000000 --- a/wpiformat/setup.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python3 - -from datetime import date -from glob import glob -from os.path import basename -from os.path import dirname -from os.path import exists -from os.path import join -from os.path import splitext -from setuptools import find_packages -from setuptools import setup -import subprocess -import sys - -setup_dir = dirname(__file__) -git_dir = join(setup_dir, "../.git") -base_package = "wpiformat" -version_file = join(setup_dir, base_package, "version.py") - -# Automatically generate a version.py based on the git version -if exists(git_dir): - proc = subprocess.run( - [ - "git", - "rev-list", - "--count", - # Includes previous year's commits in case one was merged after the - # year incremented. Otherwise, the version wouldn't increment. - '--after="main@{' + str(date.today().year - 1) + '-01-01}"', - "main", - ], - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - ) - # If there is no main branch, the commit count defaults to 0 - if proc.returncode: - commit_count = "0" - else: - commit_count = proc.stdout.decode("utf-8") - - # Version number: .<# commits on main> - version = str(date.today().year) + "." + commit_count.strip() - - # Create the version.py file - with open(version_file, "w") as fp: - fp.write('# Autogenerated by setup.py\n__version__ = "{0}"'.format(version)) - -if exists(version_file): - with open(version_file, "r") as fp: - exec(fp.read(), globals()) -else: - __version__ = "main" - -with open(join(setup_dir, "README.rst"), "r") as readme_file: - long_description = readme_file.read() - -setup( - name="wpiformat", - version=__version__, - description="Linters and formatters for ensuring WPILib's source code conforms to its style guide", - long_description=long_description, - author="WPILib", - maintainer="Tyler Veness", - maintainer_email="calcmogul@gmail.com", - url="https://github.com/wpilibsuite/styleguide", - keywords="frc first robotics wpilib", - packages=find_packages(), - include_package_data=True, - zip_safe=True, - setup_requires=["pytest-runner"], - tests_require=["pytest"], - install_requires=[ - "regex==2022.9.13", - "black==23.3.0", - "clang-format==16.0.4", - "clang-tidy==15.0.2.1", - ], - license="BSD License", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Intended Audience :: Education", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - "Topic :: Scientific/Engineering", - "Programming Language :: Python :: 3", - ], - entry_points={"console_scripts": ["wpiformat = wpiformat:main"]}, -) diff --git a/wpiformat/tox.ini b/wpiformat/tox.ini new file mode 100644 index 00000000..739abd69 --- /dev/null +++ b/wpiformat/tox.ini @@ -0,0 +1,11 @@ +[tox] +min_version = 4.0 +env_list = + py38 + py39 + py310 + py311 + +[testenv] +deps = pytest +commands = pytest diff --git a/wpiformat/wpiformat/version.py b/wpiformat/wpiformat/version.py new file mode 100644 index 00000000..6953c611 --- /dev/null +++ b/wpiformat/wpiformat/version.py @@ -0,0 +1,27 @@ +from datetime import date +import subprocess + + +def get_version(): + proc = subprocess.run( + [ + "git", + "rev-list", + "--count", + # Includes previous year's commits in case one was merged after the + # year incremented. Otherwise, the version wouldn't increment. + '--after="main@{' + str(date.today().year - 1) + '-01-01}"', + "main", + ], + check=True, + encoding="utf-8", + stdout=subprocess.PIPE, + ) + # If there is no main branch, the commit count defaults to 0 + if proc.returncode: + commit_count = "0" + else: + commit_count = proc.stdout.rstrip() + + # Version number: .<# commits on main> + return f"{date.today().year}.{commit_count}"