From b36f3e9f3eb72d38febc9e25c45699193b6f53c3 Mon Sep 17 00:00:00 2001 From: Craig Macdonald Date: Wed, 25 Sep 2024 11:44:39 +0100 Subject: [PATCH] initial pyproject.toml --- .github/workflows/publish-to-pypi.yml | 7 ++- pyproject.toml | 46 ++++++++++++++ setup.py | 89 --------------------------- 3 files changed, 51 insertions(+), 91 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 5c14416a..54bcf035 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -25,13 +25,16 @@ jobs: with: python-version: 3.8 + - name: Install build tool + run: pip install build + - name: Build a test source tarball if: github.event.inputs.releasetype == 'test' - run: PYTERRIER_VERSION_SUFFIX=".`date +%s`" python setup.py sdist + run: PYTERRIER_VERSION_SUFFIX=".`date +%s`" python setup.py sdist # TODO fix this - how to override version - name: Build a release source tarball if: github.event.inputs.releasetype == 'release' - run: python setup.py sdist + run: python -m build - name: Publish distribution 📦 to Test PyPI if: github.event.inputs.releasetype == 'test' diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..c3ff682f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,46 @@ +[build-system] +requires = ["setuptools >= 61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "python-terrier" +description="PyTerrier" +requires-python = ">=3.8" +authors = [ + {name = "Craig Macdonald", email = "craig.macdonald@glasgow.ac.uk"}, +] +maintainers = [ + {name = "Craig Macdonald", email = "craig.macdonald@glasgow.ac.uk"}, +] +readme = "README.md" +classifiers = [ + "Topic :: Text Processing", + "Topic :: Text Processing :: Indexing", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", + "Operating System :: OS Independent", +] +dynamic = ["version", "dependencies"] + +[tool.setuptools.dynamic] +version = {attr = "pyterrier.__version__"} +dependencies = {file = ["requirements.txt"]} + +#package_data={'': ['LICENSE.txt', 'requirements.txt', 'requirements-test.txt']} +#include_package_data=True + +[tool.setuptools.packages.find] +exclude = ["tests"] + +[tool.setuptools.package-data] +mypkg = ["README.md", "LICENSE.txt"] + +[project.urls] +Repository = "https://github.com/terrier-org/pyterrier" +"Bug Tracker" = "https://github.com/terrier-org/pyterrier/issues" +Changelog = "https://github.com/terrier-org/pyterrier/releases" +CI = "https://github.com/terrier-org/pyterrier/actions" + +[project.entry-points."pyterrier.java.init"] +"pyterrier.java" = "pyterrier.java:CoreJavaInit" +"pyterrier.terrier.java" = "pyterrier.terrier.java:TerrierJavaInit" \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 0587aaef..00000000 --- a/setup.py +++ /dev/null @@ -1,89 +0,0 @@ -import sys - -assert sys.version_info[0] > 2, "PyTerrier requires Python 3.7 minimum" - -import os -try: - from setuptools import setup, find_packages -except ImportError: - from distutils.core import setup - - def find_packages(where='.'): - # os.walk -> list[(dirname, list[subdirs], list[files])] - return [folder.replace("/", ".").lstrip(".") - for (folder, _, fils) in os.walk(where) - if "__init__.py" in fils] -with open("README.md", "r") as fh: - long_description = fh.read() - -# see https://packaging.python.org/guides/single-sourcing-package-version/ -import codecs -import os.path - -def read(rel_path): - here = os.path.abspath(os.path.dirname(__file__)) - with codecs.open(os.path.join(here, rel_path), 'r') as fp: - return fp.read() - -def get_version(rel_path): - import os - suffix = os.environ["PYTERRIER_VERSION_SUFFIX" ] if "PYTERRIER_VERSION_SUFFIX" in os.environ else "" - for line in read(rel_path).splitlines(): - if line.startswith('__version__'): - delim = '"' if '"' in line else "'" - return line.split(delim)[1] + suffix - else: - raise RuntimeError("Unable to find version string.") - - -requirements = [] -with open('requirements.txt', 'rt') as f: - for req in f.read().splitlines(): - # A line that begins with # is treated as a comment and ignored. Whitespace followed - # by a # causes the # and the remainder of the line to be treated as a comment. - if req.startswith("#"): - continue - req = req.split(" #")[0] - if req.strip() == "": - continue - if req.startswith('git+'): - # support for git urls - pkg_name = req.split('/')[-1].replace('.git', '') - if "#egg=" in pkg_name: - pkg_name = pkg_name.split("#egg=")[1] - requirements.append("%s @ %s" % (pkg_name, req)) - else: - requirements.append(req) - -setup( - name="python-terrier", - version=get_version("pyterrier/__init__.py"), - author="Craig Macdonald", - author_email='craigm@dcs.gla.ac.uk', - description="Terrier IR platform Python API", - project_urls={ - 'Documentation': 'https://pyterrier.readthedocs.io', - 'Changelog': 'https://github.com/terrier-org/pyterrier/releases', - 'Issue Tracker': 'https://github.com/terrier-org/pyterrier/issues', - 'CI': 'https://github.com/terrier-org/pyterrier/actions', - }, - long_description=long_description, - long_description_content_type="text/markdown", - package_data={'': ['LICENSE.txt', 'requirements.txt', 'requirements-test.txt']}, - include_package_data=True, - url="https://github.com/terrier-org/pyterrier", - packages=['pyterrier'] + ['pyterrier.' + i for i in find_packages('pyterrier')], - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", - "Operating System :: OS Independent", - ], - entry_points={ - 'pyterrier.java.init': [ - 'pyterrier.java = pyterrier.java:CoreJavaInit', - 'pyterrier.terrier.java = pyterrier.terrier.java:TerrierJavaInit', - ], - }, - install_requires=requirements, - python_requires='>=3.8', -)