Skip to content

Commit 2e42cc1

Browse files
Added support for the uv package and project manager (#408)
* Added light compatibility with my own repository * Copied over uv harness * Added uv to ccds.json and ccds-help.json as well as added it to the makefile. Is untested. * Simplified harness and added it to valid environment managers * Minor simplifications to harness and virtualenv + Makefile * Updated uv and requirements.txt to use uv instead of default pip * Made uv install requested python version * Added uv to dev-requirements.txt and removed redundant pip install from makefile * revert gitignore and pyproject.toml changes * add newline at end of venv harness * remove uv pip install pip (unnecessary) * add newline to uv_harness * add lint and format makefile test commands per #387 --------- Co-authored-by: Chris Kucharczyk <[email protected]>
1 parent b51df3e commit 2e42cc1

File tree

7 files changed

+63
-1
lines changed

7 files changed

+63
-1
lines changed

ccds-help.json

+7
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
140140
"more_information": "[Docs](https://pipenv.pypa.io/en/latest/)"
141141
}
142142
},
143+
{
144+
"choice": "uv",
145+
"help": {
146+
"description": "An extremely fast Python package and project manager, written in Rust.",
147+
"more_information": "[Docs](https://docs.astral.sh/uv/)"
148+
}
149+
},
143150
{
144151
"choice": "none",
145152
"help": {

ccds.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"virtualenv",
1616
"conda",
1717
"pipenv",
18+
"uv",
1819
"none"
1920
],
2021
"dependency_file": [

dev-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ pipenv
1515
pytest
1616
termynal
1717
twine
18+
uv
1819
virtualenvwrapper; sys_platform != 'win32'
1920
virtualenvwrapper-win; sys_platform == 'win32'

tests/test_creation.py

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def verify_makefile_commands(root, config):
169169
harness_path = test_path / "virtualenv_harness.sh"
170170
elif config["environment_manager"] == "pipenv":
171171
harness_path = test_path / "pipenv_harness.sh"
172+
elif config["environment_manager"] == "uv":
173+
harness_path = test_path / "uv_harness.sh"
172174
elif config["environment_manager"] == "none":
173175
return True
174176
else:

tests/uv_harness.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
PROJECT_NAME=$(basename $1)
5+
CCDS_ROOT=$(dirname $0)
6+
MODULE_NAME=$2
7+
8+
# Configure exit / teardown behavior
9+
function finish {
10+
# Deactivate venv if we're in one
11+
if [[ $(which python) == *"$PROJECT_NAME"* ]]; then
12+
deactivate
13+
fi
14+
# Clean up venv directory
15+
if [ -d ".venv" ]; then
16+
rm -rf .venv
17+
fi
18+
}
19+
trap finish EXIT
20+
21+
# Source the steps in the test
22+
source $CCDS_ROOT/test_functions.sh
23+
24+
# Navigate to the generated project and run make commands
25+
cd $1
26+
make
27+
28+
# Create and activate virtual environment
29+
make create_environment
30+
31+
32+
# Check if running on Windows and use appropriate activate path
33+
if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then
34+
source ".venv/Scripts/activate"
35+
else
36+
source ".venv/bin/activate"
37+
fi
38+
39+
make requirements
40+
make lint
41+
make format
42+
43+
run_tests $PROJECT_NAME $MODULE_NAME

tests/virtualenv_harness.sh

-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ make lint
5959
make format
6060

6161
run_tests $PROJECT_NAME $MODULE_NAME
62-

{{ cookiecutter.repo_name }}/Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ PYTHON_INTERPRETER = python
1515
.PHONY: requirements
1616
requirements:
1717
{% if "requirements.txt" == cookiecutter.dependency_file -%}
18+
{% if "uv" == cookiecutter.environment_manager -%}
19+
uv pip install -r requirements.txt
20+
{% else -%}
1821
$(PYTHON_INTERPRETER) -m pip install -U pip
1922
$(PYTHON_INTERPRETER) -m pip install -r requirements.txt
23+
{% endif -%}
2024
{% elif "environment.yml" == cookiecutter.dependency_file -%}
2125
conda env update --name $(PROJECT_NAME) --file environment.yml --prune
2226
{% elif "Pipfile" == cookiecutter.dependency_file -%}
@@ -103,6 +107,11 @@ create_environment:
103107
{% elif cookiecutter.environment_manager == 'pipenv' -%}
104108
pipenv --python $(PYTHON_VERSION)
105109
@echo ">>> New pipenv created. Activate with:\npipenv shell"
110+
{% elif cookiecutter.environment_manager == 'uv' -%}
111+
uv venv --python $(PYTHON_VERSION)
112+
@echo ">>> New uv virtual environment created. Activate with:"
113+
@echo ">>> Windows: .\\\\.venv\\\\Scripts\\\\activate"
114+
@echo ">>> Unix/macOS: source ./.venv/bin/activate"
106115
{% endif %}
107116
{% endif %}
108117

0 commit comments

Comments
 (0)