Skip to content

Update pyproject.toml to use PEP-621 dependency specification #584

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

Merged
merged 9 commits into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v3
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: '3.10'
python-version: "3.10"
- name: Get tag
uses: olegtarasov/get-tag@v2.1
- name: Install pandoc
run: sudo apt-get install -y pandoc
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 'latest'
- name: Install package and test dependencies
run: |
poetry install --with dev,nbtools
run: uv sync --extra dev
- name: build sphinx docs
run: |
cd docsrc
poetry run make github
uv run make github
- name: Determine directory to publish docs to
id: docs-publish-dir
uses: jannekem/run-python-script-action@v1
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/format_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: "3.9"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 'latest'
- name: Install dependencies
run: |
poetry install --with dev
run: uv sync --extra dev
- name: Run pre-commit
run : poetry run pre-commit run --all-files --show-diff-on-failure --color=always
run: uv run pre-commit run --all-files --show-diff-on-failure --color=always
16 changes: 8 additions & 8 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will upload a Python Package using poetry when a release is created
# This workflow will upload a Python Package using uv when a release is created
# Note that you must manually update the version number in pyproject.toml before attempting this.

name: Upload Python Package
Expand All @@ -14,10 +14,10 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v2.0
with:
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
# python_version: "3.10"
# poetry_version: "==1.8" # can lock versions if we want
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- run: uv build
- name: Publish to pypi
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: uv publish --token "$PYPI_API_TOKEN"
29 changes: 7 additions & 22 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# This workflow will install Python dependencies and run tests in multiple versions of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: tests
Expand All @@ -25,31 +25,16 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
with:
version: "latest"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 'latest'
- name: Install test dependencies
run: |
poetry self add poetry-plugin-export
poetry export -f requirements.txt --with dev,nbtools --without-hashes --output requirements-dev.txt
echo "numpy${{ matrix.numpy-version }}" >> constraints.txt
uv pip compile requirements-dev.txt --output-file requirements.txt \
--python-version ${{ matrix.python-version }} \
--override constraints.txt
poetry run pip install -r requirements.txt
poetry install --only-root
- name: Test with pytest
run: |
poetry run pytest --cov-report xml --cov=bayes_opt/
uv sync --extra dev
uv pip install "numpy${{ matrix.numpy-version}}"
- name: Run pytest
run: uv run --no-sync pytest --cov-report xml --cov=bayes_opt/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ docsrc/static/*
docsrc/README.md

poetry.lock
uv.lock

# Add log files and optimizer state files to gitignore
examples/logs.log
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ repos:
name: ruff-format
args: [--check]
repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.6
rev: v0.12.3
4 changes: 2 additions & 2 deletions bayes_opt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@


__all__ = [
"acquisition",
"BayesianOptimization",
"TargetSpace",
"ConstraintModel",
"ScreenLogger",
"SequentialDomainReductionTransformer",
"TargetSpace",
"acquisition",
]
2 changes: 1 addition & 1 deletion bayes_opt/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def approx(self, X: NDArray[Float]) -> NDArray[Float]:
return self._model[0].predict(X).reshape(X_shape[:-1])

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

def allowed(self, constraint_values: NDArray[Float]) -> NDArray[np.bool_]:
"""Check whether `constraint_values` fulfills the specified limits.
Expand Down
2 changes: 1 addition & 1 deletion bayes_opt/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

__all__ = [
"BayesianOptimizationError",
"NotUniqueError",
"ConstraintNotSupportedError",
"NoValidPointRegisteredError",
"NotUniqueError",
"TargetSpaceEmptyError",
]

Expand Down
67 changes: 28 additions & 39 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Bayesian Optimization package"
authors = [{ name = "Fernando Nogueira", email = "fmfnogueira@gmail.com" }]
license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.9,<4.0"
requires-python = ">=3.9"
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
Expand All @@ -17,51 +17,40 @@ classifiers = [
"Programming Language :: Python :: 3.13",
]
dependencies = [
"scikit-learn>=1.0.0,<2.0.0",
"colorama>=0.4.6",
"numpy>=1.25; python_version<'3.13'",
"numpy>=2.1.3; python_version>='3.13'",
"scipy>=1.0.0,<2.0.0; python_version<'3.13'",
"scipy>=1.14.1,<2.0.0; python_version>='3.13'",
"colorama>=0.4.6,<1.0.0",
"scikit-learn>=1.0.0",
"scipy>=1.0.0; python_version<'3.13'",
"scipy>=1.14.1; python_version>='3.13'",
]

[tool.poetry]
requires-poetry = ">=2.0"
packages = [{ include = "bayes_opt" }]


[tool.poetry.group.dev] # for testing/developing
optional = true
[tool.poetry.group.dev.dependencies]
pytest = "^8.0.0"
pytest-cov = "^4.1.0"
coverage = "^7.4.1"
ruff = "0.6.6"
pre-commit = "^3.7.1"


[tool.poetry.group.nbtools] # for running/converting notebooks
optional = true
[tool.poetry.group.nbtools.dependencies]
nbformat = "^5.9.2"
nbconvert = "^7.14.2"
jupyter = "^1.0.0"
matplotlib = "^3.0"
nbsphinx = "^0.9.4"
sphinx-immaterial = "^0.12.0"
sphinx = [
{ version = "^7.0.0", python = "<3.10" },
{ version = "^8.0.0", python = ">=3.10" },
[project.optional-dependencies]
dev = [
"coverage>=7.4.1",
"jupyter>=1.0.0",
"matplotlib>=3.0",
"nbconvert>=7.14.2",
"nbformat>=5.9.2",
"nbsphinx>=0.9.4",
"pre-commit>=3.7.1",
"pytest>=8.0.0",
"pytest-cov>=4.1.0",
"ruff>=0.12.3",
"sphinx-immaterial>=0.12.0",
"sphinx>=7.0.0; python_version<'3.10'",
"sphinx>=8.0.0; python_version>='3.10'",
"sphinx-autodoc-typehints>=2.3.0; python_version<'3.10'",
"sphinx-autodoc-typehints>=2.4.0; python_version>='3.10'",
]
sphinx-autodoc-typehints = [
{ version = "^2.3.0", python = "<3.10" },
{ version = "^2.4.0", python = ">=3.10" },
]


[build-system]
requires = ["poetry-core>=2.0"]
build-backend = "poetry.core.masonry.api"
requires = ["uv_build>=0.7.21,<0.8.0"]
build-backend = "uv_build"

[tool.uv.build-backend]
module-name = "bayes_opt"
module-root = ""

[tool.coverage.report]
exclude_lines = [
Expand Down
4 changes: 2 additions & 2 deletions scripts/check.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
set -ex

poetry run ruff format --check bayes_opt tests
poetry run ruff check bayes_opt tests
uv run ruff format --check bayes_opt tests
uv run ruff check bayes_opt tests
4 changes: 2 additions & 2 deletions scripts/check_precommit.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
set -ex

poetry run pre-commit install
poetry run pre-commit run --all-files --show-diff-on-failure
uv run pre-commit install
uv run pre-commit run --all-files --show-diff-on-failure
5 changes: 2 additions & 3 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env sh
set -ex

poetry run ruff format bayes_opt tests
poetry run ruff check bayes_opt --fix

uv run ruff format bayes_opt tests
uv run ruff check bayes_opt --fix
4 changes: 2 additions & 2 deletions tests/test_seq_domain_red.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ def verify_bounds_in_range(new_bounds, global_bounds):

# test if both (upper/lower) bounds for a parameter exceed the global bounds
new_bounds = np.array([[-50, -20], [20, 50]])
with pytest.warns(UserWarning):
with pytest.warns(UserWarning, match="A parameter's lower bound is greater than the global upper bound"):
trimmed_bounds = bounds_transformer._trim(new_bounds, global_bounds)
assert verify_bounds_in_range(trimmed_bounds, global_bounds)

# test if both (upper/lower) bounds for a parameter exceed the global bounds
# while they are out of order
new_bounds = np.array([[-20, -50], [-10, 10]])
with pytest.warns(UserWarning):
with pytest.warns(UserWarning, match="A parameter's lower bound is greater than the global upper bound"):
trimmed_bounds = bounds_transformer._trim(new_bounds, global_bounds)
assert verify_bounds_in_range(trimmed_bounds, global_bounds)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_target_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_register_point_beyond_bounds():
PBOUNDS = {"p1": (0, 1), "p2": (1, 10)}
space = TargetSpace(target_func, PBOUNDS)

with pytest.warns(UserWarning):
with pytest.warns(UserWarning, match="is outside the bounds of the parameter"):
space.register(params={"p1": 0.5, "p2": 20}, target=2.5)


Expand Down Expand Up @@ -209,7 +209,7 @@ def test_y_max_within_pbounds():
assert space._target_max() is None
space.probe(params={"p1": 1, "p2": 2})
space.probe(params={"p1": 0, "p2": 1})
with pytest.warns(UserWarning):
with pytest.warns(UserWarning, match="is outside the bounds of the parameter"):
space.probe(params={"p1": 5, "p2": 1})
assert space._target_max() == 3

Expand Down