Skip to content

Commit b9b2812

Browse files
mhuckasergeisakovgemini-code-assist[bot]
authored
Move setup.py metadata into pyproject.toml, remove dev-requirements.txt, & fix #839 (#985)
This addresses deprecation warnings originating from the use of outdated `setuptools` functions, and takes the opportunity to modernize the management of the version number and the dependencies in accordance with current Python practices (PEP [621](https://peps.python.org/pep-0631/), [735](https://peps.python.org/pep-0735/)). Key changes include: - All declarative package metadata (e.g., name, author, classifiers) has been moved from `setup.py` to `pyproject.toml`. What's left in `setup.py` has been simplified to only contain the logic necessary for building the C++ extensions and calling `setup`. - The qsim version number is now stored in only one file, `qsimcirq/_version.py`, and both `pyproject.toml` and `setup.py` read it from there. In the case of `setup.py`, the use of the deprecated `self.distribution.get_version()` has been replaced with the use of `runpy` to read the version number from `qsimcirq/_version.py`. (The latter change fixes #839.) - The development dependencies are no longer stored as "extras" but rather use the pyproject.toml `[dependency-groups]` section introduced in 2024 by [PEP 735](https://peps.python.org/pep-0735/) and recognized by [pip version 25.1+](https://packaging.python.org/en/latest/specifications/dependency-groups/#specification). This means `dev-requirements.txt` is gone, and development dependencies are installed using ```shell pip install --group dev ``` - `pyproject.toml` defines the versions of Python for which cibuildwheel builds wheels (in section `[tool.cibuildwheel]`). --------- Co-authored-by: Sergei Isakov <54642992+sergeisakov@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent d7acd1f commit b9b2812

9 files changed

Lines changed: 174 additions & 129 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@ jobs:
7373
cache: pip
7474
cache-dependency-path: |
7575
requirements.txt
76-
dev-requirements.txt
76+
pyproject.toml
77+
78+
- name: Upgrade pip
79+
run: python -m pip install --upgrade pip
7780

7881
- name: Install dependencies
79-
run: pip install -r requirements.txt -r dev-requirements.txt
82+
run: pip install -r requirements.txt --group dev
8083

8184
- name: Check format
8285
continue-on-error: ${{inputs.soft-linting == 'true'}}
@@ -243,10 +246,13 @@ jobs:
243246
cache: pip
244247
cache-dependency-path: |
245248
requirements.txt
246-
dev-requirements.txt
249+
pyproject.toml
250+
251+
- name: Upgrade pip
252+
run: python -m pip install --upgrade pip
247253

248254
- name: Install dependencies
249-
run: pip install -r requirements.txt -r dev-requirements.txt
255+
run: pip install -r requirements.txt --group dev
250256

251257
- name: Set up Bazel
252258
uses: './.github/actions/set-up-bazel'
@@ -331,10 +337,13 @@ jobs:
331337
cache: pip
332338
cache-dependency-path: |
333339
requirements.txt
334-
dev-requirements.txt
340+
pyproject.toml
341+
342+
- name: Upgrade pip
343+
run: python -m pip install --upgrade pip
335344

336345
- name: Install dependencies
337-
run: pip install -r requirements.txt -r dev-requirements.txt
346+
run: pip install -r requirements.txt --group dev
338347

339348
- name: Set up Bazel
340349
uses: './.github/actions/set-up-bazel'
@@ -387,10 +396,13 @@ jobs:
387396
cache: pip
388397
cache-dependency-path: |
389398
requirements.txt
390-
dev-requirements.txt
399+
pyproject.toml
400+
401+
- name: Upgrade pip
402+
run: python -m pip install --upgrade pip
391403

392404
- name: Install dependencies
393-
run: pip install -r requirements.txt -r dev-requirements.txt
405+
run: pip install -r requirements.txt --group dev
394406

395407
- name: Set up Bazel
396408
uses: './.github/actions/set-up-bazel'

.github/workflows/cirq_compatibility.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,13 @@ jobs:
5353
cache: pip
5454
cache-dependency-path: |
5555
requirements.txt
56-
dev-requirements.txt
56+
pyproject.toml
5757
5858
- name: Install latest dev version of Cirq
5959
run: pip install --upgrade cirq~=1.0.dev
6060

6161
- name: Install qsim dev requirements
62-
run: |
63-
pip install -r requirements.txt
64-
pip install -r dev-requirements.txt
62+
run: pip install -r requirements.txt --group dev
6563

6664
- name: Run Python tests
6765
env:

Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,20 @@ COPY ./lib/ /qsim/lib/
3838
COPY ./pybind_interface/ /qsim/lib/
3939
COPY ./qsimcirq_tests/ /qsim/qsimcirq_tests/
4040
COPY ./requirements.txt /qsim/requirements.txt
41-
COPY ./dev-requirements.txt /qsim/dev-requirements.txt
41+
COPY ./pyproject.toml /qsim/pyproject.toml
42+
43+
WORKDIR /qsim/
4244

4345
# Create venv to avoid collision between system packages and what we install.
4446
RUN python3 -m venv --upgrade-deps test_env
4547

4648
# Activate venv.
47-
ENV PATH="/test_env/bin:$PATH"
49+
ENV PATH="/qsim/test_env/bin:$PATH"
4850

4951
# Install qsim requirements.
50-
# hadolint ignore=DL3042
51-
RUN python3 -m pip install -r /qsim/requirements.txt && \
52-
python3 -m pip install -r /qsim/dev-requirements.txt
52+
RUN python3 -m pip install --no-cache-dir -r requirements.txt --group dev
5353

5454
# Compile qsim.
55-
WORKDIR /qsim/
5655
RUN make -j qsim
5756

5857
ENTRYPOINT ["/qsim/apps/qsim_base.x"]

dev-requirements.txt

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

dev_tools/test_libs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if [[ "$1" == "-h" || "$1" == "--help" || "$1" == "help" ]]; then
3333
fi
3434

3535
if ! python -m pip show -qq py-cpuinfo 2>/dev/null; then
36-
echo "Error: missing 'py-cpuinfo'. Please install dev-requirements.txt." >&2
36+
echo "Error: missing package 'py-cpuinfo'." >&2
3737
exit 1
3838
fi
3939

docs/install_qsimcirq.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ directly in C++ code without building and installing the qsimcirq interface.
1010

1111
## Before installation
1212

13-
Prior to installation, consider opening a
13+
Prior to installation, consider creating a
1414
[virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/).
1515

16-
Prerequisites are included in the
16+
Prerequisites for installing and running qsim are included in the
1717
[`requirements.txt`](https://github.com/quantumlib/qsim/blob/main/requirements.txt)
18-
file, and will be automatically installed along with qsimcirq.
18+
file, and will be automatically installed along with qsimcirq when you install
19+
it with pip.
1920

20-
If you'd like to develop qsimcirq, a separate set of dependencies are includes
21+
If you'd like to develop qsimcirq, a separate set of dependencies are defined
2122
in the
22-
[`dev-requirements.txt`](https://github.com/quantumlib/qsim/blob/main/dev-requirements.txt)
23-
file. You can install them with `pip3 install -r dev-requirements.txt` or
24-
`pip3 install qsimcirq[dev]`.
23+
[`pyproject.toml`](https://github.com/quantumlib/qsim/blob/main/pyproject.toml)
24+
file. Using pip version 25.1 or higher, you can install them with the following
25+
commands:
26+
27+
```shell
28+
pip install -r requirements.txt
29+
pip install --group dev
30+
```
2531

2632
## Linux installation
2733

pyproject.toml

Lines changed: 123 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,140 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Note: there are altogether 3 types of dependencies listed in this file:
16+
#
17+
# [build-system].requires: the packages needed by the build backend to build
18+
# the project from source. This list is not stored in the package metadata.
19+
#
20+
# [project].dependencies: core packages needed to be able to run qsimcirq.
21+
# Equivalent to "install_requires" in setuptools' setup.py. The list is stored
22+
# in the metadata of the package; when the project is installed by pip, this is
23+
# the specification that is used to install its dependencies.
24+
#
25+
# [dependency-groups].dev: the development dependencies; i.e., what a
26+
# developer needs in order to run unit tests, linters, and formatters. The
27+
# "[dependency-groups]" section is a Python packaging feature introduced in
28+
# 2025. This list is not stored in the metadata of the package. To install the
29+
# development dependencies, use "pip install --group dev".
30+
1531
[build-system]
32+
build-backend = "setuptools.build_meta"
1633
requires = [
17-
"packaging",
18-
"setuptools>=78.1.1",
19-
"pybind11[global]",
20-
# "pip install" from sources needs to build Pybind, which needs CMake too.
21-
"cmake~=3.28.1",
34+
"cmake~=3.28.1",
35+
"pybind11[global]",
36+
"setuptools-scm[toml]>=6.2",
37+
"setuptools>=78.1.1",
38+
"wheel",
2239
]
23-
build-backend = "setuptools.build_meta"
40+
41+
[project]
42+
name = "qsimcirq"
43+
description = "High-performance quantum circuit simulator for C++ and Python."
44+
authors = [
45+
{ name = "The qsim/qsimh Developers", email = "qsim-qsimh-dev@googlegroups.com" }
46+
]
47+
maintainers = [
48+
{ name = "Google Quantum AI", email = "quantum-oss-maintainers@google.com" }
49+
]
50+
readme = {file = "README.md", content-type = "text/markdown"}
51+
license = "Apache-2.0"
52+
requires-python = ">=3.10.0"
53+
dynamic = ["version", "dependencies"]
54+
classifiers = [
55+
"Development Status :: 5 - Production/Stable",
56+
"Environment :: GPU :: NVIDIA CUDA",
57+
"Intended Audience :: Developers",
58+
"Intended Audience :: Science/Research",
59+
"Operating System :: MacOS :: MacOS X",
60+
"Operating System :: Microsoft :: Windows",
61+
"Operating System :: POSIX :: Linux",
62+
"Programming Language :: C++",
63+
"Programming Language :: Python :: 3",
64+
"Programming Language :: Python :: 3.10",
65+
"Programming Language :: Python :: 3.11",
66+
"Programming Language :: Python :: 3.12",
67+
"Programming Language :: Python :: 3.13",
68+
"Topic :: Scientific/Engineering :: Quantum Computing",
69+
"Topic :: Software Development :: Libraries :: Python Modules",
70+
"Typing :: Typed",
71+
]
72+
keywords = [
73+
"cirq",
74+
"nisq",
75+
"quantum algorithm development",
76+
"quantum circuit simulator",
77+
"quantum computing",
78+
"quantum programming",
79+
"quantum simulation",
80+
"quantum",
81+
"schrödinger-feynman simulation",
82+
"simulation",
83+
"state vector simulator",
84+
]
85+
86+
[project.urls]
87+
documentation = "https://quantumai.google/qsim"
88+
download = "https://pypi.org/project/qsimcirq/#files"
89+
homepage = "https://quantumai.google/qsim"
90+
issues = "https://github.com/quantumlib/qsim/issues"
91+
source = "https://github.com/quantumlib/qsim"
92+
93+
[dependency-groups]
94+
# Development dependencies. Install these with "pip install --group dev".
95+
dev = [
96+
# The following repeats [build-system].requires b/c pyproject.toml has no
97+
# mechanism to reference that list. Keep these versions in sync with above.
98+
"cmake~=3.28.1",
99+
"pybind11[global]",
100+
"setuptools>=78.1.1; python_version >= '3.12'",
101+
102+
# Other build, packaging, and distribution utilities.
103+
"cibuildwheel",
104+
105+
# Linters, formatters, and test utilities.
106+
"black~=25.9.0",
107+
"isort[colors]~=6.0.1",
108+
"py-cpuinfo",
109+
"pylint~=4.0.2",
110+
"pytest",
111+
"pytest-xdist",
112+
]
113+
114+
[tool.setuptools]
115+
packages = ["qsimcirq"]
116+
package-data = {"qsimcirq" = ["py.typed"]}
117+
118+
[tool.setuptools.dynamic]
119+
# The next one becomes the value of [project].version.
120+
version = {attr = "qsimcirq._version.__version__"}
121+
# The next one becomes [project].dependencies, equivalent to "install_requires"
122+
# in setuptools' setup.py. "pip install qsim" installs these automatically.
123+
dependencies = {file = ["requirements.txt"] }
24124

25125
[tool.cibuildwheel]
26-
test-extras = "dev"
126+
build = "cp310-* cp311-* cp312-* cp313-*"
27127
dependency-versions = "latest"
28128
enable = ["cpython-prerelease"]
29129
environment.PIP_PREFER_BINARY = "1"
30130
# Due to package & module name conflict, temporarily move it away to run tests:
31-
before-test = "mv {package}/qsimcirq /tmp"
32-
test-command = "pytest -s -v {package}/qsimcirq_tests/qsimcirq_test.py && mv /tmp/qsimcirq {package}"
131+
before-test = "pip install --group dev && mv {package}/qsimcirq /tmp"
132+
test-command = """
133+
pytest -s -v {package}/qsimcirq_tests/qsimcirq_test.py &&
134+
mv /tmp/qsimcirq {package}
135+
"""
33136

34137
[tool.cibuildwheel.macos]
35-
before-build = "brew install -q libomp llvm@19 && brew unlink libomp && brew unlink llvm@19 && brew link --force libomp && brew link --force llvm@19"
36-
repair-wheel-command = "delocate-listdeps {wheel} && delocate-wheel --verbose --require-archs {delocate_archs} -w {dest_dir} {wheel}"
138+
before-build = """
139+
brew install -q libomp llvm@19 &&
140+
brew unlink libomp &&
141+
brew unlink llvm@19 &&
142+
brew link --force libomp &&
143+
brew link --force llvm@19
144+
"""
145+
repair-wheel-command = """
146+
delocate-listdeps {wheel} &&
147+
delocate-wheel --verbose --require-archs {delocate_archs} -w {dest_dir} {wheel}
148+
"""
37149

38150
[tool.cibuildwheel.linux]
39151
manylinux-x86_64-image = "manylinux2014"

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Run-time dependencies for qsimcirq. This file is read from pyproject.toml.
2+
3+
# Core dependencies:
14
absl-py
25
cirq-core~=1.0
36

0 commit comments

Comments
 (0)