-
Notifications
You must be signed in to change notification settings - Fork 118
Migrate static metadata to pyproject.toml #2136
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
Open
allenwang28
wants to merge
1
commit into
meta-pytorch:main
Choose a base branch
from
allenwang28:export-D89066231
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
@allenwang28 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D89066231. |
cf8bd45 to
7845e3f
Compare
allenwang28
added a commit
to allenwang28/monarch-1
that referenced
this pull request
Dec 12, 2025
Summary:
Migrates Monarch to more modern Python packaging standards by moving static metadata to pyproject.toml, adopting a declarative config approach.
Ideally, everything is kept within pyproject.toml and is easily installed with `pip install .`
Concretely this means, getting rid of setup.py altogether and all `*-requirements.txt`. But there are a few challenges that I want to cover:
Why we need setup.py still:
`setup.py` cannot be fully eliminated because Monarch has dynamic build requirements:
1. C++ extensions that link against PyTorch (requires torch library paths and headers)
2. Rust extensions via setuptools-rust (requires LIBTORCH_LIB environment variables)
3. Dynamic CUDA detection and CXX11 ABI detection at build time
4. Platform-specific rpath configuration for linking
5. Environment variable overrides (MONARCH_PACKAGE_NAME, MONARCH_VERSION,
USE_TENSOR_ENGINE)
6. Custom build commands (Clean command)
Why we still need build-requirements.txt in this change:
build-requirements.txt (mirroring [build-system.requires]) is required because:
1. setup.py detects torch paths at module import time (lines 99-103) BEFORE the build
2. This requires torch to be pre-installed in the build environment
3. torch cannot be declared in [build-system.requires] because it needs custom index URLs (e.g., --index-url https://download.pytorch.org/whl/nightly/cu126)
4. Therefore we use `--no-build-isolation` which then disables automatic installation of `[build-system.requires]`, requiring manual installation via build-requirements.txt
To eliminate build-requirement.txt, this would require us to enable standard isolated builds. Concretely:
1. Refactor setup.py to move torch detection from module-level into build command methods (e.g., inside CustomBuildExt.run())
2. Delay all torch path detection until the build_ext command actually executes
3. This would allow build isolation to work because torch would be installed by the user before running `pip install .`, but build deps would be auto-installed
Changes:
- Add [build-system] configuration per PEP 517/518
- Move all static metadata to [project] section per PEP 621 (dependencies, authors, license, entry points, etc.)
- Migrate runtime dependencies from requirements.txt to pyproject.toml
- Migrate test dependencies to [project.optional-dependencies.test]
- Simplify setup.py to only contain dynamic configuration (torch detection, C++/Rust extensions, environment variables)
- Updates in CI and READMEs
- Migrates from `python setup.py bdist_wheel` to `python -m build`. Setup.py is being deprecated: https://packaging.python.org/en/latest/discussions/setup-py-deprecated/
Differential Revision: D89066231
allenwang28
added a commit
to allenwang28/monarch-1
that referenced
this pull request
Dec 12, 2025
Summary:
Migrates Monarch to more modern Python packaging standards by moving static metadata to pyproject.toml, adopting a declarative config approach.
Ideally, everything is kept within pyproject.toml and is easily installed with `pip install .`
Concretely this means, getting rid of setup.py altogether and all `*-requirements.txt`. But there are a few challenges that I want to cover:
Why we need setup.py still:
`setup.py` cannot be fully eliminated because Monarch has dynamic build requirements:
1. C++ extensions that link against PyTorch (requires torch library paths and headers)
2. Rust extensions via setuptools-rust (requires LIBTORCH_LIB environment variables)
3. Dynamic CUDA detection and CXX11 ABI detection at build time
4. Platform-specific rpath configuration for linking
5. Environment variable overrides (MONARCH_PACKAGE_NAME, MONARCH_VERSION,
USE_TENSOR_ENGINE)
6. Custom build commands (Clean command)
Why we still need build-requirements.txt in this change:
build-requirements.txt (mirroring [build-system.requires]) is required because:
1. setup.py detects torch paths at module import time (lines 99-103) BEFORE the build
2. This requires torch to be pre-installed in the build environment
3. torch cannot be declared in [build-system.requires] because it needs custom index URLs (e.g., --index-url https://download.pytorch.org/whl/nightly/cu126)
4. Therefore we use `--no-build-isolation` which then disables automatic installation of `[build-system.requires]`, requiring manual installation via build-requirements.txt
To eliminate build-requirement.txt, this would require us to enable standard isolated builds. Concretely:
1. Refactor setup.py to move torch detection from module-level into build command methods (e.g., inside CustomBuildExt.run())
2. Delay all torch path detection until the build_ext command actually executes
3. This would allow build isolation to work because torch would be installed by the user before running `pip install .`, but build deps would be auto-installed
Changes:
- Add [build-system] configuration per PEP 517/518
- Move all static metadata to [project] section per PEP 621 (dependencies, authors, license, entry points, etc.)
- Migrate runtime dependencies from requirements.txt to pyproject.toml
- Migrate test dependencies to [project.optional-dependencies.test]
- Simplify setup.py to only contain dynamic configuration (torch detection, C++/Rust extensions, environment variables)
- Updates in CI and READMEs
- Migrates from `python setup.py bdist_wheel` to `python -m build`. Setup.py is being deprecated: https://packaging.python.org/en/latest/discussions/setup-py-deprecated/
- Changes setuptools to >=64 ensures stable PEP 621 support - this enables the standard for `[project]` metadata etc. in pyproject.toml.
Differential Revision: D89066231
7845e3f to
4b3ef52
Compare
Summary:
Migrates Monarch to more modern Python packaging standards by moving static metadata to pyproject.toml, adopting a declarative config approach.
Ideally, everything is kept within pyproject.toml and is easily installed with `pip install .`
Concretely this means, getting rid of setup.py altogether and all `*-requirements.txt`. But there are a few challenges that I want to cover:
Why we need setup.py still:
`setup.py` cannot be fully eliminated because Monarch has dynamic build requirements:
1. C++ extensions that link against PyTorch (requires torch library paths and headers)
2. Rust extensions via setuptools-rust (requires LIBTORCH_LIB environment variables)
3. Dynamic CUDA detection and CXX11 ABI detection at build time
4. Platform-specific rpath configuration for linking
5. Environment variable overrides (MONARCH_PACKAGE_NAME, MONARCH_VERSION,
USE_TENSOR_ENGINE)
6. Custom build commands (Clean command)
Why we still need build-requirements.txt in this change:
build-requirements.txt (mirroring [build-system.requires]) is required because:
1. setup.py detects torch paths at module import time (lines 99-103) BEFORE the build
2. This requires torch to be pre-installed in the build environment
3. torch cannot be declared in [build-system.requires] because it needs custom index URLs (e.g., --index-url https://download.pytorch.org/whl/nightly/cu126)
4. Therefore we use `--no-build-isolation` which then disables automatic installation of `[build-system.requires]`, requiring manual installation via build-requirements.txt
To eliminate build-requirement.txt, this would require us to enable standard isolated builds. Concretely:
1. Refactor setup.py to move torch detection from module-level into build command methods (e.g., inside CustomBuildExt.run())
2. Delay all torch path detection until the build_ext command actually executes
3. This would allow build isolation to work because torch would be installed by the user before running `pip install .`, but build deps would be auto-installed
Changes:
- Add [build-system] configuration per PEP 517/518
- Move all static metadata to [project] section per PEP 621 (dependencies, authors, license, entry points, etc.)
- Migrate runtime dependencies from requirements.txt to pyproject.toml
- Migrate test dependencies to [project.optional-dependencies.test]
- Simplify setup.py to only contain dynamic configuration (torch detection, C++/Rust extensions, environment variables)
- Updates in CI and READMEs
- Migrates from `python setup.py bdist_wheel` to `python -m build`. Setup.py is being deprecated: https://packaging.python.org/en/latest/discussions/setup-py-deprecated/
- Changes setuptools to >=64 ensures stable PEP 621 support - this enables the standard for `[project]` metadata etc. in pyproject.toml.
Differential Revision: D89066231
4b3ef52 to
e616591
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Migrates Monarch to more modern Python packaging standards by moving static metadata to pyproject.toml, adopting a declarative config approach.
Ideally, everything is kept within pyproject.toml and is easily installed with
pip install .Concretely this means, getting rid of setup.py altogether and all
*-requirements.txt. But there are a few challenges that I want to cover:Why we need setup.py still:
setup.pycannot be fully eliminated because Monarch has dynamic build requirements:USE_TENSOR_ENGINE)
Why we still need build-requirements.txt in this change:
build-requirements.txt (mirroring [build-system.requires]) is required because:
--no-build-isolationwhich then disables automatic installation of[build-system.requires], requiring manual installation via build-requirements.txtTo eliminate build-requirement.txt, this would require us to enable standard isolated builds. Concretely:
pip install ., but build deps would be auto-installedChanges:
python setup.py bdist_wheeltopython -m build. Setup.py is being deprecated: https://packaging.python.org/en/latest/discussions/setup-py-deprecated/Differential Revision: D89066231