Skip to content

Commit

Permalink
Add linter & pipeline (#1)
Browse files Browse the repository at this point in the history
* Add linter & pipeline

* Should work now

* Remove ignores

* Update lockfile

* Update pre commit

* Update lock

* Update poetry

* ignore pyright
  • Loading branch information
Kludex authored Apr 24, 2024
1 parent 29179fc commit d988745
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
push:
branches:
- main
tags:
- '**'
pull_request: {}

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: |
pip install poetry
poetry install -E test
- uses: pre-commit/[email protected]
with:
extra_args: --all-files --verbose
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: no-commit-to-branch # prevent direct commits to main branch
- id: check-yaml
args: ["--unsafe"]
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: local
hooks:
- id: ruff
name: Ruff
entry: poetry run ruff
args: ["check", "--fix"]
types: [python]
language: system
- id: ruff format
name: Ruff Format
entry: poetry run ruff
args: [format]
language: system
types: [python]
# - id: pyright
# name: pyright
# entry: poetry run pyright
# language: system
# types: [python]
# pass_filenames: false
- id: lockfile
name: lockfile
entry: poetry check
args: [--lock]
language: system
pass_filenames: false
files: "pyproject.toml|poetry.lock"
62 changes: 60 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
in-project = true
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pytest-django = { version = "^4.8.0", optional = true }
openai = { version = ">=1.17.0", optional = true }
structlog = { version = ">=21.1.0", optional = true }
loguru = { version = "*", optional = true }
ruff = "*"
pyright = "*"

[tool.poetry.extras]
system-metrics = ["opentelemetry-instrumentation-system-metrics"]
Expand Down Expand Up @@ -115,6 +117,8 @@ test = [
"inline-snapshot",
"structlog",
"loguru",
"ruff",
"pyright"
]

[tool.poetry.scripts]
Expand All @@ -129,3 +133,46 @@ logfire = "logfire.testing"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

# https://beta.ruff.rs/docs/configuration/
[tool.ruff]
line-length = 120

[tool.ruff.lint]
extend-select = [
'Q',
'RUF100',
'C90',
'UP',
'I',
'D',
'DTZ005', # https://docs.astral.sh/ruff/rules/call-datetime-now-without-tzinfo/
] # add 'T' to disallow prints
flake8-quotes = { inline-quotes = 'single', multiline-quotes = 'double' }
isort = { combine-as-imports = true, known-first-party = ['logfire'] }
mccabe = { max-complexity = 14 }
ignore = [
'D107', # ignore missing docstring in __init__ methods
'D100', # ignore missing docstring in module
'D104', # ignore missing docstring in public package
'D105', # ignore missing docstring in magic methods
'C901', # ignore too complex functions, doesn't seem to be worth it
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ['D']
"docs/**/*.py" = ['D']

[tool.ruff.format]
docstring-code-format = true
quote-style = 'single'

[tool.pyright]
typeCheckingMode = 'strict'
reportUnnecessaryTypeIgnoreComment = true
reportMissingTypeStubs = false
exclude = ['docs/**/*.py', 'site/**/*.py']
venvPath = '.venv'

0 comments on commit d988745

Please sign in to comment.