Skip to content

Commit

Permalink
Prepare for Black autoformatting: dependencies, string staging, singl…
Browse files Browse the repository at this point in the history
…e-quote string override
  • Loading branch information
klardotsh committed Jul 25, 2019
1 parent 8100b91 commit 5c0c13e
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 60 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ docker-base-deploy: docker-base
devdeps: .devdeps

lint: devdeps
@$(PIPENV) run black --check
@$(PIPENV) run flake8

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

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

Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ipython = "*"
isort = "*"
neovim = "*"
s3cmd = "*"
black = "==19.3b0"
flake8-quotes = "*"

[requires]
python_version = "3.7"
38 changes: 37 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ below (we'll try to keep this up to date!):
> their help has been crucial to KMK's success, KMK is not an official Adafruit
> project, and the Core team is not compensated by Adafruit for its development.
## Code Style

KMK uses [Black](https://github.com/psf/black) with a Python 3.6 target and,
[(controversially?)](https://github.com/psf/black/issues/594) single quotes.
Further code styling is enforced with isort and flake8 with several plugins.
`make fix-isort fix-formatting` before a commit is a good idea, and CI will fail
if inbound code does not adhere to these formatting rules. Some exceptions are
found in `setup.cfg` loosening the rules in isolated cases, notably
`user_keymaps` (which is *also* not subject to Black formatting for reasons
documented in `pyproject.toml`).

## License, Copyright, and Legal

All software in this repository is licensed under the [GNU Public License,
Expand Down
29 changes: 21 additions & 8 deletions kmk/handlers/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@


def df_pressed(key, state, *args, **kwargs):
"""Switches the default layer"""
'''
Switches the default layer
'''
state.active_layers[-1] = key.meta.layer
return state


def mo_pressed(key, state, *args, **kwargs):
"""Momentarily activates layer, switches off when you let go"""
'''
Momentarily activates layer, switches off when you let go
'''
state.active_layers.insert(0, key.meta.layer)
return state

Expand All @@ -32,7 +36,9 @@ def mo_released(key, state, KC, *args, **kwargs):


def lm_pressed(key, state, *args, **kwargs):
"""As MO(layer) but with mod active"""
'''
As MO(layer) but with mod active
'''
state.hid_pending = True
# Sets the timer start and acts like MO otherwise
state.start_time['lm'] = ticks_ms()
Expand All @@ -41,7 +47,9 @@ def lm_pressed(key, state, *args, **kwargs):


def lm_released(key, state, *args, **kwargs):
"""As MO(layer) but with mod active"""
'''
As MO(layer) but with mod active
'''
state.hid_pending = True
state.keys_pressed.discard(key.meta.kc)
state.start_time['lm'] = None
Expand All @@ -68,8 +76,9 @@ def lt_released(key, state, *args, **kwargs):


def tg_pressed(key, state, *args, **kwargs):
"""Toggles the layer (enables it if not active, and vise versa)"""

'''
Toggles the layer (enables it if not active, and vise versa)
'''
# See mo_released for implementation details around this
try:
del_idx = state.active_layers.index(key.meta.layer)
Expand All @@ -81,15 +90,19 @@ def tg_pressed(key, state, *args, **kwargs):


def to_pressed(key, state, *args, **kwargs):
"""Activates layer and deactivates all other layers"""
'''
Activates layer and deactivates all other layers
'''
state.active_layers.clear()
state.active_layers.insert(0, key.meta.layer)

return state


def tt_pressed(key, state, *args, **kwargs):
"""Momentarily activates layer if held, toggles it if tapped repeatedly"""
'''
Momentarily activates layer if held, toggles it if tapped repeatedly
'''
# TODO Make this work with tap dance to function more correctly, but technically works.
if state.start_time['tt'] is None:
# Sets the timer start and acts like MO otherwise
Expand Down
5 changes: 2 additions & 3 deletions kmk/keyboard_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,9 @@ def go(self):

if self.split_flip and not self.is_master:
self.col_pins = list(reversed(self.col_pins))

if self.split_side == "Left":
if self.split_side == 'Left':
self.split_master_left = self.is_master
elif self.split_side == "Right":
elif self.split_side == 'Right':
self.split_master_left = not self.is_master
else:
self.is_master = True
Expand Down
6 changes: 3 additions & 3 deletions kmk/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def _argumented_key(*user_args, **user_kwargs):
else:
raise ValueError(
'Argumented key validator failed for unknown reasons. '
'This may not be the keymap\'s fault, as a more specific error '
"This may not be the keymap's fault, as a more specific error "
'should have been raised.',
)

Expand Down Expand Up @@ -439,7 +439,7 @@ def _argumented_key(*user_args, **user_kwargs):
make_key(code=48, names=('RBRACKET', 'RBRC', ']'))
make_key(code=49, names=('BACKSLASH', 'BSLASH', 'BSLS', '\\'))
make_key(code=51, names=('SEMICOLON', 'SCOLON', 'SCLN', ';'))
make_key(code=52, names=('QUOTE', 'QUOT', '\''))
make_key(code=52, names=('QUOTE', 'QUOT', "'"))
make_key(code=53, names=('GRAVE', 'GRV', 'ZKHK', '`'))
make_key(code=54, names=('COMMA', 'COMM', ','))
make_key(code=55, names=('DOT', '.'))
Expand Down Expand Up @@ -539,7 +539,7 @@ def _argumented_key(*user_args, **user_kwargs):
make_shifted_key('RBRACKET', names=('RIGHT_CURLY_BRACE', 'RCBR', '}'))
make_shifted_key('BACKSLASH', names=('PIPE', '|'))
make_shifted_key('SEMICOLON', names=('COLON', 'COLN', ':'))
make_shifted_key('QUOTE', names=('DOUBLE_QUOTE', 'DQUO', 'DQT', '\''))
make_shifted_key('QUOTE', names=('DOUBLE_QUOTE', 'DQUO', 'DQT', '"'))
make_shifted_key('COMMA', names=('LEFT_ANGLE_BRACKET', 'LABK', '<'))
make_shifted_key('DOT', names=('RIGHT_ANGLE_BRACKET', 'RABK', '>'))
make_shifted_key('SLSH', names=('QUESTION', 'QUES', '?'))
Expand Down
12 changes: 6 additions & 6 deletions kmk/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ def off(self):
self.set_brightness(0)

def increase_ani(self):
"""
'''
Increases animation speed by 1 amount stopping at 10
:param step:
"""
'''
if (self.animation_speed + 1) >= 10:
self.animation_speed = 10
else:
self.val += 1

def decrease_ani(self):
"""
'''
Decreases animation speed by 1 amount stopping at 0
:param step:
"""
'''
if (self.val - 1) <= 0:
self.val = 0
else:
Expand All @@ -127,10 +127,10 @@ def effect_static(self):
return self

def animate(self):
"""
'''
Activates a "step" in the animation based on the active mode
:return: Returns the new state in animation
"""
'''
if self.effect_init:
self._init_effect()
if self.enabled:
Expand Down
Loading

0 comments on commit 5c0c13e

Please sign in to comment.