Skip to content

Commit

Permalink
Uv migration (#11)
Browse files Browse the repository at this point in the history
* Refactor: move source files

* Fix: tests and version metadata

* Refactor: initial migration to uv + pyproject.toml

* Refactor: improve project metadata

* Refactor: move tox configuration to pyproject

* ci: setup attempt #1

* ci: setup attempt #2

* ci: setup attempt #3

* ci: setup attempt #4

* ci: setup attempt #5

* ci: setup attempt #6

* ci: setup attempt #7

* ci: setup attempt #8

* ci: setup attempt #9

* ci: setup attempt #10

* ci: setup attempt #11

* ci: setup attempt #12

* ci: setup attempt #13

* ci: setup attempt #14

* Update README

* Update README

* Refactor: move pytest configuration to pyproject.toml

* Fix: remove warnings on datetime.utcnow

* Refactor: remove setup.cfg, adopt ruff defaults

* Test coveralls integration #1

* Test coveralls integration #2

* Test coveralls integration #3

* Test coveralls integration #4

* Test coveralls integration #5

* Test coveralls integration #6

* Test coveralls integration #7

* Test coveralls integration #8

* Remove coveralls

* Remove travis-ci references

* Remove requirements.txt

* Remove setup.py

* Sync dependencies

* Update pre-commit

* Update makefile

* Update ci
  • Loading branch information
georgeyk authored Dec 18, 2024
1 parent 41716ac commit 9fdaec6
Show file tree
Hide file tree
Showing 18 changed files with 627 additions and 140 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
name: CI

on:
push:
branches: [master]
pull_request:
workflow_dispatch:

env:
FORCE_COLOR: "1"
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_NO_PYTHON_VERSION_WARNING: "1"

permissions: {}

jobs:
lint:
name: Linters
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: 3.13

- name: Install pre-commit
run: uv tool install pre-commit

- name: Run pre-commit
run: uv run pre-commit run --all-files --show-diff-on-failure

tests:
name: Tests with ${{ matrix.env }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
env:
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.env }}
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"

- name: Install tox
run: uv tool install tox --with tox-uv

- name: Setup tests
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.env }}

- name: Run tests
run: tox run --skip-pkg-install -e ${{ matrix.env }}

- name: Coverage file
uses: actions/upload-artifact@v4
if: matrix.env == '3.12'
with:
name: cov-report
path: coverage.lcov
overwrite: true

coverage:
name: Coverage
needs: tests
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Coverage file
uses: actions/download-artifact@v4
with:
name: cov-report

- name: Coveralls
uses: coverallsapp/github-action@v2
with:
file: coverage.lcov
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ ENV/

# Rope project settings
.ropeproject

tmp/*
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ repos:
- id: forbid-new-submodules
- id: no-commit-to-branch

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.5.10
hooks:
- id: uv-lock

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
hooks:
Expand Down
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ clean-pyc:
@find . -iname '.coverage' -delete
@rm -rf htmlcov/
@rm -rf *.tox/
@rm -f coverage.*

clean-dist:
@rm -rf dist/
Expand All @@ -25,8 +26,7 @@ test:
test-ci: clean lint test

dist: clean
python setup.py sdist
python setup.py bdist_wheel
uv build

release: dist
git tag `python setup.py -q version`
Expand Down
20 changes: 10 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ Belogging

*Don't fight with logging ...*

|TravisCI Build Status| |Coverage Status| |PyPI Version| |PyPI License| |PyPI latest|
|Coverage Status| |PyPI Version| |PyPI License| |PyPI latest|

----

Easy logging configuration based on environment variables.

Features:

* Set logging level using environment variable LOG_LEVEL (defaults to 'INFO')
* Set which loggers to enable using environment variable LOGGERS (defaults to '', everything)
* Always output to stdout
* Optional JSON formatter
* Completely disable logging setting LOG_LEVEL=DISABLED
* Set logging level using environment variable LOG_LEVEL (defaults to `INFO`)
* Set which loggers to enable using environment variable `LOGGERS` (defaults to `''`, everything)
* Always output to stdout
* Optional JSON formatter
* Completely disable logging setting `LOG_LEVEL=DISABLED`

Requirements:

* Python 3.5 and beyond
* Python 3.10+

Install:

`pip install belogging`
.. code-block:: bash
pip install belogging
Examples:
Expand Down Expand Up @@ -105,8 +107,6 @@ Logging follows a hierarchy, so you easily select or skip some logging messages:
# all messages from my_lib will show up
.. |TravisCI Build Status| image:: https://travis-ci.org/georgeyk/belogging.svg?branch=master
:target: https://travis-ci.org/georgeyk/belogging
.. |Coverage Status| image:: https://coveralls.io/repos/github/georgeyk/belogging/badge.svg?branch=master
:target: https://coveralls.io/github/georgeyk/belogging?branch=master
.. |PyPI Version| image:: https://img.shields.io/pypi/pyversions/belogging.svg?maxAge=2592000
Expand Down
68 changes: 68 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[project]
name = "belogging"
dynamic = ["version"]
description = "Easy and opinionated logging configuration for Python apps"
readme = "README.rst"
license = {file = "LICENSE"}
keywords = ["logging"]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: System :: Logging",

]
authors = [{name = "George Y. Kussumoto", email = "[email protected]"}]
requires-python = ">=3.10"
dependencies = [
"python-json-logger>=3.2.0",
]

[project.urls]
Github = "https://github.com/georgeyk/belogging/"
Releases = "https://github.com/georgeyk/belogging/releases"

[tool.hatch.version]
path = "src/belogging/__init__.py"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
reinstall-package = ["belogging"]
dev-dependencies = [
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
"tox>=4.23.2",
"tox-uv>=1.16.1",
"pre-commit>=4.0.1",
]

[tool.ruff]
src = ["src", "tests"]

[tool.ruff.lint.isort]
lines-between-types = 1
lines-after-imports = 2

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-s -x --cov=src/belogging --cov-report=lcov"
markers = ["slow: marks tests as slow (deselect with '-m \"not slow\"')",]

[tool.tox]
requires = ["tox>=4.19"]
env_list = ["3.10", "3.11", "3.12"]

[tool.tox.env_run_base]
runner = "uv-venv-lock-runner"
with_dev = true
commands = [["pytest"]]
3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

7 changes: 0 additions & 7 deletions requirements.txt

This file was deleted.

10 changes: 0 additions & 10 deletions setup.cfg

This file was deleted.

81 changes: 0 additions & 81 deletions setup.py

This file was deleted.

4 changes: 4 additions & 0 deletions belogging/__init__.py → src/belogging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from .loader import BeloggingLoader


__version__ = "v0.2.0"


# Sugar

__loaded = False
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions belogging/filters.py → src/belogging/filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
from collections import OrderedDict
from datetime import datetime
from datetime import datetime, timezone
from threading import Lock

from .defaults import LEVEL_MAP
Expand Down Expand Up @@ -61,7 +61,7 @@ def filter(self, record):
msg = record.getMessage()
with self.lock:
if msg in self._cache:
now = datetime.utcnow()
now = datetime.now(timezone.utc)
delta = now - self._cache[msg]["time"]
if delta.seconds >= self._cache_expire:
self._cache[msg]["time"] = now
Expand All @@ -78,6 +78,6 @@ def filter(self, record):
self._cache.pop(key, None)

with self.lock:
self._cache[msg] = {"time": datetime.utcnow(), "hits": 0}
self._cache[msg] = {"time": datetime.now(timezone.utc), "hits": 0}

return True
File renamed without changes.
Loading

0 comments on commit 9fdaec6

Please sign in to comment.