summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2018-04-07 11:27:30 +0200
committerDennis Fink2018-04-07 11:27:30 +0200
commit91459e815de26e98e84b37e842295b332f10425f (patch)
tree7d49bcc3ec8e9b7543ca740d7c75838340842ed1
parentd1bccafa9399c74fd6814dff8d11c383078550f0 (diff)
downloadpatternutils-91459e815de26e98e84b37e842295b332f10425f.tar.gz
patternutils-91459e815de26e98e84b37e842295b332f10425f.zip
Add annotations
Diffstat (limited to '')
-rw-r--r--patternutils/commands/patterncfg.py14
-rw-r--r--patternutils/config.py9
-rw-r--r--patternutils/template.py14
3 files changed, 17 insertions, 20 deletions
diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py
index da90ead..e92ce7d 100644
--- a/patternutils/commands/patterncfg.py
+++ b/patternutils/commands/patterncfg.py
@@ -8,12 +8,12 @@ from .. import utils
@click.group(context_settings={'help_option_names': ('-h', '--help', '-?')})
-def patterncfg():
+def patterncfg() -> None:
pass
@patterncfg.command(name='list', help='list all patternutils template files')
-def list():
+def list() -> None:
for d in os.listdir(config.CONFIG_PATH):
click.secho(d, fg='blue')
for f in os.listdir(os.path.join(config.CONFIG_PATH, d)):
@@ -26,9 +26,9 @@ def list():
@click.argument('command', type=click.Choice(['pmatch', 'tmv', 'targs']))
@click.argument('name')
def add(
- file_type,
- command,
- name
+ file_type: str,
+ command: str,
+ name: str,
) -> None:
if command == 'pmatch':
fileext = 'regex'
@@ -44,7 +44,7 @@ def add(
@patterncfg.command(name='remove', help='remove template file')
@click.argument('command', type=click.Choice(['pmatch', 'tmv', 'targs']))
@click.argument('name')
-def remove(command, name):
+def remove(command: str, name: str) -> None:
files = config.find_templates(name, command)
try:
os.remove(files[0])
@@ -56,7 +56,7 @@ def remove(command, name):
@patterncfg.command(name='view', help='view template file')
@click.option('-p', '--program', default=None, type=click.Choice(['pmatch', 'tmv', 'targs']))
@click.argument('name')
-def view(name, program):
+def view(name: str, program: str) -> None:
if program is not None:
files = config.find_templates(name, program)
diff --git a/patternutils/config.py b/patternutils/config.py
index a8feb36..0daa4bc 100644
--- a/patternutils/config.py
+++ b/patternutils/config.py
@@ -34,12 +34,9 @@ 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: Union[str, None]) -> List[str]:
+def find_templates(template_name: str, command_name: str=None) -> List[str]:
template_glob = '.'.join((template_name, '*'))
- if command_name is None:
- command_glob = '*'
- else:
- command_glob = os.path.join(CONFIG_PATH, command_name)
-
+ 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 a40630b..2bd670c 100644
--- a/patternutils/template.py
+++ b/patternutils/template.py
@@ -1,4 +1,3 @@
-
from typing import Callable
try:
@@ -6,25 +5,26 @@ try:
except ImportError:
jinja_feature = False
else:
- import datetime
import shlex
+ from datetime import datetime
+
jinja_feature = True
jinja_env = jinja2.Environment()
- def to_datetime(value, format='%Y-%m-%d'):
+ def to_datetime(value: str, format: str='%Y-%m-%d') -> datetime:
return datetime.strptime(value, format)
- def format_datetime(value, format='%Y-%m-%d'):
+ def format_datetime(value: datetime, format: str='%Y-%m-%d') -> str:
return value.strftime(format)
- def to_int(value, base=10):
+ def to_int(value: str, base: int=10) -> int:
return int(value, base=base)
- def to_float(value):
+ def to_float(value: str) -> float:
return float(value)
- def quote(value):
+ def quote(value: str) -> str:
return shlex.quote(value)
jinja_env.filters['datetime'] = to_datetime