-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
454 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "pip" | ||
directory: "/pkg" | ||
schedule: | ||
interval: "daily" | ||
groups: | ||
patches: | ||
update-types: | ||
- "minor" | ||
- "patch" | ||
open-pull-requests-limit: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: On Push Workflow | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
check-uv: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 | ||
- name: Install UV | ||
run: | | ||
pipx install uv | ||
- name: Check UV | ||
run: ./bin/check-uv.sh | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
needs: check-uv | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install UV | ||
run: | | ||
pipx install uv | ||
- name: Run tests | ||
run: | | ||
uv run pytest tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Python-generated files | ||
__pycache__/ | ||
*.py[oc] | ||
build/ | ||
dist/ | ||
wheels/ | ||
*.egg-info | ||
|
||
# Virtual environments | ||
.venv | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
PYTHON_VERSION=$(cat .python-version) | ||
BRANCH_NAME=${GITHUB_REF#refs/heads/} | ||
|
||
# Case: user has added new dependencies to uv | ||
# Check if there is a change in uv.lock but not in requirements.txt in the last commit | ||
if git diff --name-only HEAD~1 | grep -q "uv.lock" && \ | ||
! git diff --name-only HEAD~1 | grep -q "requirements.txt"; then | ||
|
||
echo "Export new uv.lock to requirements.txt" | ||
uv export --no-hashes -o requirements.txt | ||
fi | ||
|
||
# Case: dependabot has updated a requirements.txt | ||
# Check if there is a change in requirements.txt but not in uv.lock in the last commit | ||
if git diff --name-only HEAD~1 | grep -q "requirements.txt" &&\ | ||
! git diff --name-only HEAD~1 | grep -q "uv.lock" && \ | ||
! ( \ | ||
grep -q "uv export" requirements.txt && \ | ||
grep -q "pip-compile pyproject.toml" requirements.txt \ | ||
); then | ||
# Read requirements.txt, exclude comments, and format as TOML array | ||
constraints=$(grep -vE '^\s*#' requirements.txt | awk '{print " \""$0"\","}') | ||
|
||
# Create the section to append | ||
cat << EOF >> pyproject.toml | ||
[tool.uv] | ||
constraint-dependencies = [ | ||
$constraints | ||
] | ||
EOF | ||
|
||
echo "Lock uv with a new requirements.txt as constraint" | ||
uv lock | ||
uv export --no-hashes -o requirements.txt | ||
fi | ||
|
||
# Remove comments from requirements.txt | ||
sed -i '' '/^#/d' requirements.txt | ||
|
||
# Add pip-compile like comment to the top of requirements.txt | ||
# for dependabot to detect a pip-compile workflow | ||
cat << EOF | cat - requirements.txt > temp && mv temp requirements.txt | ||
# | ||
# This file is autogenerated by pip-compile with Python $PYTHON_VERSION | ||
# by the following command: | ||
# | ||
# pip-compile pyproject.toml | ||
# | ||
# The above comment was added for dependabot to support uv. | ||
# The file was exported via: | ||
# | ||
# uv export --no-hashes -o requirements.txt | ||
# | ||
EOF | ||
|
||
git add uv.lock requirements.txt | ||
if ! git diff --cached --quiet; then | ||
git commit -m "Sync uv.lock and requirements.txt" | ||
git push origin $BRANCH_NAME | ||
exit 1 | ||
else | ||
echo "No changes detected in uv.lock and requirements.txt" | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from uv_light.lens import Lens | ||
from uv_light.beam import Beam | ||
|
||
if __name__ == "main": | ||
print(Beam().project_on(Lens())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[project] | ||
name = "uv-light" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"flask==3.*", | ||
"pandas==2.*", | ||
"pyarrow==17.*", | ||
"pytest>=8.3.3", | ||
] |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from uv_light.beam import Beam | ||
from uv_light.lens import Lens | ||
|
||
def test_beam_project_on(): | ||
actual = Beam().project_on(Lens()) | ||
expected = "~~~|--->\n~~~|--->\n~~~|--->\n~~~|--->" | ||
assert actual == expected |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pandas as pd | ||
import pyarrow as pa | ||
|
||
class Beam: | ||
def __init__(self): | ||
# Represent the beam with an arrow | ||
self.beam_pattern = pa.array(["--->", "--->", "--->", "--->"]) | ||
|
||
def project_on(self, lens): | ||
# Convert pyarrow array to pandas DataFrame | ||
beam_frame = pd.DataFrame({'Beam': self.beam_pattern.to_pandas()}) | ||
return lens.focus_beam(beam_frame) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pandas as pd | ||
|
||
class Lens: | ||
def focus_beam(self, beam_frame): | ||
# Add lens symbol to the DataFrame | ||
beam_frame['Lens'] = '~~~|' | ||
# Combine Beam and Lens columns into a single string representation | ||
beam_frame['Projection'] = beam_frame['Lens'] + beam_frame['Beam'] | ||
return beam_frame['Projection'].to_string(index=False, header=False) |