diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..16aa20f --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,17 @@ +name: Verify formatting + +on: + push: + branches: master + pull_request: + +jobs: + ruff: + runs-on: ubuntu-latest + name: Verify Python formatting + steps: + - uses: actions/checkout@v4 + + - uses: astral-sh/ruff-action@v2 + with: + args: "format --check" diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 6d0ddac..b09643c 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -3,6 +3,14 @@ name: Python package on: [push, pull_request] jobs: + ruff: + runs-on: ubuntu-latest + name: Lint Python + steps: + - uses: actions/checkout@v4 + - uses: astral-sh/ruff-action@v2 + + build: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index dcdf0b3..7c5115d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ build/ dist/ *.egg-info/ -!.github/ \ No newline at end of file +!.github/ +!.gitignore +!.pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a5d59a4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,22 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: mixed-line-ending + - id: end-of-file-fixer + exclude: &exclude_pattern '^changelog.d/' + - id: debug-statements +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.2 + hooks: + # Run the linter + - id: ruff + name: "Ruff linting" + args: [ + '--output-format=full', + '--statistics' + ] + # Run the formatter + - id: ruff-format + name: "Ruff formatting" diff --git a/README.md b/README.md index 5bbb132..2dc2d5a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # Argus API Client +[![test badge](https://img.shields.io/github/actions/workflow/status/Uninett/pyargus/tox.yml?branch=master)](https://github.com/Uninett/pyargus/actions) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) This is the official Python client library for the [Argus](https://github.com/Uninett/Argus) API server. @@ -136,3 +138,17 @@ stateless_incident = Incident( ## BUGS * Doesn't provide high-level error handling yet. + +## Development + +### Code style + +Pyargus uses *ruff* as a source code formatter. Ruff is part of the optional dev dependencies listed in +[pyproject.toml](./pyproject.toml) + +A pre-commit hook will format new code automatically before committing. +To enable this pre-commit hook, run + +```console +$ pre-commit install +``` diff --git a/pyproject.toml b/pyproject.toml index f65fc65..c333faa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,9 +19,33 @@ dependencies = [ "iso8601", ] +[project.optional-dependencies] +dev = [ + "build", + "coverage", + "ipython", + "isort", + "pre-commit", + "pytest", + "ruff", + "tox", + "twine", +] + [tool.setuptools.dynamic] version = {attr = "pyargus.VERSION"} [tool.setuptools.packages.find] where = ["src"] exclude = ["tests*"] + +[tool.ruff] +line-length = 88 +extend-exclude = [ + ".egg-info", +] +output-format = "full" + +[tool.ruff.lint] +select = ["E4", "E7", "E9", "F4", "F5", "F6", "F7", "F8", "F9"] +ignore = ["F403", "F405"] diff --git a/src/pyargus/api.py b/src/pyargus/api.py index 9f829a6..7676936 100644 --- a/src/pyargus/api.py +++ b/src/pyargus/api.py @@ -1,4 +1,5 @@ """Defines a low-level API interface for Argus using simple_rest_client""" + from simple_rest_client.api import API from simple_rest_client.resource import Resource diff --git a/src/pyargus/client.py b/src/pyargus/client.py index becc005..0e08b76 100644 --- a/src/pyargus/client.py +++ b/src/pyargus/client.py @@ -1,4 +1,5 @@ """Slightly higher level Argus API client abstraction""" + from __future__ import annotations from datetime import datetime diff --git a/src/pyargus/models.py b/src/pyargus/models.py index 2cd53a9..c7b3090 100644 --- a/src/pyargus/models.py +++ b/src/pyargus/models.py @@ -11,8 +11,11 @@ # need an explicit value to flag stateless incidents. class _STATELESS_TYPE: pass + + STATELESS = _STATELESS_TYPE() + @dataclass class SourceSystem: """Class for describing an Argus Source system""" diff --git a/tests/test_api.py b/tests/test_api.py index c817059..64afae4 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -10,4 +10,4 @@ def test_connect_should_return_api_client(): def test_api_client_with_bad_args_should_fail(): client = api.connect("random", "token") with pytest.raises(Exception): - response = client.incidents.list_open_unacked() + client.incidents.list_open_unacked()