Skip to content

Commit

Permalink
Refactor venv (#1031)
Browse files Browse the repository at this point in the history
* Merge setup.cfg into pyproject.toml

* Use includes instead of excludes for black

* Remove pipenv dependency

* Keep spellcheck from searching hidden directories.

Otherwise spellcheck will search for example in `.venv` for typos in
tooling packages. Maybe the search expression should be a positive list.

* Remove the last non-english doc and simplify spellcheck search
  • Loading branch information
xs5871 authored Oct 8, 2024
1 parent ad16dd2 commit 5514117
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 670 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.11' # Version range or exact version of a Python version to use, using SemVer's version range syntax
- run: python -m pip install --upgrade pipenv wheel
- run: make devdeps
- run: make test
30 changes: 16 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ DOCKER_TAG ?= latest
AMPY_PORT ?= /dev/ttyUSB0
AMPY_BAUD ?= 115200
AMPY_DELAY ?= 1.5
PIPENV ?= $(shell which pipenv 2>/dev/null)
VENV ?= .venv
PYTHON = $(VENV)/bin/python

MPY_CROSS ?= $(shell which mpy-cross 2>/dev/null)
MPY_FLAGS ?= '-O2'
Expand All @@ -44,12 +45,13 @@ $(MPY_TARGET_DIR)/%.mpy: %.py
@$(MPY_CROSS) $(MPY_FLAGS) $? -o $@
endif

.devdeps: Pipfile.lock
@echo "===> Installing dependencies with pipenv"
@$(PIPENV) sync --dev
@touch .devdeps
$(VENV):
@echo "===> Installing virtual environment"
python -m venv $(VENV)
$(PYTHON) -m pip install --upgrade pip
$(PYTHON) -m pip install .[dev]

devdeps: .devdeps
devdeps: $(VENV)

dist: clean-dist dockerbase
@mkdir -p .dist
Expand All @@ -62,20 +64,22 @@ dockerbase:
--build-arg KMKPY_REF=$$(cut -f2 < kmkpython_ref.tsv)

lint: devdeps
@$(PIPENV) run flake8
@$(PYTHON) -m flake8

spellcheck:
./util/spellcheck.sh --no-interactive

fix-formatting: devdeps
@$(PIPENV) run black .
@$(PYTHON) -m black .

fix-isort: devdeps
@find boards/ kmk/ tests/ user_keymaps/ -name "*.py" | xargs $(PIPENV) run isort
@$(PYTHON) -m isort .

clean: clean-dist
@echo "===> Cleaning build artifacts"
@rm -rf .devdeps build dist $(MPY_TARGET_DIR)
rm -rf .venv build dist $(MPY_TARGET_DIR)
find . -type f -name '*.pyc' -delete
find . -type d -name '__pycache__' -delete

clean-dist:
@echo "===> Cleaning KMKPython dists"
Expand All @@ -88,18 +92,16 @@ clean-dist:
powerwash: clean
@echo "===> Removing vendor/ to force a re-pull"
@rm -rf vendor
@echo "===> Removing pipenv-managed virtual environment"
@$(PIPENV) --rm || true

test: lint unit-tests

TESTS ?= tests
.PHONY: unit-tests
unit-tests: devdeps
ifdef TESTS
@$(PIPENV) run python3 -m unittest $(TESTS)
$(PYTHON) -m unittest $(TESTS)
else
@$(PIPENV) run python3 -m unittest discover -t . -s tests
$(PYTHON) -m unittest discover -t . -s tests
endif # TESTS

reset-bootloader:
Expand Down
22 changes: 0 additions & 22 deletions Pipfile

This file was deleted.

503 changes: 0 additions & 503 deletions Pipfile.lock

This file was deleted.

67 changes: 0 additions & 67 deletions hardware/README-ptBR.md

This file was deleted.

96 changes: 81 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,88 @@
[project]
name = 'kmk_firmware'
dependencies = []
version = '0'
requires-python = '>=3.10'

[project.optional-dependencies]
dev = [
'flake8==7.0.0',
'flake8-black',
'flake8-commas',
'flake8-comprehensions',
'flake8-isort',
'flake8-pyproject',
'flake8-quotes',
]

[tool.setuptools]
packages = []

[tool.black]
# since black refuses to allow single-quotes... see locked conversation at
# https://github.com/psf/black/issues/594
skip-string-normalization = true
# explicitly exclude user_keymaps from black formatting rules
# because a visually-appealing keymap list will be flattened
# by black into a much harder to understand format
target-version = ['py36']
exclude = '''
include = '''
/(
\.git
| \.mypy_cache
| \.tox
| \.venv
| \.pytest_cache
| \.compiled
| dist
| build
| docs
| mnt
)/
boards
|kmk
|tests
|user_keymaps
)/.*\.py
'''

[tool.flake8]
filename = [
'./boards/*.py',
'./kmk/*.py',
'./tests/*.py',
'./user_keymaps/*.py',
]
# match black expectations
max-line-length = 88

# enforce single quotes
docstring-quotes = "'''"
multiline-quotes = "'''"

extend-ignore = [
# manage trailing commas
'C812', 'C813',
# ignore: comment should start with '# '
'E262',
# manage line lengths
'E501',
]

per-file-ignores = [
# Allow misaligned array entries
'boards/**/*.py: E131',
'user_keymaps/**/*.py: E131',
]

[tool.isort]
known_standard_library = [
'analogio',
'bitbangio',
'bleio',
'board',
'busio',
'digitalio',
'framebuf',
'gc',
'machine',
'microcontroller',
'micropython',
'neopixel',
'pulseio',
'supervisor',
'usb_hid'
]
profile = 'black'
skip_glob = [
'!boards/*.py',
'!kmk/*.py',
'!tests/*.py',
'!user_keymaps/*.py',
]
47 changes: 0 additions & 47 deletions setup.cfg

This file was deleted.

2 changes: 1 addition & 1 deletion util/spellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi
ROOT=$(git rev-parse --show-toplevel)

# This gets us only english .md files at the moment, but is clearly brittle
MARKDOWN_FILES=$(find "$ROOT" -name '*.md' -not -path '**/ptBR/**' -not -path '**/*-ptBR.md' -not -path '**/ja/**')
MARKDOWN_FILES=$(find "$ROOT" -name '*.md' -not -path '**/.*/**')
# Use our local dict for saved words, and use en_US for the main dict
ASPELL="aspell -M --dont-save-repl -p $ROOT/util/aspell.en.pws -d en_US"

Expand Down

0 comments on commit 5514117

Please sign in to comment.