Skip to content

Commit 8261d13

Browse files
committed
Add UV demo
1 parent 5e282be commit 8261d13

File tree

14 files changed

+438
-0
lines changed

14 files changed

+438
-0
lines changed

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
groups:
8+
patches:
9+
update-types:
10+
- "minor"
11+
- "patch"
12+
open-pull-requests-limit: 100

.github/workflows/push.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: On Push Workflow
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
uv-sync:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
12+
steps:
13+
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 2
18+
19+
- name: UV sync
20+
id: uv-sync
21+
# a new commit will not trigger this workflow again
22+
run: |
23+
pipx install uv
24+
./bin/uv-sync.sh
25+
26+
build:
27+
runs-on: ubuntu-latest
28+
needs: uv-sync
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Install UV
35+
run: |
36+
pipx install uv
37+
38+
- name: Run tests
39+
run: |
40+
uv run pytest tests

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
9+
# Virtual environments
10+
.venv
11+
.vscode

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

bin/uv-sync.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
PYTHON_VERSION=$(cat .python-version)
5+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
6+
AUTHOR_NAME=$(git log -1 --pretty=format:"%an")
7+
AUTHOR_EMAIL=$(git log -1 --pretty=format:"%ae")
8+
9+
if [[ "$AUTHOR_NAME" == *dependabot* ]] ; then
10+
# Read requirements.txt, exclude comments, and format as TOML array
11+
constraints=$(grep -vE '^\s*#' requirements.txt | awk '{print " \""$0"\","}')
12+
13+
# Append constraint-dependencies to pyproject.toml
14+
cat <<EOF >> pyproject.toml
15+
16+
[tool.uv]
17+
constraint-dependencies = [
18+
$constraints
19+
]
20+
EOF
21+
22+
echo "Lock uv with a new requirements.txt as constraint"
23+
uv lock
24+
fi
25+
26+
echo "Export uv.lock to requirements.txt"
27+
uv export --no-hashes -o requirements.txt
28+
29+
# Add pip-compile like comment to the top of requirements.txt
30+
# for dependabot to detect a pip-compile workflow
31+
cat << EOF | cat - requirements.txt > temp && mv temp requirements.txt
32+
#
33+
# This file is autogenerated by pip-compile with Python $PYTHON_VERSION
34+
# by the following command:
35+
#
36+
# pip-compile pyproject.toml
37+
#
38+
#
39+
# The above comment was added for dependabot to support uv.
40+
#
41+
EOF
42+
43+
git add uv.lock requirements.txt
44+
if ! git diff --cached --quiet; then
45+
git config --global user.name "$AUTHOR_NAME"
46+
git config --global user.email "$AUTHOR_EMAIL"
47+
git commit -m "Sync uv.lock and requirements.txt"
48+
git push origin $BRANCH_NAME
49+
echo "push changes"
50+
fi

main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from uv_light.lens import Lens
2+
from uv_light.beam import Beam
3+
4+
if __name__ == "main":
5+
print(Beam().project_on(Lens()))

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "uv-light"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"flask==3.*",
9+
"pandas==2.*",
10+
"pyarrow==17.*",
11+
"pytest>=8.3.3",
12+
]

tests/__init__.py

Whitespace-only changes.

tests/uv_light/__init__.py

Whitespace-only changes.

tests/uv_light/test_beam.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from uv_light.beam import Beam
2+
from uv_light.lens import Lens
3+
4+
def test_beam_project_on():
5+
actual = Beam().project_on(Lens())
6+
expected = "~~~|--->\n~~~|--->\n~~~|--->\n~~~|--->"
7+
assert actual == expected

0 commit comments

Comments
 (0)