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

Switch to Ruff for linting and formatting #97

Merged
merged 2 commits into from
Apr 4, 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
4 changes: 3 additions & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"customizations": {
"vscode": {
"extensions": [
"github.vscode-github-actions"
"github.vscode-github-actions",
"ms-python.mypy-type-checker",
"charliermarsh.ruff"
]
}
}
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ on:
workflow_dispatch:

jobs:
format:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Format code with Black
uses: psf/black@stable
- name: Lint with Ruff
uses: chartboost/ruff-action@v1
- name: Format with Ruff
uses: chartboost/ruff-action@v1
with:
args: 'format --check'

type:
typing:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -29,7 +33,7 @@ jobs:
python-version: '3.x'
- name: Install typing dependencies
run: |
pip install .[type]
pip install .[typing]
- name: Check types with mypy
run: |
mypy
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Codecov](https://codecov.io/gh/microfluidica/electrolytes/branch/main/graph/badge.svg)](https://codecov.io/gh/microfluidica/electrolytes)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/5697b1e4c4a9790ece607654e6c02a160620c7e1/docs/badge/v2.json)](https://pydantic.dev)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![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)
[![PyPI](https://img.shields.io/pypi/v/electrolytes)](https://pypi.org/project/electrolytes/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/electrolytes)](https://pypi.org/project/electrolytes/)
[![Docker image](https://img.shields.io/badge/docker%20image-microfluidica%2Felectrolytes-0085a0)](https://hub.docker.com/r/microfluidica/electrolytes/)
Expand Down
24 changes: 12 additions & 12 deletions electrolytes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
class Constituent(BaseModel, populate_by_name=True, frozen=True):
id: Optional[int] = None
name: str
u_neg: Annotated[list[float], Field(alias="uNeg")] = (
[]
) # [-neg_count, -neg_count+1, -neg_count+2, ..., -1]
u_pos: Annotated[list[float], Field(alias="uPos")] = (
[]
) # [+1, +2, +3, ..., +pos_count]
pkas_neg: Annotated[list[float], Field(alias="pKaNeg")] = (
[]
) # [-neg_count, -neg_count+1, -neg_count+2, ..., -1]
pkas_pos: Annotated[list[float], Field(alias="pKaPos")] = (
[]
) # [+1, +2, +3, ..., +pos_count]
u_neg: Annotated[
list[float], Field(alias="uNeg")
] = [] # [-neg_count, -neg_count+1, -neg_count+2, ..., -1]
u_pos: Annotated[
list[float], Field(alias="uPos")
] = [] # [+1, +2, +3, ..., +pos_count]
pkas_neg: Annotated[
list[float], Field(alias="pKaNeg")
] = [] # [-neg_count, -neg_count+1, -neg_count+2, ..., -1]
pkas_pos: Annotated[
list[float], Field(alias="pKaPos")
] = [] # [+1, +2, +3, ..., +pos_count]
neg_count: Annotated[int, Field(alias="negCount", validate_default=True)] = None # type: ignore
pos_count: Annotated[int, Field(alias="posCount", validate_default=True)] = None # type: ignore

Expand Down
66 changes: 51 additions & 15 deletions electrolytes/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,54 @@ def complete_name_user_defined(incomplete: str) -> list[str]:
@app.command()
def add(
name: Annotated[str, typer.Argument(autocompletion=complete_name_user_defined)],
p1: Annotated[tuple[float, float], typer.Option("+1", help="Mobility (*1e-9) and pKa for +1", show_default=False)] = (None, None), # type: ignore
p2: Annotated[tuple[float, float], typer.Option("+2", help="Mobility (*1e-9) and pKa for +2", show_default=False)] = (None, None), # type: ignore
p3: Annotated[tuple[float, float], typer.Option("+3", help="Mobility (*1e-9) and pKa for +3", show_default=False)] = (None, None), # type: ignore
p4: Annotated[tuple[float, float], typer.Option("+4", help="Mobility (*1e-9) and pKa for +4", show_default=False)] = (None, None), # type: ignore
p5: Annotated[tuple[float, float], typer.Option("+5", help="Mobility (*1e-9) and pKa for +5", show_default=False)] = (None, None), # type: ignore
p6: Annotated[tuple[float, float], typer.Option("+6", help="Mobility (*1e-9) and pKa for +6", show_default=False)] = (None, None), # type: ignore
m1: Annotated[tuple[float, float], typer.Option("-1", help="Mobility (*1e-9) and pKa for -1", show_default=False)] = (None, None), # type: ignore
m2: Annotated[tuple[float, float], typer.Option("-2", help="Mobility (*1e-9) and pKa for -2", show_default=False)] = (None, None), # type: ignore
m3: Annotated[tuple[float, float], typer.Option("-3", help="Mobility (*1e-9) and pKa for -3", show_default=False)] = (None, None), # type: ignore
m4: Annotated[tuple[float, float], typer.Option("-4", help="Mobility (*1e-9) and pKa for -4", show_default=False)] = (None, None), # type: ignore
m5: Annotated[tuple[float, float], typer.Option("-5", help="Mobility (*1e-9) and pKa for -5", show_default=False)] = (None, None), # type: ignore
m6: Annotated[tuple[float, float], typer.Option("-6", help="Mobility (*1e-9) and pKa for -6", show_default=False)] = (None, None), # type: ignore
p1: Annotated[
tuple[float, float],
typer.Option("+1", help="Mobility (*1e-9) and pKa for +1", show_default=False),
] = (None, None), # type: ignore
p2: Annotated[
tuple[float, float],
typer.Option("+2", help="Mobility (*1e-9) and pKa for +2", show_default=False),
] = (None, None), # type: ignore
p3: Annotated[
tuple[float, float],
typer.Option("+3", help="Mobility (*1e-9) and pKa for +3", show_default=False),
] = (None, None), # type: ignore
p4: Annotated[
tuple[float, float],
typer.Option("+4", help="Mobility (*1e-9) and pKa for +4", show_default=False),
] = (None, None), # type: ignore
p5: Annotated[
tuple[float, float],
typer.Option("+5", help="Mobility (*1e-9) and pKa for +5", show_default=False),
] = (None, None), # type: ignore
p6: Annotated[
tuple[float, float],
typer.Option("+6", help="Mobility (*1e-9) and pKa for +6", show_default=False),
] = (None, None), # type: ignore
m1: Annotated[
tuple[float, float],
typer.Option("-1", help="Mobility (*1e-9) and pKa for -1", show_default=False),
] = (None, None), # type: ignore
m2: Annotated[
tuple[float, float],
typer.Option("-2", help="Mobility (*1e-9) and pKa for -2", show_default=False),
] = (None, None), # type: ignore
m3: Annotated[
tuple[float, float],
typer.Option("-3", help="Mobility (*1e-9) and pKa for -3", show_default=False),
] = (None, None), # type: ignore
m4: Annotated[
tuple[float, float],
typer.Option("-4", help="Mobility (*1e-9) and pKa for -4", show_default=False),
] = (None, None), # type: ignore
m5: Annotated[
tuple[float, float],
typer.Option("-5", help="Mobility (*1e-9) and pKa for -5", show_default=False),
] = (None, None), # type: ignore
m6: Annotated[
tuple[float, float],
typer.Option("-6", help="Mobility (*1e-9) and pKa for -6", show_default=False),
] = (None, None), # type: ignore
force: Annotated[
bool,
typer.Option(
Expand Down Expand Up @@ -100,7 +136,7 @@ def info(
names: Annotated[
Optional[list[str]],
typer.Argument(help="Component names", autocompletion=complete_name),
] = None
] = None,
) -> None:
"""
Show the properties of components.
Expand Down Expand Up @@ -158,7 +194,7 @@ def ls(
typer.Option(
"--user/--default", help="List only user-defined/default components"
),
] = None
] = None,
) -> None:
"""List components in the database."""

Expand Down Expand Up @@ -244,7 +280,7 @@ def common(
typer.Option(
"--version", help="Show version and exit.", callback=version_callback
),
] = False
] = False,
) -> None:
"""Database of electrolytes and their properties."""
pass
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ dependencies = [
dynamic = ["version"]

[project.optional-dependencies]
lint = ["black"]
type = [
lint = ["ruff"]
typing = [
"mypy==1.*",
"pytest>=7,<9",
]
Expand Down
16 changes: 8 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import electrolytes
from electrolytes import *
from electrolytes import Constituent, database


def test_version() -> None:
Expand All @@ -10,13 +10,13 @@ def test_version() -> None:

def test_list_components() -> None:
assert database
l = list(database)
assert len(l) == len(database)
assert isinstance(l[0], str)
assert l == sorted(l)
assert "LYSINE" in l
assert "CYSTINE" in l
assert "SILVER" in l
lst = list(database)
assert len(lst) == len(database)
assert isinstance(lst[0], str)
assert lst == sorted(lst)
assert "LYSINE" in lst
assert "CYSTINE" in lst
assert "SILVER" in lst


def test_get_component() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typer.testing import CliRunner

import electrolytes
from electrolytes import *
from electrolytes import Constituent, database
from electrolytes.__main__ import app


Expand Down
4 changes: 1 addition & 3 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pytest

import subprocess
from time import sleep

from electrolytes import *
from electrolytes import Constituent, database


def test_lock_api_cli() -> None:
Expand Down