Skip to content

Commit 3bb9c98

Browse files
authored
Run examples using pytest + optimize CI setup (conda#675)
* run examples with pytest (draft) * rethink testing CI * typo in path * do not use python explicitly * import or skip * just include pillow in core deps * add debug, pre-commit * set level in the root constructor logger * mkdir * ensure string? * move to 3.11 * enable keep_artifacts via env var * deprecate script * parametrize sh miniforge tests * format * refactor a bit * ensure debug * add news * constructor debug as an env var too * implement windows signing in pytest too * update docstring * make str * fix missing arg * skip on unix * fix space check * membership is enough (nested configs...) * str env var * fix input for interactive path * iterate * print directory contents? * pwd too * str here too * uninstall after sentinel checks * fix path for scripts * fix sentinel checks on macos PKGs * export certificate path * do not initialize or register conda on examples * sort shell installers first * just move * remove $HOME stuff after PKG installs * add extension as suffix * pre-commit * add warning * use conda-canary * Update tests/test_examples.py * update readme
1 parent 504c427 commit 3bb9c98

File tree

18 files changed

+558
-176
lines changed

18 files changed

+558
-176
lines changed

.github/workflows/main.yml

Lines changed: 91 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -28,201 +28,143 @@ concurrency:
2828

2929
defaults:
3030
run:
31-
shell: bash
31+
shell: bash -el {0}
3232
jobs:
33-
package:
34-
name: ${{ matrix.os }}, Python ${{ matrix.pyver }}, ${{ matrix.micromamba && 'micromamba' || 'conda-standalone' }}
33+
tests:
34+
name: ${{ matrix.os }}, Python ${{ matrix.python-version }}, ${{ matrix.micromamba && 'micromamba' || 'conda-standalone' }}
3535
runs-on: ${{ matrix.os }}-latest
3636
strategy:
3737
fail-fast: false
3838
matrix:
3939
os: [macos, ubuntu, windows]
40-
pyver: ["3.7", "3.8", "3.9", "3.10"]
40+
python-version: ["3.8", "3.9", "3.10", "3.11"]
41+
check-docs: [false]
4142
include:
4243
- os: ubuntu
43-
pyver: "3.9"
44+
python-version: "3.9"
4445
micromamba: true
46+
check-docs: true
4547
- os: macos
46-
pyver: "3.10"
48+
python-version: "3.10"
4749
micromamba: true
50+
check-docs: false
4851
# Re-enable once micromamba supports menu creation
4952
# - os: windows
50-
# pyver: "3.8"
53+
# python-version: "3.8"
5154
# micromamba: true
55+
# check-docs: false
5256
env:
53-
PYTHONUNBUFFERED: True
57+
PYTHONUNBUFFERED: "1"
5458
steps:
55-
- name: Print github context
56-
run: |
57-
echo "EVENT_NAME:" "$GITHUB_EVENT_NAME"
58-
echo " REF:" "$GITHUB_REF"
59-
echo " HEAD_REF:" "$GITHUB_HEAD_REF"
60-
echo " BASE_REF:" "$GITHUB_BASE_REF"
61-
echo " SHA:" "$GITHUB_SHA"
62-
- name: Set temp dirs correctly
63-
if: startsWith(matrix.os, 'windows')
64-
# https://github.com/actions/virtual-environments/issues/712
65-
shell: powershell
66-
run: |
67-
echo "TMPDIR=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
68-
echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
69-
echo "TMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
7059
- name: Retrieve the source code
7160
uses: actions/checkout@v3
7261
with:
7362
fetch-depth: 0
74-
ref: ${{ github.event.pull_request.head.sha }}
75-
- name: Build the build environment
76-
run: |
77-
source $CONDA/etc/profile.d/conda.sh
78-
[ $RUNNER_OS == macOS ] && export CONDA_PKGS_DIRS=~/.pkgs
79-
conda create -p ../conda conda-build conda-verify
80-
- name: Build the package
81-
env:
82-
PYTHONIOENCODING: utf-8
83-
# Uncomment to run within conda build
84-
# RUN_EXAMPLES: "1"
85-
run: |
86-
source $CONDA/etc/profile.d/conda.sh
87-
conda activate ../conda
88-
export CODECOV_COMMIT=$(git rev-parse --verify HEAD)
89-
CODECOV_FOLDER=${PWD} \
90-
CONDA_BLD_PATH="${{ runner.temp }}/conda-bld" \
91-
conda build conda.recipe --python=${{ matrix.pyver }}
92-
- uses: codecov/codecov-action@v3
63+
- uses: conda-incubator/setup-miniconda@v2
9364
with:
94-
token: ${{ secrets.CODECOV_TOKEN }}
95-
flags: unit
96-
- name: Upload the packages as artifact
97-
if: github.event_name == 'push'
98-
uses: actions/upload-artifact@v3
99-
with:
100-
# By uploading to the same artifact we can download all of the packages
101-
# and upload them all to anaconda.org in a single job
102-
name: package-${{ github.sha }}
103-
path: ${{ runner.temp }}/conda-bld/*/*.tar.bz2
104-
- name: Install local constructor
105-
run: |
106-
source $CONDA/etc/profile.d/conda.sh
107-
CONDA_BLD_PATH="${{ runner.temp }}/conda-bld" \
108-
conda create -n constructor -c local --strict-channel-priority constructor coverage
109-
conda activate constructor
110-
set -x
111-
installed_channel=$(conda list constructor --json | jq -r '.[].channel')
112-
if [[ "$installed_channel" != "conda-bld" ]]; then
113-
echo $(conda list constructor --json)
114-
echo "Installed constructor is not local!"
115-
exit 1
116-
fi
117-
constructor --version
118-
constructor --help-construct
119-
- name: Update to NSIS logging builds on Windows
120-
if: startsWith(matrix.os, 'windows')
65+
activate-environment: constructor-dev
66+
environment-file: dev/environment.yml
67+
python-version: ${{ matrix.python-version }}
68+
- name: Supply extra dependencies and install constructor
12169
run: |
122-
source $CONDA/etc/profile.d/conda.sh
123-
conda activate constructor
124-
conda install -y "conda-forge::nsis=*=*_log_*"
70+
files=(--file "tests/requirements.txt")
71+
test -f dev/extra-requirements-${{ matrix.os }}.txt \
72+
&& files+=(--file "dev/extra-requirements-${{ matrix.os }}.txt")
73+
conda install ${files[@]} -y
12574
echo "NSIS_USING_LOG_BUILD=1" >> $GITHUB_ENV
126-
- name: Generate self-signed certificate (Windows)
127-
if: startsWith(matrix.os, 'windows')
128-
shell: cmd
129-
run: |
130-
set "CONSTRUCTOR_SIGNING_CERTIFICATE=${{ runner.temp }}\certificate.pfx"
131-
set "CONSTRUCTOR_PFX_CERTIFICATE_PASSWORD=1234"
132-
powershell scripts\create_self_signed_certificate.ps1
133-
copy /Y "%CONSTRUCTOR_SIGNING_CERTIFICATE%" examples\signing\certificate.pfx
134-
135-
:: Careful with the trailing spaces before the >> redirect!
136-
echo CONSTRUCTOR_PFX_CERTIFICATE_PASSWORD=1234>> %GITHUB_ENV%
137-
echo CONSTRUCTOR_SIGNTOOL_PATH=C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\signtool.exe>> %GITHUB_ENV%
75+
pip install -e . --no-deps --no-build-isolation
13876
- name: Set up conda executable
13977
run: |
140-
source $CONDA/etc/profile.d/conda.sh
14178
if [[ "${{ matrix.micromamba }}" != "" ]]; then
142-
conda create -yqp ./micromamba -c conda-forge micromamba
79+
conda create -yqp "${{ runner.temp }}/micromamba" -c conda-forge micromamba
14380
if [[ ${{ matrix.os }} == "windows" ]]; then
144-
echo "CONSTRUCTOR_CONDA_EXE=./micromamba/Library/bin/micromamba.exe" >> $GITHUB_ENV
81+
echo "CONSTRUCTOR_CONDA_EXE=${{ runner.temp }}/micromamba/Library/bin/micromamba.exe" >> $GITHUB_ENV
14582
else
146-
echo "CONSTRUCTOR_CONDA_EXE=./micromamba/bin/micromamba" >> $GITHUB_ENV
83+
echo "CONSTRUCTOR_CONDA_EXE=${{ runner.temp }}/micromamba/bin/micromamba" >> $GITHUB_ENV
14784
fi
14885
else
149-
conda activate constructor
86+
conda activate constructor-dev
15087
echo "CONSTRUCTOR_CONDA_EXE=$CONDA_PREFIX/standalone_conda/conda.exe" >> $GITHUB_ENV
15188
fi
152-
- name: Run examples and prepare artifacts
89+
- name: Run unit tests
15390
run: |
154-
rm -rf coverage.json
155-
source $CONDA/etc/profile.d/conda.sh
156-
conda activate constructor
157-
mkdir -p examples_artifacts/
158-
python scripts/run_examples.py \
159-
--keep-artifacts=examples_artifacts/ \
160-
--conda-exe="${CONSTRUCTOR_CONDA_EXE}"
91+
pytest -vv --cov=constructor --cov-branch tests/ -m "not examples"
92+
coverage run --branch --append -m constructor -V
16193
coverage json
162-
- name: Test with conda-libmamba-solver
94+
- uses: codecov/codecov-action@v3
95+
with:
96+
token: ${{ secrets.CODECOV_TOKEN }}
97+
flags: unit
98+
- name: Run examples
99+
env:
100+
CONSTRUCTOR_EXAMPLES_KEEP_ARTIFACTS: "${{ runner.temp }}/examples_artifacts"
101+
# signtool only exists on Windows, but doesn't cause errors on unix when absent
102+
CONSTRUCTOR_SIGNTOOL_PATH: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe"
163103
run: |
164-
source $CONDA/etc/profile.d/conda.sh
165-
conda activate constructor
166-
conda install -yq conda-libmamba-solver
167-
conda list
168-
CONDA_SOLVER=libmamba CONDA_VERBOSITY=1 constructor examples/noconda/ --output-dir=examples_artifacts/
104+
rm -rf coverage.json
105+
pytest -vv --cov=constructor --cov-branch tests/test_examples.py
106+
coverage run --branch --append -m constructor -V
107+
coverage json
169108
- uses: codecov/codecov-action@v3
170109
with:
171110
token: ${{ secrets.CODECOV_TOKEN }}
172111
flags: integration
112+
- name: Test with conda-libmamba-solver
113+
run: |
114+
conda install -yq conda-libmamba-solver
115+
CONDA_SOLVER=libmamba CONDA_VERBOSITY=1 pytest -vv tests/test_examples.py -k noconda
116+
- name: Check docs are up-to-date
117+
if: matrix.check-docs
118+
run: |
119+
python scripts/make_docs.py
120+
git diff --exit-code
173121
- name: Upload the example installers as artifacts
174-
if: github.event_name == 'pull_request' && matrix.pyver == '3.9'
122+
if: github.event_name == 'pull_request' && matrix.python-version == '3.9'
175123
uses: actions/upload-artifact@v3
176124
with:
177125
name: installers-${{ runner.os }}-${{ github.sha }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}
178-
path: examples_artifacts/
126+
path: "${{ runner.temp }}/examples_artifacts"
179127
retention-days: 7
180128

181-
upload:
182-
needs: package
183-
runs-on: ubuntu-latest
184-
if: github.event_name == 'push'
129+
build:
130+
name: Canary Build
131+
needs: [tests]
132+
# only build canary build if
133+
# only build canary build if
134+
# - prior steps succeeded,
135+
# - this is the main repo, and
136+
# - we are on the main (or feature) branch
137+
if: >-
138+
success()
139+
&& !github.event.repository.fork
140+
&& (
141+
github.ref_name == 'main'
142+
|| startsWith(github.ref_name, 'feature/')
143+
)
144+
strategy:
145+
matrix:
146+
include:
147+
- runner: ubuntu-latest
148+
subdir: linux-64
149+
- runner: macos-latest
150+
subdir: osx-64
151+
- runner: windows-latest
152+
subdir: win-64
153+
runs-on: ${{ matrix.runner }}
185154
steps:
186-
- name: Retrieve the source code
187-
uses: actions/checkout@v3
155+
# Clean checkout of specific git ref needed for package metadata version
156+
# which needs env vars GIT_DESCRIBE_TAG and GIT_BUILD_STR:
157+
- uses: actions/checkout@v3
188158
with:
159+
ref: ${{ github.ref }}
160+
clean: true
189161
fetch-depth: 0
190-
- name: Download the build artifacts
191-
uses: actions/download-artifact@v3
192-
with:
193-
name: package-${{ github.sha }}
194-
path: conda-bld
195-
- name: Install conda packages
196-
run: |
197-
source $CONDA/bin/activate
198-
conda install -y sphinx anaconda-client
199-
- name: Upload to anaconda.org
200-
env:
201-
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
202-
GITHUB_REF: ${{ github.ref }}
203-
run: |
204-
source $CONDA/bin/activate
205-
[[ "$GITHUB_REF" =~ ^refs/tags/ ]] || export LABEL="--label dev"
206-
anaconda --verbose --token $ANACONDA_TOKEN upload --user ctools $LABEL conda-bld/*/*.tar.bz2 --force
207-
208-
docs:
209-
name: Check docs are up-to-date
210-
runs-on: ubuntu-latest
211-
steps:
212-
- name: Retrieve the source code
213-
uses: actions/checkout@v3
162+
- name: Create and upload canary build
163+
uses: conda/actions/[email protected]
214164
with:
215-
fetch-depth: 0
216-
- name: Install local constructor
217-
run: |
218-
source $CONDA/bin/activate
219-
conda create -n constructor constructor jinja2
220-
conda activate constructor
221-
pip install -U . --no-deps
222-
- name: Build docs
223-
run: |
224-
source $CONDA/bin/activate
225-
conda activate constructor
226-
set -ex
227-
python scripts/make_docs.py
228-
git diff --exit-code
165+
package-name: ${{ github.event.repository.name }}
166+
subdir: ${{ matrix.subdir }}
167+
anaconda-org-channel: conda-canary
168+
anaconda-org-label: ${{ github.ref_name == 'main' && 'dev' || format('{0}-{1}', github.event.repository.name, github.ref_name) }}
169+
anaconda-org-token: ${{ secrets.CONDA_CANARY_ANACONDA_ORG_TOKEN }}
170+
conda-build-arguments: '--override-channels -c conda-forge -c defaults'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ the script directly with ``python scripts/make_docs.py``.
4242

4343
## Build status
4444

45-
| [![Build status](https://github.com/conda/constructor/actions/workflows/main.yml/badge.svg)](https://github.com/conda/constructor/actions/workflows/main.yml) [![Docs status](https://github.com/conda/constructor/actions/workflows/docs.yml/badge.svg)](https://github.com/conda/constructor/actions/workflows/docs.yml) [![codecov](https://codecov.io/gh/conda/constructor/branch/main/graph/badge.svg)](https://codecov.io/gh/conda/constructor) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/conda/constructor/main.svg)](https://results.pre-commit.ci/latest/github/conda/constructor/main) | [![Anaconda-Server Badge](https://anaconda.org/ctools/constructor/badges/latest_release_date.svg)](https://anaconda.org/ctools/constructor) |
45+
| [![Build status](https://github.com/conda/constructor/actions/workflows/main.yml/badge.svg)](https://github.com/conda/constructor/actions/workflows/main.yml) [![Docs status](https://github.com/conda/constructor/actions/workflows/docs.yml/badge.svg)](https://github.com/conda/constructor/actions/workflows/docs.yml) [![codecov](https://codecov.io/gh/conda/constructor/branch/main/graph/badge.svg)](https://codecov.io/gh/conda/constructor) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/conda/constructor/main.svg)](https://results.pre-commit.ci/latest/github/conda/constructor/main) | [![Anaconda-Server Badge](https://anaconda.org/conda-canary/constructor/badges/latest_release_date.svg)](https://anaconda.org/conda-canary/constructor) |
4646
| --- | :-: |
4747
| [`conda install defaults::constructor`](https://anaconda.org/anaconda/constructor) | [![Anaconda-Server Badge](https://anaconda.org/anaconda/constructor/badges/version.svg)](https://anaconda.org/anaconda/constructor) |
4848
| [`conda install conda-forge::constructor`](https://anaconda.org/conda-forge/constructor) | [![Anaconda-Server Badge](https://anaconda.org/conda-forge/constructor/badges/version.svg)](https://anaconda.org/conda-forge/constructor) |
49-
| [`conda install ctools/label/dev::constructor`](https://anaconda.org/ctools/constructor) | [![Anaconda-Server Badge](https://anaconda.org/ctools/constructor/badges/version.svg)](https://anaconda.org/ctools/constructor) |
49+
| [`conda install conda-canary/label/dev::constructor`](https://anaconda.org/conda-canary/constructor) | [![Anaconda-Server Badge](https://anaconda.org/conda-canary/constructor/badges/version.svg)](https://anaconda.org/conda-canary/constructor) |

constructor/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def main():
314314
logger.info("Got the following cli arguments: '%s'", args)
315315

316316
if args.verbose or args.debug:
317-
logger.setLevel(logging.DEBUG)
317+
logging.getLogger("constructor").setLevel(logging.DEBUG)
318318

319319
if args.clean:
320320
import shutil

constructor/osxpkg.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from tempfile import NamedTemporaryFile
1111

1212
from . import preconda
13-
from .construct import ns_platform
13+
from .conda_interface import conda_context
14+
from .construct import ns_platform, parse
1415
from .imaging import write_images
1516
from .utils import add_condarc, approx_size_kb, fill_template, get_final_channels, preprocess, rm_rf
1617

@@ -20,6 +21,17 @@
2021
logger = logging.getLogger(__name__)
2122

2223

24+
def calculate_install_dir(yaml_file, subdir=None):
25+
contents = parse(yaml_file, subdir or conda_context.subdir)
26+
if contents.get("installer_type") == "sh":
27+
return contents["name"]
28+
name = contents.get("pkg_name") or contents["name"]
29+
location = contents.get("default_location_pkg")
30+
if location:
31+
return f"{location}/{name}"
32+
return name
33+
34+
2335
def write_readme(dst, info):
2436

2537
src = join(OSX_DIR, 'readme_header.rtf')

dev/environment.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: constructor-dev
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python
6+
- conda >=4.6
7+
- ruamel.yaml >=0.11.14,<0.18
8+
- conda-standalone <23.1.0 # https://github.com/conda/constructor/issues/628
9+
- pillow >=3.1 # [osx or win]

dev/extra-requirements-windows.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
conda-forge::nsis>=3.08=*_log_*

examples/extra_envs/construct.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ build_outputs:
3131
- licenses:
3232
include_text: True
3333
text_errors: replace
34+
initialize_by_default: false
35+
register_python: False

examples/miniforge/construct.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ specs:
2020
installer_type: all
2121
post_install: test_install.sh # [unix]
2222
post_install: test_install.bat # [win]
23+
initialize_by_default: false
24+
register_python: False

examples/miniforge/test_install.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ SetLocal EnableDelayedExpansion
55
call "%PREFIX%\Scripts\activate.bat
66
conda info || exit 1
77
conda config --show-sources || exit 1
8-
conda config --show --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert info['channels'] == ['conda-forge'], info"
8+
conda config --show --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert 'conda-forge' in info['channels'], info"

examples/miniforge/test_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ echo "+ conda config"
1616
conda config --show-sources
1717

1818
echo "+ Testing channels"
19-
conda config --show --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert info['channels'] == ['conda-forge'], info"
19+
conda config --show --json | python -c "import sys, json; info = json.loads(sys.stdin.read()); assert 'conda-forge' in info['channels'], info"
2020
echo " OK"

0 commit comments

Comments
 (0)