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

Switch to hatchling backend #4747

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 0 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def set_environment_variables(env_dict, session):
def run_coverage(session):
"""Run the coverage tests and generate an XML report."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("setuptools", silent=False)
kratman marked this conversation as resolved.
Show resolved Hide resolved
session.install("coverage", silent=False)
# Using plugin here since coverage runs unit tests on linux with latest python version.
if "CI" in os.environ:
Expand All @@ -50,7 +49,6 @@ def run_coverage(session):
def run_integration(session):
"""Run the integration tests."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("setuptools", silent=False)
if (
"CI" in os.environ
and sys.version_info[:2] == (3, 12)
Expand Down Expand Up @@ -80,7 +78,6 @@ def run_doctests(session):
def run_unit(session):
"""Run the unit tests."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev,jax]", silent=False)
session.run("python", "-m", "pytest", "-m", "unit")

Expand All @@ -89,7 +86,6 @@ def run_unit(session):
def run_examples(session):
"""Run the examples tests for Jupyter notebooks."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev,jax]", silent=False)
notebooks_to_test = session.posargs if session.posargs else []
session.run(
Expand Down Expand Up @@ -134,7 +130,6 @@ def set_dev(session):
def run_tests(session):
"""Run the unit tests and integration tests sequentially."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev,jax]", silent=False)
session.run(
"python",
Expand Down
23 changes: 21 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[build-system]
requires = [
"setuptools",
"hatchling>=1.13.0",
]
build-backend = "setuptools.build_meta"
build-backend = "hatchling.build"

[project]
name = "pybamm"
Expand Down Expand Up @@ -120,6 +120,10 @@ jax = [
"jax==0.4.27",
"jaxlib==0.4.27",
]
# For MLIR expression evaluation (IDAKLU Solver)
iree = [
"iree-compiler==20240507.886",
]
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +123 to +126
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not have been re-added

Suggested change
# For MLIR expression evaluation (IDAKLU Solver)
iree = [
"iree-compiler==20240507.886",
]

# Contains all optional dependencies, except for jax, iree, and dev dependencies
all = [
"scikit-fem>=8.1.0",
Expand All @@ -146,6 +150,21 @@ ECM_Example = "pybamm.input.parameters.ecm.example_set:get_parameter_values"
MSMR_Example = "pybamm.input.parameters.lithium_ion.MSMR_example_set:get_parameter_values"
Chayambuka2022 = "pybamm.input.parameters.sodium_ion.Chayambuka2022:get_parameter_values"

[tool.hatch.version]
source = "vcs"
Comment on lines +153 to +154
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are using the hatch versioning, then we have to make a bunch of other changes for the release process. I thought the agreement from the earlier review was to switch to hatch first, then change the versioning

raw-options = { local_scheme = "no-local-version", version_scheme = "python-simplified-semver" }
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved

[tool.hatch.build]
packages = ["src/pybamm"]
include = [
"src/pybamm/**/*.txt",
"src/pybamm/**/*.md",
"src/pybamm/**/*.csv",
"src/pybamm/**/*.py",
"src/pybamm/CITATIONS.bib",
"src/pybamm/plotting/mplstyle",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this file in the repo

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +159 to +165
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment explaining why this is not automatically generated is left below when the code was moved.

It would be nice if we could switch to this being automatic though

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, it's automatic for setuptools if include_package_data is set to True. Could you check if a similar option is available for hatchling, @vidipsingh?

Copy link
Member

@Saransh-cpp Saransh-cpp Jan 13, 2025

Choose a reason for hiding this comment

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

It is not automatic for setuptools (you need to specify files in MANIFEST.in, as we do right now), but it is automatic for hatch 😉

See my comment below.

Comment on lines +157 to +165
Copy link
Member

Choose a reason for hiding this comment

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

include-package-data was used to include the files from MANIFEST.in in the wheel file.

hatchling includes everything not ignored by .gitignore by default. Therefore, we should just include the required files -

Suggested change
[tool.hatch.build]
packages = ["src/pybamm"]
include = [
"src/pybamm/**/*.txt",
"src/pybamm/**/*.md",
"src/pybamm/**/*.csv",
"src/pybamm/**/*.py",
"src/pybamm/CITATIONS.bib",
"src/pybamm/plotting/mplstyle",
[tool.hatch]
build.targets.sdist.include = [
"src/pybamm",
"CITATION.cff",
]

We should not bundle the CITATION.cff file with the wheel (as it is being done now). We should also get rid off MANIFEST.in.

]

[tool.setuptools]
include-package-data = true
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading