Skip to content

Commit

Permalink
fix: Utilize regular file handler instead of a rotating one. Convert …
Browse files Browse the repository at this point in the history
…to Github Actions.
  • Loading branch information
oakhan3 committed Jul 20, 2023
1 parent 8c2b8e8 commit 08f7aa8
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 137 deletions.
124 changes: 0 additions & 124 deletions .circleci/config.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/lint_and_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Lint And Test
on:
pull_request:
merge_group:
branches:
- "main"
push:
branches:
- "main"
schedule:
- cron: '0 0 */3 * *'

jobs:
lint-and-test:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
id: setup-python
with:
python-version: '3.9.16'
env:
PYTHON_CONFIGURE_OPTS: --enable-shared --enable-optimizations

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
if: ${{ github.event.action }} != "schedule"
uses: actions/cache@v3
with:
path: ${{ inputs.working-directory }}/.venv
key: venv-${{ runner.os }}-ubuntu-latest-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install

- name: Lint
run: |
source .venv/bin/activate
make lint
- name: Test
run: |
source .venv/bin/activate
make test
36 changes: 36 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Github Release/Publish PyPi

on:
push:
tags:
- "v*.*.*"

jobs:
gh-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true

publish-pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Run image
uses: abatilo/[email protected]
with:
poetry-version: 1.2.2

- name: Publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ shell.nix

# Documentation
docs/_*
.python-version
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ test:
coverage xml

lint:
flake8 src tests
isort --check-only --recursive src tests
pydocstyle src tests
black --check src tests
mypy src tests
bandit src
flake8 --max-line-length=120 src tests || exit 1
isort --check-only --recursive src tests || exit 1
pydocstyle src tests || exit 1
black --check src tests || exit 1
mypy src tests || exit 1
bandit src || exit 1

format:
isort --recursive src tests
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "setuplog"
version = "0.3.1"
version = "0.4.1"
description = ""
authors = []
license = "MIT"
Expand Down
8 changes: 5 additions & 3 deletions src/setuplog/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def get_logger() -> logging.Logger:

style_adaptor = getattr(logging.config, "style_adaptor", None)

# Ensure the logger name is pulled from 2 frames up rather than from the local frame. One frame for this function, and one for the
# `_Logging` function calls.
# Ensure the logger name is pulled from 2 frames up rather than from the local frame.
# One frame for this function, and one for the `_Logging` function calls.
frame_name = sys._getframe(2).f_globals["__name__"]
segments.append(frame_name)

Expand All @@ -66,7 +66,9 @@ def error(self, msg: Union[object, str, M], *args: Any, **kwargs: Any) -> None:
logger = get_logger()
logger.error(msg, *args, **kwargs)

def exception(self, msg: Union[object, str, M], *args: Any, exc_info=True, **kwargs: Any) -> None:
def exception(
self, msg: Union[object, str, M], *args: Any, exc_info=True, **kwargs: Any
) -> None:
logger = get_logger()
logger.exception(msg, *args, exc_info=exc_info, **kwargs)

Expand Down
5 changes: 2 additions & 3 deletions src/setuplog/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
_DEFAULT_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
_DEFAULT_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
_DEFAULT_LOG_LEVEL_OVERRIDES = {"requests": "INFO"}
_FILE_HANDLER_MAX_BYTES = 1048576


def generate_loggers(*, log_level_overrides):
Expand All @@ -31,12 +30,12 @@ def generate_handlers(level, formatter, *, log_file=None):
}
if log_file:
handlers["file_handler"] = {
"class": "logging.handlers.RotatingFileHandler",
"class": "logging.FileHandler",
"formatter": formatter,
"filename": log_file,
"maxBytes": _FILE_HANDLER_MAX_BYTES,
"level": level,
}

return handlers


Expand Down

0 comments on commit 08f7aa8

Please sign in to comment.