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

Added support for the uv package and project manager #408

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ manual_test/

# other local dev info
.vscode/
.history/

# Mac OS-specific storage files
.DS_Store
Icon?
Icon
Icon[\r]

# ruff
.ruff_cache/

# vim
*.swp
Expand Down
7 changes: 7 additions & 0 deletions ccds-help.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@
"more_information": "[Docs](https://pipenv.pypa.io/en/latest/)"
}
},
{
"choice": "uv",
"help": {
"description": "An extremely fast Python package and project manager, written in Rust.",
"more_information": "[Docs](https://docs.astral.sh/uv/)"
}
},
{
"choice": "none",
"help": {
Expand Down
1 change: 1 addition & 0 deletions ccds.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"virtualenv",
"conda",
"pipenv",
"uv",
"none"
],
"dependency_file": [
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ pipenv
pytest
termynal
twine
uv
virtualenvwrapper; sys_platform != 'win32'
virtualenvwrapper-win; sys_platform == 'win32'
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ ccds = "ccds.__main__:main"
"Source Code" = "https://github.com/drivendataorg/cookiecutter-data-science/"
"Bug Tracker" = "https://github.com/drivendataorg/cookiecutter-data-science/issues"
"DrivenData" = "https://drivendata.co"

[tool.pytest.ini_options]
testpaths = "./tests"
addopts = "-vv --color=yes"
2 changes: 2 additions & 0 deletions tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def verify_makefile_commands(root, config):
harness_path = test_path / "virtualenv_harness.sh"
elif config["environment_manager"] == "pipenv":
harness_path = test_path / "pipenv_harness.sh"
elif config["environment_manager"] == "uv":
harness_path = test_path / "uv_harness.sh"
elif config["environment_manager"] == "none":
return True
else:
Expand Down
41 changes: 41 additions & 0 deletions tests/uv_harness.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -ex

PROJECT_NAME=$(basename $1)
CCDS_ROOT=$(dirname $0)
MODULE_NAME=$2

# Configure exit / teardown behavior
function finish {
# Deactivate venv if we're in one
if [[ $(which python) == *"$PROJECT_NAME"* ]]; then
deactivate
fi
# Clean up venv directory
if [ -d ".venv" ]; then
rm -rf .venv
fi
}
trap finish EXIT

# Source the steps in the test
source $CCDS_ROOT/test_functions.sh

# Navigate to the generated project and run make commands
cd $1
make

# Create and activate virtual environment
make create_environment


# Check if running on Windows and use appropriate activate path
if [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then
source ".venv/Scripts/activate"
else
source ".venv/bin/activate"
fi

make requirements

run_tests $PROJECT_NAME $MODULE_NAME
3 changes: 1 addition & 2 deletions tests/virtualenv_harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ fi

make requirements

run_tests $PROJECT_NAME $MODULE_NAME

run_tests $PROJECT_NAME $MODULE_NAME
10 changes: 10 additions & 0 deletions {{ cookiecutter.repo_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ PYTHON_INTERPRETER = python
.PHONY: requirements
requirements:
{% if "requirements.txt" == cookiecutter.dependency_file -%}
{% if "uv" == cookiecutter.environment_manager -%}
uv pip install pip
uv pip install -r requirements.txt
{% else -%}
$(PYTHON_INTERPRETER) -m pip install -U pip
$(PYTHON_INTERPRETER) -m pip install -r requirements.txt
{% endif -%}
{% elif "environment.yml" == cookiecutter.dependency_file -%}
conda env update --name $(PROJECT_NAME) --file environment.yml --prune
{% elif "Pipfile" == cookiecutter.dependency_file -%}
Expand Down Expand Up @@ -88,6 +93,11 @@ create_environment:
{% elif cookiecutter.environment_manager == 'pipenv' -%}
pipenv --python $(PYTHON_VERSION)
@echo ">>> New pipenv created. Activate with:\npipenv shell"
{% elif cookiecutter.environment_manager == 'uv' -%}
uv venv --python $(PYTHON_VERSION)
@echo ">>> New uv virtual environment created. Activate with:"
@echo ">>> Windows: .\\\\.venv\\\\Scripts\\\\activate"
@echo ">>> Unix/macOS: source ./.venv/bin/activate"
{% endif %}
{% endif %}

Expand Down
Loading