Skip to content

Commit d622e9a

Browse files
Uv project management (surrealdb#188)
1 parent 5eedb0c commit d622e9a

File tree

21 files changed

+1798
-189
lines changed

21 files changed

+1798
-189
lines changed

.dockerignore

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Version control
2+
.git/
3+
.gitignore
4+
5+
# Python caches and artifacts
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# Virtual environments
30+
.env
31+
.venv
32+
env/
33+
venv/
34+
ENV/
35+
env.bak/
36+
venv.bak/
37+
38+
# IDE and editor files
39+
.vscode/
40+
.idea/
41+
*.swp
42+
*.swo
43+
*~
44+
45+
# OS generated files
46+
.DS_Store
47+
.DS_Store?
48+
._*
49+
.Spotlight-V100
50+
.Trashes
51+
ehthumbs.db
52+
Thumbs.db
53+
54+
# Testing
55+
.coverage
56+
.pytest_cache/
57+
.tox/
58+
.nox/
59+
.cache
60+
nosetests.xml
61+
coverage.xml
62+
*.cover
63+
*.py,cover
64+
.hypothesis/
65+
66+
# Documentation
67+
docs/_build/
68+
69+
# Jupyter Notebooks
70+
.ipynb_checkpoints
71+
72+
# Docker
73+
Dockerfile*
74+
.dockerignore
75+
docker-compose*.yml
76+
77+
# Logs
78+
logs/
79+
*.log
80+
81+
# Runtime data
82+
pids
83+
*.pid
84+
*.seed
85+
*.pid.lock
86+
87+
# Dependency directories
88+
node_modules/
89+
90+
# Local development
91+
.env.local
92+
.env.development.local
93+
.env.test.local
94+
.env.production.local
95+
96+
# Temporary files
97+
tmp/
98+
temp/

.github/workflows/stability.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,20 @@ jobs:
2222
- name: Checkout repository
2323
uses: actions/checkout@v4
2424

25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v4
27+
with:
28+
version: "latest"
29+
enable-cache: true
30+
2531
- name: Setup Python
2632
uses: actions/setup-python@v4
2733
with:
2834
python-version: 3.13
2935

36+
- name: Install dependencies
37+
run: uv sync --group dev
38+
3039
- name: Run ruff checks
3140
uses: astral-sh/ruff-action@v3
3241
with:
@@ -38,6 +47,5 @@ jobs:
3847
src: "./src"
3948
args: "format --check --diff"
4049

41-
# This is currently disabled because MyPy is very confused about Coroutine types
42-
# - name: Run mypy checks
43-
# run: mypy --explicit-package-bases src/
50+
- name: Run mypy checks
51+
run: uv run mypy --explicit-package-bases src/

.github/workflows/tests.yml

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,93 @@ on:
1212
concurrency:
1313
group: tests-${{ github.head_ref || github.ref }}
1414
cancel-in-progress: true
15-
15+
1616
jobs:
17-
run-unit-tests:
17+
# Job to discover latest v2.x versions dynamically
18+
discover-versions:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
v2-versions: ${{ steps.get-versions.outputs.v2-versions }}
22+
steps:
23+
- name: Get latest SurrealDB v2.x versions
24+
id: get-versions
25+
run: |
26+
# For now, use known stable versions to avoid API/shell complexity
27+
# This ensures reliable CI while still testing multiple versions
28+
V2_VERSIONS='["v2.0.5", "v2.1.8", "v2.2.6", "v2.3.6"]'
29+
30+
echo "v2-versions=$V2_VERSIONS" >> $GITHUB_OUTPUT
31+
32+
# Test against core stable v2.x versions (always run)
33+
test-core:
34+
runs-on: ubuntu-latest
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
python-version: ["3.10", "3.11", "3.12", "3.13"] # Python SDK requires 3.10+
39+
surrealdb-version:
40+
# Core stable v2.x versions we always want to support
41+
- "v2.0.5" # Latest v2.0.x
42+
- "v2.1.8" # Latest v2.1.x
43+
- "v2.2.6" # Latest v2.2.x
44+
- "v2.3.6" # Latest v2.3.x
45+
name: Core Tests - Python ${{ matrix.python-version }} - SurrealDB ${{ matrix.surrealdb-version }}
46+
steps:
47+
- name: Checkout repository
48+
uses: actions/checkout@v4
49+
50+
- name: Install uv
51+
uses: astral-sh/setup-uv@v4
52+
with:
53+
version: "latest"
54+
enable-cache: true
55+
56+
- name: Setup Python
57+
uses: actions/setup-python@v4
58+
with:
59+
python-version: ${{ matrix.python-version }}
60+
61+
- name: Install surrealdb
62+
run: curl -sSf https://install.surrealdb.com | sh -s -- --version ${{ matrix.surrealdb-version }}
63+
64+
- name: Start surrealdb
65+
run: surreal start --allow-all -u root -p root --log trace &
66+
67+
- name: Wait for startup
68+
run: sleep 5
69+
70+
- name: Install dependencies
71+
run: uv sync --group dev
72+
73+
- name: Run unit tests
74+
run: uv run python -m unittest discover -s tests
75+
env:
76+
PYTHONPATH: ./src
77+
SURREALDB_URL: http://localhost:8000
78+
SURREALDB_VERSION: ${{ matrix.surrealdb-version }}
79+
PYTHONWARNINGS: ignore::ResourceWarning
80+
81+
# Comprehensive matrix test (runs on schedule or manual trigger)
82+
test-comprehensive:
83+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
84+
needs: discover-versions
1885
runs-on: ubuntu-latest
1986
strategy:
2087
fail-fast: false
2188
matrix:
22-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
23-
# surrealdb-version: ["v2.1.0", "v2.1.1", "v2.1.2", "v2.1.3", "v2.1.4"] # v2.0.0 has different UPSERT behaviour
24-
surrealdb-version: ["v2.1.1", "v2.1.2", "v2.1.3", "v2.1.4"] # v2.0.0 has different UPSERT behaviour and v2.1.0 does not support async batching
25-
name: Python ${{ matrix.python-version }} - SurrealDB ${{ matrix.surrealdb-version }}
89+
python-version: ["3.10", "3.11", "3.12", "3.13"]
90+
surrealdb-version: ${{ fromJson(needs.discover-versions.outputs.v2-versions) }}
91+
name: Comprehensive - Python ${{ matrix.python-version }} - SurrealDB ${{ matrix.surrealdb-version }}
2692
steps:
2793
- name: Checkout repository
2894
uses: actions/checkout@v4
2995

96+
- name: Install uv
97+
uses: astral-sh/setup-uv@v4
98+
with:
99+
version: "latest"
100+
enable-cache: true
101+
30102
- name: Setup Python
31103
uses: actions/setup-python@v4
32104
with:
@@ -42,17 +114,18 @@ jobs:
42114
run: sleep 5
43115

44116
- name: Install dependencies
45-
run: pip install -r requirements.txt
117+
run: uv sync --group dev
46118

47119
- name: Run unit tests
48-
run: python -m unittest discover -s tests
120+
run: uv run python -m unittest discover -s tests
49121
env:
50122
PYTHONPATH: ./src
51123
SURREALDB_URL: http://localhost:8000
52124
SURREALDB_VERSION: ${{ matrix.surrealdb-version }}
125+
PYTHONWARNINGS: ignore::ResourceWarning
53126

54127
# - name: Run unit tests (WebSocket)
55-
# run: python -m unittest discover -s tests
128+
# run: uv run python -m unittest discover -s tests
56129
# env:
57130
# PYTHONPATH: ./src
58131
# SURREALDB_URL: ws://localhost:8000

Dockerfile

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,30 @@
1-
FROM ubuntu:latest
1+
FROM ghcr.io/astral-sh/uv:latest
22

3-
# Set the working directory
4-
WORKDIR /app
5-
6-
# Copy the source code
7-
COPY src /app/src
8-
9-
# Copy the .cargo directory
10-
COPY .cargo /app/.cargo
3+
# Create non-root user for security
4+
RUN useradd --create-home --shell /bin/bash app
115

12-
# Copy the surrealdb directory
13-
COPY surrealdb /app/surrealdb
14-
15-
# Copy the Cargo.toml file
16-
COPY Cargo.toml /app/Cargo.toml
6+
# Set working directory and switch to app user
7+
WORKDIR /app
8+
USER app
179

18-
# Copy the pyproject.toml file
19-
COPY pyproject.toml /app/pyproject.toml
10+
# Copy dependency files first for better caching
11+
COPY --chown=app:app pyproject.toml uv.lock ./
2012

21-
# Copy the setup.py file
22-
COPY setup.py /app/setup.py
13+
# Install dependencies
14+
RUN uv sync --frozen
2315

24-
RUN apt update
25-
RUN apt install -y clang
26-
RUN apt-get install -y libclang-dev
27-
RUN apt install -y python3
28-
RUN apt install -y python3-pip
29-
RUN apt install -y curl
30-
RUN apt install -y vim
31-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
32-
RUN export PATH="$HOME/.cargo/bin:$PATH"
33-
RUN pip3 install setuptools_rust
34-
RUN python3 setup.py bdist_wheel
16+
# Copy source code
17+
COPY --chown=app:app src/ ./src/
18+
COPY --chown=app:app tests/ ./tests/
19+
COPY --chown=app:app README.md LICENSE ./
3520

36-
# docker build . -t package-test
37-
# docker run -d -p 18000:18000 package-test
21+
# Build and install the package
22+
RUN uv build && uv pip install dist/*.whl
3823

39-
EXPOSE 18000
24+
# Health check
25+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
26+
CMD uv run python -c "import surrealdb; print('SurrealDB Python client is ready')" || exit 1
4027

41-
CMD ["bash", "-c", "trap : TERM INT; sleep infinity & wait"]
28+
# Default command - can be overridden
29+
CMD ["uv", "run", "python", "-c", "import surrealdb; print('SurrealDB Python client container is running')"]
4230

0 commit comments

Comments
 (0)