From 08f7aa8e5f091a09b328d4a9e45d1cd69212d591 Mon Sep 17 00:00:00 2001 From: Omar Ali Khan Date: Wed, 19 Jul 2023 15:33:13 -0400 Subject: [PATCH] fix: Utilize regular file handler instead of a rotating one. Convert to Github Actions. --- .circleci/config.yml | 124 --------------------------- .github/workflows/lint_and_test.yaml | 52 +++++++++++ .github/workflows/publish.yaml | 36 ++++++++ .gitignore | 1 + Makefile | 12 +-- pyproject.toml | 2 +- src/setuplog/logger.py | 8 +- src/setuplog/setup.py | 5 +- 8 files changed, 103 insertions(+), 137 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/lint_and_test.yaml create mode 100644 .github/workflows/publish.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 1ec6123..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,124 +0,0 @@ -version: 2.1 - -executors: - python36: - docker: - - image: circleci/python:3.6 - - python37: - docker: - - image: circleci/python:3.7 - - python38: - docker: - - image: circleci/python:3.8 - - publish: - docker: - - image: circleci/python:3.6 - -commands: - setup: - steps: - - checkout - - run: - name: Execute prerequisite setup - command: | - curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python - echo 'export PATH="$HOME/.poetry/bin:$PATH"' >> $BASH_ENV - - run-make: - parameters: - command: - type: string - steps: - - run: - name: Run a make command - command: | - poetry run make << parameters.command >> - - setup-python: - description: Install python dependencies - steps: - - setup - - restore_cache: - key: v1-{{ checksum "pyproject.toml" }}-{{ checksum "poetry.lock" }} - - run-make: - command: install - - save_cache: - paths: - - /home/circleci/.cache/pypoetry/virtualenvs - key: v1-{{ checksum "pyproject.toml" }}-{{ checksum "poetry.lock" }} - - persist-coverage: - steps: - - persist_to_workspace: - root: . - paths: - - .coverage - - coverage.xml - - publish: - steps: - - attach_workspace: - at: . - - run: bash <(curl -s https://codecov.io/bash) - -jobs: - test-python36: - executor: python36 - steps: - - setup-python - - setup_remote_docker - - attach_workspace: - at: . - - run-make: - command: test - - persist-coverage - - test-python37: - executor: python37 - steps: - - setup-python - - setup_remote_docker - - run-make: - command: test - - test-python38: - executor: python38 - steps: - - setup-python - - setup_remote_docker - - run-make: - command: test - - lint: - executor: python36 - steps: - - setup-python - - run-make: - command: lint - - publish: - executor: publish - steps: - - setup-python - - publish - - -workflows: - build_all: - jobs: - - test-python36 - - test-python37 - - test-python38 - - - publish: - requires: - - test-python36 - - test-python37 - - test-python38 - filters: - branches: - only: - - /^master$/ diff --git a/.github/workflows/lint_and_test.yaml b/.github/workflows/lint_and_test.yaml new file mode 100644 index 0000000..eee5d91 --- /dev/null +++ b/.github/workflows/lint_and_test.yaml @@ -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 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..8141378 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -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/actions-poetry@v2.0.0 + 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 diff --git a/.gitignore b/.gitignore index 5e42028..89fd173 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ shell.nix # Documentation docs/_* +.python-version diff --git a/Makefile b/Makefile index fa52195..af260b9 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 5e0d531..84be0c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "setuplog" -version = "0.3.1" +version = "0.4.1" description = "" authors = [] license = "MIT" diff --git a/src/setuplog/logger.py b/src/setuplog/logger.py index 3d0b283..e38b286 100644 --- a/src/setuplog/logger.py +++ b/src/setuplog/logger.py @@ -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) @@ -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) diff --git a/src/setuplog/setup.py b/src/setuplog/setup.py index 6edcfa4..3b7e7ab 100644 --- a/src/setuplog/setup.py +++ b/src/setuplog/setup.py @@ -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): @@ -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