Skip to content

Commit

Permalink
Add initial changes for issue 59 refactor of build system
Browse files Browse the repository at this point in the history
* Remove hardcoded version (which will be replaced dynamically)
* Add specific lines to init
* Add scripts directory, which contains a few helpers
  • Loading branch information
matthewcarbone committed Feb 14, 2024
1 parent a335c7d commit 2c21d34
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 1 deletion.
7 changes: 7 additions & 0 deletions gpax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------------
1 change: 0 additions & 1 deletion gpax/__version__.py

This file was deleted.

29 changes: 29 additions & 0 deletions scripts/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 25 additions & 0 deletions scripts/build_docs.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions scripts/build_project.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions scripts/update_version.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2c21d34

Please sign in to comment.