Skip to content

Commit fbe30aa

Browse files
authored
Merge pull request #42 from jacebrowning/update-tooling
Update tooling from my Python template
2 parents b739ae1 + 7aac076 commit fbe30aa

File tree

11 files changed

+245
-94
lines changed

11 files changed

+245
-94
lines changed

.isort.cfg

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
multi_line_output = 3
44

5-
known_standard_library = dataclasses,typing_extensions
6-
known_third_party = click,log
7-
known_first_party = log
8-
95
combine_as_imports = true
106
force_grid_wrap = false
117
include_trailing_comma = true

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.0.1 (2021-06-03)
2+
3+
- Fixed logging within interactive sessions.
4+
15
# 2.0 (2020-09-10)
26

37
- Removed automatic call to `init()` when creating the first logging record.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $ make run
7878
Launch an IPython session:
7979
8080
```text
81-
$ make ipython
81+
$ make shell
8282
```
8383

8484
# Release Tasks

Makefile

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
1-
# Project settings
2-
PROJECT := minilog
31
PACKAGE := log
4-
REPOSITORY := jacebrowning/minilog
5-
6-
# Project paths
7-
PACKAGES := $(PACKAGE) tests
8-
CONFIG := $(wildcard *.py)
92
MODULES := $(wildcard $(PACKAGE)/*.py)
103

11-
# Virtual environment paths
12-
VIRTUAL_ENV ?= .venv
13-
144
# MAIN TASKS ##################################################################
155

166
.PHONY: all
177
all: install
188

199
.PHONY: ci
20-
ci: format check test-repeat mkdocs ## Run all tasks that determine CI status
10+
ci: format check test mkdocs ## Run all tasks that determine CI status
2111

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

26-
.PHONY: run ## Start the program
27-
run: install
16+
.PHONY: run
17+
run: install ## Start the program
2818
poetry run python $(PACKAGE)/__main__.py
2919

30-
.PHONY: ipython ## Launch an IPython session
31-
ipython: install
20+
.PHONY: shell
21+
shell: install ## Launch an IPython session
3222
poetry run ipython --ipython-dir=notebooks
3323

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

4030
# PROJECT DEPENDENCIES ########################################################
4131

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

4435
.PHONY: install
4536
install: $(DEPENDENCIES) .cache
4637

4738
$(DEPENDENCIES): poetry.lock
39+
@ rm -rf $(VIRTUAL_ENV)/.poetry-*
4840
@ poetry config virtualenvs.in-project true
4941
poetry install
5042
@ touch $@
5143

5244
ifndef CI
5345
poetry.lock: pyproject.toml
54-
poetry lock
46+
poetry lock --no-update
5547
@ touch $@
5648
endif
5749

@@ -62,18 +54,18 @@ endif
6254

6355
.PHONY: format
6456
format: install
65-
poetry run isort $(PACKAGES) notebooks
66-
poetry run black $(PACKAGES) notebooks
57+
poetry run isort $(PACKAGE) tests notebooks
58+
poetry run black $(PACKAGE) tests notebooks
6759
@ echo
6860

6961
.PHONY: check
7062
check: install format ## Run formaters, linters, and static analysis
7163
ifdef CI
7264
git diff --exit-code
7365
endif
74-
poetry run mypy $(PACKAGES) --config-file=.mypy.ini
75-
poetry run pylint $(PACKAGES) --rcfile=.pylint.ini
76-
poetry run pydocstyle $(PACKAGES) $(CONFIG)
66+
poetry run mypy $(PACKAGE) tests --config-file=.mypy.ini
67+
poetry run pylint $(PACKAGE) tests --rcfile=.pylint.ini
68+
poetry run pydocstyle $(PACKAGE) tests
7769

7870
# TESTS #######################################################################
7971

@@ -94,25 +86,30 @@ test-unit: install
9486
@ ( mv $(FAILURES) $(FAILURES).bak || true ) > /dev/null 2>&1
9587
poetry run pytest $(PACKAGE) $(PYTEST_OPTIONS)
9688
@ ( mv $(FAILURES).bak $(FAILURES) || true ) > /dev/null 2>&1
97-
poetry run coveragespace $(REPOSITORY) unit
89+
ifndef DISABLE_COVERAGE
90+
poetry run coveragespace update unit
91+
endif
9892

9993
.PHONY: test-int
10094
test-int: install
10195
@ if test -e $(FAILURES); then poetry run pytest tests $(PYTEST_RERUN_OPTIONS); fi
10296
@ rm -rf $(FAILURES)
10397
poetry run pytest tests $(PYTEST_OPTIONS)
104-
poetry run coveragespace $(REPOSITORY) integration
98+
ifndef DISABLE_COVERAGE
99+
poetry run coveragespace update integration
100+
endif
105101

106102
.PHONY: test-all
107103
test-all: install
108-
@ if test -e $(FAILURES); then poetry run pytest $(PACKAGES) $(PYTEST_RERUN_OPTIONS); fi
104+
@ if test -e $(FAILURES); then poetry run pytest $(PACKAGE) tests $(PYTEST_RERUN_OPTIONS); fi
109105
@ rm -rf $(FAILURES)
110-
poetry run pytest $(PACKAGES) $(PYTEST_OPTIONS)
111-
poetry run coveragespace $(REPOSITORY) overall
106+
poetry run pytest $(PACKAGE) tests $(PYTEST_OPTIONS)
107+
ifndef DISABLE_COVERAGE
108+
poetry run coveragespace update overall
109+
endif
112110

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

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

160158
DIST_FILES := dist/*.tar.gz dist/*.whl
161-
EXE_FILES := dist/$(PROJECT).*
159+
EXE_FILES := dist/$(PACKAGE).*
162160

163161
.PHONY: dist
164162
dist: install $(DIST_FILES)
@@ -168,20 +166,20 @@ $(DIST_FILES): $(MODULES) pyproject.toml
168166

169167
.PHONY: exe
170168
exe: install $(EXE_FILES)
171-
$(EXE_FILES): $(MODULES) $(PROJECT).spec
169+
$(EXE_FILES): $(MODULES) $(PACKAGE).spec
172170
# For framework/shared support: https://github.com/yyuu/pyenv/wiki
173-
poetry run pyinstaller $(PROJECT).spec --noconfirm --clean
171+
poetry run pyinstaller $(PACKAGE).spec --noconfirm --clean
174172

175-
$(PROJECT).spec:
176-
poetry run pyi-makespec $(PACKAGE)/__main__.py --onefile --windowed --name=$(PROJECT)
173+
$(PACKAGE).spec:
174+
poetry run pyi-makespec $(PACKAGE)/__main__.py --onefile --windowed --name=$(PACKAGE)
177175

178176
# RELEASE #####################################################################
179177

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

186184
# CLEANUP #####################################################################
187185

@@ -194,7 +192,7 @@ clean-all: clean
194192

195193
.PHONY: .clean-install
196194
.clean-install:
197-
find $(PACKAGES) -name '__pycache__' -delete
195+
find $(PACKAGE) tests -name '__pycache__' -delete
198196
rm -rf *.egg-info
199197

200198
.PHONY: .clean-test

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
A minimalistic logging wrapper for Python.
44

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

bin/update

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def run():
4848

4949
def copy():
5050
for filename in [
51-
'.appveyor.yml',
5251
'.coveragerc',
5352
'.gitattributes',
5453
'.gitignore',
@@ -57,7 +56,6 @@ def copy():
5756
'.pydocstyle.ini',
5857
'.pylint.ini',
5958
'.scrutinizer.yml',
60-
'.travis.yml',
6159
'.verchew.ini',
6260
'CONTRIBUTING.md',
6361
'Makefile',

docs/index.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

log/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def create_logger_record(
2323
record = logger.makeRecord(
2424
name,
2525
level,
26-
fn=frame.f_globals['__file__'],
26+
fn=parse_fn(frame.f_globals),
2727
lno=frame.f_lineno,
2828
msg=message,
2929
args=args,
@@ -35,6 +35,10 @@ def create_logger_record(
3535
return True
3636

3737

38+
def parse_fn(frame_info: Dict) -> str:
39+
return frame_info.get('__file__', 'interactive')
40+
41+
3842
def parse_name(custom_name: str, frame_info: Dict) -> Tuple[str, str]:
3943
module_name = custom_name or frame_info['__name__']
4044
if module_name == '__main__':

0 commit comments

Comments
 (0)