Skip to content

Commit

Permalink
github actions
Browse files Browse the repository at this point in the history
ghstack-source-id: 992c24b5555aced54ffc3af4556abff1c846057c
Pull Request resolved: #1654
  • Loading branch information
bottler committed Nov 28, 2024
1 parent fbfa539 commit c72f135
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 21 deletions.
26 changes: 26 additions & 0 deletions .github/actions/ubuntu_restore_all/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ubuntu_restore_all
runs:
using: composite
steps:
# - uses: actions/[email protected]
# - name: restore_cache
# uses: actions/[email protected]
# 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 -v IOHexperimenter>=0.2.9.2
pip install --progress-bar off -v -v -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
125 changes: 125 additions & 0 deletions .github/workflows/every_commit.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- name: restore_cache
uses: actions/[email protected]
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/[email protected]
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/[email protected]
- 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/[email protected]
- 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
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- uses: "./.github/actions/ubuntu_restore_all"
- name: Check links
run: |
. venv/bin/activate
cd docs/
make linkcheck
44 changes: 44 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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
40 changes: 22 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 23 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@
# 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 pprint import pprint

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]] = {}
Expand All @@ -32,6 +44,7 @@
match = re.search(r"^__version__ = \"(?P<version>[\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:
Expand Down Expand Up @@ -67,6 +80,13 @@ def run(self) -> None:
sys.exit(info)


print(f"{version=}")
print(f"{long_description=}")
print(f"{find_packages()=}")
print(f"{requirements=}")

pprint(dict(os.environ))

# setup
setup(
name="nevergrad",
Expand Down

0 comments on commit c72f135

Please sign in to comment.