summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2019-08-24 19:13:15 +0200
committerDennis Fink2019-08-24 19:13:15 +0200
commitb12e201d9eb6ea3c14638408123207192541d082 (patch)
tree967bdc43cb738074609f78857b49db4b5a2b1ef7
parent76c994e470f7b781c1d1620b22f5cf2e56497732 (diff)
downloadpatternutils-b12e201d9eb6ea3c14638408123207192541d082.tar.gz
patternutils-b12e201d9eb6ea3c14638408123207192541d082.zip
Pep8
Diffstat (limited to '')
-rw-r--r--patternutils/config.py7
-rw-r--r--patternutils/template.py8
2 files changed, 7 insertions, 8 deletions
diff --git a/patternutils/config.py b/patternutils/config.py
index 016f7e2..2f9e8ce 100644
--- a/patternutils/config.py
+++ b/patternutils/config.py
@@ -10,7 +10,7 @@ CONFIG_PATH = click.get_app_dir('patternutils')
def load_template(template_name: str, command_name: str) -> Tuple[str, str]:
"""Load a template from the config directory."""
-
+
files = find_templates(template_name, command_name)
if len(files) == 1:
with open(files[0], encoding='utf-8') as f:
@@ -19,7 +19,7 @@ def load_template(template_name: str, command_name: str) -> Tuple[str, str]:
raise FileNotFoundError
elif len(files) > 1:
raise RuntimeError('Multiple files found!')
-
+
output_pattern = template_lines.replace('\n', '')
template_file = files[0]
if template_file.endswith('regex'):
@@ -31,8 +31,7 @@ def load_template(template_name: str, command_name: str) -> Tuple[str, str]:
return output_pattern, template_engine
-def find_templates(template_name: str, command_name: str=None) -> List[str]:
- template_glob = '.'.join((template_name, '*'))
+def find_templates(template_name: str, command_name: str = None) -> List[str]:
command_glob = '*' if command_name is None else command_name
command_glob = os.path.join(CONFIG_PATH, command_glob)
return glob.glob(os.path.join(command_glob, template_glob))
diff --git a/patternutils/template.py b/patternutils/template.py
index 2bd670c..a4cf794 100644
--- a/patternutils/template.py
+++ b/patternutils/template.py
@@ -12,13 +12,13 @@ else:
jinja_feature = True
jinja_env = jinja2.Environment()
- def to_datetime(value: str, format: str='%Y-%m-%d') -> datetime:
+ def to_datetime(value: str, format: str = '%Y-%m-%d') -> datetime:
return datetime.strptime(value, format)
- def format_datetime(value: datetime, format: str='%Y-%m-%d') -> str:
+ def format_datetime(value: datetime, format: str = '%Y-%m-%d') -> str:
return value.strftime(format)
- def to_int(value: str, base: int=10) -> int:
+ def to_int(value: str, base: int = 10) -> int:
return int(value, base=base)
def to_float(value: str) -> float:
@@ -34,7 +34,7 @@ else:
jinja_env.filters['quote'] = quote
-def get_render_function(template: str, *, engine: str='python') -> Callable[..., str]:
+def get_render_function(template: str, *, engine: str = 'python') -> Callable[..., str]:
if engine == 'jinja2':
if jinja_feature:
env_template = jinja_env.from_string(template)