Skip to content

Commit

Permalink
Ruff and pre-commit update
Browse files Browse the repository at this point in the history
  • Loading branch information
kmagusiak committed Aug 4, 2024
1 parent 436d2ff commit b56732b
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 49 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,33 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
# use minimum version here from setup.py
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install -e .[pinned,dev]
- name: Run pre-commit checks
run: |
./pre-commit
./pre-commit lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
# lowest, common (defaut ubuntu LTS), newest
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install -e .[pinned,dev,test]
- name: Run tests
run: |
pytest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# don't use shallow checkout to determine an intermediary version correctly
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
Expand Down
5 changes: 0 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"black-formatter.args": [
"--skip-string-normalization",
"--line-length",
"100"
],
"python.testing.pytestArgs": [
"tests"
],
Expand Down
6 changes: 3 additions & 3 deletions alphaconf/internal/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
self.argument_parser = self._build_argument_parser()

def _build_argument_parser(self) -> arg_parser.ArgumentParser:
from .. import _global_configuration
from .. import _global_configuration # noqa: TID252

p = arg_parser.ArgumentParser(_global_configuration.helpers)
arg_parser.configure_parser(p, app=self)
Expand Down Expand Up @@ -162,7 +162,7 @@ def setup_configuration(
env_prefixes: Union[bool, Iterable[str]] = True,
resolve_configuration: bool = True,
):
from .. import _global_configuration as ctx_configuration
from .. import _global_configuration as ctx_configuration # noqa: TID252
from .dotenv_vars import try_dotenv

try_dotenv(load_dotenv=load_dotenv)
Expand Down Expand Up @@ -208,7 +208,7 @@ def masked_configuration(
:param mask_keys: Which keys to mask
:return: Configuration copy with masked values
"""
from .. import SECRET_MASKS
from .. import SECRET_MASKS # noqa: TID252

config = cast(dict, OmegaConf.to_container(self.configuration.c))
if mask_secrets:
Expand Down
2 changes: 1 addition & 1 deletion alphaconf/internal/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _add_config(self, value: Union[list[str], DictConfig, dict, str]):
if isinstance(value, list):
self._config.extend(value)
return
elif isinstance(value, DictConfig):
if isinstance(value, DictConfig):
pass
elif isinstance(value, dict):
value = OmegaConf.create(value)
Expand Down
2 changes: 1 addition & 1 deletion alphaconf/internal/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _find_name(parts: list[str], conf: DictConfig) -> str:
sub_conf = conf.get(name)
if next_offset == len(parts):
return name
elif isinstance(sub_conf, DictConfig):
if isinstance(sub_conf, DictConfig):
return name + "." + Configuration._find_name(parts[next_offset:], sub_conf)
return ".".join([name, *parts[next_offset:]])
return ".".join(parts)
Expand Down
33 changes: 22 additions & 11 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,39 @@ cd "$(dirname "$0")"
[ -d .git ] || cd ../..
[ -d .git ]

pre_commit() {
ruff check .
black --check .
check() {
echo " ruff:"
ruff check
ruff format --check
}

lint() {
check
echo " mypy:"
mypy .
}

fix_all() {
black .
fix() {
ruff check --fix-only .
}

format() {
black .
ruff format
}

# Commands
case "${1:-run}" in
run|lint)
pre_commit
echo "All good to commit"
run|check)
check
echo " all good to commit."
;;
lint)
lint
;;
fix)
fix_all
echo "Fix all..."
fix
format
;;
format)
format
Expand All @@ -42,5 +53,5 @@ case "${1:-run}" in
;;
*)
echo "Invalid argument: $*"
echo "Supported options: lint, format, install, uninstall"
echo "Supported options: lint, fix, format, install, uninstall"
esac
62 changes: 45 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
[build-system]
requires = [
"setuptools>=61",
"setuptools-scm>=6",
"setuptools>=70",
"setuptools-scm>=8",
"wheel",
]
build-backend = "setuptools.build_meta"

[tools.setuptools]
packages = ["alphaconf"]

[tool.setuptools_scm]
local_scheme = "no-local-version"

[project]
name = "alphaconf"
dynamic = ["version"]
Expand All @@ -31,6 +37,17 @@ dotenv = ["python-dotenv"]
invoke = ["invoke"]
pydantic = ["pydantic>=2"]
toml = ["toml"]
pinned = [
"toml==0.10.2",
]
dev = [
"mypy~=1.11",
"ruff==0.5.6",
"types-toml==0.10.2",
]
test = [
"pytest==8.3.2",
]

[project.urls]
Homepage = "https://github.com/kmagusiak/alphaconf"
Expand All @@ -46,38 +63,49 @@ skip-string-normalization = 1
[tool.mypy]
ignore_missing_imports = true

[tools.setuptools]
packages = ["alphaconf"]

[tool.setuptools_scm]
local_scheme = "no-local-version"

[tool.ruff]
line-length = 100
target-version = "py39"

[tool.ruff.format]
quote-style="preserve"

[tool.ruff.lint]
# https://beta.ruff.rs/docs/rules/
select = [
"C4", # flake8 comprehensions
#"C9", # mccabe
#"D", # documentation
"E",
"F",
"W",
"COM", # flake8 commas
#"D", # pydocstyle, pydoclint
"E", # pycodestyle
"EXE", # flake8-executable
"F", # pyflakes
"I", # isort
"LOG", # flake8 logging
"N", # naming
"PLE", # pylint errors
"RET", # flake8 return
"RUF", # ruff specific
"SIM", # flake8 simplify
"TID", # flake8 tidy imports
"UP", # pyupdate
"C4", # comprehensions
"EXE",
"SIM",
"RUF",
"W", # pycodestyle
# specific rules
"FIX003" # comments with XXX should become TODO or FIXME
]
ignore = [
"COM812", # trailing commas (because we use the ruff formatter)
"D102", # mission doc in public method, function
"D205", # blank line required betweeen summary and description
"D205", # blank line required between summary and description
"D400", # first line should end with a period
"E731", # don't assign lambda
"SIM108", # simplify ITE by operator
"SIM300", # yoda condition
"UP038", # isinstance must use union operator on types
]

[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]

0 comments on commit b56732b

Please sign in to comment.