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

Fix * imports #138

Merged
merged 23 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
25 changes: 25 additions & 0 deletions .github/workflows/code-style.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Code style

on:
push:
branches:
- master
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:

jobs:
codestyle:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
with:
changed-files: 'true'
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
---
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.2
hooks:
- id: ruff
args: [--fix]
types_or: [python, pyi]
# - id: ruff-format
# types_or: [python, pyi]
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,41 @@ conda activate proteus
pip install -e .[develop]
```

### Linting

Linting is a term for static code analysis to flag programming errors,
bugs, stylistic errors and [suspicious constructs](https://en.wikipedia.org/wiki/Lint_(software)).
PROTEUS uses [`ruff`](https://astral.sh/ruff) for linting.
The linting [rules](https://docs.astral.sh/ruff/rules/) are defined in [`pyproject.toml`](https://github.com/FormingWorlds/PROTEUS/blob/master/pyproject.toml).

This check are run automatically via a Github Action: [codestyle](https://github.com/FormingWorlds/PROTEUS/blob/master/.github/workflows/codestyle.yaml).

You can `ruff` on locally using one of these commands:

```console
ruff check start_proteus.py # single file
ruff check src/proteus # directory
ruff check . # everything
```

If you prepend `--fix`, it can also fix some issues for you:

```console
ruff check . --fix
```

You can also use [pre-commit](https://pre-commit.com/#usage) to automatically run `ruff` on every commit, e.g.:

```console
pre-commit install
```

### Running tests

PROTEUS uses [pytest](https://docs.pytest.org/en/latest/) to run the tests.

The tests are run automatically via a Github Action: [tests](https://github.com/FormingWorlds/PROTEUS/blob/master/.github/workflows/tests.yaml).

You can run the tests for yourself using:

```console
Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ changelog = "https://github.com/FormingWorlds/PROTEUS/releases"
develop = [
"coverage[toml]",
"pytest >= 8.1",
"pre-commit",
"ruff",
]

docs = [
Expand All @@ -83,3 +85,29 @@ source = ["proteus"]

[tool.pytest.ini_options]
testpaths = ["tests"]

[tool.ruff]
line-length = 96
target-version = "py310"

[tool.ruff.lint]
select = [
# "F", # Pyflakes
# "E", # pycodestyle (error)
# "W", # pycodestyle (warning)
"I", # isort
"F401", # {name} imported but unused
"F402", # from __future__ imports must occur at the beginning of the file
"F403", # from {name} import * only allowed at module level
"F404", # from {name} import * only allowed at module level
"E401", # Multiple imports on one line
"E402", # Module level import not at top of cell
]

[tool.ruff.lint.isort]
known-first-party=["proteus"]
required-imports = ["from __future__ import annotations"]

[tool.ruff.format]
quote-style = "single"
indent-style = "space"
3 changes: 3 additions & 0 deletions src/proteus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from __future__ import annotations


def hello_world():
print('hello world')
5 changes: 5 additions & 0 deletions src/proteus/atmos_clim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from __future__ import annotations

from .wrapper_atmosphere import RunAtmosphere

__all__ = [
'RunAtmosphere',
]
Loading
Loading