Skip to content

Commit 51e57a8

Browse files
committed
no more setup.py called explicitly
1 parent d11ed2f commit 51e57a8

File tree

6 files changed

+59
-43
lines changed

6 files changed

+59
-43
lines changed

.github/workflows/nightly_build.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ jobs:
6666
run: |
6767
rm -r dist || true
6868
export PATH="/opt/python/${{ matrix.python_version[1] }}/bin:$PATH"
69-
python3 -mpip install wheel
70-
python3 setup.py bdist_wheel \
71-
--python-tag=${{ matrix.python-tag }}
72-
find dist -name '*whl' -exec bash -c ' mv $0 ${0/linux/manylinux1}' {} \;
69+
python3 -mpip install build
70+
python3 -m build --wheel
71+
find dist -name '*whl' -exec bash -c ' mv $0 ${0/linux/manylinux1}' {} \;
7372
# pytorch/pytorch binaries are also manylinux_2_17 compliant but they
7473
# pretend that they're manylinux1 compliant so we do the same.
7574
- name: Upload wheel for the test-wheel job
@@ -229,9 +228,8 @@ jobs:
229228
shell: bash
230229
run: |
231230
rm -r dist || true
232-
python3 -mpip install wheel
233-
python3 setup.py bdist_wheel \
234-
--python-tag=${{ matrix.python-tag }}
231+
python3 -mpip install build
232+
python3 -m build --wheel
235233
- name: Upload wheel for the test-wheel job
236234
uses: actions/upload-artifact@v4
237235
with:

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include torchrl/version.py
1+
include torchrl/version.py

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,8 @@ such as `apt`, `apt-get`, `conda` or `yum` but NOT `pip`, as well as `pip instal
972972

973973
One can also build the wheels to distribute to co-workers using
974974
```bash
975-
python setup.py bdist_wheel
975+
pip install build
976+
python -m build --wheel
976977
```
977978
Your wheels will be stored there `./dist/torchrl<name>.whl` and installable via
978979
```bash

packaging/build_wheels.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
77
export BUILD_TYPE=wheel
88
setup_env
99
setup_wheel_python
10-
pip_install numpy pyyaml future ninja
10+
pip_install numpy pyyaml future ninja build
1111
pip_install --upgrade setuptools
1212
setup_pip_pytorch_version
13-
python setup.py clean
1413

1514
# Copy binaries to be included in the wheel distribution
1615
if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
@@ -29,9 +28,9 @@ else
2928
fi
3029

