Skip to content

Commit

Permalink
Use dependency groups, upgrade to typer 0.13.1 (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
pederhan authored Nov 19, 2024
1 parent 80cada8 commit 77b7318
Show file tree
Hide file tree
Showing 15 changed files with 948 additions and 141 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
- name: Set up Python 3.12
run: uv python install 3.12

- name: Install build dependencies
run: uv sync --all-extras --dev
- name: Install project dependencies only
run: uv sync --no-dev

- name: Build source distribution
run: uv run python -m build
- name: Build source and wheel distributions
run: uv build

- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
run: uv python install ${{ matrix.python-version }}

- name: Install build dependencies
run: uv sync --all-extras --dev
run: uv sync --group build --no-dev

- name: Build binary with PyInstaller
run: uv run pyinstaller --onefile zabbix_cli/main.py --name zabbix-cli
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v2

- name: Install hatch
run: |
uv pip install --system hatch
- name: Install dependencies
run: uv sync --group docs --no-dev

- name: Build documentation and publish
run: hatch run docs:mkdocs gh-deploy --force
run: uv run mkdocs gh-deploy --force
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ jobs:
uses: astral-sh/setup-uv@v2
- name: Install dependencies
run: |
uv sync --all-extras --dev
uv sync --group test
- name: Test
run: uv run pytest -vv tests
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ The type of the `result` field varies based on the command run. For `show_host`

<details>
<summary><code>show_host foo.example.com*</code></summary>

```json
{
"message": "",
Expand Down Expand Up @@ -262,7 +262,7 @@ The type of the `result` field varies based on the command run. For `show_host`

<details>
<summary><code>show_hosts foo.*</code></summary>

```json
{
"message": "",
Expand Down Expand Up @@ -350,28 +350,20 @@ The type of the `result` field varies based on the command run. For `show_host`

## Development

Zabbix-cli currently uses [Hatch](https://hatch.pypa.io/latest/) for project management and packaging. To start off, clone the repository:
Zabbix-cli currently uses [uv](https://docs.astral.sh/uv/) and [Hatch](https://hatch.pypa.io/latest/) for project management and packaging. To start off, clone the repository:

```bash
git clone https://github.com/unioslo/zabbix-cli.git
```

Then make a virtual environment using Hatch:
Then make a virtual environment using uv:

```bash
hatch shell
uv venv
```

This will create a new virtual environment, install the required dependencies and enter the environment.

If you do not wish to use Hatch, you can create a virtual environment manually:

```bash
python -m venv .venv
source .venv/bin/activate
pip install -U -e ".[test]"
```

### Testing

Run unit tests (without coverage):
Expand Down
2 changes: 0 additions & 2 deletions docs/scripts/utils/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class ParamSummary(BaseModel):
is_argument: bool
is_eager: bool = False
is_bool_flag: Optional[bool] = None
is_flag: Optional[bool] = None
is_option: Optional[bool]
max: Optional[int] = None
min: Optional[int] = None
Expand Down Expand Up @@ -89,7 +88,6 @@ def from_param(cls, param: click.Parameter) -> ParamSummary:
is_argument=is_argument,
is_bool_flag=get(param, "is_bool_flag"),
is_eager=param.is_eager,
is_flag=get(param, "is_flag"),
is_option=get(param, "is_option"),
max=get(param.type, "max"),
min=get(param.type, "min"),
Expand Down
2 changes: 1 addition & 1 deletion docs/templates/category.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% if param.secondary_opts | length > 0 -%}
/{% for param in param.secondary_opts -%} **`{{ param }}`**{% if not loop.last %}, {% endif %}{% endfor -%}
{% endif -%}
{%- if not param.is_flag %}
{%- if not param.type | lower == "boolean" %}
`{{ param.metavar }}`
{% endif -%}
{% endif %}<br />
Expand Down
76 changes: 42 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "hatchling.build"
description = "ZABBIX-CLI - Zabbix terminal client"
name = "zabbix-cli-uio"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = "GPL-3.0-or-later"
keywords = []
maintainers = [{ name = "Peder Hovdan Andresen", email = "pederhan@uio.no" }]
Expand All @@ -26,15 +26,14 @@ classifiers = [
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = [
"typer>=0.9.0",
"typer>=0.13.1",
"rich>=13.3.1",
"prompt_toolkit>=3.0.47",
"httpx[socks]>=0.26.0",
Expand All @@ -49,6 +48,40 @@ dependencies = [
]
dynamic = ["version"]

[dependency-groups]
dev = [
{ include-group = "test" },
{ include-group = "lint" },
{ include-group = "build" },
{ include-group = "docs" },
]
lint = ["ruff", "pyright"]
test = [
"pytest>=8.0.0",
"pytest-cov>=5.0.0",
"inline-snapshot>=0.13.0",
"freezegun>=1.5.1",
]
docs = [
"mkdocs>=1.5.3",
"mkdocs-material>=9.5.13",
"mkdocs-include-markdown-plugin>=6.0.4",
"pymdown-extensions>=9.11",
"mdx-gh-links>=0.3",
"mkdocs-simple-hooks>=0.1.5",
"mkdocs-version-annotations>=1.0.0",
"mkdocstrings[python]",
"mkdocs-macros-plugin",
"mkdocs-literate-nav",
"mkdocs-simple-hooks",
"mkdocs-gen-files",
"mkdocs-glightbox",
"sanitize-filename",
"jinja2",
"pyyaml",
]
build = ["pyinstaller"]

[project.urls]
Documentation = "https://github.com/unioslo/zabbix-cli#readme"
Issues = "https://github.com/unioslo/zabbix-cli/issues"
Expand All @@ -59,10 +92,6 @@ zabbix-cli = "zabbix_cli.main:main"
zabbix-cli-init = "zabbix_cli.scripts.init:main"
zabbix-cli-bulk-execution = "zabbix_cli.scripts.bulk_execution:main"

[project.optional-dependencies]
test = ["pytest", "pytest-cov", "freezegun", "inline-snapshot"]
build = ["pyinstaller", "build"]

[tool.hatch.version]
path = "zabbix_cli/__about__.py"

Expand All @@ -78,14 +107,6 @@ pyapp-version = "0.12.0"
python-version = "3.11"

[tool.hatch.envs.default]
dependencies = [
# Linting and formatting only here
# Dependencies used for testing are specified in the main metadata
# optional dependencies
"ruff",
"pyright",
"zabbix-cli-uio[test]",
]
installer = "uv"

[tool.hatch.envs.default.scripts]
Expand All @@ -95,31 +116,18 @@ no-cov = "cov --no-cov {args}"
lint = "ruff check zabbix_cli {args}"

[[tool.hatch.envs.test.matrix]]
python = ["38", "39", "310", "311"]
python = ["39", "310", "311"]

[tool.hatch.envs.docs]
dependencies = [
"mkdocs>=1.5.3",
"mkdocs-material>=9.5.13",
"mkdocs-include-markdown-plugin>=6.0.4",
"pymdown-extensions>=9.11",
"mdx-gh-links>=0.3",
"mkdocs-simple-hooks>=0.1.5",
"mkdocs-version-annotations>=1.0.0",
"mkdocstrings[python]",
"mkdocs-macros-plugin",
"mkdocs-literate-nav",
"mkdocs-simple-hooks",
"mkdocs-gen-files",
"mkdocs-glightbox",
"sanitize-filename",
"jinja2",
"pyyaml",
]


[tool.hatch.envs.docs.scripts]
build = "mkdocs build --clean --strict {args}"
serve = "mkdocs serve --dev-addr localhost:8001 {args}"

[tool.pytest.ini_options]
addopts = "-v"

[tool.coverage.run]
branch = true
parallel = true
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def mixed_command(
"--reqopt",
"-R",
),
flag: bool = typer.Option(False, "--flag", "-F", is_flag=True),
flag: bool = typer.Option(False, "--flag", "-F"),
boolopt: Optional[bool] = typer.Option(
False,
# Not specifying anything here should generate the options
Expand Down
Loading

0 comments on commit 77b7318

Please sign in to comment.