Skip to content
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

Update infrastructure #507

Merged
merged 26 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e47650d
Use hatch for packaging
timmens Jul 21, 2024
821e6ed
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 21, 2024
a3d2f8f
Use ruff instead of nbqa and black
timmens Jul 21, 2024
798b6cb
Update micromamba setup kwargs
timmens Jul 22, 2024
5e79c85
Prepare for double release
timmens Jul 22, 2024
57544d8
Update terminology in GHA
timmens Jul 22, 2024
dd75dd6
First version of mypy in pre-commit hooks
timmens Jul 22, 2024
2f0dfa3
Use correct PyPi token for optimagic publishing
timmens Jul 22, 2024
8d8634d
Some fixes
timmens Jul 22, 2024
0f0cc70
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 22, 2024
d7b3fcf
Fix errors
timmens Jul 22, 2024
a7b2cf7
Add mypy as separate CI task again
timmens Jul 25, 2024
5695ed8
Fix faulty pyproject updating
timmens Jul 25, 2024
87314c0
Update file path in pyproject.toml update script
timmens Jul 25, 2024
881ca7a
Remove black and related libraries from environments
timmens Jul 25, 2024
b70c255
Combine .envs and .scripts to .tools
timmens Jul 29, 2024
dada973
Update mypy version restriction
timmens Jul 29, 2024
06d75d1
Set minimal Python version to 3.10
timmens Jul 29, 2024
5c365c2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 29, 2024
3b101e6
Add FutureWarning to init files
timmens Jul 29, 2024
c87fc0b
Set correct path for local installation in testing
timmens Jul 29, 2024
180dc64
Replace .script by .tools in pypi publishing
timmens Jul 29, 2024
1fd03f9
Fix
timmens Jul 29, 2024
b01619f
Remove warnings from init files
timmens Jul 30, 2024
575fcb3
Add tool to update init files
timmens Jul 30, 2024
891293a
Update init files before releasing estimagic
timmens Jul 30, 2024
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
19 changes: 10 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: create build environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ./.envs/testenv-linux.yml
environment-file: ./.tools/envs/testenv-linux.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- name: create build environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ./.envs/testenv-others.yml
environment-file: ./.tools/envs/testenv-others.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
Expand All @@ -87,7 +87,7 @@ jobs:
- name: create build environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ./.envs/testenv-pandas.yml
environment-file: ./.tools/envs/testenv-pandas.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
Expand All @@ -104,10 +104,11 @@ jobs:
- name: create build environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ./.envs/testenv-linux.yml
environment-file: ./.tools/envs/testenv-linux.yml
environment-name: optimagic
cache-env: true
extra-specs: python=3.12
cache-environment: true
create-args: |
python=3.12
- name: run sphinx
shell: bash -l {0}
run: |-
Expand All @@ -124,10 +125,10 @@ jobs:
- name: create build environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ./.envs/testenv-linux.yml
environment-file: ./.tools/envs/testenv-linux.yml
environment-name: optimagic
cache-env: true
extra-specs: |
cache-environment: true
create-args: |
python=3.10
- name: Run mypy
shell: bash -l {0}
Expand Down
38 changes: 36 additions & 2 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name: PyPI
on: push
jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
build-n-publish-optimagic:
name: Build and publish optimagic Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -24,6 +24,40 @@ jobs:
--sdist
--wheel
--outdir dist/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN_OPTIMAGIC }}
build-n-publish-estimagic:
name: Build and publish estimagic Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install pypa/build
run: >-
python -m
pip install
build
toml
--user
- name: Set name entry in pyproject.toml to estimagic
run: >-
python .tools/update_name_pyproject.py
- name: Add FutureWarning to init files
run: >-
python .tools/update_init_files.py
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
60 changes: 30 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
hooks:
- id: update-environment-files
name: check environment file updates
entry: python .envs/update_envs.py
entry: python .tools/update_envs.py
language: python
always_run: true
require_serial: true
Expand Down Expand Up @@ -55,16 +55,6 @@ repos:
hooks:
- id: yamllint
exclude: tests/optimagic/optimizers/_pounders/fixtures
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
language_version: python3.10
- repo: https://github.com/asottile/blacken-docs
rev: 1.18.0
hooks:
- id: blacken-docs
exclude: docs/source/how_to/how_to_constraints.md
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
Expand All @@ -78,21 +68,30 @@ repos:
- --blank
exclude: src/optimagic/optimization/algo_options.py
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.5.4
hooks:
# Run the linter.
- id: ruff
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.5
hooks:
- id: nbqa-black
- id: nbqa-ruff
types_or:
- python
- pyi
- jupyter
args:
- --fix
# Run the formatter.
- id: ruff-format
types_or:
- python
- pyi
- jupyter
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm
- mdformat-black
- mdformat-gfm-alerts
- mdformat-ruff
args:
- --wrap
- '88'
Expand All @@ -103,23 +102,24 @@ repos:
- id: mdformat
additional_dependencies:
- mdformat-myst
- mdformat-black
- mdformat-ruff
args:
- --wrap
- '88'
files: (docs/.)
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/mgedmin/check-manifest
rev: '0.49'
hooks:
- id: check-manifest
args:
- --no-build-isolation
- id: mypy
files: src|tests
additional_dependencies:
- setuptools-scm
- toml
- packaging
- pandas-stubs
- sqlalchemy-stubs
- types-cffi
- types-openpyxl
- types-jinja2
args:
- --config=pyproject.toml
ci:
autoupdate_schedule: monthly
4 changes: 2 additions & 2 deletions .envs/testenv-linux.yml → .tools/envs/testenv-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- seaborn # dev, tests
- mypy # dev, tests
- mypy>=1.10 # dev, tests
- pyyaml # dev, tests
- jinja2 # dev, tests
- pip: # dev, tests, docs
Expand All @@ -33,4 +33,4 @@ dependencies:
- types-cffi # dev, tests
- types-openpyxl # dev, tests
- types-jinja2 # dev, tests
- -e ../
- -e ../../
4 changes: 2 additions & 2 deletions .envs/testenv-others.yml → .tools/envs/testenv-others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- seaborn # dev, tests
- mypy # dev, tests
- mypy>=1.10 # dev, tests
- pyyaml # dev, tests
- jinja2 # dev, tests
- pip: # dev, tests, docs
Expand All @@ -32,4 +32,4 @@ dependencies:
- types-cffi # dev, tests
- types-openpyxl # dev, tests
- types-jinja2 # dev, tests
- -e ../
- -e ../../
4 changes: 2 additions & 2 deletions .envs/testenv-pandas.yml → .tools/envs/testenv-pandas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
- scipy>=1.2.1 # run, tests
- sqlalchemy # run, tests
- seaborn # dev, tests
- mypy # dev, tests
- mypy>=1.10 # dev, tests
- pyyaml # dev, tests
- jinja2 # dev, tests
- pip: # dev, tests, docs
Expand All @@ -30,4 +30,4 @@ dependencies:
- types-cffi # dev, tests
- types-openpyxl # dev, tests
- types-jinja2 # dev, tests
- -e ../
- -e ../../
7 changes: 4 additions & 3 deletions .envs/update_envs.py → .tools/update_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main():
# create standard testing environments

