Skip to content

Commit

Permalink
style: flake8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BradenM committed Jun 9, 2019
1 parent e60b2fe commit d2e0aed
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clean-test: ## remove test and coverage artifacts
rm -fr .pytest_cache

lint: ## check style with flake8
flake8 micropy tests --exclude micropy/lib
flake8 micropy tests --config=setup.cfg

test: ## run tests quickly with the default Python
py.test
Expand Down
3 changes: 2 additions & 1 deletion micropy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def reload(project_name=''):


@stubs.command()
@click.argument('path', required=True, type=click.Path(exists=True, file_okay=False, resolve_path=True))
@click.argument('path', required=True, type=click.Path(
exists=True, file_okay=False, resolve_path=True))
def add(path):
"""Add stubs"""
return mp.add_stub(path)
Expand Down
5 changes: 2 additions & 3 deletions micropy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

"""Micropy Exceptions"""

from micropy.logger import Log


class StubError(Exception):
"""Exception for any errors raised by stubs"""
Expand All @@ -20,7 +18,8 @@ class StubValidationError(StubError):

def __init__(self, stub, errors):
errs = '\n'.join(errors)
msg = f"Stub at [{stub.path}] encountered the following validation errors: {errs}"
msg = f"Stub at [{stub.path}] encountered \
the following validation errors: {errs}"
super().__init__(stub, message=msg)

def __str__(self):
Expand Down
13 changes: 9 additions & 4 deletions micropy/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ServiceLog:
"""
LOG_FILE = Path.home() / '.micropy' / 'micropy.log'

def __init__(self, service_name='MicroPy', base_color='bright_green', **kwargs):
def __init__(
self, service_name='MicroPy', base_color='bright_green', **kwargs):
self.parent = kwargs.get('parent', None)
self.LOG_FILE.parent.mkdir(exist_ok=True)
logging.basicConfig(level=logging.DEBUG,
Expand Down Expand Up @@ -160,7 +161,9 @@ def exception(self, error, **kwargs):
"""
logging.exception(str(error))
return self.echo(str(error), title_color='red', title_bold=True, **kwargs)
return self.echo(
str(error),
title_color='red', title_bold=True, **kwargs)

def success(self, msg, **kwargs):
"""Prints message with success formatting
Expand Down Expand Up @@ -201,7 +204,8 @@ def prompt(self, msg, **kwargs):
nl_default = kwargs.get('default', None)
msg = self.parse_msg(msg)
msg = msg + \
style(f"\n Press Enter to Use: [{nl_default}]", dim=True) if nl_default and len(
style(f"\n Press Enter to Use: [{nl_default}]", dim=True) if \
nl_default and len(
nl_default) > 0 else msg
title = self.get_service()
suffix = style('\u27a4 ', fg=self.accent_color)
Expand All @@ -222,7 +226,8 @@ def confirm(self, msg, **kwargs):
title = self.get_service()
suffix = style('\u27a4 ', fg=self.accent_color)
secho(f"{title} ", nl=False)
return confirm(msg, show_default="[y/N] ", prompt_suffix=suffix, **kwargs)
return confirm(
msg, show_default="[y/N] ", prompt_suffix=suffix, **kwargs)

def clear(self):
"""Clears terminal screen"""
Expand Down
11 changes: 6 additions & 5 deletions micropy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import tempfile
from pathlib import Path
from shutil import copytree

from rshell import main as rsh

Expand Down Expand Up @@ -59,7 +58,6 @@ def add_stub(self, path):
stub = Stub(path, copy_to=stub_out)
except StubValidationError:
self.log.error(f"{stub_path.name} is not a valid stub!")
pass
else:
self.STUBS.append(stub)
self.log.debug(f"Added New Stub: {stub}")
Expand Down Expand Up @@ -93,10 +91,13 @@ def create_stubs(self, port):
self.log.success("Done!")
self.log.info("Downloading Stubs...")
stub_name = rsh.auto(
rsh.listdir_stat, f'{dev.name_path}/stubs', show_hidden=False)[0][0]
rsh.listdir_stat, f'{dev.name_path}/stubs',
show_hidden=False)[0][0]
with tempfile.TemporaryDirectory() as tmpdir:
rsh.rsync(f"{dev.name_path}/stubs", tmpdir, recursed=True, mirror=False,
dry_run=False, print_func=lambda *args: None, sync_hidden=False)
rsh.rsync(
f"{dev.name_path}/stubs", tmpdir, recursed=True, mirror=False,
dry_run=False, print_func=lambda * args: None,
sync_hidden=False)
stub_path = Path(tmpdir) / stub_name
self.add_stub(stub_path)
self.log.success("Done!")
Expand Down
6 changes: 4 additions & 2 deletions micropy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ def load_stubs(self):
vs_stubs = [f'"{s.path}"' for s in stubs]
self.log.info(f"Found $[{len(stubs)}] stubs, injecting...")
lint_stubs = prompt.checkbox(
"Which stubs would you like pylint to load?", choices=[str(i) for i in stubs]).ask()
"Which stubs would you like pylint to load?",
choices=[str(i) for i in stubs]).ask()
pylint_stubs = [
f'sys.path.insert(1,"{str(stub.path)}")' for stub in stubs if str(stub) in lint_stubs]
f'sys.path.insert(1,"{str(stub.path)}")' for stub in stubs
if str(stub) in lint_stubs]
vscode_sub = {
'stubs': ',\n'.join(vs_stubs)
}
Expand Down
8 changes: 5 additions & 3 deletions micropy/stubs/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import json
from pathlib import Path

from jsonschema import Draft7Validator, ValidationError
from jsonschema import Draft7Validator
from shutil import copytree

from micropy.logger import Log
from micropy.exceptions import StubError, StubValidationError
from micropy.exceptions import StubValidationError


class Stub:
Expand Down Expand Up @@ -70,7 +70,9 @@ def copy_to(self, dest):
return self

def __repr__(self):
return f"Stub(machine={self.machine}, nodename={self.nodename}, release={self.release}, sysname={self.sysname}, version={self.version}, modules={self.modules})"
return f"Stub(machine={self.machine}, nodename={self.nodename}, \
release={self.release}, sysname={self.sysname}, \
version={self.version}, modules={self.modules})"

def __str__(self):
return f"{self.sysname}@{self.version}"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ replace = __version__ = '{new_version}'
universal = 1

[flake8]
exclude = docs,micropy/lib
exclude = docs,micropy/lib,tests/data

[aliases]
test = pytest
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
import micropy
from pathlib import Path
import questionary


Expand Down
4 changes: 0 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-

import pytest
from micropy import main
from pathlib import Path
import os
import requests


def test_setup(mock_micropy_path):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_stubs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-

import pytest
from pathlib import Path
from micropy import stubs, exceptions
import json


def test_bad_stub(tmp_path):
Expand Down

0 comments on commit d2e0aed

Please sign in to comment.