From d83f3fb4cc4785535f5ec711c9c99dec46357608 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Wed, 14 Feb 2024 10:43:46 -0500 Subject: [PATCH 01/26] Add initial changes for issue 59 refactor of build system * Remove hardcoded version (which will be replaced dynamically) * Add specific lines to init * Add scripts directory, which contains a few helpers --- gpax/__init__.py | 7 +++++++ gpax/__version__.py | 1 - scripts/LICENSE | 29 +++++++++++++++++++++++++++++ scripts/README.md | 7 +++++++ scripts/build_docs.sh | 25 +++++++++++++++++++++++++ scripts/build_project.sh | 6 ++++++ scripts/install.sh | 27 +++++++++++++++++++++++++++ scripts/update_version.sh | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 136 insertions(+), 1 deletion(-) delete mode 100644 gpax/__version__.py create mode 100644 scripts/LICENSE create mode 100644 scripts/README.md create mode 100644 scripts/build_docs.sh create mode 100644 scripts/build_project.sh create mode 100644 scripts/install.sh create mode 100644 scripts/update_version.sh diff --git a/gpax/__init__.py b/gpax/__init__.py index 7529e8f..f40247c 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -10,3 +10,10 @@ __all__ = ["utils", "kernels", "mtkernels", "acquisition", "ExactGP", "vExactGP", "DKL", "viDKL", "iBNN", "vi_iBNN", "MultiTaskGP", "viMTDKL", "viGP", "sPM", "VarNoiseGP", "UIGP", "MeasuredNoiseGP", "viSparseGP", "CoregGP", "sample_next", "__version__"] + +# DO NOT CHANGE BELOW --------------------------------------------------------- +# This is replaced at build time automatically during deployment and +# installation. Replacing anything will mess that up and crash the entire +# build. +__version__ = ... # semantic-version-placeholder +# DO NOT CHANGE ABOVE --------------------------------------------------------- diff --git a/gpax/__version__.py b/gpax/__version__.py deleted file mode 100644 index 0f29d8c..0000000 --- a/gpax/__version__.py +++ /dev/null @@ -1 +0,0 @@ -version = '0.1.7' diff --git a/scripts/LICENSE b/scripts/LICENSE new file mode 100644 index 0000000..deacfc5 --- /dev/null +++ b/scripts/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2022, Brookhaven Science Associates, LLC, Brookhaven National Laboratory +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..6f2bd92 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,7 @@ +# Scripts + +This directory contains helper scripts for GPax. + +- Build scripts for building the project +- Testing script for the notebook smoke tests +- `LICENSE` file, attributing code in this directory only to Brookhaven Science Associates (location from which the code was sourced) diff --git a/scripts/build_docs.sh b/scripts/build_docs.sh new file mode 100644 index 0000000..d42d820 --- /dev/null +++ b/scripts/build_docs.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +build_docs () { + + if [[ "${GITHUB_ACTION_IS_RUNNING}" = 1 ]]; then + bash scripts/install.sh doc + fi + + make -C docs/ html + + # Helper when running on local. If not running in a GitHub Actions + # environment, this will attempt to open index.html with the users' + # default program + if [[ -z "${GITHUB_ACTION_IS_RUNNING}" ]]; then + open docs/build/html/index.html + fi + +} + +pip install toml +bash scripts/install.sh +bash scripts/install.sh doc +bash scripts/update_version.sh set +build_docs +bash scripts/update_version.sh reset diff --git a/scripts/build_project.sh b/scripts/build_project.sh new file mode 100644 index 0000000..0d5f6f8 --- /dev/null +++ b/scripts/build_project.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +pip install flit~=3.7 +bash scripts/update_version.sh set +flit build +bash scripts/update_version.sh reset diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..f4cf1f5 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Good stuff. The poor man's toml parser +# https://github.com/pypa/pip/issues/8049 +# This is the analog of pip install -e ".[...]" since for whatever reason +# it does not appear to work cleanly with pip +install_doc_requirements_only () { + python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["optional-dependencies"]["doc"]))' | pip install -r /dev/stdin +} + +install_test_requirements_only () { + python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["optional-dependencies"]["test"]))' | pip install -r /dev/stdin +} + +install_requirements() { + python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["dependencies"]))' | pip install -r /dev/stdin +} + + +pip install toml +if [ "$1" = "doc" ]; then + install_doc_requirements_only +elif [ "$1" = "test" ]; then + install_test_requirements_only +else + install_requirements +fi diff --git a/scripts/update_version.sh b/scripts/update_version.sh new file mode 100644 index 0000000..0bd018e --- /dev/null +++ b/scripts/update_version.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +PACKAGE_NAME="gpax" + +replace_version_in_init () { + pip install dunamai~=1.12 + version="$(dunamai from git --style pep440 --no-metadata)" + dunamai check "$version" --style pep440 + sed_command="s/... # semantic-version-placeholder/'$version'/g" + if [[ "$OSTYPE" == "darwin"* ]]; then + sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py + else + sed -i "$sed_command" "$PACKAGE_NAME"/__init__.py + fi + echo "__init__ version set to" "$version" + export _TMP_VERSION="$version" +} + +reset_version_to_ellipsis () { + current_version=$(grep "__version__" "$PACKAGE_NAME"/__init__.py) + sed_command="s/$current_version/__version__ = ... # semantic-version-placeholder/g" + if [[ "$OSTYPE" == "darwin"* ]]; then + sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py + else + sed -i "$sed_command" "$PACKAGE_NAME"/__init__.py + fi + echo "$current_version" "reset to placeholder" +} + + +if [ "$1" == "set" ]; then + replace_version_in_init +elif [ "$1" == "reset" ]; then + reset_version_to_ellipsis +fi From ff920c41cc383a7df8dc0aa7edef7943040ddb0b Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Wed, 14 Feb 2024 16:41:57 -0500 Subject: [PATCH 02/26] Update pyproject, ignore some IDE tools --- .gitignore | 3 +++ pyproject.toml | 41 +++++++++++++++++++++++++++++++++++++++++ scripts/install.sh | 7 +------ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b6e4761..c0fb41c 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# Pyright +pyrightconfig.json diff --git a/pyproject.toml b/pyproject.toml index 1eeed4c..6091e9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,44 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "gpax" +authors = [ + {"name" = "Maxim Ziatdinov", "email" = "maxim.ziatdinov@ai4microcopy.com"} +] +readme = "README.md" +requires-python = ">=3.9" +license = {"file" = "LICENSE"} +description='Gaussian processes in NumPyro and JAX' +classifiers=[ + 'Programming Language :: Python', + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Science/Research', + 'Operating System :: POSIX :: Linux', + 'Operating System :: MacOS :: MacOS X', + 'Topic :: Scientific/Engineering' +] + +# Core dependencies +dependencies = [ + "matplotlib>=3.1.1", + "jax>=0.4.8", + "numpyro>=0.11.0", + "dm-haiku>=0.0.5", + "jaxopt", # TODO: do we want to require this? +] + +dynamic = ["version"] + +[project.optional-dependencies] +test = [ + "flake8", + "jaxlib", + "pytest", + "pytest-cov", +] + [tool.black] line-length = 127 include = '\.pyi?$' diff --git a/scripts/install.sh b/scripts/install.sh index f4cf1f5..bbd3224 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -4,9 +4,6 @@ # https://github.com/pypa/pip/issues/8049 # This is the analog of pip install -e ".[...]" since for whatever reason # it does not appear to work cleanly with pip -install_doc_requirements_only () { - python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["optional-dependencies"]["doc"]))' | pip install -r /dev/stdin -} install_test_requirements_only () { python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["optional-dependencies"]["test"]))' | pip install -r /dev/stdin @@ -18,9 +15,7 @@ install_requirements() { pip install toml -if [ "$1" = "doc" ]; then - install_doc_requirements_only -elif [ "$1" = "test" ]; then +if [ "$1" = "test" ]; then install_test_requirements_only else install_requirements From 0e610b110587bfd5e0fc4483492ac064af95294d Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 08:15:26 -0500 Subject: [PATCH 03/26] Remove old version code in init, remove setup.py --- gpax/__init__.py | 1 - setup.py | 40 ---------------------------------------- 2 files changed, 41 deletions(-) delete mode 100644 setup.py diff --git a/gpax/__init__.py b/gpax/__init__.py index f40247c..10ceef4 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -1,4 +1,3 @@ -from .__version__ import version as __version__ from . import utils from . import kernels from . import acquisition diff --git a/setup.py b/setup.py deleted file mode 100644 index 537b639..0000000 --- a/setup.py +++ /dev/null @@ -1,40 +0,0 @@ -__author__ = "Maxim Ziatdinov" -__copyright__ = "Copyright Maxim Ziatdinov (2021)" -__maintainer__ = "Maxim Ziatdinov" -__email__ = "maxim.ziatdinov@ai4microcopy.com" - -from setuptools import setup, find_packages -import os - -module_dir = os.path.dirname(os.path.abspath(__file__)) - -with open(os.path.join(module_dir, 'gpax/__version__.py')) as f: - __version__ = f.read().split("'")[1] - -if __name__ == "__main__": - setup( - name='gpax', - python_requires='>=3.9', - version=__version__, - description='Gaussian processes in NumPyro and JAX', - long_description=open(os.path.join(module_dir, 'README.md')).read(), - long_description_content_type='text/markdown', - url='https://github.com/ziatdinovmax/gpax/', - author='Maxim Ziatdinov', - author_email='maxim.ziatdinov@ai4microcopy.com', - license='MIT license', - packages=find_packages(), - zip_safe=False, - install_requires=[ - 'jax>=0.4.8', - 'numpyro>=0.11.0', - 'dm-haiku>=0.0.5', - 'matplotlib>=3.1' - ], - classifiers=['Programming Language :: Python', - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Science/Research', - 'Operating System :: POSIX :: Linux', - 'Operating System :: MacOS :: MacOS X', - 'Topic :: Scientific/Engineering'] - ) From e6b1a51663516e82c73525c099a3df67e1e8a753 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 08:19:08 -0500 Subject: [PATCH 04/26] Reformat __init__ --- gpax/__init__.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/gpax/__init__.py b/gpax/__init__.py index 10ceef4..36b28cd 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -1,14 +1,32 @@ -from . import utils -from . import kernels -from . import acquisition +from . import acquisition, kernels, utils from .hypo import sample_next -from .models import (DKL, CoregGP, ExactGP, MultiTaskGP, iBNN, vExactGP, - vi_iBNN, viDKL, viGP, sPM, viMTDKL, VarNoiseGP, UIGP, - MeasuredNoiseGP, viSparseGP) +from .models import (DKL, UIGP, CoregGP, ExactGP, MeasuredNoiseGP, MultiTaskGP, + VarNoiseGP, iBNN, sPM, vExactGP, vi_iBNN, viDKL, viGP, + viMTDKL, viSparseGP) -__all__ = ["utils", "kernels", "mtkernels", "acquisition", "ExactGP", "vExactGP", "DKL", - "viDKL", "iBNN", "vi_iBNN", "MultiTaskGP", "viMTDKL", "viGP", "sPM", "VarNoiseGP", - "UIGP", "MeasuredNoiseGP", "viSparseGP", "CoregGP", "sample_next", "__version__"] +__all__ = [ + "utils", + "kernels", + "mtkernels", + "acquisition", + "ExactGP", + "vExactGP", + "DKL", + "viDKL", + "iBNN", + "vi_iBNN", + "MultiTaskGP", + "viMTDKL", + "viGP", + "sPM", + "VarNoiseGP", + "UIGP", + "MeasuredNoiseGP", + "viSparseGP", + "CoregGP", + "sample_next", + "__version__", +] # DO NOT CHANGE BELOW --------------------------------------------------------- # This is replaced at build time automatically during deployment and From 73bedcea7c2369774dc03010949289e1f0a50623 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 14:09:49 -0500 Subject: [PATCH 05/26] Add dunamai support for if version is not set by build system --- gpax/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gpax/__init__.py b/gpax/__init__.py index 36b28cd..dd1e792 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -34,3 +34,15 @@ # build. __version__ = ... # semantic-version-placeholder # DO NOT CHANGE ABOVE --------------------------------------------------------- + +# Useful for local development +if __version__ == ...: + try: + from dunamai import Version + version = Version.from_any_vcs() + __version__ = version.serialize() + except ImportError: + print("You are running a local copy of gpax (not installed via pip)") + print("__version__ = ...; pip install dunamai to track local version") + pass + From 8bda8562009e06d3c6dbeba096c6aa0c8626dccd Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 14:12:29 -0500 Subject: [PATCH 06/26] Update github actions files --- .github/workflows/actions.yml | 11 ++----- .github/workflows/ci.yml | 12 ++++++++ .github/workflows/unit.yml | 54 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/unit.yml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 3183a4f..62021c1 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -1,17 +1,10 @@ -name: build +name: build/test env: PYTHON_MAIN_VERSION: 3.9 on: - pull_request: - branches: - - '*' - push: - branches: - - '*' - tags: - - '*' + workflow_call: jobs: build-linux: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..39e8c90 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,12 @@ +name: CI + +on: + + pull_request: + branches: ["master", "dev/*", issue-59] + + push: + branches: ["master", "dev/*", issue-59] + + unit: + uses: ./.github/workflows/unit.yml diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml new file mode 100644 index 0000000..d7b69d0 --- /dev/null +++ b/.github/workflows/unit.yml @@ -0,0 +1,54 @@ +name: Unit + +env: + PYTHON_MAIN_VERSION: 3.9 + +on: + workflow_call: + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + bash scripts/install.sh + bash scripts/install.sh test + + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + - name: Run tests + run: | + pytest -v --cov --cov-report xml tests + + - name: Upload coverage to Codecov + if: ${{ matrix.python-version == env.PYTHON_MAIN_VERSION }} + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + # directory: ./coverage/reports/ + flags: unittests + env_vars: OS,PYTHON + name: codecov-umbrella + fail_ci_if_error: true + # path_to_write_report: ./coverage/codecov_report.txt + verbose: true From 1290690af71dd84939d2baee4898d7c762a688b7 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 14:16:00 -0500 Subject: [PATCH 07/26] Add some more useful comments to __init__ --- gpax/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gpax/__init__.py b/gpax/__init__.py index dd1e792..7a7c304 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -29,13 +29,14 @@ ] # DO NOT CHANGE BELOW --------------------------------------------------------- +# ALSO DO NOT CALL __version__ ANYWHERE ABOVE THIS # This is replaced at build time automatically during deployment and # installation. Replacing anything will mess that up and crash the entire # build. __version__ = ... # semantic-version-placeholder # DO NOT CHANGE ABOVE --------------------------------------------------------- -# Useful for local development +# Silly hack. Useful for local development if __version__ == ...: try: from dunamai import Version From 56523037eaa779c1c3dc7be596691a29e1b9a143 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 14:16:17 -0500 Subject: [PATCH 08/26] Change update version script to only grep first instance --- scripts/update_version.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/update_version.sh b/scripts/update_version.sh index 0bd018e..db98116 100644 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -17,7 +17,8 @@ replace_version_in_init () { } reset_version_to_ellipsis () { - current_version=$(grep "__version__" "$PACKAGE_NAME"/__init__.py) + # we only grep the first instance of __version__ + current_version=$(grep -m 1 "__version__" "$PACKAGE_NAME"/__init__.py) sed_command="s/$current_version/__version__ = ... # semantic-version-placeholder/g" if [[ "$OSTYPE" == "darwin"* ]]; then sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py From adb0676a13802a51ce922af9ab0168c95f050fa5 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 14:27:51 -0500 Subject: [PATCH 09/26] Make the update version script a bit more robust --- scripts/update_version.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/update_version.sh b/scripts/update_version.sh index db98116..ac0e0e6 100644 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -1,16 +1,21 @@ #!/bin/bash PACKAGE_NAME="gpax" +SEMANTIC_PLACEHOLDER="... # semantic-version-placeholder/" +INIT_FILE_NAME="$PACKAGE_NAME"/__init__.py + + replace_version_in_init () { pip install dunamai~=1.12 version="$(dunamai from git --style pep440 --no-metadata)" dunamai check "$version" --style pep440 - sed_command="s/... # semantic-version-placeholder/'$version'/g" + sed_command="s/'$SEMANTIC_PLACEHOLDER'/'$version'/g" + cp "$INIT_FILE_NAME" "$INIT_FILE_NAME".bak if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py + sed -i '' "$sed_command" "$INIT_FILE_NAME" else - sed -i "$sed_command" "$PACKAGE_NAME"/__init__.py + sed -i "$sed_command" "$INIT_FILE_NAME" fi echo "__init__ version set to" "$version" export _TMP_VERSION="$version" @@ -18,13 +23,9 @@ replace_version_in_init () { reset_version_to_ellipsis () { # we only grep the first instance of __version__ - current_version=$(grep -m 1 "__version__" "$PACKAGE_NAME"/__init__.py) - sed_command="s/$current_version/__version__ = ... # semantic-version-placeholder/g" - if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py - else - sed -i "$sed_command" "$PACKAGE_NAME"/__init__.py - fi + current_version=$(grep -m 1 "__version__" "$INIT_FILE_NAME"/__init__.py) + cp "$INIT_FILE_NAME".bak "$INIT_FILE_NAME" + rm "$INIT_FILE_NAME".bak echo "$current_version" "reset to placeholder" } From 0ffa91eab4d94a3781de514075ecadb5a61f1acc Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 15:48:23 -0500 Subject: [PATCH 10/26] Debug update_version --- scripts/update_version.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/update_version.sh b/scripts/update_version.sh index ac0e0e6..82d7267 100644 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -1,7 +1,7 @@ #!/bin/bash PACKAGE_NAME="gpax" -SEMANTIC_PLACEHOLDER="... # semantic-version-placeholder/" +SEMANTIC_PLACEHOLDER="... # semantic-version-placeholder" INIT_FILE_NAME="$PACKAGE_NAME"/__init__.py @@ -11,6 +11,7 @@ replace_version_in_init () { version="$(dunamai from git --style pep440 --no-metadata)" dunamai check "$version" --style pep440 sed_command="s/'$SEMANTIC_PLACEHOLDER'/'$version'/g" + echo "$sed_command" cp "$INIT_FILE_NAME" "$INIT_FILE_NAME".bak if [[ "$OSTYPE" == "darwin"* ]]; then sed -i '' "$sed_command" "$INIT_FILE_NAME" From 8ee711617137d5602197a2a184268b1a5fa1e664 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 15:58:20 -0500 Subject: [PATCH 11/26] Debug update_version --- gpax/__init__.py | 1 - scripts/update_version.sh | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/gpax/__init__.py b/gpax/__init__.py index 7a7c304..f6631f1 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -25,7 +25,6 @@ "viSparseGP", "CoregGP", "sample_next", - "__version__", ] # DO NOT CHANGE BELOW --------------------------------------------------------- diff --git a/scripts/update_version.sh b/scripts/update_version.sh index 82d7267..db98116 100644 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -1,22 +1,16 @@ #!/bin/bash PACKAGE_NAME="gpax" -SEMANTIC_PLACEHOLDER="... # semantic-version-placeholder" -INIT_FILE_NAME="$PACKAGE_NAME"/__init__.py - - replace_version_in_init () { pip install dunamai~=1.12 version="$(dunamai from git --style pep440 --no-metadata)" dunamai check "$version" --style pep440 - sed_command="s/'$SEMANTIC_PLACEHOLDER'/'$version'/g" - echo "$sed_command" - cp "$INIT_FILE_NAME" "$INIT_FILE_NAME".bak + sed_command="s/... # semantic-version-placeholder/'$version'/g" if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "$sed_command" "$INIT_FILE_NAME" + sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py else - sed -i "$sed_command" "$INIT_FILE_NAME" + sed -i "$sed_command" "$PACKAGE_NAME"/__init__.py fi echo "__init__ version set to" "$version" export _TMP_VERSION="$version" @@ -24,9 +18,13 @@ replace_version_in_init () { reset_version_to_ellipsis () { # we only grep the first instance of __version__ - current_version=$(grep -m 1 "__version__" "$INIT_FILE_NAME"/__init__.py) - cp "$INIT_FILE_NAME".bak "$INIT_FILE_NAME" - rm "$INIT_FILE_NAME".bak + current_version=$(grep -m 1 "__version__" "$PACKAGE_NAME"/__init__.py) + sed_command="s/$current_version/__version__ = ... # semantic-version-placeholder/g" + if [[ "$OSTYPE" == "darwin"* ]]; then + sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py + else + sed -i "$sed_command" "$PACKAGE_NAME"/__init__.py + fi echo "$current_version" "reset to placeholder" } From cf5bd0deb6af877ebb8287a37943fe1e09f6b4fe Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 15:59:39 -0500 Subject: [PATCH 12/26] Debug update_version --- gpax/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpax/__init__.py b/gpax/__init__.py index f6631f1..72d5ec7 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -28,7 +28,7 @@ ] # DO NOT CHANGE BELOW --------------------------------------------------------- -# ALSO DO NOT CALL __version__ ANYWHERE ABOVE THIS +# ALSO DO NOT TYPE dunder version ANYWHERE ABOVE THIS # This is replaced at build time automatically during deployment and # installation. Replacing anything will mess that up and crash the entire # build. From 1a8624c2d9099a4f256e8af926dad80e0b3b1a98 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 16:12:49 -0500 Subject: [PATCH 13/26] Update and refactor actions --- .github/workflows/actions.yml | 67 ---------------------------- .github/workflows/ci.yml | 7 ++- .github/workflows/notebook_smoke.yml | 24 +--------- scripts/test_notebooks.sh | 4 +- 4 files changed, 10 insertions(+), 92 deletions(-) delete mode 100644 .github/workflows/actions.yml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml deleted file mode 100644 index 62021c1..0000000 --- a/.github/workflows/actions.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: build/test - -env: - PYTHON_MAIN_VERSION: 3.9 - -on: - workflow_call: - -jobs: - build-linux: - - strategy: - max-parallel: 5 - matrix: - python-version: ['3.9', '3.10', '3.11'] - os: [ubuntu-latest] - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - sudo apt-get update -qq - python -m pip install --upgrade pip - python -m pip install flake8 pytest - python -m pip install jaxlib - python -m pip install jax - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: install package - run: | - pip install . - pip list - - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - - name: Generate coverage report - run: | - pip install pytest - pip install pytest-cov - pytest --cov=./ --cov-report=xml - - - name: Upload coverage to Codecov - if: ${{ matrix.python-version == env.PYTHON_MAIN_VERSION }} - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./coverage.xml - # directory: ./coverage/reports/ - flags: unittests - env_vars: OS,PYTHON - name: codecov-umbrella - fail_ci_if_error: true - # path_to_write_report: ./coverage/codecov_report.txt - verbose: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39e8c90..c8ff29b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,13 @@ name: CI on: pull_request: - branches: ["master", "dev/*", issue-59] + branches: ["master", "dev/*", mc/issue-59] push: - branches: ["master", "dev/*", issue-59] + branches: ["master", "dev/*", mc/issue-59] unit: uses: ./.github/workflows/unit.yml + + notebooks: + uses: ./.github/workflows/notebook_smoke.yml diff --git a/.github/workflows/notebook_smoke.yml b/.github/workflows/notebook_smoke.yml index 312a5df..a6d8ab7 100644 --- a/.github/workflows/notebook_smoke.yml +++ b/.github/workflows/notebook_smoke.yml @@ -4,14 +4,7 @@ env: CI_SMOKE: True on: - pull_request: - branches: - - '*' - push: - branches: - - '*' - tags: - - '*' + workflow_call: jobs: build-linux: @@ -34,22 +27,9 @@ jobs: - name: Install dependencies run: | - sudo apt-get update -qq - python -m pip install --upgrade pip - python -m pip install flake8 pytest - python -m pip install jaxlib - python -m pip install jax - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: install package - run: | - pip install . - pip list + bash scripts/install.sh - name: Notebook smoke tests run: | - pip install ipython - pip install nbformat - pip install seaborn bash scripts/test_notebooks.sh diff --git a/scripts/test_notebooks.sh b/scripts/test_notebooks.sh index f1f1771..e63cef5 100644 --- a/scripts/test_notebooks.sh +++ b/scripts/test_notebooks.sh @@ -1,6 +1,8 @@ #!/bin/bash -#!/bin/bash +pip install ipython +pip install nbformat +pip install seaborn for nb in examples/*.ipynb; do echo "Running notebook smoke test on $nb" ipython -c "%run $nb" From 5951f32c9565c23819047370affd20f9c3612e06 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 16:13:35 -0500 Subject: [PATCH 14/26] Disable publish to pypi for now --- .github/workflows/publish-to-pypi.yml | 42 +++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 8ba346d..34d5e5b 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -27,24 +27,24 @@ jobs: name: python-package-distributions path: dist/ - publish-to-pypi: - name: >- - Publish Python 🐍 distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes - needs: - - build - runs-on: ubuntu-latest - environment: - name: pypi - url: https://pypi.org/p/gpax - permissions: - id-token: write # IMPORTANT: mandatory for trusted publishing - - steps: - - name: Download all the dists - uses: actions/download-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + # publish-to-pypi: + # name: >- + # Publish Python 🐍 distribution 📦 to PyPI + # if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + # needs: + # - build + # runs-on: ubuntu-latest + # environment: + # name: pypi + # url: https://pypi.org/p/gpax + # permissions: + # id-token: write # IMPORTANT: mandatory for trusted publishing + # + # steps: + # - name: Download all the dists + # uses: actions/download-artifact@v3 + # with: + # name: python-package-distributions + # path: dist/ + # - name: Publish distribution 📦 to PyPI + # uses: pypa/gh-action-pypi-publish@release/v1 From 2b0003ddc68f33a52ececc4020432f7d6e94b1d8 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 16:18:47 -0500 Subject: [PATCH 15/26] Debug CI --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8ff29b..b2df5c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,8 @@ on: push: branches: ["master", "dev/*", mc/issue-59] +jobs: + unit: uses: ./.github/workflows/unit.yml From a257a75e3112d17ff1b95d2751c153eb2fa4e2bd Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 15 Feb 2024 17:01:16 -0500 Subject: [PATCH 16/26] Refactor CI/deploy --- .github/workflows/ci-deploy.yml | 60 +++++++++++++++++++++++++++ .github/workflows/publish-to-pypi.yml | 50 ---------------------- 2 files changed, 60 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/ci-deploy.yml delete mode 100644 .github/workflows/publish-to-pypi.yml diff --git a/.github/workflows/ci-deploy.yml b/.github/workflows/ci-deploy.yml new file mode 100644 index 0000000..aa9c92a --- /dev/null +++ b/.github/workflows/ci-deploy.yml @@ -0,0 +1,60 @@ +name: CI/Deploy + +on: + push: + tags: ["v*"] + +jobs: + + unit: + uses: ./.github/workflows/unit.yml + + notebooks: + uses: ./.github/workflows/notebook_smoke.yml + + check_semantic_version_placeholder: + name: Check semantic version placeholder exists in the __init__ + + runs-on: ubuntu-latest + + steps: + + - uses: actions/checkout@v3 + + - name: Check lines exist + run: | + grep -x "__version__ = ... # semantic-version-placeholder" gpax/__init__.py + + build_and_publish: + name: Upload release to PyPI + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/gpax + permissions: + id-token: write + + needs: + - check_semantic_version_placeholder + - unit + - notebooks + + steps: + + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - name: Build and apply version + run: bash scripts/build_project.sh + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + # CURRENTLY USING TEST SERVER FOR NOW!!!! + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml deleted file mode 100644 index 34d5e5b..0000000 --- a/.github/workflows/publish-to-pypi.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI - -on: push - -jobs: - build: - name: Build distribution 📦 - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - name: Install pypa/build - run: >- - python3 -m - pip install - build - --user - - name: Build a binary wheel and a source tarball - run: python3 -m build - - name: Store the distribution packages - uses: actions/upload-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - # publish-to-pypi: - # name: >- - # Publish Python 🐍 distribution 📦 to PyPI - # if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes - # needs: - # - build - # runs-on: ubuntu-latest - # environment: - # name: pypi - # url: https://pypi.org/p/gpax - # permissions: - # id-token: write # IMPORTANT: mandatory for trusted publishing - # - # steps: - # - name: Download all the dists - # uses: actions/download-artifact@v3 - # with: - # name: python-package-distributions - # path: dist/ - # - name: Publish distribution 📦 to PyPI - # uses: pypa/gh-action-pypi-publish@release/v1 From a5481a92d35905da74c89ea7d96c823797f0770f Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Wed, 28 Feb 2024 17:33:14 -0500 Subject: [PATCH 17/26] Remove my version hack in favor of dunamai --- gpax/__init__.py | 42 +++++++++++++++++++-------------------- scripts/build_project.sh | 2 -- scripts/update_version.sh | 36 --------------------------------- 3 files changed, 21 insertions(+), 59 deletions(-) delete mode 100644 scripts/update_version.sh diff --git a/gpax/__init__.py b/gpax/__init__.py index 72d5ec7..53cf61a 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -1,8 +1,22 @@ from . import acquisition, kernels, utils from .hypo import sample_next -from .models import (DKL, UIGP, CoregGP, ExactGP, MeasuredNoiseGP, MultiTaskGP, - VarNoiseGP, iBNN, sPM, vExactGP, vi_iBNN, viDKL, viGP, - viMTDKL, viSparseGP) +from .models import ( + DKL, + UIGP, + CoregGP, + ExactGP, + MeasuredNoiseGP, + MultiTaskGP, + VarNoiseGP, + iBNN, + sPM, + vExactGP, + vi_iBNN, + viDKL, + viGP, + viMTDKL, + viSparseGP, +) __all__ = [ "utils", @@ -27,22 +41,8 @@ "sample_next", ] -# DO NOT CHANGE BELOW --------------------------------------------------------- -# ALSO DO NOT TYPE dunder version ANYWHERE ABOVE THIS -# This is replaced at build time automatically during deployment and -# installation. Replacing anything will mess that up and crash the entire -# build. -__version__ = ... # semantic-version-placeholder -# DO NOT CHANGE ABOVE --------------------------------------------------------- -# Silly hack. Useful for local development -if __version__ == ...: - try: - from dunamai import Version - version = Version.from_any_vcs() - __version__ = version.serialize() - except ImportError: - print("You are running a local copy of gpax (not installed via pip)") - print("__version__ = ...; pip install dunamai to track local version") - pass - +import dunamai as _dunamai + +__version__ = _dunamai.get_version("gpax", third_choice=_dunamai.Version.from_any_vcs).serialize() +del _dunamai diff --git a/scripts/build_project.sh b/scripts/build_project.sh index 0d5f6f8..5e9b2ce 100644 --- a/scripts/build_project.sh +++ b/scripts/build_project.sh @@ -1,6 +1,4 @@ #!/bin/bash pip install flit~=3.7 -bash scripts/update_version.sh set flit build -bash scripts/update_version.sh reset diff --git a/scripts/update_version.sh b/scripts/update_version.sh deleted file mode 100644 index db98116..0000000 --- a/scripts/update_version.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -PACKAGE_NAME="gpax" - -replace_version_in_init () { - pip install dunamai~=1.12 - version="$(dunamai from git --style pep440 --no-metadata)" - dunamai check "$version" --style pep440 - sed_command="s/... # semantic-version-placeholder/'$version'/g" - if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py - else - sed -i "$sed_command" "$PACKAGE_NAME"/__init__.py - fi - echo "__init__ version set to" "$version" - export _TMP_VERSION="$version" -} - -reset_version_to_ellipsis () { - # we only grep the first instance of __version__ - current_version=$(grep -m 1 "__version__" "$PACKAGE_NAME"/__init__.py) - sed_command="s/$current_version/__version__ = ... # semantic-version-placeholder/g" - if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "$sed_command" "$PACKAGE_NAME"/__init__.py - else - sed -i "$sed_command" "$PACKAGE_NAME"/__init__.py - fi - echo "$current_version" "reset to placeholder" -} - - -if [ "$1" == "set" ]; then - replace_version_in_init -elif [ "$1" == "reset" ]; then - reset_version_to_ellipsis -fi From fc0d70b7ddacf3e1d2b416b50e3538163cec1b2f Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Wed, 28 Feb 2024 17:33:48 -0500 Subject: [PATCH 18/26] Update pyproject with version-locked dunamai dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 6091e9b..b225a6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ dependencies = [ "jax>=0.4.8", "numpyro>=0.11.0", "dm-haiku>=0.0.5", + "dunamai==1.19.2", "jaxopt", # TODO: do we want to require this? ] From d53a25cf807447ec1d289fe2caf60c785b947fa4 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 29 Feb 2024 20:11:24 -0500 Subject: [PATCH 19/26] Revise dunamai usage for dynamic versioning --- gpax/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gpax/__init__.py b/gpax/__init__.py index 53cf61a..44c3c1e 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -18,6 +18,8 @@ viSparseGP, ) +# WARNING: I don't think __all__ is really needed, and I'm not sure it's +# actually accurate __all__ = [ "utils", "kernels", @@ -41,8 +43,11 @@ "sample_next", ] +try: + # _version.py is only written dynamically during build time + from gpax._version import __version__ +except ImportError: + import dunamai as _dunamai -import dunamai as _dunamai - -__version__ = _dunamai.get_version("gpax", third_choice=_dunamai.Version.from_any_vcs).serialize() -del _dunamai + __version__ = _dunamai.Version.from_any_vcs().serialize() + del _dunamai From e19efc8021d310d061c6b80078e4919a875dfb51 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 29 Feb 2024 20:37:40 -0500 Subject: [PATCH 20/26] Update ci-deploy, remove semantic version placeholder --- .github/workflows/ci-deploy.yml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-deploy.yml b/.github/workflows/ci-deploy.yml index aa9c92a..e10bb6b 100644 --- a/.github/workflows/ci-deploy.yml +++ b/.github/workflows/ci-deploy.yml @@ -12,19 +12,6 @@ jobs: notebooks: uses: ./.github/workflows/notebook_smoke.yml - check_semantic_version_placeholder: - name: Check semantic version placeholder exists in the __init__ - - runs-on: ubuntu-latest - - steps: - - - uses: actions/checkout@v3 - - - name: Check lines exist - run: | - grep -x "__version__ = ... # semantic-version-placeholder" gpax/__init__.py - build_and_publish: name: Upload release to PyPI if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') @@ -36,7 +23,6 @@ jobs: id-token: write needs: - - check_semantic_version_placeholder - unit - notebooks @@ -44,6 +30,8 @@ jobs: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python 3.9 uses: actions/setup-python@v2 From ea3b684ea9f6b84c02558550c00197829d57d0aa Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 29 Feb 2024 20:38:49 -0500 Subject: [PATCH 21/26] Update build script for writing _version.py --- scripts/build_project.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build_project.sh b/scripts/build_project.sh index 5e9b2ce..e7a8fcf 100644 --- a/scripts/build_project.sh +++ b/scripts/build_project.sh @@ -1,4 +1,5 @@ #!/bin/bash pip install flit~=3.7 +echo "__version__ = '$(dunamai from any --style=pep440 --no-metadata)'" >gpax/_version.py flit build From b696b9714e995c7034930f629ac5152219e0791b Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 29 Feb 2024 20:41:39 -0500 Subject: [PATCH 22/26] Add _version.py file back, debugging dunamai build --- gpax/__init__.py | 11 ++--------- gpax/_version.py | 7 +++++++ 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 gpax/_version.py diff --git a/gpax/__init__.py b/gpax/__init__.py index 44c3c1e..f4a8f73 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -1,3 +1,5 @@ +from gpax._version import __version__ + from . import acquisition, kernels, utils from .hypo import sample_next from .models import ( @@ -42,12 +44,3 @@ "CoregGP", "sample_next", ] - -try: - # _version.py is only written dynamically during build time - from gpax._version import __version__ -except ImportError: - import dunamai as _dunamai - - __version__ = _dunamai.Version.from_any_vcs().serialize() - del _dunamai diff --git a/gpax/_version.py b/gpax/_version.py new file mode 100644 index 0000000..cabbf9c --- /dev/null +++ b/gpax/_version.py @@ -0,0 +1,7 @@ +"""Version file. This is overwritten during build and will contain a static +__version__ variable.""" + +import dunamai as _dunamai + +__version__ = _dunamai.Version.from_any_vcs().serialize() +del _dunamai From 869a8b413347b8032ca53ebf84359d16cd8d3e48 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 29 Feb 2024 22:32:30 -0500 Subject: [PATCH 23/26] Add init from main --- gpax/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gpax/__init__.py b/gpax/__init__.py index f4a8f73..a231301 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -1,8 +1,8 @@ -from gpax._version import __version__ - from . import acquisition, kernels, utils +from .__version__ import version as __version__ from .hypo import sample_next from .models import ( + BNN, DKL, UIGP, CoregGP, @@ -20,8 +20,6 @@ viSparseGP, ) -# WARNING: I don't think __all__ is really needed, and I'm not sure it's -# actually accurate __all__ = [ "utils", "kernels", @@ -42,5 +40,7 @@ "MeasuredNoiseGP", "viSparseGP", "CoregGP", + "BNN", "sample_next", + "__version__", ] From e3cfefd204820dd4458e48763aa17d0acbbe4a73 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 29 Feb 2024 22:35:48 -0500 Subject: [PATCH 24/26] Make __init__ imports explicit --- gpax/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gpax/__init__.py b/gpax/__init__.py index adfafdd..132fcb4 100644 --- a/gpax/__init__.py +++ b/gpax/__init__.py @@ -1,8 +1,7 @@ +from gpax import acquisition, kernels, utils from gpax._version import __version__ - -from . import acquisition, kernels, utils -from .hypo import sample_next -from .models import ( +from gpax.hypo import sample_next +from gpax.models import ( BNN, DKL, UIGP, From 7d8156b89185493e2216e3aed5553674f498c59c Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Thu, 29 Feb 2024 22:43:48 -0500 Subject: [PATCH 25/26] Make the version detection slightly more flexible Just in case someone using GPax as a dev copy does not have dunamai installed, GPax will now gracefully fail to detect the version and will simply use "dev" as the version name. --- gpax/_version.py | 9 ++++++--- scripts/build_project.sh | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gpax/_version.py b/gpax/_version.py index cabbf9c..9807bb2 100644 --- a/gpax/_version.py +++ b/gpax/_version.py @@ -1,7 +1,10 @@ """Version file. This is overwritten during build and will contain a static __version__ variable.""" -import dunamai as _dunamai +try: + import dunamai as _dunamai -__version__ = _dunamai.Version.from_any_vcs().serialize() -del _dunamai + __version__ = _dunamai.Version.from_any_vcs().serialize() + del _dunamai +except ImportError: + __version__ = "dev" diff --git a/scripts/build_project.sh b/scripts/build_project.sh index e7a8fcf..e746e62 100644 --- a/scripts/build_project.sh +++ b/scripts/build_project.sh @@ -1,5 +1,6 @@ #!/bin/bash pip install flit~=3.7 +pip install dunamai==1.19.2 echo "__version__ = '$(dunamai from any --style=pep440 --no-metadata)'" >gpax/_version.py flit build From af60f98965b887a1836c00c275faccb7d414f798 Mon Sep 17 00:00:00 2001 From: Matthew Carbone Date: Fri, 29 Mar 2024 14:19:40 -0400 Subject: [PATCH 26/26] Modify scripts in scripts directory, remove unused scripts --- .github/workflows/ci-deploy.yml | 2 +- scripts/LICENSE | 29 -------------------------- scripts/README.md | 7 ------- scripts/{build_project.sh => build.sh} | 0 scripts/build_docs.sh | 25 ---------------------- scripts/install.sh | 20 ++++-------------- 6 files changed, 5 insertions(+), 78 deletions(-) delete mode 100644 scripts/LICENSE delete mode 100644 scripts/README.md rename scripts/{build_project.sh => build.sh} (100%) delete mode 100644 scripts/build_docs.sh diff --git a/.github/workflows/ci-deploy.yml b/.github/workflows/ci-deploy.yml index e10bb6b..14f09d0 100644 --- a/.github/workflows/ci-deploy.yml +++ b/.github/workflows/ci-deploy.yml @@ -39,7 +39,7 @@ jobs: python-version: 3.9 - name: Build and apply version - run: bash scripts/build_project.sh + run: bash scripts/build.sh - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/scripts/LICENSE b/scripts/LICENSE deleted file mode 100644 index deacfc5..0000000 --- a/scripts/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2022, Brookhaven Science Associates, LLC, Brookhaven National Laboratory -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/scripts/README.md b/scripts/README.md deleted file mode 100644 index 6f2bd92..0000000 --- a/scripts/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Scripts - -This directory contains helper scripts for GPax. - -- Build scripts for building the project -- Testing script for the notebook smoke tests -- `LICENSE` file, attributing code in this directory only to Brookhaven Science Associates (location from which the code was sourced) diff --git a/scripts/build_project.sh b/scripts/build.sh similarity index 100% rename from scripts/build_project.sh rename to scripts/build.sh diff --git a/scripts/build_docs.sh b/scripts/build_docs.sh deleted file mode 100644 index d42d820..0000000 --- a/scripts/build_docs.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -build_docs () { - - if [[ "${GITHUB_ACTION_IS_RUNNING}" = 1 ]]; then - bash scripts/install.sh doc - fi - - make -C docs/ html - - # Helper when running on local. If not running in a GitHub Actions - # environment, this will attempt to open index.html with the users' - # default program - if [[ -z "${GITHUB_ACTION_IS_RUNNING}" ]]; then - open docs/build/html/index.html - fi - -} - -pip install toml -bash scripts/install.sh -bash scripts/install.sh doc -bash scripts/update_version.sh set -build_docs -bash scripts/update_version.sh reset diff --git a/scripts/install.sh b/scripts/install.sh index bbd3224..6ca7894 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,22 +1,10 @@ #!/bin/bash -# Good stuff. The poor man's toml parser -# https://github.com/pypa/pip/issues/8049 -# This is the analog of pip install -e ".[...]" since for whatever reason -# it does not appear to work cleanly with pip - -install_test_requirements_only () { - python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["optional-dependencies"]["test"]))' | pip install -r /dev/stdin -} - -install_requirements() { - python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["dependencies"]))' | pip install -r /dev/stdin -} - - pip install toml + if [ "$1" = "test" ]; then - install_test_requirements_only + python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["optional-dependencies"]["test"]))' | pip install -r /dev/stdin + else - install_requirements + python3 -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["project"]["dependencies"]))' | pip install -r /dev/stdin fi