test_env = [line for line in lines if _keep_line(line, "tests")]
test_env.append(" - -e ../") # add local installation
test_env.append(" - -e ../../") # add local installation

# find index to insert additional dependencies
_insert_idx = [i for i, line in enumerate(lines) if "dependencies:" in line][0] + 1
Expand All @@ -42,16 +42,17 @@ def main():
# create docs testing environment

docs_env = [line for line in lines if _keep_line(line, "docs")]
docs_env.append(" - -e ../") # add local installation
docs_env.append(" - -e ../../") # add local installation

# write environments
for name, env in zip(
["linux", "others", "pandas"],
[test_env_linux, test_env_others, test_env_pandas],
strict=False,
):
# Specify newline to avoid wrong line endings on Windows.
# See: https://stackoverflow.com/a/69869641
Path(f".envs/testenv-{name}.yml").write_text(
Path(f".tools/envs/testenv-{name}.yml").write_text(
"\n".join(env) + "\n", newline="\n"
)

Expand Down
29 changes: 29 additions & 0 deletions .tools/update_init_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pathlib import Path

SRC = Path(__file__).parent.parent.resolve() / "src"


to_append = r"""
import warnings
warnings.warn(
"estimagic has been renamed to optimagic. Please uninstall estimagic and install "
"optimagic instead. Don't worry, your estimagic imports will still work if you "
"install optimagic, and simple warnings will help you to adjust them for future "
"releases.\n\n"
"To make these changes using pip, run:\n"
"-------------------------------------\n"
"$ pip uninstall estimagic\n"
"$ pip install optimagic\n\n"
"For conda users, use:\n"
"---------------------\n"
"$ conda remove estimagic\n"
"$ conda install -c conda-forge optimagic\n",
FutureWarning,
)
"""

for package in ("estimagic", "optimagic"):
init_file = SRC / package / "__init__.py"
current_content = init_file.read_text()
new_content = current_content + to_append
init_file.write_text(new_content)
12 changes: 12 additions & 0 deletions .tools/update_name_pyproject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import toml
from pathlib import Path

file_path = Path(__file__).parent.parent.resolve() / "pyproject.toml"

with file_path.open("r") as f:
config = toml.load(f)

config["project"]["name"] = "estimagic"

with file_path.open("w") as f:
toml.dump(config, f)
34 changes: 0 additions & 34 deletions MANIFEST.in

This file was deleted.

1 change: 0 additions & 1 deletion docs/rtd_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dependencies:
- pip
- setuptools_scm
- toml
- black
- sphinx
- sphinxcontrib-bibtex
- sphinx-copybutton
Expand Down
2 changes: 0 additions & 2 deletions docs/source/development/ep-02-typing.md
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,6 @@ class ScipyNelderMead(Algorithm):
def _solve_internal_problem(
self, problem: InternalProblem, x0: NDArray[float]
) -> InternalOptimizeResult:

timmens marked this conversation as resolved.
Show resolved Hide resolved
options = {
"maxiter": self.stopping_max_iterations,
"maxfev": self.stopping_max_criterion_evaluations,
Expand Down Expand Up @@ -1540,7 +1539,6 @@ FvalType = TypeVar("FvalType", bound=float | NDArray[float])


class BenchmarkNoise(ABC):

@abstractmethod
def draw_noise(
self, fval: FvalType, params: NDArray, size: int, rng: np.random.Generator
Expand Down
Loading