From 2eb34c537bb91f2d94c20c7b2901479858bb114d Mon Sep 17 00:00:00 2001 From: mirai-mjelavic Date: Tue, 19 Dec 2023 15:54:27 +0100 Subject: [PATCH 1/4] Initial commit for switching to pyproject.toml, expecting build failure --- pyproject.toml | 56 ++++++++++++++++++++ secretsanta/__init__.py | 1 - setup.py | 114 ---------------------------------------- tox.ini | 9 ---- 4 files changed, 56 insertions(+), 124 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d395497 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,56 @@ +[build-system] +requires = ["setuptools", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[project] +name = "secretsanta" +description = "Secret Santa randomizer" +readme = "README.md" +authors = [ + { name = "Mirai Solutions", email = "opensource@mirai-solutions.com" }, +] +urls = { Homepage = "https://github.com/miraisolutions/secretsanta" } +classifiers = [ + 'Development Status :: 4 - Beta', + 'License :: OSI Approved :: MIT License', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python :: 3 :: Only', + 'Topic :: Games/Entertainment', +] +license = { text = "MIT" } +version = "0.1.0" +keywords = ["secret", "santa"] + +[project.scripts] +santa = "secretsanta.cli.cli:santa" + +[tool.setuptools.packages.find] +include = ["secretsanta"] + +[tool.setuptools_scm] + +[tool.coverage.html] +# Directory where coverage report should be written. +directory = "coverage" + +[tool.coverage.report] +# Show which lines were missed in summary report. +show_missing = true + +[tool.coverage.run] +# Measure branch coverage in addition to statement coverage. +branch = true +# The source directory to measure. This is already in 'tox.ini'. +#source = secretsanta + +[tool.pytest.ini_options] +norecursedirs = [ + "bin", + "include", + "lib", + "lib64", + "share", + ".tox", + ".git", + "docs" +] \ No newline at end of file diff --git a/secretsanta/__init__.py b/secretsanta/__init__.py index b794fd4..e69de29 100644 --- a/secretsanta/__init__.py +++ b/secretsanta/__init__.py @@ -1 +0,0 @@ -__version__ = '0.1.0' diff --git a/setup.py b/setup.py deleted file mode 100644 index 0704790..0000000 --- a/setup.py +++ /dev/null @@ -1,114 +0,0 @@ -import os -import re -import glob -import sys -import shutil - -from pathlib import Path -from setuptools import setup, find_packages, Command - -PROJ_DIR = Path(__file__).parent.resolve() - -PKG_NAME = 'secretsanta' - -# distutils should not be depended on anymore, as it will be deprecated soon -DISTUTILS_LOG_LEVELS = {'WARN': 3, 'ERROR': 4} - - -def get_readme(): - with open(PROJ_DIR / 'README.md', encoding='utf-8') as fh: - return fh.read() - - -def get_install_requirements(): - with open(PROJ_DIR / 'requirements-package.in', encoding='utf-8') as fh: - return fh.readlines() - - -def get_version(): - """ - Return package version as listed in `__version__` in `init.py`. - """ - with open(PROJ_DIR / PKG_NAME / '__init__.py', encoding='utf-8') as fh: - return re.search('__version__ = [\'"]([^\'"]+)[\'"]', fh.read()).group(1) - - -class Publish(Command): - command_name = 'publish' - user_options = [ - ('wheel', None, 'Publish the wheel'), - ('sdist', None, 'Publish the sdist tar'), - ('no-clean', None, 'Don\'t clean the build artifacts'), - ('sign', None, 'Sign the artifacts using GPG') - ] - boolean_options = ['wheel', 'sdist'] - - def initialize_options(self): - self.wheel = False - self.sdist = False - self.no_clean = False - self.sign = False - - def finalize_options(self): - if not (self.wheel or self.sdist): - self.announce('Either --wheel and/or --sdist must be provided', DISTUTILS_LOG_LEVELS["ERROR"]) - sys.exit(1) - - def run(self): - if os.system('pip freeze | grep twine'): - self.announce('twine not installed.\nUse `pip install twine`.\nExiting.', DISTUTILS_LOG_LEVELS["WARN"]) - sys.exit(1) - - if self.sdist: - os.system('python setup.py sdist') - - if self.wheel: - os.system('python setup.py bdist_wheel') - - if self.sign: - for p in glob.glob('dist/*'): - os.system(f'gpg --detach-sign -a {p}') - - os.system('twine upload dist/*') - # enter credentials for PyPI when prompted - print('You probably want to also tag the version now:') - print(f' git tag -a {get_version()} -m \'version {get_version()}\'') - print(' git push --tags') - - if not self.no_clean: - shutil.rmtree('dist') - shutil.rmtree('build') - shutil.rmtree(PKG_NAME + '.egg-info') - - -# https://pypi.org/pypi?%3Aaction=list_classifiers -setup( - name=PKG_NAME, - version=get_version(), - entry_points={ - 'console_scripts': [ - 'santa=secretsanta.cli.cli:santa', - ], - }, - description='Secret Santa randomizer', - long_description=get_readme(), - long_description_content_type='text/markdown', - classifiers=[ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: MIT License', - 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python :: 3 :: Only', - 'Topic :: Games/Entertainment', - ], - keywords='secret santa', - url='https://github.com/miraisolutions/secretsanta', - author='Mirai Solutions', - author_email='opensource@mirai-solutions.com', - license='MIT', - packages=find_packages(exclude=('tests', 'tests.*', 'tests.*.*')), - install_requires=get_install_requirements(), - zip_safe=False, - cmdclass={ - 'publish': Publish, - }, -) diff --git a/tox.ini b/tox.ini index 385ab94..9b04608 100644 --- a/tox.ini +++ b/tox.ini @@ -16,15 +16,6 @@ setenv = COV_CORE_CONFIG={toxinidir}/.coveragerc COVERAGE_FILE={toxinidir}/.coverage.{envname} -[pytest] -# this could also be inside setup.cfg, but then the section must be named [tool:pytest] -# https://docs.pytest.org/en/latest/example/pythoncollection.html -# don't look for tests inside these directories: -norecursedirs = bin include lib lib64 share .tox .git docs -#addopts = --cov=secretsanta --cov-report html -# Note a warning like "PytestWarning: Module already imported so cannot be rewritten: pytest_cov" is expected: -# https://github.com/pytest-dev/pytest-cov/issues/148 - [flake8] # ignore lines longer than 79 chars ignore = E501 From 3a226901d4b3a5580372ee6571c09b69e0a402de Mon Sep 17 00:00:00 2001 From: Marko Jelavic Date: Thu, 11 Jan 2024 13:46:10 +0100 Subject: [PATCH 2/4] Changing publish github action to reflext removal of setup.py and usage of pyproject.toml --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 610087f..4e03085 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,11 +16,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install build twine - name: Build and publish env: TWINE_USERNAME: ${{ secrets.PYPI_USER }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - python setup.py sdist bdist_wheel + python3 -m build twine upload dist/* From 7427d033efe5a45724e0b4a992d582af3c54ad6a Mon Sep 17 00:00:00 2001 From: Marko Jelavic Date: Thu, 18 Jan 2024 14:52:14 +0100 Subject: [PATCH 3/4] Reflecting the removal of setup.py in README as well --- README.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a46ae58..f34f9d8 100644 --- a/README.md +++ b/README.md @@ -348,23 +348,19 @@ If you install the package, you can use the CLI tool as designed for the end use ```bash python -m pip install --upgrade pip -pip install --upgrade setuptools wheel +pip install --upgrade build -python setup.py sdist bdist_wheel # creates build and dist directories +python -m build # creates build and dist directories # Windows: -pip install .\dist\secretsanta-0.1.0-py3-none-any.whl -e +pip install .\dist\secretsanta-0.1.0-py3-none-any.whl # if already installed, use below to force re-installation: -pip install --force-reinstall .\dist\secretsanta-0.1.0-py3-none-any.whl -e +pip install --force-reinstall .\dist\secretsanta-0.1.0-py3-none-any.whl # Ubuntu: -pip install ./dist/secretsanta-0.1.0.tar.gz -e +pip install ./dist/secretsanta-0.1.0.tar.gz # if already installed, use below to force re-installation: -pip install --force-reinstall ./dist/secretsanta-0.1.0.tar.gz -e - -# Note the `-e` flag which stands for "editable mode" and will install the -# package in the repository, which means that one can adjust the code -# and test the updated command line without having to re-install. +pip install --force-reinstall ./dist/secretsanta-0.1.0.tar.gz # now you can use the CLI tool properly as below: santa --help From 77307e7bc8d7404250844afdec3f262ec49e8471 Mon Sep 17 00:00:00 2001 From: Marko Jelavic Date: Tue, 23 Jan 2024 13:50:14 +0100 Subject: [PATCH 4/4] Bumping version in pyproject.toml to a dev one --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d395497..ad65cb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ classifiers = [ 'Topic :: Games/Entertainment', ] license = { text = "MIT" } -version = "0.1.0" +version = "0.1.dev1" keywords = ["secret", "santa"] [project.scripts]