diff options
Diffstat (limited to '')
| -rw-r--r-- | patternutils/config.py | 7 | ||||
| -rw-r--r-- | patternutils/template.py | 8 |
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) |
