Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to uv #494

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 29 additions & 42 deletions .github/workflows/code-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,32 @@ jobs:
python_version: "3.10"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{matrix.python_version}}
uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: pyproject.toml
fetch-depth: 0
- uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
python-version: ${{matrix.python_version}}
- name: Upgrade Pip
run: python -m pip install -U pip
- name: Install test dependencies
run: python -m pip install '.[test]'
- name: Run unit tests
run: python -m pytest --cov-report=term --cov=capellambse --rootdir=.
run: uv run coverage run
- name: Report coverage
if: always()
run: uv run coverage report

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: pyproject.toml
fetch-depth: 0
- uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
python-version: "3.12"
- name: Upgrade pip
run: python -m pip install -U pip
- name: Install pre-commit
run: python -m pip install 'pre-commit'
- name: Run Pre-Commit
run: pre-commit run --all-files
run: uv run pre-commit run --all-files

build:
name: Build wheel
Expand All @@ -67,18 +65,15 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v4
with:
cache: pip
cache-dependency-path: pyproject.toml
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
python-version: "3.12"
- name: Install dependencies
run: python -m pip install -U pip build twine
- name: Build packages
run: python -m build
run: uv build
- name: Verify packages
run: python -m twine check dist/*
run: uvx twine check dist/*
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -120,15 +115,11 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v4
with:
cache: pip
cache-dependency-path: pyproject.toml
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
python-version: "3.12"
- name: Upgrade pip
run: python -m pip install -U pip
- name: Install dependencies
run: python -m pip install jupyter '.[docs,png]' capellambse-context-diagrams
- name: Run example notebooks
run: |
jq --version
Expand All @@ -142,7 +133,7 @@ jobs:
}
for file in docs/source/examples/*.ipynb; do
old_outputs="$(celloutputs "$file")"
if ! jupyter nbconvert --to notebook --execute "$file" --output "${file##*/}" --ExecutePreprocessor.timeout "${NOTEBOOK_TIMEOUT_SEC:-300}"; then
if ! uv run --all-extras jupyter nbconvert --to notebook --execute "$file" --output "${file##*/}" --ExecutePreprocessor.timeout "${NOTEBOOK_TIMEOUT_SEC:-300}"; then
ok=false
continue
fi
Expand All @@ -160,17 +151,13 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v4
with:
cache: pip
cache-dependency-path: pyproject.toml
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
python-version: "3.12"
- name: Upgrade pip
run: python -m pip install -U pip
- name: Install dependencies
run: |
sudo apt-get install -y pandoc
python -m pip install '.[docs]'
- name: Install system-level dependencies
run: sudo apt-get install -y pandoc
- name: Auto-generate APIDOC sources
run: make -C docs apidoc
- name: Create docs
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Ignore all custom known_models by default, to avoid accidental information
# leaks. To commit one anyway, use: git add -f filename.json
capellambse/known_models/*.json
src/capellambse/known_models/*.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -162,6 +162,9 @@ dmypy.json
# Cython debug symbols
cython_debug/

# don't commit lock files for library projects
uv.lock

# Mac garbage
.DS_Store

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repos:
name: mypy
types_or: [python, pyi, toml, yaml]
pass_filenames: false
args: [capellambse, tests]
args: [src/capellambse, tests]
additional_dependencies:
- mypypp==0.1.1

Expand Down
42 changes: 38 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,48 @@ our style guidelines outlined below.
Developing
----------

We recommend that you [develop inside of a virtual
environment](README.md#installation). After you have set it up, simply run the
unit tests to verify that everything is set up correctly:
Use [uv](https://docs.astral.sh/uv/) to set up a local development environment.

```bash
git clone https://github.com/DSD-DBS/py-capellambse
cd py-capellambse
uv sync
uv run pre-commit install

# You may need to explicitly activate the project venv
# to make code completion and tools available:
source .venv/bin/activate.sh # for Linux / Mac
.venv\Scripts\activate # for Windows
```

You can use `uv run <tool>` to avoid having to manually activate the project
venv. For example, to run the unit tests, use:

```sh
pytest
uv run pytest
```

The example notebooks (see above) are verified during CI, to ensure their
output is up to date. This means they have to be re-run whenever the expected
output changes.

Use the following command to start a Jupyter server, which can be used to
develop and re-run the example notebooks:

```bash
cd docs/source/examples
CAPELLAMBSE_UUID_SEED=0 uv run jupyter lab
```

> [!NOTE]
> The above command provides a static seed for the internal pseudo-random
> number generator. This is not recommended for production environments. [Read
> more about
> CAPELLAMBSE_UUID_SEED.](https://dsd-dbs.github.io/py-capellambse/start/envvars.html)

If your browser did not open automatically, follow the instructions in the
terminal to start it manually.

We additionally recommend that you set up your editor / IDE as follows.

- Indent with 4 spaces per level of indentation
Expand Down
43 changes: 2 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,47 +181,8 @@ pip install capellambse
Development
-----------

To set up a development environment, clone the project and install it into a
virtual environment.

```bash
git clone https://github.com/DSD-DBS/py-capellambse
cd py-capellambse
python -m venv .venv

source .venv/bin/activate.sh # for Linux / Mac
.venv\Scripts\activate # for Windows

pip install -U pip pre-commit
pip install -e '.[docs,test]'
pre-commit install
```

The example notebooks (see above) are verified during CI, to ensure their
output is up to date. This means they have to be re-run whenever the expected
output changes.

Use the following command to start a Jupyter server, which can be used to
develop and re-run the example notebooks:

```bash
pip install jupyter capellambse
cd docs/source/examples
CAPELLAMBSE_UUID_SEED=0 jupyter-notebook
```

> [!NOTE]
> The above command provides a static seed for the internal pseudo-random
> number generator. This is not recommended for production environments. [Read
> more about
> CAPELLAMBSE_UUID_SEED.](https://dsd-dbs.github.io/py-capellambse/start/envvars.html)

If your browser did not open automatically, follow the instructions in the
terminal to start it manually.

Once in the browser, simply click on the [01
Introduction.ipynb](https://dsd-dbs.github.io/py-capellambse/examples/01%20Introduction.html)
notebook to start!
For details on how to set up a local development environment, please refer to
the [CONTRIBUTING guide](CONTRIBUTING.md).

Current limitations
-------------------
Expand Down
16 changes: 9 additions & 7 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

export UV_PYTHON = 3.12

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@uv run --no-dev --group docs $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@uv run --no-dev --group docs $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)


# Auto-generate API documentation
apidoc:
sphinx-apidoc --module-first --output-dir source/code --force .. \
../capellambse/aird/diagram.py \
../capellambse/extensions/reqif/elements.py \
../capellambse/repl.py \
../capellambse/sphinx.py
uv run --no-dev --group docs sphinx-apidoc --module-first --output-dir source/code --force ../src \
../src/capellambse/aird/diagram.py \
../src/capellambse/extensions/reqif/elements.py \
../src/capellambse/repl.py \
../src/capellambse/sphinx.py
sed -i -e '/^\.\. automodule:: capellambse$$/a \ :no-index:' source/code/capellambse.rst

clean-apidoc:
Expand Down
Loading
Loading