Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit and workflows for linting and formatting using ruff #18

Merged
merged 8 commits into from
Dec 10, 2024
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
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 @@ -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
```
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",
lunkwill42 marked this conversation as resolved.
Show resolved Hide resolved
"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()
Loading