Skip to content

Move some metadata from setup.py to pyproject.toml#37

Merged
chaoming0625 merged 11 commits intochaobrain:mainfrom
ChromatinRemodeling:main
Jun 12, 2025
Merged

Move some metadata from setup.py to pyproject.toml#37
chaoming0625 merged 11 commits intochaobrain:mainfrom
ChromatinRemodeling:main

Conversation

@ChromatinRemodeling
Copy link
Contributor

@ChromatinRemodeling ChromatinRemodeling commented May 28, 2025

Description

I do this to add the ability to specify extras in editable installs. Example: pip install -e ./saiunit[cuda12].

How Has This Been Tested

Passed CI.

Types of changes

  • Code style (formatting, renaming)
  • Refactoring (no functional changes, no api changes)

Checklist

  • Code follows the code style of this project.
  • Changes follow the CONTRIBUTING guidelines.
  • Update necessary documentation accordingly.
  • Lint and tests pass locally with the changes.
  • Check issues and pull requests first. You don't want to duplicate effort.

Summary by Sourcery

Move project metadata (name, description, author, license, classifiers, keywords, dependencies, and extras) from setup.py into pyproject.toml to support specifying extras in editable installs

Enhancements:

  • Migrate project metadata and packaging settings from setup.py to pyproject.toml
  • Add editable-install extras definitions (cpu, cuda12, tpu) in pyproject.toml
  • Remove redundant packaging configuration from setup.py
  • Update author formatting and expand keywords and classifiers in pyproject.toml

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 28, 2025

Reviewer's Guide

Migrates package metadata and optional dependencies from setup.py into pyproject.toml to streamline configuration and enable extras in editable installs.

File-Level Changes

Change Details Files
Cleaned up setup.py by removing package metadata and configuration
  • Removed find_packages logic and packages parameter
  • Deleted name, description, author, install_requires, extras_require, keywords, classifiers, and license arguments
setup.py
Consolidated project metadata in pyproject.toml
  • Updated authors field formatting
  • Moved description, license, keywords, and classifiers under [project]
  • Reordered and refined classifier entries
pyproject.toml
Enabled extras for editable installs via pyproject.toml extras
  • Defined cpu, cuda12, and tpu optional dependency groups
  • Removed extras_require from setup.py
pyproject.toml
setup.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ChromatinRemodeling - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

long_description_content_type="text/markdown",
author='SAIUnit Developers',
author_email='chao.brain@qq.com',
packages=packages,
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Specify which packages to include in setup()

Without specifying packages, setuptools cannot determine which modules to include. Please add this back using find_packages() or specify packages in pyproject.toml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the packages are already specified in the pyproject.toml.

Copy link
Contributor

Choose a reason for hiding this comment

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

You’re right—if you’ve moved your find_packages() call into pyproject.toml under the setuptools section, then you don’t need to re-introduce it in setup.py. Just double-check that you have something like:

[tool.setuptools.packages.find]
include = ["saiunit*"]
exclude = ["docs*", "build*", "dev*", "dist*", "saiunit.egg-info*", "saiunit/__pycache__*"]

in your pyproject.toml. As long as that’s present, setuptools will pick up your packages automatically and you can safely leave setup.py lean. If you’re not seeing your modules packaged, then add that snippet (or the equivalent where/include settings) back into the TOML.

testing = [
'pytest',
]
cpu = ["jax[cpu]"]
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Extras need to be under [project.optional-dependencies]

Place cpu, cuda12, and tpu under [project.optional-dependencies] to ensure pip recognizes them as installable extras.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The extras are indeed under [project.optional-dependencies].

Copy link
Contributor

Choose a reason for hiding this comment

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

You’re right—those lines are already in the [project.optional-dependencies] table. My bad, that comment was misplaced. I’ve double-checked the TOML and the extras (cpu, cuda12, tpu) are indeed nested correctly under:

[project.optional-dependencies]
testing = ["pytest"]
cpu     = ["jax[cpu]"]
…

I’ll resolve that thread. Thanks for catching it! If you haven’t already, it might be worth doing a quick smoke-test:

pip install -e '.[cpu]'

to make sure pip picks up the extra exactly as intended. Otherwise, looks good to me.

@chaoming0625
Copy link
Member

How to build wheel using pyproject.toml?

@ChromatinRemodeling
Copy link
Contributor Author

How to build wheel using pyproject.toml?

IIUC it's as simple as python -m build. I have tried to build it myself. The build script will read the pyproject.toml. The pyproject.toml can do a lot now and is recommended over setup.py.

According to https://packaging.python.org/en/latest/guides/writing-pyproject-toml/:

For new projects, use the [project] table, and keep setup.py only if some programmatic configuration is needed (such as building C extensions), but the setup.cfg and setup.py formats are still valid.

@chaoming0625
Copy link
Member

chaoming0625 commented May 29, 2025

Thanks. Please update command lines in build_wheel.sh. Also pyproject.toml.template and setup.py.template in brainunit directory.

@ChromatinRemodeling
Copy link
Contributor Author

I updated the command lines and also made some changes to avoid warnings. Some notable changes are:

  1. made the URL change according to Well-known Project URLs in Metadata - Python Packaging User Guide. Also change http to https.

  2. Fix license warnings. During the packaging, I encountered the following warnings:

Please use a simple string containing a SPDX expression for `project.license`

Solution: updated the project.license as a simple SPDX string Apache-2.0.

Also:

License classifiers are deprecated.

Solution: removed the license classifier line.

  1. Fix the bdist_wheel.universal warning.
bdist_wheel.universal is deprecated

Solution: Remove [tool.distutils.bdist_wheel] because it is for universal Python 2-3 support but there's no need to support Python 2.

@ChromatinRemodeling
Copy link
Contributor Author

I am unable to test the twine upload part. But I checked that the built wheels are installable by pip. Some tests failed on my local computer though, maybe due to memory issue, but the CI is fine.

Copy link
Member

@chaoming0625 chaoming0625 left a comment

Choose a reason for hiding this comment

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

Thanks

@chaoming0625 chaoming0625 merged commit 8645ece into chaobrain:main Jun 12, 2025
15 checks passed
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.

2 participants