Skip to content

Commit

Permalink
add black format checking to travis (#1)
Browse files Browse the repository at this point in the history
* add black format checking to travis

* Empty Commit to setup travis

* install black only in travis, and only in python3

* fix if statement, use quotes around python version

* try to install black during testing

* run black to appease travis

* black setup.py too

* black tests too..

* add note about black in README, update version
  • Loading branch information
tchoedak authored Jun 12, 2019
1 parent 7c41c0c commit 407a8d2
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 87 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: python
python:
- "2.7"
- "3.6"
install:
- pip install -r requirements.txt
- pip install document-your-code
# command to run tests
script:
- pytest
- pytest
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then pip install black; black --check --diff --skip-string-normalization .; fi
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ To get started.
$ pip install --editable .
```

We use [black](https://github.com/python/black) to maintain a standard format for our code. Contributions must be black formatted to pass CI.

## License

MIT ©
28 changes: 22 additions & 6 deletions dyc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self, filename, config, placeholders=False):
self.filename = filename
self.config = config
self.placeholders = placeholders

details = dict()

def initialize(self, change=None):
Expand All @@ -25,7 +25,16 @@ def initialize(self, change=None):
filename = fileinput.filename()
lineno = fileinput.lineno()
keywords = self.config.get('keywords')
found = len([word.lstrip() for word in line.split(' ') if word.lstrip() in keywords]) > 0
found = (
len(
[
word.lstrip()
for word in line.split(' ')
if word.lstrip() in keywords
]
)
> 0
)

if change and found:
found = self._is_line_part_of_patches(lineno, line, patches)
Expand All @@ -35,7 +44,9 @@ def initialize(self, change=None):

if found:
length = get_file_lines(filename)
result = self.extract_and_set_information(filename, lineno, line, length)
result = self.extract_and_set_information(
filename, lineno, line, length
)
if self.validate(result):
self.details[filename][result.name] = result

Expand Down Expand Up @@ -82,7 +93,7 @@ def apply(self):
pass


class FilesDirector():
class FilesDirector:

WILD_CARD = ['.', '*']

Expand Down Expand Up @@ -133,7 +144,7 @@ def set_files_to_read(self, files=[]):
self.file_list = result


class FormatsDirector():
class FormatsDirector:

formats = dict()

Expand All @@ -146,6 +157,7 @@ def prepare_formats(self):

class Processor(FilesDirector, FormatsDirector):
"""Subclass process that runs complete lifecycle for DYC"""

def start(self):
"""
TODO Method wrapper for starting the process
Expand All @@ -170,4 +182,8 @@ def extensions(self):
"""
Property that returns all the allowed extensions
"""
return list(filter(None, map(lambda fmt: fmt.get('extension'), self.config.get('formats'))))
return list(
filter(
None, map(lambda fmt: fmt.get('extension'), self.config.get('formats'))
)
)
7 changes: 5 additions & 2 deletions dyc/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
DEFAULT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'defaults.yaml')
CUSTOM = os.path.join(ROOT_PATH, 'dyc.yaml')


class Config(object):

default = read_yaml(DEFAULT)
Expand Down Expand Up @@ -36,8 +37,10 @@ def _override_formats(self):
cnf_index = self._get_custom_extension_index(extension)
try:
for nested_key, nested_obj in value.iteritems():
try:
self.plain.get('formats')[cnf_index][nested_key].update(**nested_obj) if nested_obj else None
try:
self.plain.get('formats')[cnf_index][nested_key].update(
**nested_obj
) if nested_obj else None
except AttributeError:
continue
except (IndexError, TypeError):
Expand Down
8 changes: 5 additions & 3 deletions dyc/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .base import Processor


class DiffParser():
class DiffParser:

PREFIX = 'diff --git'

Expand Down Expand Up @@ -89,7 +89,7 @@ def __pack(self, patch):
for index, line in enumerate(patch):
_hunk = get_hunk(line)

if (len(patch) -1) == index:
if (len(patch) - 1) == index:
final.append(dict(patch='\n'.join(result), hunk=(start, end)))

if len(_hunk) and not hit:
Expand All @@ -109,7 +109,9 @@ def __pack(self, patch):
def __clean(self, patch, diff):
"""Returns a clean dict of a path"""
result = {}
result['additions'] = self.__additions(self.__pack(patch.split('\n')), diff.a_path) # [{hunk: (start, end), patch:}]
result['additions'] = self.__additions(
self.__pack(patch.split('\n')), diff.a_path
) # [{hunk: (start, end), patch:}]
result['plain'] = patch
result['diff'] = diff
result['name'] = ntpath.basename(diff.a_path)
Expand Down
5 changes: 3 additions & 2 deletions dyc/dyc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def start(config, files, placeholders):
dyc.process_methods()



@main.command()
@click.option('--watch', help='Add default placeholder when watching', is_flag=True, default=False)
@click.option(
'--watch', help='Add default placeholder when watching', is_flag=True, default=False
)
@config
def diff(config, watch):
"""
Expand Down
15 changes: 12 additions & 3 deletions dyc/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .diff import Diff
from .main import DYC


class WatchEvent(LoggingEventHandler):

config = None
Expand All @@ -20,15 +21,23 @@ def dispatch(self, event):
"""
diff = Diff(self.config.plain)
uncommitted = diff.uncommitted
paths = [idx.get('path') for idx in uncommitted if './{}'.format(idx.get('path')) == event.src_path]
filtered = [idx for idx in uncommitted if './{}'.format(idx.get('path')) == event.src_path]
paths = [
idx.get('path')
for idx in uncommitted
if './{}'.format(idx.get('path')) == event.src_path
]
filtered = [
idx
for idx in uncommitted
if './{}'.format(idx.get('path')) == event.src_path
]
if len(filtered):
dyc = DYC(self.config.plain, placeholders=True)
dyc.prepare(files=paths)
dyc.process_methods(diff_only=True, changes=uncommitted)

class Watcher:

class Watcher:
@classmethod
def start(cls, config):
"""
Expand Down
40 changes: 32 additions & 8 deletions dyc/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
"""
All exception classes are defined here
"""
class DYCError(Exception): pass
class SetupError(DYCError): pass
class UndefinedPattern(DYCError): pass
class ConfigurationMissing(Exception): pass
class FormattingConfigurationHandler(ConfigurationMissing): pass
class QuitConfirmEditor(DYCError): pass
class DYCConfigurationSetup(DYCError): pass
class OverrideConfigurations(DYCError): pass


class DYCError(Exception):
pass


class SetupError(DYCError):
pass


class UndefinedPattern(DYCError):
pass


class ConfigurationMissing(Exception):
pass


class FormattingConfigurationHandler(ConfigurationMissing):
pass


class QuitConfirmEditor(DYCError):
pass


class DYCConfigurationSetup(DYCError):
pass


class OverrideConfigurations(DYCError):
pass
2 changes: 1 addition & 1 deletion dyc/hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
"""
"""
Loading

0 comments on commit 407a8d2

Please sign in to comment.