Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate project metadata from setup.py to pyproject.toml following PEP621 #1848

Merged
merged 19 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
requires = ["setuptools>=61", "setuptools_scm[toml]>=6.2"]
Copy link
Member Author

@seisman seisman Mar 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that changes in this PR require setuptools>=61.

setuptools v61.0.0 was released on Mar. 24, 2022. This version starts to support storing project metadata in pyproject.toml following PEP621 but it's still experimental and may change in future versions. I think we should not merge this PR unless the pyproject.toml support is stable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's wait and see first. I've had to pin to setuptools=58.4.0 on one of my projects 3 weeks ago because one of the dependencies didn't like setuptools v60.9. There might be some other packages pinning to a lower setuptools version too.

build-backend = "setuptools.build_meta"

[project]
name = "pygmt"
description = "A Python interface for the Generic Mapping Tools"
readme = "README.rst"
requires-python = ">=3.8"
license = {text = "BSD License"}
authors = [{name = "The PyGMT Developers", email = "[email protected]"}]
maintainers = [{name = "The PyGMT Developers", email = "[email protected]"}]
keywords = []
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Topic :: Scientific/Engineering",
"Topic :: Software Development :: Libraries",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: BSD License",
]
dependencies = ["numpy>=1.19", "pandas", "xarray", "netCDF4", "packaging"]
dynamic = ["version"]

[project.urls]
homepage = "https://www.pygmt.org"
documentation = "https://www.pygmt.org"
repository = "https://github.com/GenericMappingTools/pygmt"
changelog = "https://www.pygmt.org/latest/changes.html"

[tool.setuptools]
platforms = ["Any"]
include-package-data = true

[tool.setuptools.packages.find]
include = ["pygmt*"]
exclude = ["doc"]

[tool.setuptools_scm]
local_scheme = "node-and-date"
fallback_version = "unknown"
seisman marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
61 changes: 6 additions & 55 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,10 @@
"""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup.py is no longer required since setuptools 64.0.0 (https://setuptools.pypa.io/en/latest/userguide/development_mode.html)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, it seems like setuptools v64.0.0 enabled non setup.py editable installs!

On the developer side, this seems ok to remove setup.py, but are there any potential side effects for users not having such a new setuptools version? Or to put it another way, do we want to remove setup.py for PyGMT v0.8.0, or wait another minor version (e.g. v0.9.0)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any potential side effects for users not having such a new setuptools version?

I have setuptools 62.6.0 installed. Checking out this branch and running make install and make package work well for me.

When running make package, I see the following messages:

$ make package 
python -m build --sdist --wheel
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools>=64, setuptools_scm[toml]>=6.2)
* Getting dependencies for sdist...
/tmp/build-env-ld441dbo/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py:108: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
  warnings.warn(msg, _BetaConfiguration)
running egg_info
writing pygmt.egg-info/PKG-INFO
writing dependency_links to pygmt.egg-info/dependency_links.txt
writing requirements to pygmt.egg-info/requires.txt
writing top-level names to pygmt.egg-info/top_level.txt
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE.txt'
adding license file 'AUTHORS.md'
adding license file 'AUTHORSHIP.md'
writing manifest file 'pygmt.egg-info/SOURCES.txt'
* Building sdist...
/tmp/build-env-ld441dbo/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py:108: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
  warnings.warn(msg, _BetaConfiguration)
running sdist
running egg_info
writing pygmt.egg-info/PKG-INFO
writing dependency_links to pygmt.egg-info/dependency_links.txt
writing requirements to pygmt.egg-info/requires.txt
writing top-level names to pygmt.egg-info/top_level.txt
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE.txt'
adding license file 'AUTHORS.md'
adding license file 'AUTHORSHIP.md'
writing manifest file 'pygmt.egg-info/SOURCES.txt'
running check
...

It seems build dependencies like setuptools>=64 are automatically installed in isolated environments and do not affect users' installations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A downside here is that make install no longer works without internet access, even if setuptools>=64 is installed in the environment. I'll do some more searching for a workaround but if anyone knows a solution that would be helpful.

Copy link
Member

@weiji14 weiji14 Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried disconnecting and used pip install --no-deps --no-build-isolation --editable=. which seems to work offline (presumably it manages to pick up a pre-downloaded setuptools>=64). However, it results in a editable version named pygmt-0.0.0. Maybe the offline feature can be raised upstream to PyPA?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A downside here is that make install no longer works without internet access, even if setuptools>=64 is installed in the environment.

It's unrelated to this PR. Offline make install worked for pygmt<=0.2.0 and started to fail since v0.3.0, in which we switched from versioneer to setuptools_scm (https://www.pygmt.org/dev/changes.html#id47). So it's likely a problem for setuptools_scm.

I tried disconnecting and used pip install --no-deps --no-build-isolation --editable=. which seems to work offline (presumably it manages to pick up a pre-downloaded setuptools>=64). However, it results in a editable version named pygmt-0.0.0.

This command gives the correct version for pygmt <= 0.6.0 but results in pygmt-0.0.0 for pygmt v0.7.0. Not sure if it's caused by changes in #1945.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxrjones Perhaps open an issue report for the offline pip issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened a PR in #2097.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the issue @seisman. Apologies for not responding to your question. I had originally interpreted your comment as opening an issue in the PyPA repo and wanted to do more debugging before taking that step.

Build and install the project.
A simple setup.py script to support editable installs.
"""
from setuptools import find_packages, setup
# References:
# - https://github.com/pypa/setuptools/issues/2816
# - https://setuptools.pypa.io/en/latest/userguide/quickstart.html#development-mode

NAME = "pygmt"
FULLNAME = "PyGMT"
AUTHOR = "The PyGMT Developers"
AUTHOR_EMAIL = "[email protected]"
MAINTAINER = AUTHOR
MAINTAINER_EMAIL = AUTHOR_EMAIL
LICENSE = "BSD License"
URL = "https://github.com/GenericMappingTools/pygmt"
DESCRIPTION = "A Python interface for the Generic Mapping Tools"
KEYWORDS = ""
with open("README.rst", "r", encoding="utf8") as f:
LONG_DESCRIPTION = "".join(f.readlines())
from setuptools import setup

PACKAGES = find_packages(exclude=["doc"])
SCRIPTS = []
PACKAGE_DATA = {"pygmt.tests": ["data/*", "baseline/*"]}
weiji14 marked this conversation as resolved.
Show resolved Hide resolved

CLASSIFIERS = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Topic :: Scientific/Engineering",
"Topic :: Software Development :: Libraries",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
f"License :: OSI Approved :: {LICENSE}",
]
PLATFORMS = "Any"
PYTHON_REQUIRES = ">=3.8"
INSTALL_REQUIRES = ["numpy>=1.19", "pandas", "xarray", "netCDF4", "packaging"]

if __name__ == "__main__":
setup(
name=NAME,
fullname=FULLNAME,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
license=LICENSE,
url=URL,
platforms=PLATFORMS,
scripts=SCRIPTS,
packages=PACKAGES,
package_data=PACKAGE_DATA,
classifiers=CLASSIFIERS,
keywords=KEYWORDS,
python_requires=PYTHON_REQUIRES,
install_requires=INSTALL_REQUIRES,
)
setup()
seisman marked this conversation as resolved.
Show resolved Hide resolved