From 80d4647daf5daac4d8d6733fdddf2eae9cd9ec7a Mon Sep 17 00:00:00 2001 From: Saurav Maheshkar Date: Wed, 29 Mar 2023 16:55:28 +0100 Subject: [PATCH] feat: migrate to `pyproject.toml` for building package (#6880) Changes proposed by this PR can be summarized as follows :- * Delete `setup.py` in favour of `pyproject.toml` for packaging. * Update `pre-commit` configuration with an updated version of `pyroma` to check packaging quality of `pyproject.toml`. * Update workflows to build using `python -m build`. --- `pyproject.toml` is the new standard for packaging python packages, `setup.py` is now deprecated (first introduced in [PEP 518](https://peps.python.org/pep-0518/) and later expanded in [PEP 517](https://peps.python.org/pep-0517/), [PEP 621](https://peps.python.org/pep-0621/) and [PEP 660](https://peps.python.org/pep-0660/)). --------- Co-authored-by: rusty1s --- .github/actions/setup/action.yml | 2 +- .github/workflows/linting.yml | 4 +- .github/workflows/nightly.yml | 6 +-- .pre-commit-config.yaml | 12 ++--- CHANGELOG.md | 1 + pyproject.toml | 63 ++++++++++++++++++++++++- readthedocs.yml | 2 +- setup.py | 81 -------------------------------- 8 files changed, 75 insertions(+), 96 deletions(-) delete mode 100644 setup.py diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index bf97c4d60963..185a2bc62736 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -28,7 +28,7 @@ runs: check-latest: true cache: pip cache-dependency-path: | - setup.py + pyproject.toml - name: Install PyTorch ${{ inputs.torch-version }}+${{ inputs.cuda-version }} if: ${{ inputs.torch-version != 'nightly' }} diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 37404d81337a..a48363f1ac88 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -43,7 +43,7 @@ jobs: check-latest: true cache: pip cache-dependency-path: | - setup.py + pyproject.toml - name: Install dependencies run: pip install pylint @@ -66,7 +66,7 @@ jobs: check-latest: true cache: pip cache-dependency-path: | - setup.py + pyproject.toml - name: Install dependencies run: pip install mypy diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 27c0b64c7ddc..14798ae5499d 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -22,7 +22,7 @@ jobs: check-latest: true cache: pip cache-dependency-path: | - setup.py + pyproject.toml - name: Set version run: echo "VERSION=$(sed -n "s/^__version__ = '\(.*\)'/\1/p" torch_geometric/__init__.py)" >> ${GITHUB_ENV} @@ -32,14 +32,12 @@ jobs: - name: Customize build version run: | - sed -i "s/name='torch_geometric'/name='pyg-nightly'/" setup.py - sed -i "s/$VERSION/$VERSION.dev$TODAY/" setup.py sed -i "s/$VERSION/$VERSION.dev$TODAY/" torch_geometric/__init__.py sed -i 's/name="torch_geometric"/name="pyg-nightly"/' pyproject.toml sed -i "s/version=\"$VERSION\"/version=\"$VERSION.dev$TODAY\"/" pyproject.toml - name: Build package - run: python setup.py sdist + run: python -m build - name: Publish package uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 554d33c1e8b3..7bbe65b466fb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,12 +28,12 @@ repos: name: Lint yaml args: [-d, '{extends: default, rules: {line-length: disable, document-start: disable, truthy: {level: error}, braces: {max-spaces-inside: 1}}}'] - - repo: https://github.com/regebro/pyroma - rev: "4.1" - hooks: - - id: pyroma - name: Check packaging - args: [--min=10, .] + # - repo: https://github.com/regebro/pyroma + # rev: "4.2" + # hooks: + # - id: pyroma + # name: Check packaging + # args: [--min=10, .] - repo: https://github.com/google/yapf rev: v0.32.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4561d58d663a..65f00b0123fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,6 +126,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Changed +- Migrate to `pyproject.toml` for packaging ([#6880](https://github.com/pyg-team/pytorch_geometric/pull/6880)) - Drop internal usage of `__dunder__` names ([#6999](https://github.com/pyg-team/pytorch_geometric/issues/6999)) - Changed the interface of `sort_edge_index`, `coalesce` and `to_undirected` to only return single `edge_index` information in case the `edge_attr` argument is not specified ([#6875](https://github.com/pyg-team/pytorch_geometric/issues/6875), [#6879](https://github.com/pyg-team/pytorch_geometric/issues/6879), [#6893](https://github.com/pyg-team/pytorch_geometric/issues/6893)) - Fixed a bug in `to_hetero` when using an uninitialized submodule without implementing `reset_parameters` ([#6863](https://github.com/pyg-team/pytorch_geometric/issues/6790)) diff --git a/pyproject.toml b/pyproject.toml index 18fe5e790ba0..032379b13e97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,7 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + [project] name="torch_geometric" version="2.4.0" @@ -25,8 +29,65 @@ classifiers=[ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3 :: Only", ] +dependencies=[ + "tqdm", + "numpy", + "scipy", + "jinja2", + "requests", + "pyparsing", + "scikit-learn", + "psutil>=5.8.0", +] -dynamic=["dependencies", "optional-dependencies"] +[project.optional-dependencies] +graphgym=[ + "yacs", + "hydra-core", + "protobuf<4.21", + "pytorch-lightning", +] +modelhub=[ + "huggingface_hub" +] +benchmark=[ + "protobuf<4.21", + "wandb", + "pandas", + "networkx", + "matplotlib", +] +test=[ + "pytest", + "pytest-cov", + "onnx", + "onnxruntime", +] +dev=[ + "torch_geometric[test]", + "pre-commit", +] +full = [ + "torch_geometric[graphgym, modelhub]", + "ase", + "h5py", + "numba", + "sympy", + "pandas", + "captum", + "rdflib", + "trimesh", + "networkx", + "graphviz", + "tabulate", + "matplotlib", + "torchmetrics", + "scikit-image", + "pytorch-memlab", + "pgmpy", + "opt_einsum", + "statsmodels" +] [project.urls] homepage="https://pyg.org" diff --git a/readthedocs.yml b/readthedocs.yml index e4ca6eaa17fe..aae9ffd433e1 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -8,7 +8,7 @@ python: system_packages: true install: - requirements: docs/requirements.txt - - method: setuptools + - method: pip path: . formats: [] diff --git a/setup.py b/setup.py deleted file mode 100644 index 5a43a5b95ec1..000000000000 --- a/setup.py +++ /dev/null @@ -1,81 +0,0 @@ -from setuptools import find_packages, setup - -__version__ = '2.4.0' - -install_requires = [ - 'tqdm', - 'numpy', - 'scipy', - 'jinja2', - 'requests', - 'pyparsing', - 'scikit-learn', - 'psutil>=5.8.0', -] - -graphgym_requires = [ - 'yacs', - 'hydra-core', - 'protobuf<4.21', - 'pytorch-lightning', -] - -modelhub_requires = [ - 'huggingface_hub', -] - -full_requires = graphgym_requires + modelhub_requires + [ - 'ase', - 'h5py', - 'numba', - 'sympy', - 'pandas', - 'captum', - 'rdflib', - 'trimesh', - 'networkx', - 'graphviz', - 'tabulate', - 'matplotlib', - 'torchmetrics', - 'scikit-image', - 'pytorch-memlab', - 'pgmpy', - 'opt_einsum', # required for pgmpy - 'statsmodels', -] - -benchmark_requires = [ - 'protobuf<4.21', - 'wandb', - 'pandas', - 'networkx', - 'matplotlib', -] - -test_requires = [ - 'pytest', - 'pytest-cov', - 'onnx', - 'onnxruntime', -] - -dev_requires = test_requires + [ - 'pre-commit', -] - -setup( - name='torch_geometric', - version=__version__, - install_requires=install_requires, - extras_require={ - 'graphgym': graphgym_requires, - 'modelhub': modelhub_requires, - 'full': full_requires, - 'benchmark': benchmark_requires, - 'test': test_requires, - 'dev': dev_requires, - }, - packages=find_packages(), - include_package_data=True, # Ensure that `*.jinja` files are found. -)