Skip to content

Commit

Permalink
[FEATURE] Logging (#182)
Browse files Browse the repository at this point in the history
# Logging

## Description

This PR adds pre-defined logging configuration.

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] This change requires a documentation update

## Checklist

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
Diapolo10 authored Oct 23, 2024
2 parents 30b9aa0 + 2f3581c commit a55d49e
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 142 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

permissions:
contents: write
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: [
'3.8',
'3.9',
'3.10',
'3.11',
# 'pypy-3.10',
'3.12',
'pypy-3.10',
]

exclude:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,6 @@ tests/reports

# Ruff
.ruff_cache

# Logs
logs/
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Remember to:

1. Replace all instances of `project-name` with the real name of the project
2. Replace all instances of `project_name` with the "package name" of the project
3. Rename the source code folder from `project_name` to something more fitting
4. Generate a lock file
3. Rename the source code folder from `project_name` to your package name
4. Generate a lock file (`poetry install --with dev,tests,linters`)
5. Rewrite the `README.md`
6. If the project is not an executable, delete the files:
* `src/project_name/main.py`
* `src/project_name/logger.py`
* `src/project_name/logger_config.toml`
* `src/project_name/config.py`
* `python-dotenv` and `tomli` as dependencies in `pyproject.toml` (unless otherwise needed)
164 changes: 94 additions & 70 deletions poetry.lock

Large diffs are not rendered by default.

158 changes: 90 additions & 68 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ requires = ["poetry-core>=1.2.0", "wheel",]
build-backend = "poetry.core.masonry.api"


[tool.coverage.report]
exclude_lines = [
"pragma: not covered",
"@overload",
]


