Skip to content

Commit 9796097

Browse files
committed
Replace setup.py with pyproject.toml for Python package builds
The direct invocation of setup.py for building wheels and sdists is deprecated by setuptools. Migrate both moteus and moteus_gui packages to use pyproject.toml (PEP 621) for metadata and `python3 -m build` for package creation.
1 parent 93972cf commit 9796097

File tree

10 files changed

+109
-152
lines changed

10 files changed

+109
-152
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: setup
1313
run: |
1414
sudo apt update
15-
sudo apt install -y python3-can python3-serial python3-setuptools python3-pyelftools python3-qtpy python3-wheel python3-importlib-metadata python3-scipy python3-usb mypy nodejs
15+
sudo apt install -y python3-build python3-can python3-serial python3-setuptools python3-pyelftools python3-qtpy python3-wheel python3-importlib-metadata python3-scipy python3-usb mypy nodejs
1616
wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb
1717
sudo apt install -y ./libtinfo5_6.3-2ubuntu0.1_amd64.deb
1818
- name: test

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To run the python unit tests, the following Ubuntu python packages must be insta
2424

2525
```
2626
sudo apt update
27-
sudo apt install -y python3-can python3-serial python3-setuptools python3-pyelftools python3-qtpy python3-wheel python3-importlib-metadata python3-scipy python3-usb mypy nodejs
27+
sudo apt install -y python3-build python3-can python3-serial python3-setuptools python3-pyelftools python3-qtpy python3-wheel python3-importlib-metadata python3-scipy python3-usb mypy nodejs
2828
```
2929

3030
The apt packages (numpy, scipy, etc.) are built for the system Python 3.12. If `/usr/local/bin/python3` exists and points to a different Python version, it will shadow the system Python and cause import failures. Remove or rename it:

lib/python/BUILD

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ test_suite(
2929
)
3030

