Skip to content

Commit 1b1f8b1

Browse files
authored
Switch to uv for project management (#20)
* Remove .python-version from gitignore. Add uv.lock and .python-version. * Adapt the pyproject.toml. Update contributing docs. Update docs build Makefile. * Update workflows.
1 parent 2000ef6 commit 1b1f8b1

File tree

9 files changed

+1404
-107
lines changed

9 files changed

+1404
-107
lines changed

.github/workflows/docs.yml

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,62 @@ on:
55
push:
66
branches: ["master"]
77

8-
98
jobs:
109
build:
1110
runs-on: ubuntu-24.04
1211
permissions:
1312
contents: write
1413
steps:
15-
- uses: actions/checkout@v4
16-
with:
17-
persist-credentials: false
18-
fetch-depth: 0 # Fetch the full history
19-
ref: ${{ github.ref }} # Check out the current branch or tag
14+
- uses: actions/checkout@v4
15+
with:
16+
persist-credentials: false
17+
fetch-depth: 0 # Fetch the full history
18+
ref: ${{ github.ref }} # Check out the current branch or tag
2019

21-
- name: Fetch tags only
22-
run: git fetch --tags --no-recurse-submodules
20+
- name: Fetch tags only
21+
run: git fetch --tags --no-recurse-submodules
2322

24-
- name: Set up Python
25-
uses: actions/setup-python@v4
26-
with:
27-
python-version: "3.10"
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: "3.10"
2827

29-
- name: Install dependencies
30-
run: |
31-
python -m pip install --upgrade pip
32-
pip install -e .[docs]
28+
- name: Install uv and dependencies
29+
run: |
30+
curl -LsSf https://astral.sh/uv/0.9.8/install.sh | sh
31+
uv sync --group docs
3332
34-
- name: Build documentation
35-
run: sphinx-multiversion docs/source docs/build/html --keep-going --no-color
33+
- name: Build documentation
34+
run: uv run sphinx-multiversion docs/source docs/build/html --keep-going --no-color
3635

37-
- name: Get the latest tag
38-
run: |
39-
# Fetch all tags
40-
git fetch --tags
41-
# Get the latest tag
42-
latest_tag=$(git tag --sort=-creatordate | head -n 1)
43-
echo "LATEST_RELEASE=$latest_tag" >> $GITHUB_ENV
36+
- name: Get the latest tag
37+
run: |
38+
# Fetch all tags
39+
git fetch --tags
40+
# Get the latest tag
41+
latest_tag=$(git tag --sort=-creatordate | head -n 1)
42+
echo "LATEST_RELEASE=$latest_tag" >> $GITHUB_ENV
4443
45-
- name: Generate index.html for judge0.github.io/judge0-python.
46-
run: |
47-
echo '<!DOCTYPE html>
48-
<html>
49-
<head>
50-
<meta http-equiv="refresh" content="0; URL=${{ env.latest_release }}/index.html">
51-
</head>
52-
</html>' > docs/build/html/index.html
53-
env:
54-
latest_release: ${{ env.LATEST_RELEASE }}
44+
- name: Generate index.html for judge0.github.io/judge0-python.
45+
run: |
46+
echo '<!DOCTYPE html>
47+
<html>
48+
<head>
49+
<meta http-equiv="refresh" content="0; URL=${{ env.latest_release }}/index.html">
50+
</head>
51+
</html>' > docs/build/html/index.html
52+
env:
53+
latest_release: ${{ env.LATEST_RELEASE }}
5554

56-
- name: Upload artifacts
57-
uses: actions/upload-artifact@v4
58-
with:
59-
name: html-docs
60-
path: docs/build/html/
55+
- name: Upload artifacts
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: html-docs
59+
path: docs/build/html/
6160

62-
- name: Deploy
63-
uses: peaceiris/actions-gh-pages@v3
64-
if: github.ref == 'refs/heads/master'
65-
with:
66-
github_token: ${{ secrets.GITHUB_TOKEN }}
67-
publish_dir: docs/build/html
61+
- name: Deploy
62+
uses: peaceiris/actions-gh-pages@v3
63+
if: github.ref == 'refs/heads/master'
64+
with:
65+
github_token: ${{ secrets.GITHUB_TOKEN }}
66+
publish_dir: docs/build/html

.github/workflows/publish.yml

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,30 @@ on:
1010

1111
jobs:
1212
publish:
13-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-24.04
1414

1515
steps:
16-
# Checkout the repository
17-
- name: Checkout Code
18-
uses: actions/checkout@v3
19-
20-
# Set up Python environment
21-
- name: Set up Python
22-
uses: actions/setup-python@v4
23-
with:
24-
python-version: "3.10"
25-
26-
# Install build and twine
27-
- name: Install Build Tools
28-
run: |
29-
python -m pip install --upgrade pip
30-
pip install build twine
31-
32-
# Build the package
33-
- name: Build the Package
34-
run: python -m build
35-
36-
- name: Publish to Test PyPI
37-
if: github.event.inputs.repository == 'test'
38-
env:
39-
TWINE_USERNAME: __token__
40-
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
41-
run: twine upload --repository-url https://test.pypi.org/legacy/ dist/*
42-
43-
- name: Publish to Regular PyPI
44-
if: github.event.inputs.repository == 'pypi'
45-
env:
46-
TWINE_USERNAME: __token__
47-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
48-
run: twine upload dist/*
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.10"
22+
23+
- name: Install uv
24+
run: curl -LsSf https://astral.sh/uv/0.9.8/install.sh | sh
25+
26+
- name: Build package with uv
27+
run: uv build
28+
29+
- name: Publish to Test PyPI
30+
if: github.event.inputs.repository == 'test'
31+
env:
32+
UV_PUBLISH_TOKEN: ${{ secrets.TEST_PYPI_TOKEN }}
33+
run: uv publish --token $UV_PUBLISH_TOKEN --repository testpypi
34+
35+
- name: Publish to Regular PyPI
36+
if: github.event.inputs.repository == 'pypi'
37+
env:
38+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
39+
run: uv publish --token $UV_PUBLISH_TOKEN

.github/workflows/test.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ jobs:
2222
uses: actions/setup-python@v3
2323
with:
2424
python-version: "3.10"
25-
- name: Install dependencies
25+
- name: Install uv and project
2626
run: |
27-
python -m venv venv
28-
source venv/bin/activate
29-
python -m pip install --upgrade pip
30-
pip install -e .[test]
27+
curl -LsSf https://astral.sh/uv/0.9.8/install.sh | sh
28+
uv sync --group test
3129
- name: Test with pytest
3230
env: # Add necessary api keys as env variables.
3331
JUDGE0_ATD_API_KEY: ${{ secrets.JUDGE0_ATD_API_KEY }}
@@ -38,6 +36,4 @@ jobs:
3836
JUDGE0_EXTRA_CE_ENDPOINT: ${{ secrets.JUDGE0_EXTRA_CE_ENDPOINT }}
3937
JUDGE0_CLOUD_CE_AUTH_HEADERS: ${{ secrets.JUDGE0_CLOUD_CE_AUTH_HEADERS }}
4038
JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS: ${{ secrets.JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS }}
41-
run: |
42-
source venv/bin/activate
43-
pytest tests
39+
run: uv run pytest tests

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ipython_config.py
8585
# pyenv
8686
# For a library or package, you might want to ignore these files since the code is
8787
# intended to run in multiple environments; otherwise, check them in:
88-
.python-version
88+
# .python-version
8989

9090
# pipenv
9191
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.

.python-version

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

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# You can set these variables from the command line, and also
55
# from the environment for the first two.
66
SPHINXOPTS ?=
7-
SPHINXBUILD ?= sphinx-build
7+
SPHINXBUILD ?= uv run sphinx-build
88
SOURCEDIR = source
99
BUILDDIR = build
1010

docs/source/contributors_guide/contributing.rst

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,37 @@ Contributing
44
Preparing the development setup
55
-------------------------------
66

7-
1. Install Python 3.10
7+
1. Install `uv <https://docs.astral.sh/uv/getting-started/installation/>`_.
8+
2. Fork the repository (in GitHub) and clone the forked repository:
89

910
.. code-block:: console
1011
11-
$ sudo add-apt-repository ppa:deadsnakes/ppa
12-
$ sudo apt update
13-
$ sudo apt install python3.10 python3.10-venv
12+
$ git clone https://github.com/<username>/judge0-python
13+
$ cd judge0-python
1414
15-
2. Clone the repo, create and activate a new virtual environment
15+
3. Prepare the virtual environment and dependencies:
1616

1717
.. code-block:: console
1818
19-
$ cd judge0-python
20-
$ python3.10 -m venv venv
21-
$ . venv/bin/activate
19+
$ uv sync --group dev
20+
21+
4. Install the necessary development tools:
22+
23+
.. code-block:: console
24+
25+
$ uv tool install pre-commit
26+
27+
5. Make sure all the necessary tools are installed:
28+
29+
.. code-block:: console
30+
31+
$ uv tool list
2232
23-
3. Install the library and development dependencies
33+
6. Finally, install the pre-commit hooks:
2434

2535
.. code-block:: console
2636
27-
$ pip install -e .[dev]
28-
$ pre-commit install
37+
$ uv tool run pre-commit install
2938
3039
Building documentation
3140
----------------------

pyproject.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ Homepage = "https://github.com/judge0/judge0-python"
3535
Repository = "https://github.com/judge0/judge0-python.git"
3636
Issues = "https://github.com/judge0/judge0-python/issues"
3737

38-
[project.optional-dependencies]
38+
[dependency-groups]
3939
test = [
4040
"ufmt==2.7.3",
41-
"pre-commit==3.8.0",
4241
"pytest==8.3.3",
4342
"python-dotenv==1.0.1",
4443
"pytest-cov==6.0.0",
@@ -50,10 +49,7 @@ docs = [
5049
"sphinx-autodoc-typehints==2.3.0",
5150
"sphinx-multiversion==0.2.4",
5251
]
53-
dev = [
54-
"judge0[test]",
55-
"judge0[docs]",
56-
]
52+
dev = [{ include-group = "test" }, { include-group = "docs" }]
5753

5854
[tool.flake8]
5955
extend-ignore = [

0 commit comments

Comments
 (0)