Skip to content
Merged
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
22 changes: 7 additions & 15 deletions .github/workflows/cli-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: "[cli] Run unit tests"

on:
push:
branches: [ main, try-self-hosted ]
branches: [main]
paths:
- cli/**
pull_request:
branches: [ main ]
branches: [main]
paths:
- cli/**

Expand All @@ -16,17 +16,9 @@ jobs:
run:
working-directory: cli
runs-on: [self-hosted, linux, jammy, X64]
strategy:
matrix:
python: ["3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: pip install tox
- name: Run tests
run: |
tox
- uses: actions/checkout@v4
- name: Install uv and set the Python version
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182
- name: Run tests
run: uvx --with tox-uv tox
1 change: 1 addition & 0 deletions cli/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
101 changes: 101 additions & 0 deletions cli/HACKING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Testflinger CLI

## Build the Snap Package

Testflinger CLI is distributed as a [Snap package][snap].

Install [`snapcraft`][snapcraft]:

```shell
sudo snap install --classic snapcraft
```

Then you can build the Snap package by running `snapcraft`:

```shell
snapcraft pack
```

Then you can install the Snap package locally with the `--dangerous` flag
(replace `testflinger.snap` with the name of the `.snap` file that was
created by the previous command):

```shell
sudo snap install --dangerous testflinger.snap
```

To learn more about `snapcraft`, refer to the
[`snapcraft` documentation][snapcraft-docs].

## Set up your Development Environment

We use [`uv`][uv] to manage our project and dependencies. You should install it
from the [Snap Store][uv-snap] by using the following command:

```shell
sudo snap install --classic astral-uv
```

To create your development environment, run the following:

```shell
uv sync
```

This will create a virtual environment under `.venv`, to activate it, you need
to source the following file:

```shell
source .venv/bin/activate
```

## Manage Dependencies

### Add a dependency

To add a new dependency to `testflinger-cli`, please use `uv`, as it will
automatically add it to both the `pyproject.toml` and `uv.lock` files:

```shell
uv add ...
```

If the dependency is only a development dependency, please add it to the `dev`
dependency group by using the `--dev` flag.

To learn more about the `uv add` command, refer to the
[`uv` documentation][uv-add].

### Remove a dependency

```shell
uv remove ...
```

If the dependency is only a development dependency, please remove it from the
`dev` dependency group by using the `--dev` flag.

To learn more about the `uv remove` command, refer to the
[`uv` documentation][uv-remove].

## Test

To run all our tests, run the `tox` tool. To run it with `uv`, use the following command:

```shell
uvx --with tox-uv tox
```

You can also run `tox` on its own, and it should automatically pull in `tox-uv` as a dependency for running the tests with our `uv` lock file.

```shell
tox
```

[snap]: https://snapcraft.io/testflinger-cli
[snapcraft]: https://snapcraft.io/snapcraft
[snapcraft-docs]: https://snapcraft.io/docs/snapcraft
[uv]: https://docs.astral.sh/uv
[uv-snap]: https://snapcraft.io/astral-uv
[uv-add]: https://docs.astral.sh/uv/reference/cli/#uv-add
[uv-remove]: https://docs.astral.sh/uv/reference/cli/#uv-remove
23 changes: 21 additions & 2 deletions cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
requires = ["setuptools>=78.1.0", "setuptools-scm>=8.2.0"]
build-backend = "setuptools.build_meta"

[project]
name = "testflinger-cli"
description = "Testflinger CLI"
readme = "README.rst"
license-files = ["COPYING"]
dependencies = ["PyYAML", "requests", "xdg-base-dirs", "argcomplete"]
dependencies = [
"argcomplete>=3.6.1",
"pyyaml>=6.0.2",
"requests>=2.32.3",
"xdg-base-dirs>=6.0.2",
]
dynamic = ["version"]
requires-python = ">= 3.10"

[project.scripts]
testflinger-cli = "testflinger_cli:cli"
testflinger = "testflinger_cli:cli"

[dependency-groups]
dev = [
"black>=25.1.0",
"flake8>=7.2.0",
"pylint>=3.3.6",
"pytest>=8.3.5",
"pytest-cov>=6.0.0",
"pytest-mock>=3.14.0",
"requests-mock>=1.12.1",
]

[tool.black]
line-length = 79

Expand All @@ -23,3 +39,6 @@ good-names = ["k", "v"]

[tool.pylint."messages control"]
disable = ["C0209", "too-many-lines"]

[tool.uv]
cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true } }]
6 changes: 4 additions & 2 deletions cli/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ apps:

parts:
testflinger-cli:
plugin: python
plugin: uv
source: .
build-snaps:
- astral-uv
build-environment:
- PIP_NO_BINARY: ":all:"
- UV_NO_BINARY: "true"
override-pull: |
set -e
craftctl default
Expand Down
49 changes: 32 additions & 17 deletions cli/tox.ini
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
[tox]
envlist = py
skipsdist = true
env_list =
lock
format
lint
unit
no_package = true
requires =
tox-uv>=1.25.0

[testenv]
setenv =
runner = uv-venv-lock-runner
dependency_groups =
dev

[testenv:lock]
description = Check lock file
commands =
uv lock --check

[testenv:format]
description = Run formatting tests
commands =
black --check testflinger_cli

[testenv:lint]
description = Run linting tests
commands =
flake8 testflinger_cli
pylint testflinger_cli

[testenv:unit]
description = Run unit tests
set_env =
HOME = {envtmpdir}
deps =
black
flake8
mock
pytest
pylint
pytest-mock
pytest-cov
requests-mock
commands =
{envbindir}/pip install .
{envbindir}/python -m black --check testflinger_cli
{envbindir}/python -m flake8 testflinger_cli
{envbindir}/python -m pylint testflinger_cli
{envbindir}/python -m pytest --doctest-modules --cov=.
pytest --cov=. --doctest-modules
Loading