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

use pyproject.toml [build-system] and setuptools_scm #188

Merged
merged 6 commits into from Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .git_archival.txt
@@ -0,0 +1,4 @@
node: $Format:%H$
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity , what is this file?

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 only just got this recently. If you define <filename> export-subst in a .gitattributes file, git will expand several placeholders when adding this file to an archive (from https://git-scm.com/docs/gitattributes). These placeholders can be the commit hash etc.

It currently still points to the wrong file (#189). With #189 merged:

mkdir archive
git archive HEAD > archive/HEAD.tar.gz
cd archive
tar -xvf HEAD.tar.gz
cat .git_archival.txt

returns

node: d933fa6f0835203e8310ca68b7307ebc34e63c43
node-date: 2022-08-15T11:05:04+02:00
describe-name: v0.8.3-39-gd933fa6
ref-names: HEAD -> fix_gitattributes_versioneer, origin/fix_gitattributes_versioneer

I think git archive is used to create the files in https://github.com/MESMER-group/mesmer/releases/tag/v0.8.3. Versioneer does it slightly differntly by writing to mesmer/_version.py export-subst.

node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true)$
ref-names: $Format:%D$
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -67,7 +67,9 @@ Internal Changes
By `Mathias Hauser <https://github.com/mathause>`_.
- Move contents of setup.py to setup.cfg (`#169 <https://github.com/MESMER-group/mesmer/pull/169>`_).
By `Mathias Hauser <https://github.com/mathause>`_.

- Use pyproject.toml for the build-system and setuptools_scm for the `__version__`
(`#188 <https://github.com/MESMER-group/mesmer/pull/188>`_).
By `Mathias Hauser <https://github.com/mathause>`_.

v0.8.3 - 2021-12-23
-------------------
Expand Down
3 changes: 0 additions & 3 deletions MANIFEST.in
@@ -1,6 +1,3 @@
include README.md
include LICENSE
include CHANGELOG.rst

include versioneer.py
include mesmer/_version.py
12 changes: 7 additions & 5 deletions docs/source/conf.py
Expand Up @@ -8,22 +8,24 @@

import datetime

from mesmer._version import get_versions
import mesmer

# -- Project information -----------------------------------------------------

project = "mesmer"
copyright_year = datetime.date.today().year
copyright = "(c) 2021-{} ETH Zurich (Land-climate dynamics group, Prof. S.I. Seneviratne), MESMER contributors listed in AUTHORS".format(
copyright_year
copyright = (
f"(c) 2021-{copyright_year} ETH Zurich (Land-climate dynamics group, Prof. S.I. "
"Seneviratne), MESMER contributors listed in AUTHORS"
)

authors = "Authors, see AUTHORS"
author = authors

# The short X.Y version
version = get_versions()["version"].split("+")[0]
version = mesmer.__version__.split("+")[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

In other packages I had to follow this pattern https://github.com/openscm/openscm-runner/blob/27eb7baddb686862c7996dbccabf34cea934fcb7/docs/source/conf.py#L19

I can't remember why exactly, but it was something to do with being installed or not being installed when building docs

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh - I wasn't aware that it's not (no longer?) installed per default in RTD. In xarray and regionmask we install it manually using pip (but I thought this is because it installs it with eager updates [making it impossible to pin packages]).

In any case RTD currently reports "mesmer 0.0.0 documentation" - I'll try your pattern to fix this in a new PR.

Related - for regionmask it reported a "dirty" version even for releases. This happens because RTD changes some files before installing the package. I used the following to work around this: regionmask/regionmask/pull/348

Copy link
Member Author

Choose a reason for hiding this comment

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

We currently do an install on RTD using "setuptools", i.e. i.e., python ./setup.py install, which is deprecated and may therefore not work together with pyproject.toml.

see #190 and

- method: setuptools

# The full version, including alpha/beta/rc tags
release = get_versions()["version"]
release = mesmer.__version__


# -- General configuration ---------------------------------------------------
Expand Down
20 changes: 15 additions & 5 deletions mesmer/__init__.py
Expand Up @@ -6,11 +6,21 @@
The mesmer package provides tools to train the MESMER emulator, create emulations, and
analyze the results.
"""
from ._version import get_versions

__version__ = get_versions()["version"]
del get_versions

# flake8: noqa

from . import calibrate_mesmer, create_emulations, io, utils

try:
from importlib.metadata import version as _get_version
except ImportError:
# importlib.metadata not available in python 3.7
import pkg_resources

_get_version = lambda pkg: pkg_resources.get_distribution(pkg).version

try:
__version__ = _get_version("mesmer-emulator")
except Exception:
# Local copy or not installed with setuptools.
# Disable minimum version checks on downstream libraries.
__version__ = "999"