Skip to content

Conversation

@emanuel-schmid
Copy link
Collaborator

@emanuel-schmid emanuel-schmid commented Jul 1, 2025

Changes proposed in this PR:

  • replace setup.py by pyproject.toml as source of package definition
  • update the env_climada.yml file

This PR fixes #984 #1009

PR Author Checklist

PR Reviewer Checklist

@emanuel-schmid emanuel-schmid changed the base branch from main to develop July 1, 2025 16:11
@emanuel-schmid
Copy link
Collaborator Author

Unfortunately I haven't found a meaningful way to get rid of env_climada.yml too.
It seems that getting rid of it would eventually increase complexity.

e.g. a script that translates and exports the content of pyproject.toml to the env_climada.yml file:
it looks like such a script cannot be written properly without adding knowledge of the specific dependencies.

@peanutfun
Copy link
Member

What about this? https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata

We can place the contents of env_climada.yml into a requirements.txt file and have the pyproject.toml reference that file:

[project]
dynamic = ["dependencies"]
# ...
[tool.setuptools.dynamic]
dependencies = {file = "requirements.txt"}

This is still considered a beta feature, but we could give it a try. Of course, the requirements.txt specifications are a bit different from conda environment specs.

requirements.txt files are supported by the conda commands conda create and conda install, therefore a new environment could be created by

conda create -n new_env --file requirements.txt python="3.11.*"

Comment on lines 79 to 94
dev = [
"ipython",
"myst-nb",
"readthedocs-sphinx-ext>=2.2",
"sphinx",
"sphinx-book-theme",
"sphinx-markdown-tables",
"sphinx-design",
"sphinx-mdinclude",
"mccabe>=0.6",
"pylint>=3.0",
"pytest",
"pytest-cov",
"pytest-subtests",
"pre-commit"
]
Copy link
Member

Choose a reason for hiding this comment

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

This is very inconvenient. I think we should omit the "dev" shortcut then instead of duplicating the lists.

@peanutfun
Copy link
Member

What about this? https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata

After personal discussion, this does not seem feasible. Packages on conda-forge may have different names than on PyPI. The conda environment file also serves a slightly different purpose (creating a conda environment) than the pyproject.toml (check that requirements are met).

pyproject.toml Outdated
description = "CLIMADA in Python"
readme = "README.md"
requires-python = ">=3.10,<3.13"
license = { text = "GNU Lesser General Public License v3 (GPLv3)" }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
license = { text = "GNU Lesser General Public License v3 (GPLv3)" }
license = { text = "GNU General Public License v3 (GPLv3)" }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch!

pyproject.toml Outdated
[project]
name = "climada"
version = "6.0.2-dev"
description = "CLIMADA in Python"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description = "CLIMADA in Python"
description = "Framework for climate risk assessment and adaptation option appraisal"

pyproject.toml Outdated
@@ -1,3 +1,106 @@
[build-system]
requires = ["setuptools >= 64"]
requires = ["setuptools>=61", "setuptools_scm"]
Copy link
Member

Choose a reason for hiding this comment

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

Why reduce the version requirement for setuptools?

Why include setuptools_scm? According to its docs:

setuptools-scm extracts Python package versions from git or hg metadata instead of declaring them as the version argument or in a Source Code Managed (SCM) managed file.

We hard-code the version in this file later on, so including this requirement serves no purpose (or does it? 🤷)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 changes reverted

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

turns out we actually need setuptools_scm for including package data

pyproject.toml Outdated
"pytest",
"pytest-cov",
"pytest-subtests",
"pre-commit"
Copy link
Member

Choose a reason for hiding this comment

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

"pre-commit" is neither part of test nor of doc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've renamed test to dev and added pre-commit

@emanuel-schmid emanuel-schmid merged commit 767eda3 into develop Aug 27, 2025
19 checks passed
@emanuel-schmid emanuel-schmid deleted the feature/pyproject-definition branch August 27, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plan migration from setup.py to pyproject.toml

3 participants