Skip to content

Commit

Permalink
build: Migrate to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Dec 18, 2024
1 parent 5866081 commit 7a791ea
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 163 deletions.
68 changes: 26 additions & 42 deletions .github/workflows/code-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,29 @@ 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 -m pytest --cov-report=term --cov=capellambse --rootdir=.

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 +62,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 +112,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 +130,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 +148,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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
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
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,18 @@ pip install capellambse
Development
-----------

To set up a development environment, clone the project and install it into a
virtual environment.
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
python -m venv .venv
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

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
Expand All @@ -206,9 +204,8 @@ 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
CAPELLAMBSE_UUID_SEED=0 uv run jupyter lab
```

> [!NOTE]
Expand All @@ -220,10 +217,6 @@ CAPELLAMBSE_UUID_SEED=0 jupyter-notebook
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!

Current limitations
-------------------

Expand Down
8 changes: 5 additions & 3 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

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-build $(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-build $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)


# Auto-generate API documentation
apidoc:
sphinx-apidoc --module-first --output-dir source/code --force .. \
uv run --no-dev --group docs-build sphinx-apidoc --module-first --output-dir source/code --force .. \
../capellambse/aird/diagram.py \
../capellambse/extensions/reqif/elements.py \
../capellambse/repl.py \
Expand Down
60 changes: 17 additions & 43 deletions docs/source/examples/01 Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -229,40 +229,14 @@
"id": "30e17ac3",
"metadata": {},
"source": [
"We can also turn the above data into a table, for example \"actor function allocation\", using `pandas`.\n",
"Using the `pandas` library, we can also easily export the data above in tabular format.\n",
"\n",
"For this, we first make sure pandas itself is installed, as well as an extension we'll use later."
"For that, first build up the table as pandas DataFrame:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "400e483d-eca7-4fdd-a9e0-71467e1af8d8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install -q pandas openpyxl"
]
},
{
"cell_type": "markdown",
"id": "acbe1247-e1a1-4da8-a95a-7b41f4836937",
"metadata": {},
"source": [
"Now we can use it together with `capellambse`:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "833220d0",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -344,7 +318,7 @@
"5 LAF 1 "
]
},
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -368,12 +342,12 @@
"id": "6e04c482",
"metadata": {},
"source": [
"and any `pandas.DataFrame` can always be turned into an Excel Spreadsheet, just like that:"
"This DataFrame can then be processed as usual. For example, to export it as Excel Spreadsheet:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "10af24a2",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -407,7 +381,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"id": "eb5f8747",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -436,7 +410,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"id": "71bf090e",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -547,7 +521,7 @@
"[47] <PortAllocation (c90bb30d-e36b-46a3-a3a1-e39fdcb519be)>"
]
},
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -575,7 +549,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"id": "cc09fd22",
"metadata": {},
"outputs": [
Expand All @@ -589,7 +563,7 @@
"<Diagram '[LAB] Wizzard Education'>"
]
},
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -608,7 +582,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"id": "b5699e75-2e4c-4b8e-81af-51be00ff6dc3",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -641,7 +615,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"id": "7798e7f0-61eb-4395-99f2-2cc6dbd46ff1",
"metadata": {},
"outputs": [],
Expand All @@ -651,7 +625,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"id": "93a2e9cf-e599-4c3d-96b7-d6c590e74b16",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -688,7 +662,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"id": "cf91c71a",
"metadata": {},
"outputs": [
Expand All @@ -703,7 +677,7 @@
"[0] <StateMachine 'FaultStates' (06cefb2b-534e-4453-9aba-fe53329197ad)>"
]
},
"execution_count": 13,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -726,7 +700,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"id": "b5751a0d",
"metadata": {},
"outputs": [
Expand All @@ -745,7 +719,7 @@
"[2] <State 'no defence' (5b6a03d8-0ef9-4b2b-9a50-a745f490d663)>"
]
},
"execution_count": 14,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
Loading

0 comments on commit 7a791ea

Please sign in to comment.