3131
template_file(
32-
name = "setup.py",
33-
src = "setup.py.TPL",
32+
name = "pyproject.toml",
33+
src = "pyproject.toml.TPL",
3434
substitutions = {
3535
"{{VERSION}}" : '"{}"'.format(VERSION),
3636
},
@@ -39,7 +39,7 @@ template_file(
3939
genrule(
4040
name = "bdist_wheel",
4141
srcs = [
42-
"setup.py",
42+
"pyproject.toml",
4343
"README.md",
4444
"//lib/python/moteus",
4545
"//lib/python/moteus:version.py",
@@ -53,11 +53,10 @@ genrule(
5353
"RELOUT=$$(realpath --relative-to $$(dirname $(location README.md)) " +
5454
" $$(dirname $(location moteus-{ver}.tar.gz))) && " +
5555
"SRCROOT=$$(dirname $(location README.md)) && " +
56-
"ln -s $$(realpath $(location setup.py)) $$SRCROOT/setup.py && " +
56+
"ln -s $$(realpath $(location pyproject.toml)) $$SRCROOT/pyproject.toml && " +
5757
"ln -s $$(realpath $(location //lib/python/moteus:version.py)) $$SRCROOT/moteus/version.py && " +
5858
"cd $$SRCROOT && " +
59-
"python3 setup.py sdist --dist-dir $$RELOUT 1>/dev/null && " +
60-
"python3 setup.py bdist_wheel --dist-dir $$RELOUT 1> /dev/null " +
59+
"python3 -m build --no-isolation --outdir $$RELOUT 1>/dev/null " +
6160
""
6261
).format(ver=VERSION),
6362
)

lib/python/pyproject.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/python/pyproject.toml.TPL

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "moteus"
7+
version = {{VERSION}}
8+
description = "moteus brushless controller library and tools"
9+
readme = "README.md"
10+
license = {text = "Apache-2.0"}
11+
requires-python = ">=3.7, <4"
12+
authors = [{name = "mjbots Robotic Systems", email = "info@mjbots.com"}]
13+
keywords = ["moteus"]
14+
classifiers = [
15+
"Development Status :: 3 - Alpha",
16+
"Intended Audience :: Developers",
17+
"License :: OSI Approved :: Apache Software License",
18+
"Programming Language :: Python :: 3",
19+
]
20+
dependencies = [
21+
"pyserial>=3.5",
22+
"python-can>=3.3",
23+
"pyelftools>=0.26",
24+
"scipy>=1.8.0",
25+
"importlib_metadata>=3.6",
26+
"pywin32; platform_system == 'Windows'",
27+
"packaging",
28+
]
29+
30+
[project.urls]
31+
Homepage = "https://github.com/mjbots/moteus"
32+
33+
[project.scripts]
34+
moteus_tool = "moteus.moteus_tool:main"
35+
36+
[tool.setuptools]
37+
packages = ["moteus"]
38+
39+
[tool.mypy]
40+
python_version = "3.11"
41+
warn_unused_configs = true
42+
ignore_missing_imports = true
43+
44+
# Start with basic checking, not strict
45+
# These are disabled to allow gradual adoption
46+
disallow_untyped_defs = false
47+
check_untyped_defs = false
48+
warn_return_any = false
49+
50+
# Exclude test files from checks initially
51+
[[tool.mypy.overrides]]
52+
module = ["moteus.test.*"]
53+
ignore_errors = true

lib/python/setup.py.TPL

Lines changed: 0 additions & 58 deletions
This file was deleted.

utils/download_bazel_deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fi
9595

9696
# Python dependencies
9797
echo "Installing Python dependencies..."
98-
apt-get install -y python3-can python3-serial python3-setuptools python3-pyelftools \
98+
apt-get install -y python3-build python3-can python3-serial python3-setuptools python3-pyelftools \
9999
python3-qtpy python3-wheel python3-importlib-metadata python3-scipy python3-usb mypy nodejs
100100

101101
echo ""

utils/gui/BUILD

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ test_suite(
2727
)
2828

2929
template_file(
30-
name = "setup.py",
31-
src = "setup.py.TPL",
30+
name = "pyproject.toml",
31+
src = "pyproject.toml.TPL",
3232
substitutions = {
3333
"{{VERSION}}" : '"{}"'.format(VERSION),
3434
},
3535
)
3636

3737
genrule(
3838
name = "bdist_wheel",
39-
srcs = ["setup.py", "README.md", "//utils/gui/moteus_gui:tview",
39+
srcs = ["pyproject.toml", "README.md", "//utils/gui/moteus_gui:tview",
4040
# We separately list :datafiles because bazel does not have
4141
# any way for py_library/binary rules to carry around non-.py
4242
# dependencies for "compile-time" use. This lets us get
@@ -53,11 +53,10 @@ genrule(
5353
"RELOUT=$$(realpath --relative-to $$(dirname $(location README.md)) " +
5454
" $$(dirname $(location moteus_gui-{ver}.tar.gz))) && " +
5555
"SRCROOT=$$(dirname $(location README.md)) && " +
56-
"ln -s $$(realpath $(location setup.py)) $$SRCROOT/setup.py && " +
56+
"ln -s $$(realpath $(location pyproject.toml)) $$SRCROOT/pyproject.toml && " +
5757
"ln -s $$(realpath $(location //utils/gui/moteus_gui:version.py)) $$SRCROOT/moteus_gui/version.py && " +
5858
"cd $$SRCROOT && " +
59-
"python3 setup.py sdist --dist-dir $$RELOUT 1>/dev/null && " +
60-
"python3 setup.py bdist_wheel --dist-dir $$RELOUT 1> /dev/null " +
59+
"python3 -m build --no-isolation --outdir $$RELOUT 1>/dev/null " +
6160
""
6261
).format(ver=VERSION),
6362
)

utils/gui/pyproject.toml.TPL

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "moteus_gui"
7+
version = {{VERSION}}
8+
description = "moteus brushless controller graphical user interfaces"
9+
readme = "README.md"
10+
license = {text = "Apache-2.0"}
11+
requires-python = ">=3.7, <4"
12+
authors = [{name = "mjbots Robotic Systems", email = "info@mjbots.com"}]
13+
keywords = ["moteus"]
14+
classifiers = [
15+
"Development Status :: 3 - Alpha",
16+
"Intended Audience :: Developers",
17+
"License :: OSI Approved :: Apache Software License",
18+
"Programming Language :: Python :: 3",
19+
]
20+
dependencies = [
21+
"asyncqt>=0.8",
22+
"moteus~=0.3.92",
23+
"matplotlib>=3.9",
24+
# For some reason, matplotlib can barf without this, but
25+
# doesn't actually list it as a dependency on Windows.
26+
"msvc-runtime; platform_system == 'Windows' and python_version < '3.12'",
27+
"PySide6>=6.6",
28+
"qtconsole>=5.6",
29+
"qtpy>=2.0.1",
30+
"scipy>=1.14",
31+
]
32+
33+
[project.urls]
34+
Homepage = "https://github.com/mjbots/moteus"
35+
36+
[project.scripts]
37+
tview = "moteus_gui.tview:main"
38+
39+
[tool.setuptools]
40+
packages = ["moteus_gui"]
41+
42+
[tool.setuptools.package-data]
43+
moteus_gui = ["tview_main_window.ui"]

utils/gui/setup.py.TPL

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)