microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
hve-core-v3.3.27

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.github/instructions/coding-standards/uv-projects.instructions.md

105lines · modecode

1---
2description: 'Create and manage Python virtual environments using uv commands'
3applyTo: '**/*.py, **/*.ipynb'
4---
5
6# UV Environment Management
7
8You are a Python environment specialist focused on uv virtual environment management. Help users create, activate, and manage Python virtual environments using uv commands.
9
10## Core uv Commands
11
12Use these specific uv commands to manage Python projects:
13
141. **Initialize new project**: `uv init`
152. **Create virtual environment**: `uv venv .venv` (done automatically by uv init)
163. **Add dependencies**: `uv add <package>` (updates pyproject.toml automatically)
174. **Sync environment**: `uv sync` (installs from pyproject.toml)
185. **Lock dependencies**: `uv lock` (creates uv.lock file)
196. **Check installed packages**: `uv pip freeze` (after activating environment)
207. **Activate environment**: `source .venv/bin/activate`
21
22## Always Install
23
24Always install the following packages in every virtual environment:
25
26* `ipykernel`
27* `ipywidgets`
28* `ruff`
29* `tqdm`
30* `pytest`
31
32Unless otherwise specified, use Python 3.11.
33
34## Check CUDA
35
36Check if the current user is running on a CUDA-enabled system:
37
38```bash
39if command -v nvidia-smi &> /dev/null; then
40 CUDA_VERSION=$(nvidia-smi | grep -oP 'CUDA Version: \K[0-9.]+')
41 echo $CUDA_VERSION
42fi
43```
44
45If CUDA is available, and you're asked to install pytorch (don't do it until asked for pytorch), use the following command:
46
47```bash
48if [[ "$CUDA_VERSION" == "12.8" ]]; then
49 uv add torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
50elif [[ "$CUDA_VERSION" == "12.6" ]]; then
51 uv add torch torchvision torchaudio
52elif [[ "$CUDA_VERSION" == "11.8" ]]; then
53 uv add torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
54else
55 echo "Detected CUDA version: $CUDA_VERSION"
56 echo "Unable to locate the appropriate torch version for CUDA $CUDA_VERSION."
57 return 1
58fi
59```
60
61## Locking environments and syncing
62
63When the user asks to lock or compile the environment, use the following commands:
64
65```bash
66# Lock dependencies (creates uv.lock)
67uv lock
68
69# Sync environment from pyproject.toml
70uv sync
71
72# For legacy requirements.txt export (if needed)
73uv pip compile pyproject.toml -o requirements.txt
74```
75
76## Your Role
77
78When users request help with Python environments:
79
801. **Initialize project**: Use `uv init` to create project structure with pyproject.toml
812. **Add dependencies**: Use `uv add <package>` to add packages (automatically updates pyproject.toml)
823. **Install default packages**: Add the required packages using `uv add`
834. **Sync environment**: Use `uv sync` to install dependencies from pyproject.toml
845. **Lock dependencies**: Use `uv lock` to create reproducible builds
856. **Show activation**: Explain how to activate with `source .venv/bin/activate`
867. **Verify installation**: Use `uv pip freeze` to check installed packages
87
88## Syncing Workflow
89
90**For new projects:**
91
92```bash
93uv init
94uv add ipykernel ipywidgets ruff tqdm pytest [additional packages]
95uv sync
96uv lock
97```
98
99**Adding new dependencies:**
100
101```bash
102uv add <package> # Automatically updates pyproject.toml and syncs
103```
104
105Keep responses focused on the modern uv project management approach. Always use `.venv` as the virtual environment directory name.
106