3130
if [[ "$OSTYPE" == "msys" ]]; then
32-
IS_WHEEL=1 "$script_dir/windows/internal/vc_env_helper.bat" python setup.py bdist_wheel
31+
IS_WHEEL=1 "$script_dir/windows/internal/vc_env_helper.bat" python -m build --wheel
3332
else
34-
python setup.py bdist_wheel
33+
python -m build --wheel
3534
if [[ "$(uname)" != Darwin ]]; then
3635
rename "linux_x86_64" "manylinux1_x86_64" dist/*.whl
3736
fi

setup.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def write_version_file(version):
4545
f.write(f"__version__ = '{version}'\n")
4646
f.write(f"git_version = {repr(sha)}\n")
4747
f.write(f"pytorch_version = '{pytorch_version}'\n")
48-
49-
logging.info(f"Version file written successfully")
48+
49+
logging.info("Version file written successfully")
5050

5151

5252
class clean(Command):
@@ -151,7 +151,12 @@ def _main():
151151
# For regular builds, append git hash for development versions
152152
try:
153153
import subprocess
154-
git_sha = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=cwd).decode("ascii").strip()[:7]
154+
155+
git_sha = (
156+
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=cwd)
157+
.decode("ascii")
158+
.strip()[:7]
159+
)
155160
version = f"{base_version}+{git_sha}"
156161
logging.info(f"Using development version: {version}")
157162
except Exception:
@@ -161,15 +166,17 @@ def _main():
161166
# Always write the version file to ensure it's up to date
162167
write_version_file(version)
163168
logging.info(f"Building torchrl-{version}")
164-
169+
165170
# Verify the version file was written correctly
166171
try:
167-
with open(os.path.join(cwd, "torchrl", "version.py"), "r") as f:
172+
with open(os.path.join(cwd, "torchrl", "version.py")) as f:
168173
content = f.read()
169174
if f"__version__ = '{version}'" in content:
170175
logging.info(f"Version file correctly contains: {version}")
171176
else:
172-
logging.error(f"Version file does not contain expected version: {version}")
177+
logging.error(
178+
f"Version file does not contain expected version: {version}"
179+
)
173180
except Exception as e:
174181
logging.error(f"Failed to verify version file: {e}")
175182

@@ -178,7 +185,7 @@ def _main():
178185
package_name = "torchrl-nightly" # Use torchrl-nightly for PyPI uploads
179186
else:
180187
package_name = "torchrl" # Use torchrl for regular builds and GitHub discovery
181-
188+
182189
setup_kwargs = {
183190
"name": package_name,
184191
# Only C++ extension configuration
@@ -193,7 +200,7 @@ def _main():
193200
},
194201
"include_package_data": True,
195202
}
196-
203+
197204
# Handle nightly tensordict dependency override
198205
if is_nightly:
199206
setup_kwargs["install_requires"] = [
@@ -207,25 +214,29 @@ def _main():
207214
# Override pyproject.toml settings for nightly builds
208215
if is_nightly:
209216
# Add all the metadata from pyproject.toml but override the name
210-
setup_kwargs.update({
211-
"description": "A modular, primitive-first, python-first PyTorch library for Reinforcement Learning",
212-
"long_description": (Path(__file__).parent / "README.md").read_text(encoding="utf8"),
213-
"long_description_content_type": "text/markdown",
214-
"author": "torchrl contributors",
215-
"author_email": "vmoens@fb.com",
216-
"url": "https://github.com/pytorch/rl",
217-
"classifiers": [
218-
"Programming Language :: Python :: 3.9",
219-
"Programming Language :: Python :: 3.10",
220-
"Programming Language :: Python :: 3.11",
221-
"Programming Language :: Python :: 3.12",
222-
"Operating System :: OS Independent",
223-
"Development Status :: 4 - Beta",
224-
"Intended Audience :: Developers",
225-
"Intended Audience :: Science/Research",
226-
"Topic :: Scientific/Engineering :: Artificial Intelligence",
227-
],
228-
})
217+
setup_kwargs.update(
218+
{
219+
"description": "A modular, primitive-first, python-first PyTorch library for Reinforcement Learning",
220+
"long_description": (Path(__file__).parent / "README.md").read_text(
221+
encoding="utf8"
222+
),
223+
"long_description_content_type": "text/markdown",
224+
"author": "torchrl contributors",
225+
"author_email": "vmoens@fb.com",
226+
"url": "https://github.com/pytorch/rl",
227+
"classifiers": [
228+
"Programming Language :: Python :: 3.9",
229+
"Programming Language :: Python :: 3.10",
230+
"Programming Language :: Python :: 3.11",
231+
"Programming Language :: Python :: 3.12",
232+
"Operating System :: OS Independent",
233+
"Development Status :: 4 - Beta",
234+
"Intended Audience :: Developers",
235+
"Intended Audience :: Science/Research",
236+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
237+
],
238+
}
239+
)
229240

230241
setup(**setup_kwargs)
231242

torchrl/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@
2929
try:
3030
import os
3131
import subprocess
32+
3233
version_file = os.path.join(os.path.dirname(__file__), "..", "version.txt")
33-
with open(version_file, "r") as f:
34+
with open(version_file) as f:
3435
base_version = f.read().strip()
35-
36+
3637
# Try to get git hash
3738
try:
38-
git_sha = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=os.path.dirname(version_file)).decode("ascii").strip()[:7]
39+
git_sha = (
40+
subprocess.check_output(
41+
["git", "rev-parse", "HEAD"], cwd=os.path.dirname(version_file)
42+
)
43+
.decode("ascii")
44+
.strip()[:7]
45+
)
3946
__version__ = f"{base_version}+{git_sha}"
4047
except Exception:
4148
__version__ = base_version

0 commit comments

Comments
 (0)