Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor venv #1031

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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 '**/ptBR/**' -not -path '**/*-ptBR.md' -not -path '**/ja/**' -not -path '**/.*/**')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lang paths could be removed here now that we've retired those paths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was still one non-english doc hidden in hardware, that's why I didn't touch that part.
It's removed now. The "hardware" part of KMK isn't maintained anyway (and imo shouldn't be part of the firmware repository).

# 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