Skip to content

Commit 7875b97

Browse files
authored
Update pyproject.toml to use PEP-621 dependency specification (#584)
* Update pyproject.toml to use PEP-621 dependency specification * Remove requirements files * Merge dependency groups, sort dependencies within groups * Remove upper bound constraints, update workflow * Update run_tests.yml * Use just uv instead of uv and poetry * Appease the new version of ruff * Fix workflow bugs * Fix numpy version issue on build
1 parent 0b4ad1c commit 7875b97

15 files changed

+68
-104
lines changed

.github/workflows/build_docs.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,20 @@ jobs:
1818
contents: write
1919
steps:
2020
- uses: actions/checkout@v3
21-
- name: Setup Python
22-
uses: actions/setup-python@v3
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v6
2323
with:
24-
python-version: '3.10'
24+
python-version: "3.10"
2525
- name: Get tag
2626
uses: olegtarasov/[email protected]
2727
- name: Install pandoc
2828
run: sudo apt-get install -y pandoc
29-
- name: Install Poetry
30-
uses: snok/install-poetry@v1
31-
with:
32-
version: 'latest'
3329
- name: Install package and test dependencies
34-
run: |
35-
poetry install --with dev,nbtools
30+
run: uv sync --extra dev
3631
- name: build sphinx docs
3732
run: |
3833
cd docsrc
39-
poetry run make github
34+
uv run make github
4035
- name: Determine directory to publish docs to
4136
id: docs-publish-dir
4237
uses: jannekem/run-python-script-action@v1

.github/workflows/format_and_lint.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v3
16-
- name: Set up Python 3.9
17-
uses: actions/setup-python@v3
16+
- name: Install uv
17+
uses: astral-sh/setup-uv@v6
1818
with:
1919
python-version: "3.9"
20-
- name: Install Poetry
21-
uses: snok/install-poetry@v1
22-
with:
23-
version: 'latest'
2420
- name: Install dependencies
25-
run: |
26-
poetry install --with dev
21+
run: uv sync --extra dev
2722
- name: Run pre-commit
28-
run : poetry run pre-commit run --all-files --show-diff-on-failure --color=always
23+
run: uv run pre-commit run --all-files --show-diff-on-failure --color=always

.github/workflows/python-publish.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflow will upload a Python Package using poetry when a release is created
1+
# This workflow will upload a Python Package using uv when a release is created
22
# Note that you must manually update the version number in pyproject.toml before attempting this.
33

44
name: Upload Python Package
@@ -14,10 +14,10 @@ jobs:
1414
deploy:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v3
18-
- name: Build and publish to pypi
19-
uses: JRubics/[email protected]
20-
with:
21-
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
22-
# python_version: "3.10"
23-
# poetry_version: "==1.8" # can lock versions if we want
17+
- uses: actions/checkout@v4
18+
- uses: astral-sh/setup-uv@v6
19+
- run: uv build
20+
- name: Publish to pypi
21+
env:
22+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
23+
run: uv publish --token "$PYPI_API_TOKEN"

.github/workflows/run_tests.yml

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflow will install Python dependencies, run tests and lint with a single version of Python
1+
# This workflow will install Python dependencies and run tests in multiple versions of Python
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

44
name: tests
@@ -25,31 +25,16 @@ jobs:
2525

2626
steps:
2727
- uses: actions/checkout@v3
28-
- name: Set up Python
29-
uses: actions/setup-python@v3
28+
- name: Install uv and set the python version
29+
uses: astral-sh/setup-uv@v6
3030
with:
3131
python-version: ${{ matrix.python-version }}
32-
- name: Install the latest version of uv
33-
uses: astral-sh/setup-uv@v5
34-
with:
35-
version: "latest"
36-
- name: Install Poetry
37-
uses: snok/install-poetry@v1
38-
with:
39-
version: 'latest'
4032
- name: Install test dependencies
4133
run: |
42-
poetry self add poetry-plugin-export
43-
poetry export -f requirements.txt --with dev,nbtools --without-hashes --output requirements-dev.txt
44-
echo "numpy${{ matrix.numpy-version }}" >> constraints.txt
45-
uv pip compile requirements-dev.txt --output-file requirements.txt \
46-
--python-version ${{ matrix.python-version }} \
47-
--override constraints.txt
48-
poetry run pip install -r requirements.txt
49-
poetry install --only-root
50-
- name: Test with pytest
51-
run: |
52-
poetry run pytest --cov-report xml --cov=bayes_opt/
34+
uv sync --extra dev
35+
uv pip install "numpy${{ matrix.numpy-version}}"
36+
- name: Run pytest
37+
run: uv run --no-sync pytest --cov-report xml --cov=bayes_opt/
5338
- name: Upload coverage to Codecov
5439
uses: codecov/codecov-action@v4
5540
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ docsrc/static/*
3737
docsrc/README.md
3838

3939
poetry.lock
40+
uv.lock
4041

4142
# Add log files and optimizer state files to gitignore
4243
examples/logs.log

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ repos:
66
name: ruff-format
77
args: [--check]
88
repo: https://github.com/astral-sh/ruff-pre-commit
9-
rev: v0.6.6
9+
rev: v0.12.3

bayes_opt/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616

1717
__all__ = [
18-
"acquisition",
1918
"BayesianOptimization",
20-
"TargetSpace",
2119
"ConstraintModel",
2220
"ScreenLogger",
2321
"SequentialDomainReductionTransformer",
22+
"TargetSpace",
23+
"acquisition",
2424
]

bayes_opt/constraint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def approx(self, X: NDArray[Float]) -> NDArray[Float]:
240240
return self._model[0].predict(X).reshape(X_shape[:-1])
241241

242242
result = np.column_stack([gp.predict(X) for gp in self._model])
243-
return result.reshape(X_shape[:-1] + (len(self._lb),))
243+
return result.reshape(*X_shape[:-1], len(self._lb))
244244

245245
def allowed(self, constraint_values: NDArray[Float]) -> NDArray[np.bool_]:
246246
"""Check whether `constraint_values` fulfills the specified limits.

bayes_opt/exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
__all__ = [
66
"BayesianOptimizationError",
7-
"NotUniqueError",
87
"ConstraintNotSupportedError",
98
"NoValidPointRegisteredError",
9+
"NotUniqueError",
1010
"TargetSpaceEmptyError",
1111
]
1212

pyproject.toml

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Bayesian Optimization package"
55
authors = [{ name = "Fernando Nogueira", email = "[email protected]" }]
66
license = { file = "LICENSE" }
77
readme = "README.md"
8-
requires-python = ">=3.9,<4.0"
8+
requires-python = ">=3.9"
99
classifiers = [
1010
"License :: OSI Approved :: MIT License",
1111
"Programming Language :: Python",
@@ -17,51 +17,40 @@ classifiers = [
1717
"Programming Language :: Python :: 3.13",
1818
]
1919
dependencies = [
20-
"scikit-learn>=1.0.0,<2.0.0",
20+
"colorama>=0.4.6",
2121
"numpy>=1.25; python_version<'3.13'",
2222
"numpy>=2.1.3; python_version>='3.13'",
23-
"scipy>=1.0.0,<2.0.0; python_version<'3.13'",
24-
"scipy>=1.14.1,<2.0.0; python_version>='3.13'",
25-
"colorama>=0.4.6,<1.0.0",
23+
"scikit-learn>=1.0.0",
24+
"scipy>=1.0.0; python_version<'3.13'",
25+
"scipy>=1.14.1; python_version>='3.13'",
2626
]
2727

28-
[tool.poetry]
29-
requires-poetry = ">=2.0"
30-
packages = [{ include = "bayes_opt" }]
31-
32-
33-
[tool.poetry.group.dev] # for testing/developing
34-
optional = true
35-
[tool.poetry.group.dev.dependencies]
36-
pytest = "^8.0.0"
37-
pytest-cov = "^4.1.0"
38-
coverage = "^7.4.1"
39-
ruff = "0.6.6"
40-
pre-commit = "^3.7.1"
41-
42-
43-
[tool.poetry.group.nbtools] # for running/converting notebooks
44-
optional = true
45-
[tool.poetry.group.nbtools.dependencies]
46-
nbformat = "^5.9.2"
47-
nbconvert = "^7.14.2"
48-
jupyter = "^1.0.0"
49-
matplotlib = "^3.0"
50-
nbsphinx = "^0.9.4"
51-
sphinx-immaterial = "^0.12.0"
52-
sphinx = [
53-
{ version = "^7.0.0", python = "<3.10" },
54-
{ version = "^8.0.0", python = ">=3.10" },
28+
[project.optional-dependencies]
29+
dev = [
30+
"coverage>=7.4.1",
31+
"jupyter>=1.0.0",
32+
"matplotlib>=3.0",
33+
"nbconvert>=7.14.2",
34+
"nbformat>=5.9.2",
35+
"nbsphinx>=0.9.4",
36+
"pre-commit>=3.7.1",
37+
"pytest>=8.0.0",
38+
"pytest-cov>=4.1.0",
39+
"ruff>=0.12.3",
40+
"sphinx-immaterial>=0.12.0",
41+
"sphinx>=7.0.0; python_version<'3.10'",
42+
"sphinx>=8.0.0; python_version>='3.10'",
43+
"sphinx-autodoc-typehints>=2.3.0; python_version<'3.10'",
44+
"sphinx-autodoc-typehints>=2.4.0; python_version>='3.10'",
5545
]
56-
sphinx-autodoc-typehints = [
57-
{ version = "^2.3.0", python = "<3.10" },
58-
{ version = "^2.4.0", python = ">=3.10" },
59-
]
60-
6146

6247
[build-system]
63-
requires = ["poetry-core>=2.0"]
64-
build-backend = "poetry.core.masonry.api"
48+
requires = ["uv_build>=0.7.21,<0.8.0"]
49+
build-backend = "uv_build"
50+
51+
[tool.uv.build-backend]
52+
module-name = "bayes_opt"
53+
module-root = ""
6554

6655
[tool.coverage.report]
6756
exclude_lines = [

0 commit comments

Comments
 (0)