diff --git a/.github/actions/ubuntu_restore_all/action.yml b/.github/actions/ubuntu_restore_all/action.yml new file mode 100644 index 000000000..5665a59b3 --- /dev/null +++ b/.github/actions/ubuntu_restore_all/action.yml @@ -0,0 +1,25 @@ +name: ubuntu_restore_all +runs: + using: composite + steps: + - uses: actions/checkout@v4.1.0 + # - name: restore_cache + # uses: actions/cache@v3.3.2 + # with: + # key: v4-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/main.txt"}}-{{ checksum "requirements/bench.txt"}} + # path: ./venv + # restore-keys: | + # v4-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/main.txt"}}-{{ checksum "requirements/bench.txt"}} + # v4-dependencies-main-{{ checksum "requirements/main.txt"}} + - name: "[all] Install dependencies" + run: | + set -ex + #python3 -m venv venv + rm -rf venv && python3 -m venv venv + . venv/bin/activate + pip install --progress-bar off -U pip setuptools + pip install --progress-bar off -v -e .[all] + #pip install --progress-bar off --use-deprecated=legacy-resolver -e .[all] + pip install --progress-bar off -U numpy==1.24.0 matplotlib==2.2.3 pyomo==5.7.1 + pip install keras==2.6.0 # issue on Nov 4th 2021 + shell: bash diff --git a/.github/workflows/every_commit.yml b/.github/workflows/every_commit.yml new file mode 100644 index 000000000..fcbb2c2b2 --- /dev/null +++ b/.github/workflows/every_commit.yml @@ -0,0 +1,125 @@ +name: facebookresearch/nevergrad/every_commit +on: + push: + branches: + - main + pull_request: +jobs: + install: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - name: restore_cache + uses: actions/cache@v3.3.2 + with: + key: v4-dependencies-main-{{ checksum "requirements/main.txt"}} + path: "./venv" + restore-keys: v4-dependencies-main-{{ checksum "requirements/main.txt"}} + - name: "[no-extra] Install dependencies" + run: | + rm -rf venv && python3 -m venv venv + . venv/bin/activate + pip install --progress-bar off pip==23.2 + pip install --progress-bar off -e . + - name: "[no-extra] Print installation" + run: | + . venv/bin/activate + pip freeze + - name: "[no-extra] Run basic tests (checking dependencies)" + run: | + . venv/bin/activate + python -m nevergrad.optimization.requirements_check # calls a bit of everything + - uses: "./.github/actions/ubuntu_restore_all" + - name: save_cache + uses: actions/cache@v3.3.2 + with: + path: "./venv" + key: v4-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/main.txt"}}-{{ checksum "requirements/bench.txt"}} + - name: "[all] Print installation" + run: | + . venv/bin/activate + pip freeze + - name: Run wheel and check package + run: | + . venv/bin/activate + pip install wheel + rm -rf dist # make sure it's clean + echo "Creating sdist" + python setup.py sdist + echo "Created sdist, now creating wheel" + python setup.py bdist_wheel + echo "Created wheel" + mkdir nevergrad-build + mv dist nevergrad-build/ + python -c "from pathlib import Path;files = Path('nevergrad.egg-info/SOURCES.txt').read_text().split(); assert 'LICENSE' in files" + python3 -m venv test_wheel + . test_wheel/bin/activate + pip install -U pip + cd .. # don't use nevergrad locally + echo "Installing wheel" + pip install --progress-bar off repo/nevergrad-build/dist/nevergrad-*any.whl + #pip install --progress-bar off --use-deprecated=legacy-resolver repo/nevergrad-build/dist/nevergrad-*any.whl + echo "Installed wheel" + python -c "from nevergrad import functions;f = functions.ArtificialFunction(name='sphere', block_dimension=2);f([2, 3])" + - name: Build docs + run: | + . venv/bin/activate + cd docs/ + make html + - name: Upload static files as artifact + id: deployment + uses: actions/upload-pages-artifact@v3 + with: + path: docs/_build/html/ + if: github.event_name != 'pull_request' + deploy-docs: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: install + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + static: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/ubuntu_restore_all" + - name: Run mypy + run: | + . venv/bin/activate + mypy --version + mypy nevergrad + - name: Run basic pylint + run: | + . venv/bin/activate + pylint --version + pylint nevergrad --disable=all --enable=unused-import,unused-argument,unused-variable,undefined-loop-variable,redefined-builtin,used-before-assignment,super-init-not-called,useless-super-delegation,dangerous-default-value,unnecessary-pass,attribute-defined-outside-init + - name: Run black + run: | + . venv/bin/activate + pip install black + black --version + black nevergrad --check --diff + pytests: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/ubuntu_restore_all" + - name: "[all] Run pytest" + run: | + . venv/bin/activate + pip install pytest + pytest --circleci-parallelize nevergrad -v --durations=20 --cov=nevergrad + #pytest nevergrad -v --exitfirst --durations=20 --cov=nevergrad diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..65e9a8077 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,19 @@ +name: facebookresearch/nevergrad/main +on: + push: + branches: + - main +jobs: + docs-links: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/ubuntu_restore_all" + - name: Check links + run: | + . venv/bin/activate + cd docs/ + make linkcheck diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 000000000..8d72e69d0 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,44 @@ +name: facebookresearch/nevergrad/release +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+.post[0-9]+' +env: + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + CIRCLE_TAG: ${{ github.ref_name }} +jobs: + pypi-deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/ubuntu_restore_all" + - name: Run wheel and check package + run: | + . venv/bin/activate + pip install wheel + rm -rf dist # make sure it's clean + echo "Creating sdist" + python setup.py sdist + echo "Created sdist, now creating wheel" + python setup.py bdist_wheel + echo "Created wheel" + mkdir nevergrad-build + mv dist nevergrad-build/ + - name: Create .pypirc + run: | + echo -e "[pypi]" >> ~/.pypirc + echo -e "username = __token__" >> ~/.pypirc + echo -e "password = $PYPI_PASSWORD" >> ~/.pypirc + - name: Verify tag + run: python setup.py verify_circleci_version + - name: upload to pypi + run: | + echo "Deploying" + . venv/bin/activate + du -h nevergrad-build/dist/* + twine check nevergrad-build/dist/nevergrad-* + twine upload nevergrad-build/dist/nevergrad-* --verbose diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03c832bfd..2f698634c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,28 @@ repos: -- repo: https://github.com/pre-commit/pre-commit-hooks + - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.2.3 hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-added-large-files -# - repo: https://github.com/pre-commit/mirrors-autopep8 -# rev: v1.4.4 # Use the sha / tag you want to point at -# hooks: -# - id: autopep8 -# exclude: ^scripts/ -# args: ['-i', '--max-line-length=140'] -- repo: https://github.com/python/black - rev: 20.8b1 + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + # - repo: https://github.com/pre-commit/mirrors-autopep8 + # rev: v1.4.4 # Use the sha / tag you want to point at + # hooks: + # - id: autopep8 + # exclude: ^scripts/ + # args: ['-i', '--max-line-length=140'] + - repo: https://github.com/python/black + rev: 22.3.0 hooks: - - id: black - language_version: python3 -- repo: https://github.com/pre-commit/mirrors-pylint + - id: black + language_version: python3 + - repo: https://github.com/pre-commit/mirrors-pylint rev: v2.4.4 hooks: - - id: pylint - exclude: ^scripts/ - args: ['--disable=bad-continuation'] # coz incompatible with black + - id: pylint + exclude: ^scripts/ + args: ['--disable=bad-continuation'] # coz incompatible with black + - repo: https://github.com/google/yamlfmt + rev: v0.14.0 + hooks: + - id: yamlfmt diff --git a/setup.py b/setup.py index fbf02148f..b9c8d36ac 100644 --- a/setup.py +++ b/setup.py @@ -4,16 +4,27 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -import re import os +import re import sys import typing as tp from pathlib import Path -from setuptools import setup -from setuptools import find_packages + +from setuptools import find_packages, setup from setuptools.command.install import install +def is_canonical(version_str: str) -> bool: + return ( + re.match( + r"^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*" + + r"((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$", + version_str, + ) + is not None + ) + + # read requirements requirements: tp.Dict[str, tp.List[str]] = {} @@ -32,6 +43,7 @@ match = re.search(r"^__version__ = \"(?P[\w\.]+?)\"$", init_str, re.MULTILINE) assert match is not None, "Could not find version in nevergrad/__init__.py" version = match.group("version") +assert is_canonical(version), f"Version {version} is not canonical" def _replace_relative_links(regex: tp.Match[str]) -> str: @@ -67,6 +79,11 @@ def run(self) -> None: sys.exit(info) +print(f"{version=}") +print(f"{long_description=}") +print(f"{find_packages()=}") +print(f"{requirements=}") + # setup setup( name="nevergrad",