Skip to content

Commit

Permalink
ci: more configuration, start using ruff, another attempt to fix make…
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
MultifokalHirn committed Nov 15, 2023
1 parent 530c321 commit de258f1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 34 deletions.
30 changes: 19 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": true,
"source.fixAll": true
},
},
"autopep8.args": [
"--max-line-length",
"127"
"ruff.lint.args": [
"--config=./pyproject.toml"
],
"ruff.enable": true,
// "autopep8.args": [
// "--max-line-length",
// "127"
// ],
"flake8.args": [
"--config=setup.cfg"
],
"isort.check": true,
"isort.args": [
"--line_length",
"127"
],
"mypy-type-checker.args": [
"--config-file=pyproject.toml"
],
Expand All @@ -26,6 +26,11 @@
"note": "Information"
},
"mypy-type-checker.ignorePatterns": [],
"[markdown]": {
"editor.codeActionsOnSave": {
"source.fixAll": true
},
},
"[toml]": {
"editor.formatOnSave": false,
"editor.defaultFormatter": "be5invis.toml"
Expand All @@ -34,5 +39,8 @@
"[properties]": {
"editor.formatOnSave": false,
},
"python.analysis.typeCheckingMode": "basic"
"python.analysis.typeCheckingMode": "basic",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.fontFamily": "\"Geist Mono Medium\", \"LigaSFMonoNerdFont\",\"Hack Nerd Font\", \"Noto Mono\", \"Jetbrains Mono Regular\", Menlo, Monaco, 'Courier New', monospace",
"editor.cursorStyle": "block"
}
4 changes: 2 additions & 2 deletions Makefile.venv
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ endif
$(VENV):
$(PY) -m venv $(VENVDIR)
$(VENV)/python -m pip install --upgrade pip setuptools wheel pdm
$(VENV)/pdm config python.use_venv false
$(VENV)/pdm use --venv in-project
$(VENV)/pdm config python.use_venv true
# $(VENV)/pdm use --venv in-project

$(VENV)/$(MARKER): $(VENVDEPENDS) | $(VENV)
# ifneq ($(strip $(REQUIREMENTS_TXT)),)
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use_parentheses = false
# plugins = ["pydantic.mypy"]
# python_version = "3.11"
ignore_missing_imports = true
disallow_any_unimported = true
disallow_any_unimported = false
pretty = true

[tool.coverage.run]
Expand Down Expand Up @@ -108,7 +108,6 @@ exclude = [
"dist",
]

# Same as Black.
line-length = 127
indent-width = 4

Expand Down
1 change: 0 additions & 1 deletion src/app/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import sys

import app
Expand Down
25 changes: 9 additions & 16 deletions src/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
from typing import cast

import structlog
from structlog.stdlib import BoundLogger, LoggerFactory, add_log_level, filter_by_level


def setup_logger(
*, logger_name: str, log_level: int = logging.INFO
) -> structlog.stdlib.BoundLogger: # pragma: no cover
def setup_logger(*, logger_name: str, log_level: int = logging.INFO) -> BoundLogger:
"""
Set up the logger object to use in your code.
Expand All @@ -30,17 +29,14 @@ def setup_logger(
"""
# pylint: disable=protected-access
_setup_structlog()
logger = cast(structlog.stdlib.BoundLogger,
structlog.get_logger(logger_name))
logger = cast(BoundLogger, structlog.get_logger(logger_name))
logger.setLevel(log_level)
if not logger.new()._logger.handlers:
logger.addHandler(_configure_logger_handlers())
return logger


def set_logger_level(
*, logger: structlog.stdlib.BoundLogger, level: str
) -> None: # pragma: no cover
def set_logger_level(*, logger: BoundLogger, level: str) -> None:
"""
Allow to set a new logging level by name for an existing logger.
Expand All @@ -57,10 +53,7 @@ def set_logger_level(
clean_level = level.upper()
numeric_level = getattr(logging, clean_level)
logger.setLevel(numeric_level)
logger.info(
"Log level changed",
new_level=clean_level,
new_level_numeric=numeric_level)
logger.info("Log level changed", new_level=clean_level, new_level_numeric=numeric_level)


def _configure_logger_handlers() -> logging.StreamHandler: # pragma: no cover
Expand All @@ -80,15 +73,15 @@ def _setup_structlog() -> None:

structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.add_log_level,
filter_by_level,
add_log_level,
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.JSONRenderer(sort_keys=False),
],
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
logger_factory=LoggerFactory(),
wrapper_class=BoundLogger,
cache_logger_on_first_use=True,
)
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def __init__(self, *args: Any, **kwargs: Any):
def entries(self) -> List[Dict]:
# build _entries only once
if not self._entries:
self._entries = [json.loads(line)
for line in self.getvalue().splitlines()]
self._entries = [json.loads(line) for line in self.getvalue().splitlines()]

return self._entries

Expand Down
1 change: 1 addition & 0 deletions tests/unit/app/test_some_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
# assert client.first_name == "Mark"
# assert client.last_name == "New"


def test_app():
assert True

0 comments on commit de258f1

Please sign in to comment.