Skip to content

Commit

Permalink
Merge pull request #18 from Uninett/dev/add-precommit-and-ruff-format…
Browse files Browse the repository at this point in the history
…ting

Add pre-commit and workflows for linting and formatting using ruff
  • Loading branch information
lunkwill42 authored Dec 10, 2024
2 parents 562c93d + 2b69fab commit 264ef18
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 8 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
build/
dist/
*.egg-info/
!.github/
!.github/
!.gitignore
!.pre-commit-config.yaml
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -150,3 +152,17 @@ c = Client(api_root_url="https://argus.example.org/api/v2", token=tokenobj.token
## 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
```
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions src/pyargus/api.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions src/pyargus/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Slightly higher level Argus API client abstraction"""

from __future__ import annotations

from datetime import datetime
Expand Down
3 changes: 3 additions & 0 deletions src/pyargus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 264ef18

Please sign in to comment.