From 72d05d877dea570abb7b8e6579a12508bf216c2b Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 10:58:47 -0400 Subject: [PATCH 1/9] Test virtual environment Python version --- dev-requirements.txt | 1 + tests/test_creation.py | 4 ++++ tests/test_functions.sh | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index a14df9bff..035327523 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -18,3 +18,4 @@ twine uv virtualenvwrapper; sys_platform != 'win32' virtualenvwrapper-win; sys_platform == 'win32' +vspect diff --git a/tests/test_creation.py b/tests/test_creation.py index 4c2069420..eec33cd0d 100644 --- a/tests/test_creation.py +++ b/tests/test_creation.py @@ -178,6 +178,9 @@ def verify_makefile_commands(root, config): f"Environment manager '{config['environment_manager']}' not found in test harnesses." ) + env = os.environ.copy() + env["EXPECTED_PYTHON_VERSION"] = config["python_version_number"] + result = run( [ BASH_EXECUTABLE, @@ -187,6 +190,7 @@ def verify_makefile_commands(root, config): ], stderr=PIPE, stdout=PIPE, + env=env, ) stdout_output, stderr_output = _decode_print_stdout_stderr(result) diff --git a/tests/test_functions.sh b/tests/test_functions.sh index 4bb6a4a6c..afac181a0 100644 --- a/tests/test_functions.sh +++ b/tests/test_functions.sh @@ -9,6 +9,15 @@ function run_tests () { exit 99 fi + # test Python version in created venv should be match configured version + CREATED_PYTHON_VERSION=$(python -c "import platform; print(platform.python_version())") + if [[ $(vspect parse $CREATED_PYTHON_VERSION "{major_minor_version}") == $EXPECTED_PYTHON_VERSION ]]; then + echo "Python version $CREATED_PYTHON_VERSION matches expected $EXPECTED_PYTHON_VERSION" + else + echo "Python version $CREATED_PYTHON_VERSION does not match $EXPECTED_PYTHON_VERSION" + exit 99 + fi + # test importable python -c "import $2" @@ -16,4 +25,4 @@ function run_tests () { if [ -f "$2/config.py" ]; then python -c "from $2 import config" fi -} \ No newline at end of file +} From d744b14987b4014c2a0ee834681f5d26365c5acd Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 17:39:36 -0400 Subject: [PATCH 2/9] Use uv in CI --- .github/workflows/tests.yml | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9bbc87127..0244f3478 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,12 +4,12 @@ name: tests on: push: branches: [master] - paths-ignore: + paths-ignore: - "docs/**" - "README.md" pull_request: branches: [master] - paths-ignore: + paths-ignore: - "docs/**" - "README.md" schedule: @@ -24,19 +24,17 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + - uses: astral-sh/setup-uv@v5 with: - python-version: "3.11" - cache: "pip" - cache-dependency-path: | + python-version: "3.13" + enable-cache: true + cache-dependency-glob: | pyproject.toml dev-requirements.txt - name: Install dependencies run: | - python -m pip install --upgrade pip - make requirements + uv pip install -r dev-requirements.txt - name: Lint run: | @@ -57,17 +55,19 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - uses: astral-sh/setup-uv@v5 with: - python-version: ${{ matrix.python-version }} - allow-prereleases: true - cache: "pip" - cache-dependency-path: | + python-version: "3.13" + enable-cache: true + cache-dependency-glob: | pyproject.toml dev-requirements.txt - - name: Set up Miniconda + - name: Make Python ${{ matrix.python-version }} available + run: + uv python install ${{ matrix.python-version }} + + - name: Set up Miniconda uses: conda-incubator/setup-miniconda@v3 with: auto-activate-base: true @@ -96,8 +96,7 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - make requirements + uv pip install -r dev-requirements.txt - name: Check dependencies run: | @@ -113,6 +112,8 @@ jobs: conda --version which pipenv pipenv --version + which uv + uv --version which virtualenv virtualenv --version From 0393ed7a822055445d2b63b3a5ccc58d4f152a68 Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 18:20:56 -0400 Subject: [PATCH 3/9] Fix python version of created environment in tests --- .github/workflows/tests.yml | 10 +++++++--- tests/conftest.py | 11 ++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0244f3478..e1bdb6990 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -51,21 +51,23 @@ jobs: defaults: run: shell: bash + env: + TEST_TARGET_PYTHON_VERSION: 3.13 steps: - uses: actions/checkout@v4 - uses: astral-sh/setup-uv@v5 with: - python-version: "3.13" + python-version: ${{ matrix.python-version }}) enable-cache: true cache-dependency-glob: | pyproject.toml dev-requirements.txt - - name: Make Python ${{ matrix.python-version }} available + - name: Make Python ${{ env.TEST_TARGET_PYTHON_VERSION }} available run: - uv python install ${{ matrix.python-version }} + uv python install $TEST_TARGET_PYTHON_VERSION - name: Set up Miniconda uses: conda-incubator/setup-miniconda@v3 @@ -108,6 +110,8 @@ jobs: fi which make make --version + which python + python --version which conda conda --version which pipenv diff --git a/tests/conftest.py b/tests/conftest.py index a564efe60..6cfd55629 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import json +import os import shutil import sys import tempfile @@ -25,13 +26,13 @@ def config_generator(fast=False): cookiecutter_json = json.load((CCDS_ROOT / "ccds.json").open("r")) - # python versions for the created environment; match the root - # python version since Pipenv needs to be able to find an executable - running_py_version = f"{sys.version_info.major}.{sys.version_info.minor}" - py_version = [("python_version_number", v) for v in [running_py_version]] + # python version for the environment of the created project + # we fix this to specific version, and the test matrix ensures things work + # whether or not it matches the current python version running ccds + test_target_python_version = os.environ.get("TEST_TARGET_PYTHON_VERSION", "3.13") configs = product( - py_version, + [test_target_python_version], [ ("environment_manager", opt) for opt in cookiecutter_json["environment_manager"] From c22bd1d532b8c434a4ce1cb4166d224681a7d7e7 Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 18:24:04 -0400 Subject: [PATCH 4/9] Pipenv should create its own virtualenv --- tests/test_creation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_creation.py b/tests/test_creation.py index eec33cd0d..42d355735 100644 --- a/tests/test_creation.py +++ b/tests/test_creation.py @@ -180,6 +180,7 @@ def verify_makefile_commands(root, config): env = os.environ.copy() env["EXPECTED_PYTHON_VERSION"] = config["python_version_number"] + env["PIPENV_IGNORE_VIRTUALENVS"] = "1" # pipenv should create its own virtualenv result = run( [ From fd5286799164a023ad74259f5a65be5662982d75 Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 18:25:29 -0400 Subject: [PATCH 5/9] Remove sys import --- tests/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6cfd55629..b36a880e5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,6 @@ import json import os import shutil -import sys import tempfile from contextlib import contextmanager from itertools import cycle, product From bf7b56f5a0e8718af64d5d09ad312ec19cf1e409 Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 18:34:17 -0400 Subject: [PATCH 6/9] Remove extraneous parenthesis --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e1bdb6990..2edcdc7ad 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -59,7 +59,7 @@ jobs: - uses: astral-sh/setup-uv@v5 with: - python-version: ${{ matrix.python-version }}) + python-version: ${{ matrix.python-version }} enable-cache: true cache-dependency-glob: | pyproject.toml From 352a049a864d0954bb4b145165496d42baa7cd19 Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 18:37:34 -0400 Subject: [PATCH 7/9] Fix wrong input to configs product --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index b36a880e5..fcee590da 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,7 +31,7 @@ def config_generator(fast=False): test_target_python_version = os.environ.get("TEST_TARGET_PYTHON_VERSION", "3.13") configs = product( - [test_target_python_version], + [("python_version_number", test_target_python_version)], [ ("environment_manager", opt) for opt in cookiecutter_json["environment_manager"] From ada20822970bf0b493c29a9b0b45162dea4e9c18 Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 20:06:38 -0400 Subject: [PATCH 8/9] Fix virtualenvwrapper to set Python version instead of Python interpreter --- {{ cookiecutter.repo_name }}/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{ cookiecutter.repo_name }}/Makefile b/{{ cookiecutter.repo_name }}/Makefile index 85eb9e5b4..d13c34bdf 100644 --- a/{{ cookiecutter.repo_name }}/Makefile +++ b/{{ cookiecutter.repo_name }}/Makefile @@ -108,7 +108,7 @@ create_environment: {% endif %} @echo ">>> conda env created. Activate with:\nconda activate $(PROJECT_NAME)" {% elif cookiecutter.environment_manager == 'virtualenv' -%} - @bash -c "if [ ! -z `which virtualenvwrapper.sh` ]; then source `which virtualenvwrapper.sh`; mkvirtualenv $(PROJECT_NAME) --python=$(PYTHON_INTERPRETER); else mkvirtualenv.bat $(PROJECT_NAME) --python=$(PYTHON_INTERPRETER); fi" + @bash -c "if [ ! -z `which virtualenvwrapper.sh` ]; then source `which virtualenvwrapper.sh`; mkvirtualenv $(PROJECT_NAME) --python=$(PYTHON_VERSION); else mkvirtualenv.bat $(PROJECT_NAME) --python=$(PYTHON_VERSION); fi" @echo ">>> New virtualenv created. Activate with:\nworkon $(PROJECT_NAME)" {% elif cookiecutter.environment_manager == 'pipenv' -%} pipenv --python $(PYTHON_VERSION) From 52c8fd18458cd46c033fe44d620996de1debbe8c Mon Sep 17 00:00:00 2001 From: Jay Qi Date: Wed, 19 Mar 2025 20:18:40 -0400 Subject: [PATCH 9/9] Install Python executables into PATH --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2edcdc7ad..d5ca01a55 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -67,7 +67,8 @@ jobs: - name: Make Python ${{ env.TEST_TARGET_PYTHON_VERSION }} available run: - uv python install $TEST_TARGET_PYTHON_VERSION + # --preview flag adds installed Python into PATH + uv python install $TEST_TARGET_PYTHON_VERSION --preview - name: Set up Miniconda uses: conda-incubator/setup-miniconda@v3 @@ -102,6 +103,7 @@ jobs: - name: Check dependencies run: | + echo $PATH if [[ -z "${BASH_EXECUTABLE}" ]]; then bash --version else