[tool.coverage.run]
branch = true
relative_files = true
Expand Down Expand Up @@ -39,7 +46,6 @@ classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -51,7 +57,9 @@ classifiers = [


[tool.poetry.dependencies]
python = "^3.8.1"
python = "^3.9.0"
python-dotenv = "^1.0.1"
tomli = { version = "^2.0.1", python = "<3.11" }


[tool.poetry.group.dev.dependencies]
Expand Down Expand Up @@ -98,113 +106,127 @@ testpaths = [


[tool.ruff]
select = [
"A", # Builtins
"ANN", # Annotations
"ARG", # Unused arguments
"B", # Bugbear
"BLE", # Blind except
"C4", # Comprehensions
"C90", # mccabe
"COM", # Commas
"D1", # Undocumented public elements
"D2", # Docstring conventions
"D3", # Triple double quotes
"D4", # Docstring text format
"DTZ", # Datetimes
"EM", # Error messages
"ERA", # Commented-out code
"EXE", # Executable
"F", # Pyflakes
"FA", # __future__ annotations
"FLY", # F-strings
# "FURB", # Refurb
"G", # Logging format
"I", # Isort
"ICN", # Import conventions
"INP", # Disallow PEP-420 (Implicit namespace packages)
"INT", # gettext
"ISC", # Implicit str concat
# "LOG", # Logging
"N", # PEP-8 Naming
"NPY", # Numpy
"PERF", # Unnecessary performance costs
"PGH", # Pygrep hooks
"PIE", # Unnecessary code
"PL", # Pylint
"PT", # Pytest
"PTH", # Use Pathlib
"PYI", # Stub files
"Q", # Quotes
"RET", # Return
"RUF", # Ruff
"RSE", # Raise
"S", # Bandit
"SIM", # Code simplification
"SLF", # Private member access
"SLOT", # __slots__
"T10", # Debugger
"T20", # Print
"TCH", # Type checking
"TID", # Tidy imports
"TRY", # Exception handling
"UP", # Pyupgrade
"W", # Warnings
"YTT", # sys.version
lint.select = [
"A", # Builtins
# "AIR", # Airflow
"ANN", # Annotations
"ARG", # Unused arguments
"ASYNC", # Asynchronous code
"B", # Bugbear
"BLE", # Blind except
"C4", # Comprehensions
"C90", # mccabe
"COM", # Commas
# "CPY", # Copyright
"D1", # Undocumented public elements
"D2", # Docstring conventions
"D3", # Triple double quotes
"D4", # Docstring text format
# "DJ", # Django
"DTZ", # Datetimes
"E", # Errors
"EM", # Error messages
"ERA", # Commented-out code
"EXE", # Executable
"F", # Pyflakes
"FA", # __future__ annotations
# "FAST", # FastAPI
"FBT", # "Boolean trap"
"FIX", # "FIXME"-comments
"FLY", # F-strings
"FURB", # Refurb
"G", # Logging format
"I", # Isort
"ICN", # Import conventions
"INP", # Disallow PEP-420 (Implicit namespace packages)
"INT", # gettext
"ISC", # Implicit str concat
"LOG", # Logging
"N", # PEP-8 Naming
# "NPY", # Numpy
# "PD", # Pandas
"PERF", # Unnecessary performance costs
"PGH", # Pygrep hooks
"PIE", # Unnecessary code
"PL", # Pylint
"PT", # Pytest
"PTH", # Use Pathlib
"PYI", # Stub files
"Q", # Quotes
"RET", # Return
"RUF", # Ruff
"RSE", # Raise
"S", # Bandit
"SIM", # Code simplification
"SLF", # Private member access
"SLOT", # __slots__
"T10", # Debugger
"T20", # Print
"TCH", # Type checking
"TD", # "TODO"-comments
"TID", # Tidy imports
"TRY", # Exception handling
"UP", # Pyupgrade
"W", # Warnings
"YTT", # sys.version
]
ignore = [
lint.ignore = [
"ANN101", # Type annotation for `self`
"D203", # One blank line before class docstring
"D212", # Multi-line summary first line
"PLR0913", # Too many arguments
"Q000", # Single quotes found but double quotes preferred
]
ignore-init-module-imports = true
line-length = 120
# preview = true
show-fixes = true
src = ["src",]
target-version = "py38"
target-version = "py39"


[tool.ruff.lint.flake8-copyright]
author = "Lari Liuhamo"


[tool.ruff.flake8-quotes]
[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"
multiline-quotes = "double"


[tool.ruff.mccabe]
# Unlike Flake8, default to a complexity level of 10.
[tool.ruff.lint.mccabe]
max-complexity = 10


[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# https://beta.ruff.rs/docs/rules/
"__init__.py" = ["F401","F403","F405",]
"__init__.py" = ["F401", "F403", "F405",]
"tests/*" = ["ANN", "ARG", "INP001", "S101",]
"logger.py" = ["N815",]


[tool.ruff.pylint]
[tool.ruff.lint.pylint]
max-args = 15
max-branches = 20
max-returns = 10
max-statements = 80


[tool.ruff.flake8-tidy-imports]
[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"


[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py38, py39, py310, py311, pypy3
envlist = py39, py310, py311, py312, pypy3
skip_missing_interpreters = true
[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312
3.12: py312
pypy-3.10: pypy3
[testenv]
Expand Down
18 changes: 18 additions & 0 deletions src/project_name/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Global config options of the package."""

import os
from importlib import resources as pkg_resources
from pathlib import Path

from dotenv import load_dotenv

import project_name

load_dotenv()

PACKAGE_NAME = "project_name"

with pkg_resources.as_file(pkg_resources.files(project_name)) as package_dir:
DEFAULT_CONFIG_FILE_PATH = package_dir / 'logger_config.toml'

LOGGER_CONFIG_FILE = Path(os.environ.get("PROJECT_NAME_LOGGER_CONFIG_FILE", DEFAULT_CONFIG_FILE_PATH))
1 change: 1 addition & 0 deletions src/project_name/lib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Code."""


def adder(first: int, second: int) -> int:
"""Lorem Ipsum dolor sit amet."""
return first + second
Loading

0 comments on commit a55d49e

Please sign in to comment.