Skip to content

Commit

Permalink
Merge pull request #42 from jacebrowning/update-tooling
Browse files Browse the repository at this point in the history
Update tooling from my Python template
  • Loading branch information
jacebrowning authored Jun 3, 2021
2 parents b739ae1 + 7aac076 commit fbe30aa
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 94 deletions.
4 changes: 0 additions & 4 deletions .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

multi_line_output = 3

known_standard_library = dataclasses,typing_extensions
known_third_party = click,log
known_first_party = log

combine_as_imports = true
force_grid_wrap = false
include_trailing_comma = true
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.0.1 (2021-06-03)

- Fixed logging within interactive sessions.

# 2.0 (2020-09-10)

- Removed automatic call to `init()` when creating the first logging record.
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $ make run
Launch an IPython session:
```text
$ make ipython
$ make shell
```

# Release Tasks
Expand Down
66 changes: 32 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
# Project settings
PROJECT := minilog
PACKAGE := log
REPOSITORY := jacebrowning/minilog

# Project paths
PACKAGES := $(PACKAGE) tests
CONFIG := $(wildcard *.py)
MODULES := $(wildcard $(PACKAGE)/*.py)

# Virtual environment paths
VIRTUAL_ENV ?= .venv

# MAIN TASKS ##################################################################

.PHONY: all
all: install

.PHONY: ci
ci: format check test-repeat mkdocs ## Run all tasks that determine CI status
ci: format check test mkdocs ## Run all tasks that determine CI status

.PHONY: watch
watch: install .clean-test ## Continuously run all CI tasks when files chanage
poetry run sniffer

.PHONY: run ## Start the program
run: install
.PHONY: run
run: install ## Start the program
poetry run python $(PACKAGE)/__main__.py

.PHONY: ipython ## Launch an IPython session
ipython: install
.PHONY: shell
shell: install ## Launch an IPython session
poetry run ipython --ipython-dir=notebooks

# SYSTEM DEPENDENCIES #########################################################
Expand All @@ -39,19 +29,21 @@ doctor: ## Confirm system dependencies are available

# PROJECT DEPENDENCIES ########################################################

VIRTUAL_ENV ?= .venv
DEPENDENCIES := $(VIRTUAL_ENV)/.poetry-$(shell bin/checksum pyproject.toml poetry.lock)

.PHONY: install
install: $(DEPENDENCIES) .cache

$(DEPENDENCIES): poetry.lock
@ rm -rf $(VIRTUAL_ENV)/.poetry-*
@ poetry config virtualenvs.in-project true
poetry install
@ touch $@

ifndef CI
poetry.lock: pyproject.toml
poetry lock
poetry lock --no-update
@ touch $@
endif

Expand All @@ -62,18 +54,18 @@ endif

.PHONY: format
format: install
poetry run isort $(PACKAGES) notebooks
poetry run black $(PACKAGES) notebooks
poetry run isort $(PACKAGE) tests notebooks
poetry run black $(PACKAGE) tests notebooks
@ echo

.PHONY: check
check: install format ## Run formaters, linters, and static analysis
ifdef CI
git diff --exit-code
endif
poetry run mypy $(PACKAGES) --config-file=.mypy.ini
poetry run pylint $(PACKAGES) --rcfile=.pylint.ini
poetry run pydocstyle $(PACKAGES) $(CONFIG)
poetry run mypy $(PACKAGE) tests --config-file=.mypy.ini
poetry run pylint $(PACKAGE) tests --rcfile=.pylint.ini
poetry run pydocstyle $(PACKAGE) tests

# TESTS #######################################################################

Expand All @@ -94,25 +86,30 @@ test-unit: install
@ ( mv $(FAILURES) $(FAILURES).bak || true ) > /dev/null 2>&1
poetry run pytest $(PACKAGE) $(PYTEST_OPTIONS)
@ ( mv $(FAILURES).bak $(FAILURES) || true ) > /dev/null 2>&1
poetry run coveragespace $(REPOSITORY) unit
ifndef DISABLE_COVERAGE
poetry run coveragespace update unit
endif

.PHONY: test-int
test-int: install
@ if test -e $(FAILURES); then poetry run pytest tests $(PYTEST_RERUN_OPTIONS); fi
@ rm -rf $(FAILURES)
poetry run pytest tests $(PYTEST_OPTIONS)
poetry run coveragespace $(REPOSITORY) integration
ifndef DISABLE_COVERAGE
poetry run coveragespace update integration
endif

.PHONY: test-all
test-all: install
@ if test -e $(FAILURES); then poetry run pytest $(PACKAGES) $(PYTEST_RERUN_OPTIONS); fi
@ if test -e $(FAILURES); then poetry run pytest $(PACKAGE) tests $(PYTEST_RERUN_OPTIONS); fi
@ rm -rf $(FAILURES)
poetry run pytest $(PACKAGES) $(PYTEST_OPTIONS)
poetry run coveragespace $(REPOSITORY) overall
poetry run pytest $(PACKAGE) tests $(PYTEST_OPTIONS)
ifndef DISABLE_COVERAGE
poetry run coveragespace update overall
endif

.PHONY: test-repeat
test-repeat: install
@ rm -rf $(FAILURES)
poetry run pytest $(PACKAGES) $(PYTEST_OPTIONS) --count=5 --exitfirst

.PHONY: test-profile
Expand All @@ -134,6 +131,7 @@ docs: mkdocs uml ## Generate documentation and UML
mkdocs: install $(MKDOCS_INDEX)
$(MKDOCS_INDEX): docs/requirements.txt mkdocs.yml docs/*.md
@ mkdir -p docs/about
@ cd docs && ln -sf ../README.md index.md
@ cd docs/about && ln -sf ../../CHANGELOG.md changelog.md
@ cd docs/about && ln -sf ../../CONTRIBUTING.md contributing.md
@ cd docs/about && ln -sf ../../LICENSE.md license.md
Expand All @@ -158,7 +156,7 @@ mkdocs-serve: mkdocs
# BUILD #######################################################################

DIST_FILES := dist/*.tar.gz dist/*.whl
EXE_FILES := dist/$(PROJECT).*
EXE_FILES := dist/$(PACKAGE).*

.PHONY: dist
dist: install $(DIST_FILES)
Expand All @@ -168,20 +166,20 @@ $(DIST_FILES): $(MODULES) pyproject.toml

.PHONY: exe
exe: install $(EXE_FILES)
$(EXE_FILES): $(MODULES) $(PROJECT).spec
$(EXE_FILES): $(MODULES) $(PACKAGE).spec
# For framework/shared support: https://github.com/yyuu/pyenv/wiki
poetry run pyinstaller $(PROJECT).spec --noconfirm --clean
poetry run pyinstaller $(PACKAGE).spec --noconfirm --clean

$(PROJECT).spec:
poetry run pyi-makespec $(PACKAGE)/__main__.py --onefile --windowed --name=$(PROJECT)
$(PACKAGE).spec:
poetry run pyi-makespec $(PACKAGE)/__main__.py --onefile --windowed --name=$(PACKAGE)

# RELEASE #####################################################################

.PHONY: upload
upload: dist ## Upload the current version to PyPI
git diff --name-only --exit-code
poetry publish
bin/open https://pypi.org/project/$(PROJECT)
bin/open https://pypi.org/project/$(PACKAGE)

# CLEANUP #####################################################################

Expand All @@ -194,7 +192,7 @@ clean-all: clean

.PHONY: .clean-install
.clean-install:
find $(PACKAGES) -name '__pycache__' -delete
find $(PACKAGE) tests -name '__pycache__' -delete
rm -rf *.egg-info

.PHONY: .clean-test
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

A minimalistic logging wrapper for Python.

[![Unix Build Status](https://img.shields.io/travis/jacebrowning/minilog/main.svg?label=unix)](https://travis-ci.org/jacebrowning/minilog)
[![Windows Build Status](https://img.shields.io/appveyor/ci/jacebrowning/minilog/main.svg?label=windows)](https://ci.appveyor.com/project/jacebrowning/minilog)
[![Unix Build Status](https://img.shields.io/travis/com/jacebrowning/minilog.svg?label=unix)](https://travis-ci.com/jacebrowning/minilog)
[![Windows Build Status](https://img.shields.io/appveyor/ci/jacebrowning/minilog.svg?label=windows)](https://ci.appveyor.com/project/jacebrowning/minilog)
[![Coverage Status](https://img.shields.io/coveralls/jacebrowning/minilog/main.svg)](https://coveralls.io/r/jacebrowning/minilog)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/jacebrowning/minilog.svg)](https://scrutinizer-ci.com/g/jacebrowning/minilog/?branch=main)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/jacebrowning/minilog.svg)](https://scrutinizer-ci.com/g/jacebrowning/minilog)
[![PyPI Version](https://img.shields.io/pypi/v/minilog.svg)](https://pypi.org/project/minilog)
[![PyPI License](https://img.shields.io/pypi/l/minilog.svg)](https://pypi.org/project/minilog)

Expand Down
2 changes: 0 additions & 2 deletions bin/update
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def run():

def copy():
for filename in [
'.appveyor.yml',
'.coveragerc',
'.gitattributes',
'.gitignore',
Expand All @@ -57,7 +56,6 @@ def copy():
'.pydocstyle.ini',
'.pylint.ini',
'.scrutinizer.yml',
'.travis.yml',
'.verchew.ini',
'CONTRIBUTING.md',
'Makefile',
Expand Down
44 changes: 0 additions & 44 deletions docs/index.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/index.md
6 changes: 5 additions & 1 deletion log/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create_logger_record(
record = logger.makeRecord(
name,
level,
fn=frame.f_globals['__file__'],
fn=parse_fn(frame.f_globals),
lno=frame.f_lineno,
msg=message,
args=args,
Expand All @@ -35,6 +35,10 @@ def create_logger_record(
return True


def parse_fn(frame_info: Dict) -> str:
return frame_info.get('__file__', 'interactive')


def parse_name(custom_name: str, frame_info: Dict) -> Tuple[str, str]:
module_name = custom_name or frame_info['__name__']
if module_name == '__main__':
Expand Down
Loading

0 comments on commit fbe30aa

Please sign in to comment.