From 4354a045480a72cc2ae8c8b01495b0c8b1307b17 Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Sat, 25 Nov 2023 12:27:11 +0100 Subject: [PATCH] Changes to use pyproject.toml --- .github/workflows/test_docker.yml | 5 +- .github/workflows/test_tox.yml | 12 +- pyproject.toml | 3 + requirements.txt | 1 - setup.cfg | 40 +++++- setup.py | 205 +----------------------------- tox.ini | 47 ++++--- 7 files changed, 77 insertions(+), 236 deletions(-) create mode 100644 pyproject.toml diff --git a/.github/workflows/test_docker.yml b/.github/workflows/test_docker.yml index fa60dbe..b365c03 100644 --- a/.github/workflows/test_docker.yml +++ b/.github/workflows/test_docker.yml @@ -58,7 +58,7 @@ jobs: run: | add-apt-repository -y ppa:gift/dev apt-get update -q - apt-get install -y build-essential python3 python3-dev python3-distutils python3-setuptools + apt-get install -y build-essential python3 python3-dev python3-distutils python3-pip python3-setuptools python3-wheel - name: Run tests env: LANG: en_US.UTF-8 @@ -69,6 +69,9 @@ jobs: LANG: en_US.UTF-8 run: | if test -f tests/end-to-end.py; then PYTHONPATH=. python3 ./tests/end-to-end.py --debug -c config/end-to-end.ini; fi + - name: Update setuptools + run: | + python3 -m pip install -U setuptools - name: Build source distribution run: | python3 ./setup.py sdist diff --git a/.github/workflows/test_tox.yml b/.github/workflows/test_tox.yml index 2b08048..4f4aef6 100644 --- a/.github/workflows/test_tox.yml +++ b/.github/workflows/test_tox.yml @@ -15,15 +15,17 @@ jobs: matrix: include: - python-version: '3.7' - toxenv: 'py37' + toxenv: 'py37,wheel' - python-version: '3.8' - toxenv: 'py38' + toxenv: 'py38,wheel' - python-version: '3.9' - toxenv: 'py39' + toxenv: 'py39,wheel' - python-version: '3.10' - toxenv: 'py310' + toxenv: 'py310,wheel' - python-version: '3.11' - toxenv: 'py311' + toxenv: 'py311,wheel' + - python-version: '3.12' + toxenv: 'py312,wheel' container: image: ubuntu:22.04 steps: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9787c3b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index 292767a..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +0,0 @@ -pip >= 7.0.0 diff --git a/setup.cfg b/setup.cfg index e70fa5f..2bf5385 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,14 +1,44 @@ [metadata] -license_files = LICENSE +name = vstools +version = 20230506 +description = Visual Studio tools for the libyal projects +long_description = Visual Studio tools for the libyal projects. +url = https://github.com/libyal/vstools +maintainer = Joachim Metz +maintainer_email = joachim.metz@gmail.com +license = Apache License, Version 2.0 +license_files = + ACKNOWLEDGEMENTS + AUTHORS + LICENSE + README +classifiers = + Development Status :: 3 - Alpha + Programming Language :: Python + +[options] +install_requires = file:requirements.txt +package_dir = + vstools = vstools +packages = find: +python_requires = >=3.7 + +[options.packages.find] +exclude = + docs + tests + tests.* + utils +where = . [bdist_rpm] release = 1 packager = Joachim Metz -doc_files = AUTHORS - LICENSE - README +doc_files = + AUTHORS + LICENSE + README build_requires = python3-setuptools [bdist_wheel] universal = 1 - diff --git a/setup.py b/setup.py index 84dedff..888841c 100755 --- a/setup.py +++ b/setup.py @@ -2,208 +2,7 @@ # -*- coding: utf-8 -*- """Installation and deployment script.""" -import glob -import os -import pkg_resources -import sys +from setuptools import setup -try: - from setuptools import find_packages, setup -except ImportError: - from distutils.core import find_packages, setup -try: - from distutils.command.bdist_rpm import bdist_rpm -except ImportError: - bdist_rpm = None - -version_tuple = (sys.version_info[0], sys.version_info[1]) -if version_tuple < (3, 7): - print(f'Unsupported Python version: {sys.version:s}, version 3.7 or higher ' - f'required.') - sys.exit(1) - -# Change PYTHONPATH to include vstools so that we can get the version. -sys.path.insert(0, '.') - -import vstools # pylint: disable=wrong-import-position - - -if not bdist_rpm: - BdistRPMCommand = None -else: - class BdistRPMCommand(bdist_rpm): - """Custom handler for the bdist_rpm command.""" - - # pylint: disable=invalid-name - def _make_spec_file(self): - """Generates the text of an RPM spec file. - - Returns: - list[str]: lines of the RPM spec file. - """ - # Note that bdist_rpm can be an old style class. - if issubclass(BdistRPMCommand, object): - spec_file = super(BdistRPMCommand, self)._make_spec_file() - else: - spec_file = bdist_rpm._make_spec_file(self) - - python_package = 'python3' - - description = [] - requires = '' - summary = '' - in_description = False - - python_spec_file = [] - for line in iter(spec_file): - if line.startswith('Summary: '): - summary = line[9:] - - elif line.startswith('BuildRequires: '): - line = (f'BuildRequires: {python_package:s}-setuptools, ' - f'{python_package:s}-devel') - - elif line.startswith('Requires: '): - requires = line[10:] - continue - - elif line.startswith('%description'): - in_description = True - - elif line.startswith('python setup.py build'): - if python_package == 'python3': - line = '%py3_build' - else: - line = '%py2_build' - - elif line.startswith('python setup.py install'): - if python_package == 'python3': - line = '%py3_install' - else: - line = '%py2_install' - - elif line.startswith('%files'): - lines = [ - f'%files -n {python_package:s}-%{{name}}', - '%defattr(644,root,root,755)', - '%license LICENSE', - '%doc ACKNOWLEDGEMENTS AUTHORS README'] - - lines.extend([ - '%{python3_sitelib}/vstools/*.py', - '%{python3_sitelib}/vstools*.egg-info/*', - '', - '%exclude %{_prefix}/share/doc/*', - '%exclude %{python3_sitelib}/vstools/__pycache__/*', - '%exclude %{_bindir}/*.py']) - - python_spec_file.extend(lines) - break - - elif line.startswith('%prep'): - in_description = False - - python_spec_file.append(f'%package -n {python_package:s}-%{{name}}') - python_summary = f'Python 3 module of {summary:s}' - - python_spec_file.extend([ - f'Requires: {requires:s}', - f'Summary: {python_summary:s}', - '', - f'%description -n {python_package:s}-%{{name}}']) - - python_spec_file.extend(description) - - python_spec_file.extend([ - '%package -n %{name}-tools', - f'Requires: {python_package:s}-vstools >= %{{version}}', - f'Summary: Tools for {summary:s}', - '', - '%description -n %{name}-tools']) - - python_spec_file.extend(description) - - elif in_description: - # Ignore leading white lines in the description. - if not description and not line: - continue - - description.append(line) - - python_spec_file.append(line) - - python_spec_file.extend([ - '', - '%files -n %{name}-tools', - '%{_bindir}/*.py']) - - return python_spec_file - - -def parse_requirements_from_file(path): - """Parses requirements from a requirements file. - - Args: - path (str): path to the requirements file. - - Returns: - list[str]: name and optional version information of the required packages. - """ - requirements = [] - if os.path.isfile(path): - with open(path, 'r') as file_object: - file_contents = file_object.read() - - for requirement in pkg_resources.parse_requirements(file_contents): - try: - name = str(requirement.req) - except AttributeError: - name = str(requirement) - - if not name.startswith('pip '): - requirements.append(name) - - return requirements - - -vstools_description = ( - 'Visual Studio tools for the libyal projects') - -vstools_long_description = ( - 'Visual Studio tools for the libyal projects.') - -command_classes = {} -if BdistRPMCommand: - command_classes['bdist_rpm'] = BdistRPMCommand - -setup( - name='vstools', - version=vstools.__version__, - description=vstools_description, - long_description=vstools_long_description, - long_description_content_type='text/plain', - license='Apache License, Version 2.0', - url='https://github.com/libyal/vstools', - maintainer='Joachim Metz', - maintainer_email='joachim.metz@gmail.com', - cmdclass=command_classes, - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Environment :: Console', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - ], - packages=find_packages('.', exclude=[ - 'scripts', 'tests', 'tests.*', 'utils']), - package_dir={ - 'vstools': 'vstools' - }, - scripts=glob.glob(os.path.join('scripts', '[a-z]*.py')), - data_files=[ - ('share/doc/vstools', [ - 'AUTHORS', 'LICENSE', 'README']), - ], - install_requires=parse_requirements_from_file('requirements.txt'), - tests_require=parse_requirements_from_file('test_requirements.txt'), -) +setup() diff --git a/tox.ini b/tox.ini index 26e9c05..f3a2486 100644 --- a/tox.ini +++ b/tox.ini @@ -1,38 +1,43 @@ [tox] -envlist = py3{7,8,9,10,11},coverage,lint +envlist = py3{7,8,9,10,11,12},coverage,lint,wheel [testenv] allowlist_externals = ./run_tests.py pip_pre = True passenv = - CFLAGS - CPPFLAGS - LDFLAGS + CFLAGS + CPPFLAGS + LDFLAGS setenv = - PYTHONPATH = {toxinidir} + PYTHONPATH = {toxinidir} deps = - -rrequirements.txt - -rtest_requirements.txt - coverage: coverage + -rrequirements.txt + -rtest_requirements.txt + coverage: coverage + wheel: + build + setuptools >= 65 + wheel commands = - py3{7,8,9,10,11}: ./run_tests.py - coverage: coverage erase - coverage: coverage run --source=vstools --omit="*_test*,*__init__*,*test_lib*" run_tests.py - coverage: coverage xml + py3{7,8,9,10,11,12}: ./run_tests.py + coverage: coverage erase + coverage: coverage run --source=vstools --omit="*_test*,*__init__*,*test_lib*" run_tests.py + coverage: coverage xml + wheel: python -m build --no-isolation --wheel [testenv:lint] skipsdist = True pip_pre = True passenv = - CFLAGS - CPPFLAGS - LDFLAGS + CFLAGS + CPPFLAGS + LDFLAGS setenv = - PYTHONPATH = {toxinidir} + PYTHONPATH = {toxinidir} deps = - -rrequirements.txt - -rtest_requirements.txt - pylint >= 2.17.0, < 2.18.0 + -rrequirements.txt + -rtest_requirements.txt + pylint >= 2.17.0, < 2.18.0 commands = - pylint --version - pylint --rcfile=.pylintrc scripts tests vstools + pylint --version + pylint --rcfile=.pylintrc scripts setup.py tests vstools