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

ENH: Add support for local builds #125

Merged
merged 19 commits into from
May 25, 2022
Merged
16 changes: 7 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,28 @@ jobs:
- name: Extract MNE_INSTALLER_VERSION
shell: bash -el {0}
run: |
VERSION=$(head -n 1 recipes/mne-python_1.0/construct.yaml | cut -d' ' -f2)
echo "Version: ${VERSION}"
source ./tools/extract_verion.sh
echo "Version: ${VERSION} (Python=${PYSHORT})"
echo "MNE_INSTALLER_VERSION=${VERSION}" >> $GITHUB_ENV
test "$VERSION" != ""
test "$PYSHORT" != ""

- name: Install Micromamba
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: environment.yml
micromamba-version: latest

- name: Patch constructor (macOS)
if: ${{ runner.os == 'macOS' }}
- name: Patch constructor
shell: bash -el {0}
run: |
export PATCH_PATH=`python -c "import pathlib; print(pathlib.Path('./assets/constructor_macOS.patch').resolve())"`
cd $CONDA_PREFIX/lib/python3.9/site-packages/constructor
patch -p1 < ${PATCH_PATH}
./tools/patch_constructor.sh

- name: Patch config (macOS pull request)
if: ${{ runner.os == 'macOS' && github.event_name == 'pull_request' }}
shell: bash -el {0}
run: |
sed -i "" "s/9779L28NP8//" recipes/mne-python_1.0/construct.yaml
sed -i "" "s/9779L28NP8//" ${RECIPE_DIR}/construct.yaml

- name: Build installer
shell: bash -el {0}
Expand All @@ -123,7 +121,7 @@ jobs:
# if something has gone wrong with dependency resolution.
timeout-minutes: 20
run: |
PYTHONUTF8=1 constructor recipes/mne-python_1.0 # enforce UTF-8 encoding when reading files even on Windows
./tools/run_constructor.sh

- name: Check installer signature (macOS)
if: ${{ runner.os == 'macOS' && github.event_name != 'pull_request' }}
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ Installers for MNE-Python for macOS, Windows, and Linux.
<img src="https://mne.tools/dev/_static/mne_installer_macOS.png" alt="Installer running on macOS" width="450px">

Please visit [the installers section of the MNE documentation](https://mne.tools/dev/install/installers.html) for instructions on how to use them.

## Development

Locally, installers can be built using `tools/build_local.sh`. This has only been tested on Linux and macOS M1.

Requirements:
- `conda` with `constructor` (`conda install -c conda-forge constructor`)

WARNING: Your constructor will be patched on macOS.
1 change: 1 addition & 0 deletions assets/current_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
2 changes: 2 additions & 0 deletions recipes/mne-python_1.0/construct.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version: 1.0.3_0
name: MNE-Python
company: MNE-Python Developers
# When the version above changes to a new major/minor, it needs to be updated
# many places here, and in assets/current_version.txt.

license_file: ../../assets/license.txt # [linux]
license_file: ../../assets/license.rtf # [not linux]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_json_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
win32='Windows',
)[sys.platform]

with open(dir_ / 'recipes' / 'mne-python_1.0' / 'construct.yaml',
with open(dir_ / 'assets' / 'current_version.txt') as fid:
ver = fid.read().strip()
with open(dir_ / 'recipes' / f'mne-python_{ver}' / 'construct.yaml',
encoding='utf-8') as fid:
params = yaml.safe_load(fid)
installer_version = params['version']
Expand Down
12 changes: 12 additions & 0 deletions tools/build_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -ef

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
source ${SCRIPT_DIR}/extract_version.sh
echo "Building installer locally"
echo "--------------------------"
echo "Version: ${VERSION}"
echo "Recipe: ${RECIPE_DIR}"
echo "OS: ${MACHINE}"
echo "Architecture: ${PYARCH}"
${SCRIPT_DIR}/patch_constructor.sh
${SCRIPT_DIR}/run_constructor.sh
19 changes: 19 additions & 0 deletions tools/extract_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash -ef

VER=$(cat assets/current_version.txt)
test VER != ""
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
export VERSION=$(head -n 1 recipes/mne-python_${VER}/construct.yaml | cut -d' ' -f2)
export RECIPE_DIR=${SCRIPT_DIR}/recipes/mne-python_$(echo $VERSION | cut -d . -f-2)
export PYSHORT=$(python -c "import sys; print(''.join(map(str, sys.version_info[:2])))")
UNAME="$(uname -s)"
case "${UNAME}" in
Linux*) MACHINE=Linux;;
Darwin*) MACHINE=macOS;;
*) MACHINE="UNKNOWN:${unameOut}"
esac
if [[ "$MACHINE" != "macOS" && "$MACHINE" != "Linux" ]]; then
exit 1
fi
export MACHINE=$MACHINE
export PYARCH=$(python -c "import platform; print(platform.architecture()[0])")
8 changes: 8 additions & 0 deletions tools/patch_constructor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -ef

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
source ${SCRIPT_DIR}/extract_version.sh
if [[ $MACHINE == "macOS" ]]; then
echo "Patching constructor..."
patch -d $CONDA_PREFIX/lib/python${PYSHORT}/site-packages/constructor -p1 < ${SCRIPT_DIR}/assets/constructor_macOS.patch
fi
7 changes: 7 additions & 0 deletions tools/run_constructor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -ef

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
source ${SCRIPT_DIR}/extract_version.sh
export PYTHONUTF8=1
# enforce UTF-8 encoding when reading files even on Windows
constructor ${RECIPE_DIR}