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

Conversation

vidipsingh
Copy link

@vidipsingh vidipsingh commented Jan 11, 2025

  • Replace setuptools with hatchling as build backend
  • Add hatch-vcs for Git tag-based versioning
  • Unify package versioning under a single source

Description

This PR switches PyBaMM's build system from setuptools to hatchling and implements Git tag-based versioning using hatch-vcs. This change simplifies our build process and version management now that PyBaMM is a pure Python package.

Related to: #4742

Type of change

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit)
  • All tests pass: $ python -m pytest (or $ nox -s tests)
  • The documentation builds: $ python -m pytest --doctest-plus src (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ nox -s quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link

codecov bot commented Jan 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.69%. Comparing base (817ac83) to head (407289b).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4747   +/-   ##
========================================
  Coverage    98.69%   98.69%           
========================================
  Files          303      303           
  Lines        23256    23256           
========================================
  Hits         22953    22953           
  Misses         303      303           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Hi @vidipsingh, thanks for taking this up! I have just a few suggestions. Please remove other references of setuptools from this file (lines 174–189) and across other files as well, and replace them with hatch/hatchling as necessary.

pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
tests/unit/test_util.py Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
Copy link
Contributor

@kratman kratman left a comment

Choose a reason for hiding this comment

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

There seems to be a lot of changes here that are not necessary for just switching to hatch. It should only be a couple lines.

Switching to hatch also requires changing the release workflow, the update version script, and other tools. There is a bunch of other stuff that needs to change

Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

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

Agree with @kratman. Switching to hatchling should be one PR, and adding hatch-vcs should be another. @vidipsingh can you restrict this PR to just switching to hatchling and getting rid of setuptool configurations?

The hatch-vcs PR can deal with updating the release workflow. Switching to hatchling will not change the release workflow.

In any case, both these PRs should go in after 25.1

@vidipsingh
Copy link
Author

Agree with @kratman. Switching to hatchling should be one PR, and adding hatch-vcs should be another. @vidipsingh can you restrict this PR to just switching to hatchling and getting rid of setuptool configurations?

The hatch-vcs PR can deal with updating the release workflow. Switching to hatchling will not change the release workflow.

In any case, both these PRs should go in after 25.1

@Saransh-cpp Okay, I will restrict this PR to just switching to hatchling and will remove the setuptools configurations.

I also wanted to ask where else I need to remove references to setuptools apart from pyproject.toml? I’ve noticed it is referred to in the following files:

  • CONTRIBUTING.md
  • noxfile.py
  • .github/workflows/publish_pypi.yml
  • docs/source/api/parameters/parameter_sets.rst

Since I’m new to the PyBaMM repo, any guidance or suggestions regarding these changes would be greatly appreciated :)

@Saransh-cpp
Copy link
Member

Saransh-cpp commented Jan 12, 2025

Sounds right! Some of the occurrences might have to be preserved, but we can point that out while reviewing the PR.

@agriyakhetarpal agriyakhetarpal added the skip release Do not merge until the next release label Jan 12, 2025
Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Thanks, @vidipsingh, looks good to me now!

pyproject.toml Outdated
Comment on lines 260 to 261
[tool.repo-review]

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
[tool.repo-review]

Copy link
Author

Choose a reason for hiding this comment

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

Should I remove this line?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

@agriyakhetarpal
Copy link
Member

Could you please rename the PR title, and replace the "Fixes" keyword in the PR description with "Related to" or similar so that the linked issue doesn't get closed, as we are no longer adding hatch-vcs in this PR?

@agriyakhetarpal
Copy link
Member

@all-contributors please add @vidipsingh for infra

Copy link
Contributor

@agriyakhetarpal

I've put up a pull request to add @vidipsingh! 🎉

@agriyakhetarpal agriyakhetarpal dismissed their stale review January 13, 2025 20:46

Actually, wait, I'm dismissing my review because the references to setuptools across other files still remain: #4747 (comment)

"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 +151 to +165
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.

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.

pyproject.toml Outdated Show resolved Hide resolved
@vidipsingh vidipsingh changed the title Switch to hatchling backend with hatch-vcs versioning Switch to hatchling backend Jan 13, 2025
pyproject.toml Outdated
Comment on lines 160 to 174
# List of files to include as package data. These are mainly the parameter CSV files in
# the input/parameters/ subdirectories. Other files such as the CITATIONS file, relevant
# README.md files, and specific .txt files inside the pybamm/ directory are also included.
# These are specified to be included in the SDist through MANIFEST.in.
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
# List of files to include as package data. These are mainly the parameter CSV files in
# the input/parameters/ subdirectories. Other files such as the CITATIONS file, relevant
# README.md files, and specific .txt files inside the pybamm/ directory are also included.
# These are specified to be included in the SDist through MANIFEST.in.

Comment on lines +149 to +165
[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
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.

@kratman kratman removed the skip release Do not merge until the next release label Jan 15, 2025
@kratman
Copy link
Contributor

kratman commented Jan 21, 2025

@vidipsingh Can you resolve the conflicts here?

- Replace setuptools with hatchling as build backend
- Add hatch-vcs for Git tag-based versioning
- Unify package versioning under a single source
- Replace setuptools with hatchling as build backend
- Remove setuptools configurations
- Revert to version 24.11.2
- Replace setuptools with hatch as build backend
- Remove setuptools configurations
- Add automatic file handling in hatch config
- Replace setuptools with hatchling as build backend
- Add hatch-vcs for Git tag-based versioning
- Unify package versioning under a single source
- Replace setuptools with hatchling as build backend
- Remove setuptools configurations
- Revert to version 24.11.2
- Replace setuptools with hatch as build backend
- Remove setuptools configurations
- Add automatic file handling in hatch config
@vidipsingh vidipsingh force-pushed the switch-to-hatchling-and-hatch-vcs branch from 53cda20 to b3a5de5 Compare January 21, 2025 19:31
@kratman
Copy link
Contributor

kratman commented Jan 21, 2025

@vidipsingh As a general rule, it is best not to force push once the review has started. It makes it really hard to see the changes. We squash most PRs (except releases), so the merge commits do not matter

Copy link
Contributor

@kratman kratman left a comment

Choose a reason for hiding this comment

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

It looks like you might have reverted a bunch of stuff from the previous reviews

Comment on lines +123 to +126
# For MLIR expression evaluation (IDAKLU Solver)
iree = [
"iree-compiler==20240507.886",
]
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",
]

Comment on lines +153 to +154
[tool.hatch.version]
source = "vcs"
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

noxfile.py Show resolved Hide resolved
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.

4 participants