From 92a5d75aac02b10a2d13ab716fcb9bd00ae43b7e Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 26 Sep 2020 08:47:02 +0200 Subject: Isort --- patternutils/commands/patterncfg.py | 2 +- patternutils/template.py | 1 - patternutils/utils.py | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py index 83168cf..fa30e01 100644 --- a/patternutils/commands/patterncfg.py +++ b/patternutils/commands/patterncfg.py @@ -9,7 +9,7 @@ from .. import config try: from pygments import highlight from pygments.formatters import TerminalFormatter - from pygments.lexers import Python3Lexer, DjangoLexer + from pygments.lexers import DjangoLexer, Python3Lexer except ImportError: has_pygments = False else: diff --git a/patternutils/template.py b/patternutils/template.py index 53746a2..56bb0be 100644 --- a/patternutils/template.py +++ b/patternutils/template.py @@ -6,7 +6,6 @@ except ImportError: jinja_feature = False else: import shlex - from datetime import datetime jinja_feature = True diff --git a/patternutils/utils.py b/patternutils/utils.py index 266f3b9..a2decea 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -1,6 +1,6 @@ -import os import json -from typing import Dict, Any +import os +from typing import Any, Dict import click -- cgit v1.3.1 From fe3da4725160110b2b4ac969190161a29204ba7c Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 26 Sep 2020 15:19:23 +0200 Subject: Use assignment expressions where applicable --- patternutils/commands/tln.py | 3 +-- patternutils/match.py | 3 +-- patternutils/utils.py | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 295cda9..7dd09f9 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -8,8 +8,7 @@ from .. import config, template, utils def link_file(old_filename: str, new_filename: str, symbolic: bool) -> None: - dirs = os.path.dirname(new_filename) - if dirs: + if (dirs := os.path.dirname(new_filename)) : os.makedirs(dirs, exist_ok=True) if symbolic: diff --git a/patternutils/match.py b/patternutils/match.py index 80f9553..1387001 100644 --- a/patternutils/match.py +++ b/patternutils/match.py @@ -2,8 +2,7 @@ from typing import Dict, Pattern def apply(subject: str, regex_pattern: Pattern[str]) -> Dict[str, str]: - match = regex_pattern.search(subject) - if match is not None: + if (match := regex_pattern.search(subject)) is not None: groupdict = match.groupdict() groupdict["_subject"] = subject return groupdict diff --git a/patternutils/utils.py b/patternutils/utils.py index a2decea..41a113c 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -16,9 +16,8 @@ def edit(data: Dict[str, str]) -> Dict[str, str]: temporary = [ "{}\t{}\n".format(key.ljust(longest), value) for key, value in data.items() ] - edited = click.edit("".join(temporary)) - if edited is not None: + if (edited := click.edit("".join(temporary))) is not None: new_data = dict() for line in edited.split("\n"): if line and "\t" in line: -- cgit v1.3.1 From 9b80026a5bc0aa0504dfb46ef8a25e5204d5a86a Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 26 Sep 2020 15:20:49 +0200 Subject: Fix targs --- patternutils/commands/targs.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 04c286d..6478377 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -12,16 +12,11 @@ from .. import config, template, utils def run_command( - data: Dict[str, str], + command: str, run: Callable[..., None], shell: bool, ) -> None: - if not shell: - prepared_command = shlex.split(c) # type: Union[str, List[str]] - else: - prepared_command = c - - run(prepared_command) + run(shlex.split(command) if not shell else command) @click.command(context_settings={"help_option_names": ("-h", "--help", "-?")}) @@ -89,7 +84,7 @@ def targs( if not stream: data = json.load(read_from) # type: ignore else: - data = [json.loads(line) for line in read_from] + data = [json.loads(line) for line in read_from] # type: ignore except json.JSONDecodeError: click.secho("JSON not valid!", fg="red", err=True) raise SystemExit @@ -110,17 +105,15 @@ def targs( click.secho("jinja2 not installed!", fg="red", err=True) raise SystemExit - commands = [render(r) for r in data] + commands = {r: render(r) for r in data} if editor: try: commands = utils.edit(commands) - except RuntimeErro: + except RuntimeError: click.secho("Your edit is not parseable!", fg="red", err=True) raise SystemExit - max_procs = utils.max_procs() if max_procs == 0 else max_procs - stdout = subprocess.DEVNULL if redirect_stdout else None stderr = subprocess.DEVNULL if redirect_stderr else None patched_subprocess = functools.partial( @@ -134,12 +127,15 @@ def targs( run=patched_subprocess, shell=shell, ) + + max_procs = utils.max_procs() if max_procs == 0 else max_procs + if max_procs == 1: for r in commands: patched_run_command(r) else: with multiprocessing.Pool(max_procs) as p: - p.map(patched_run_command, commands) + p.map(patched_run_command, commands.values()) if __name__ == "__main__": -- cgit v1.3.1 From 7bea7b219b7ac44e637f359584b914aa112fa6d4 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 26 Sep 2020 15:21:04 +0200 Subject: Add type decorations --- patternutils/commands/patterncfg.py | 6 +++--- patternutils/commands/tln.py | 2 +- patternutils/commands/tmv.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py index fa30e01..0115ed2 100644 --- a/patternutils/commands/patterncfg.py +++ b/patternutils/commands/patterncfg.py @@ -7,9 +7,9 @@ import click from .. import config try: - from pygments import highlight - from pygments.formatters import TerminalFormatter - from pygments.lexers import DjangoLexer, Python3Lexer + from pygments import highlight # type: ignore + from pygments.formatters import TerminalFormatter # type: ignore + from pygments.lexers import DjangoLexer, Python3Lexer # type: ignore except ImportError: has_pygments = False else: diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 7dd09f9..8f2bd2e 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -106,7 +106,7 @@ def tln( if not stream: data = json.load(read_from) # type: ignore else: - data = [json.loads(line) for line in read_from] + data = [json.loads(line) for line in read_from] # type: ignore except json.JSONDecodeError: click.secho("JSON not valid!", fg="red", err=True) raise SystemExit diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 3e92342..4e93ff4 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -103,7 +103,7 @@ def tmv( if not stream: data = json.load(read_from) # type: ignore else: - data = [json.loads(line) for line in read_from] + data = [json.loads(line) for line in read_from] # type: ignore except json.JSONDecodeError: click.secho("JSON not valid!", fg="red", err=True) raise SystemExit -- cgit v1.3.1 From 3f42814544ba97d4b50a8fbb96fef6b5c3117987 Mon Sep 17 00:00:00 2001 From: metalgamer Date: Mon, 7 Dec 2020 20:46:11 +0100 Subject: Add prss --- patternutils/commands/prss.py | 91 +++++++++++++++++++++++++++++++++++++++++++ setup.py | 2 + 2 files changed, 93 insertions(+) create mode 100644 patternutils/commands/prss.py diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py new file mode 100644 index 0000000..814672e --- /dev/null +++ b/patternutils/commands/prss.py @@ -0,0 +1,91 @@ +import os +import os.path +from typing import Generator + +import click +import feedparser + +from .. import utils + + +def walk(dir: str) -> Generator[os.DirEntry, None, None]: + for entry in os.scandir(dir): + if entry.is_file(): + yield entry + else: + continue + + +@click.command(context_settings={"help_option_names": ("-h", "--help", "-?")}) +@click.option("-d", "--directory", default="./") +@click.option( + "--stream", + is_flag=True, + default=False, + help="Output a stream of objects instead a list of objects", +) +@click.option( + "--human-readable", + is_flag=True, + default=False, + help="output the JSON in a human readable format", +) +@click.option( + "-v", "--verbose", is_flag=True, default=False, help="explain what is being done" +) +@click.version_option() +@click.argument("url") +def prss( + url: str, directory: str, stream: bool, human_readable: bool, verbose: bool +) -> None: + + parsed_feed = feedparser.parse(url) + + default_values = { + "feed_title": parsed_feed.feed.title, + "feed_link": parsed_feed.feed.link, + "feed_description": parsed_feed.feed.description, + } + + files = [f for f in walk(directory)] + + matches = [] + + for entry in parsed_feed.entries: + + href = entry.enclosures[0]["href"] + + splitted_href = href.split("/") + + file_to_search = splitted_href[-1] + + try: + file_index = files.index(file_to_search) + except ValueError: + click.secho(f"{file_to_search} not found!", fg="red", err=True) + else: + filename = file_to_search[file_index] + entry_values = { + "title": entry.title, + "link": entry.link, + "description": entry.description, + "id": entry.id, + "enclosure_href": entry.enclosures[0]["href"], + "_path": filename.path, + "_name": filename.name, + "_abspath": os.path.abspath(f.path), + "_realpath": os.path.realpath(f.path), + "_relpath": os.path.relpath(f.path), + } + entry_values.update(default_values) + matches.append(entry_values) + + if stream: + for m in matches: + click.echo(utils.json_dumps(m, human_readable)) + else: + click.echo(utils.json_dumps(matches, human_readable)) + + +if __name__ == "__main__": + prss() diff --git a/setup.py b/setup.py index 95a892f..1cb4252 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ ENTRY_POINTS = { "tmv=patternutils.commands.tmv:tmv", "tln=patternutils.commands.tln:tln", "patterncfg=patternutils.commands.patterncfg:patterncfg", + "prss=patternutils.commands.prss:prss", ], } @@ -28,6 +29,7 @@ REQUIRED = [ OPTIONAL = { "jinja2": ["Jinja2==2.10.1"], "pygments": ["Pygments==2.4.2"], + "prss": ["feedparser==6.0.2"], } setup( -- cgit v1.3.1 From 95f47606d64db938901074fb4c011004c391e7e4 Mon Sep 17 00:00:00 2001 From: metalgamer Date: Mon, 7 Dec 2020 20:50:10 +0100 Subject: Black and Isort --- patternutils/commands/patterncfg.py | 2 +- patternutils/commands/pmatch.py | 4 +--- patternutils/commands/targs.py | 15 +++------------ patternutils/template.py | 1 - patternutils/utils.py | 4 ++-- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py index 83168cf..fa30e01 100644 --- a/patternutils/commands/patterncfg.py +++ b/patternutils/commands/patterncfg.py @@ -9,7 +9,7 @@ from .. import config try: from pygments import highlight from pygments.formatters import TerminalFormatter - from pygments.lexers import Python3Lexer, DjangoLexer + from pygments.lexers import DjangoLexer, Python3Lexer except ImportError: has_pygments = False else: diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py index 6bbd349..521aa9d 100644 --- a/patternutils/commands/pmatch.py +++ b/patternutils/commands/pmatch.py @@ -27,9 +27,7 @@ def walk( def apply_regex( - walk_function: Iterator[Any], - regex_pattern: Pattern[str], - match_full_path: bool, + walk_function: Iterator[Any], regex_pattern: Pattern[str], match_full_path: bool, ) -> Tuple[List[Dict[str, str]], bool]: matches = [] diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 04c286d..9fd0831 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -11,11 +11,7 @@ import click from .. import config, template, utils -def run_command( - data: Dict[str, str], - run: Callable[..., None], - shell: bool, -) -> None: +def run_command(data: Dict[str, str], run: Callable[..., None], shell: bool,) -> None: if not shell: prepared_command = shlex.split(c) # type: Union[str, List[str]] else: @@ -124,15 +120,10 @@ def targs( stdout = subprocess.DEVNULL if redirect_stdout else None stderr = subprocess.DEVNULL if redirect_stderr else None patched_subprocess = functools.partial( - subprocess.run, - shell=shell, - stdout=stdout, - stderr=stderr, + subprocess.run, shell=shell, stdout=stdout, stderr=stderr, ) patched_run_command = functools.partial( - run_command, - run=patched_subprocess, - shell=shell, + run_command, run=patched_subprocess, shell=shell, ) if max_procs == 1: for r in commands: diff --git a/patternutils/template.py b/patternutils/template.py index 53746a2..56bb0be 100644 --- a/patternutils/template.py +++ b/patternutils/template.py @@ -6,7 +6,6 @@ except ImportError: jinja_feature = False else: import shlex - from datetime import datetime jinja_feature = True diff --git a/patternutils/utils.py b/patternutils/utils.py index 266f3b9..a2decea 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -1,6 +1,6 @@ -import os import json -from typing import Dict, Any +import os +from typing import Any, Dict import click -- cgit v1.3.1 From 998231e994cf58c9bd5851eb4d8f39581a60f65b Mon Sep 17 00:00:00 2001 From: metalgamer Date: Mon, 7 Dec 2020 21:53:53 +0100 Subject: Fail with error message, if feedparser not found. --- patternutils/commands/prss.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index 814672e..cc81ee1 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -3,7 +3,11 @@ import os.path from typing import Generator import click -import feedparser + +try: + import feedparser +except ImportError: + click.secho("feedparser not installed!", fg="red", err=True) from .. import utils -- cgit v1.3.1 From aea0f7c6f80d1bd1bb7af5c36f6de707527b39b4 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 7 Dec 2020 21:58:25 +0100 Subject: Use f-string in utils --- patternutils/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/patternutils/utils.py b/patternutils/utils.py index 41a113c..7e2e9e9 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -13,9 +13,7 @@ def max_procs() -> int: def edit(data: Dict[str, str]) -> Dict[str, str]: longest = len(max(data, key=len)) - temporary = [ - "{}\t{}\n".format(key.ljust(longest), value) for key, value in data.items() - ] + temporary = [f"{key.ljust(longext)}\t{value}\n" for key, value in data.items()] if (edited := click.edit("".join(temporary))) is not None: new_data = dict() -- cgit v1.3.1 From f1d5ace414c61b77fbf72f7a76f5eb01b2cf8b36 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 7 Dec 2020 22:04:45 +0100 Subject: Update requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 01156a3..12a130f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Click==7.0 Jinja2==2.10.3 MarkupSafe==1.1.1 Pygments==2.4.2 +feedparser==6.0.2 -- cgit v1.3.1 From e025686a7b7643b48ae796514d0e11afc79ff806 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 7 Dec 2020 22:05:31 +0100 Subject: Update to v0.0.9 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1cb4252..a67f25f 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ URL = "https://projects.metalgamer.eu/patternutils" EMAIL = "dennis.fink@c3l.lu" AUTHOR = "Dennis Fink" -VERSION = "0.0.8" +VERSION = "0.0.9" ENTRY_POINTS = { "console_scripts": [ "pmatch=patternutils.commands.pmatch:pmatch", -- cgit v1.3.1 -- cgit v1.3.1 From 3b8e2b64a15761d55c8d4e837cf7e0ca779cf529 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 7 Dec 2020 22:28:50 +0100 Subject: Update PKGBUILD --- PKGBUILD/PKGBUILD | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PKGBUILD/PKGBUILD b/PKGBUILD/PKGBUILD index ca4fba9..13bda81 100644 --- a/PKGBUILD/PKGBUILD +++ b/PKGBUILD/PKGBUILD @@ -1,16 +1,16 @@ # Maintainer: Dennis Fink pkgname=patternutils -pkgver=0.0.8 -_pkghash=853b2c08d397 +pkgver=0.0.9 +_pkghash=47eaa7719f84 pkgrel=1 pkgdesc="Combine regular expressions with template engines in a powerful matter." arch=('any') url="https://projects.metalgamer.eu/patternutils" license=('GPL3') -depends=('python' 'python-click' 'python-jinja' 'python-pygments') -source=('patternutils-0.0.8.zip::https://projects.metalgamer.eu/patternutils/archive/853b2c08d397ad61442b8caf7d8cd4723a1dd04e.zip?subrepos=false') -sha512sums=('dc29e9403e260a04cbe986567a37ecd17bf2b335dbe99c3b274d5568252e22464b7bb52fd2e9dba459ac83d8f79eb39a832641f224fe0911522d60f6c0069a44') +depends=('python' 'python-click' 'python-jinja' 'python-pygments' 'python-feedparser') +source=('patternutils-0.0.9.zip::https://projects.metalgamer.eu/patternutils/archive/47eaa7719f848a015eff4a27300893a9e9c44e40.zip?subrepos=false') +sha512sums=('763cfe26d0d594dce4b3d7366b98990a0effcd94dd5487409f76ae6b7d82da6eeb7acb4dd46bc173fc979f217820460ddbd8a887b589aebeb649e0e051a61e0f') prepare() { sed -i 's/==/>=/g' "$srcdir/$pkgname-$_pkghash/setup.py" -- cgit v1.3.1 From 98d9e7afc805677d0fae4f0733d2417b8a158517 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 7 Dec 2020 22:29:03 +0100 Subject: Fix prss --- patternutils/commands/prss.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index cc81ee1..95e6a3c 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -51,7 +51,7 @@ def prss( "feed_description": parsed_feed.feed.description, } - files = [f for f in walk(directory)] + files = [f.name for f in walk(directory)] matches = [] @@ -68,18 +68,15 @@ def prss( except ValueError: click.secho(f"{file_to_search} not found!", fg="red", err=True) else: - filename = file_to_search[file_index] + filename = files[file_index] entry_values = { "title": entry.title, "link": entry.link, "description": entry.description, "id": entry.id, "enclosure_href": entry.enclosures[0]["href"], - "_path": filename.path, - "_name": filename.name, - "_abspath": os.path.abspath(f.path), - "_realpath": os.path.realpath(f.path), - "_relpath": os.path.relpath(f.path), + "_name": filename, + "_abspath": os.path.abspath(filename), } entry_values.update(default_values) matches.append(entry_values) -- cgit v1.3.1 From 84e57107394d33047bc2ab14ddba1d7fb2884f99 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 7 Dec 2020 22:29:12 +0100 Subject: Fix typo --- patternutils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/utils.py b/patternutils/utils.py index 7e2e9e9..b76acee 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -13,7 +13,7 @@ def max_procs() -> int: def edit(data: Dict[str, str]) -> Dict[str, str]: longest = len(max(data, key=len)) - temporary = [f"{key.ljust(longext)}\t{value}\n" for key, value in data.items()] + temporary = [f"{key.ljust(longest)}\t{value}\n" for key, value in data.items()] if (edited := click.edit("".join(temporary))) is not None: new_data = dict() -- cgit v1.3.1 From d922fcbe586ab069eb93b6e3b2221beebcd74b48 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Tue, 8 Dec 2020 00:44:30 +0100 Subject: Add more entries in prss --- patternutils/commands/prss.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index 95e6a3c..d23f67f 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -51,16 +51,19 @@ def prss( "feed_description": parsed_feed.feed.description, } - files = [f.name for f in walk(directory)] + direntries = [] + filenames = [] + + for f in walk(directory): + direntries.append(f) + filenames.append(f.name) matches = [] for entry in parsed_feed.entries: href = entry.enclosures[0]["href"] - splitted_href = href.split("/") - file_to_search = splitted_href[-1] try: @@ -69,14 +72,22 @@ def prss( click.secho(f"{file_to_search} not found!", fg="red", err=True) else: filename = files[file_index] + direntry = direntries[file_index] entry_values = { - "title": entry.title, - "link": entry.link, - "description": entry.description, - "id": entry.id, - "enclosure_href": entry.enclosures[0]["href"], + "title": entry.get("title", None), + "link": entry.get("link", None), + "description": entry.get("description", None), + "id": entry.get("id", None), + "enclosure_href": href, + "published": entry.get("published", None), + "subtitle": entry.get("subtitle", None), + "summary": entry.get("summary", None), + "author": entry.get("author", None), "_name": filename, - "_abspath": os.path.abspath(filename), + "_path": direntry.path, + "_abspath": os.path.abspath(direntry.path), + "_realpath": os.path.realpath(direntry.path), + "_relpath": os.path.relpath(direntry.path), } entry_values.update(default_values) matches.append(entry_values) -- cgit v1.3.1 From 9eed7e530e68a3faf810d0f00b173f507398eff3 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Tue, 8 Dec 2020 10:09:44 +0100 Subject: Fix prss and targs --- patternutils/commands/prss.py | 6 +++--- patternutils/commands/targs.py | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index d23f67f..1aff122 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -5,7 +5,7 @@ from typing import Generator import click try: - import feedparser + import feedparser # type: ignore except ImportError: click.secho("feedparser not installed!", fg="red", err=True) @@ -67,11 +67,11 @@ def prss( file_to_search = splitted_href[-1] try: - file_index = files.index(file_to_search) + file_index = filenames.index(file_to_search) except ValueError: click.secho(f"{file_to_search} not found!", fg="red", err=True) else: - filename = files[file_index] + filename = filenames[file_index] direntry = direntries[file_index] entry_values = { "title": entry.get("title", None), diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index bcd2e8e..6478377 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -11,7 +11,11 @@ import click from .. import config, template, utils -def run_command(data: Dict[str, str], run: Callable[..., None], shell: bool,) -> None: +def run_command( + command: str, + run: Callable[..., None], + shell: bool, +) -> None: run(shlex.split(command) if not shell else command) @@ -113,10 +117,15 @@ def targs( stdout = subprocess.DEVNULL if redirect_stdout else None stderr = subprocess.DEVNULL if redirect_stderr else None patched_subprocess = functools.partial( - subprocess.run, shell=shell, stdout=stdout, stderr=stderr, + subprocess.run, + shell=shell, + stdout=stdout, + stderr=stderr, ) patched_run_command = functools.partial( - run_command, run=patched_subprocess, shell=shell, + run_command, + run=patched_subprocess, + shell=shell, ) max_procs = utils.max_procs() if max_procs == 0 else max_procs -- cgit v1.3.1 From bce2523f06284a3d9ec04ae6089126d279534df3 Mon Sep 17 00:00:00 2001 From: metalgamer Date: Tue, 8 Dec 2020 17:08:14 +0100 Subject: Move walk function into utils --- patternutils/commands/pmatch.py | 19 ++----------------- patternutils/commands/prss.py | 12 +----------- patternutils/utils.py | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py index 521aa9d..18df269 100644 --- a/patternutils/commands/pmatch.py +++ b/patternutils/commands/pmatch.py @@ -1,10 +1,8 @@ import functools import itertools -import json -import os import os.path import re -from typing import Any, Dict, Generator, Iterator, List, Pattern, Tuple +from typing import Any, Dict, Iterator, List, Pattern, Tuple import click @@ -13,19 +11,6 @@ from .. import match as mat from .. import utils -def walk( - dir: str, recursive: bool = False, match_directories: bool = False -) -> Generator[os.DirEntry, None, None]: - for entry in os.scandir(dir): - is_dir = entry.is_dir() - if recursive and is_dir: - yield from walk(entry.path, recursive, match_directories) - elif entry.is_file() or (match_directories and is_dir): - yield entry - else: - continue - - def apply_regex( walk_function: Iterator[Any], regex_pattern: Pattern[str], match_full_path: bool, ) -> Tuple[List[Dict[str, str]], bool]: @@ -135,7 +120,7 @@ def pmatch( # Monkey patch walk function to include commandline options walk_function = functools.partial( - walk, recursive=recursive, match_directories=match_directories + utils.walk, recursive=recursive, match_directories=match_directories ) new_walk = itertools.chain.from_iterable(map(walk_function, directory)) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index 1aff122..b2a83fc 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -1,6 +1,4 @@ -import os import os.path -from typing import Generator import click @@ -12,14 +10,6 @@ except ImportError: from .. import utils -def walk(dir: str) -> Generator[os.DirEntry, None, None]: - for entry in os.scandir(dir): - if entry.is_file(): - yield entry - else: - continue - - @click.command(context_settings={"help_option_names": ("-h", "--help", "-?")}) @click.option("-d", "--directory", default="./") @click.option( @@ -54,7 +44,7 @@ def prss( direntries = [] filenames = [] - for f in walk(directory): + for f in utils.walk(directory, recursive=False, match_directories=False): direntries.append(f) filenames.append(f.name) diff --git a/patternutils/utils.py b/patternutils/utils.py index b76acee..9160cfe 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -1,6 +1,6 @@ import json import os -from typing import Any, Dict +from typing import Any, Dict, Generator import click @@ -34,3 +34,16 @@ def json_dumps(data: Any, humand_readable: bool = False) -> str: return json.dumps(data, indent=4, sort_keys=True) else: return json.dumps(data, separators=(",", ":")) + + +def walk( + directory: str, recursive: bool = False, match_directories: bool = False +) -> Generator[os.DirEntry, None, None]: + for entry in os.scandir(directory): + is_dir = entry.is_dir() + if recursive and is_dir: + yield from walk(entry.path, recursive, match_directories) + elif entry.is_file() or (match_directories and is_dir): + yield entry + else: + continue -- cgit v1.3.1 From aebc6c5fe48795a1e5bee5d90bebfd04c5ff780b Mon Sep 17 00:00:00 2001 From: metalgamer Date: Tue, 8 Dec 2020 17:08:40 +0100 Subject: Don't use separate dictionary for common values in prss --- patternutils/commands/prss.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index b2a83fc..fb429a3 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -35,12 +35,6 @@ def prss( parsed_feed = feedparser.parse(url) - default_values = { - "feed_title": parsed_feed.feed.title, - "feed_link": parsed_feed.feed.link, - "feed_description": parsed_feed.feed.description, - } - direntries = [] filenames = [] @@ -78,8 +72,10 @@ def prss( "_abspath": os.path.abspath(direntry.path), "_realpath": os.path.realpath(direntry.path), "_relpath": os.path.relpath(direntry.path), + "feed_title": parsed_feed.feed.get("title", None), + "feed_link": parsed_feed.feed.get("link", None), + "feed_description": parsed_feed.feed.get("description", None), } - entry_values.update(default_values) matches.append(entry_values) if stream: -- cgit v1.3.1 From 62bf049c9fa6684c6811f20dac0bc392ab53802b Mon Sep 17 00:00:00 2001 From: metalgamer Date: Tue, 8 Dec 2020 17:09:36 +0100 Subject: Updated hgignore --- .hgignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgignore b/.hgignore index fc3ed61..6f5bf8f 100644 --- a/.hgignore +++ b/.hgignore @@ -13,3 +13,4 @@ PKGBUILD/src/* PKGBUILD/*.zip PKGBUILD/.git/* PKGBUILD/.SRCINFO +venv/* -- cgit v1.3.1 From c133c11f5816134d95bbcd5bf794bf2b8c3feb97 Mon Sep 17 00:00:00 2001 From: metalgamer Date: Tue, 8 Dec 2020 17:13:15 +0100 Subject: Use config dict for json.dumps --- patternutils/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/patternutils/utils.py b/patternutils/utils.py index 9160cfe..d1ccacf 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -29,11 +29,11 @@ def edit(data: Dict[str, str]) -> Dict[str, str]: return data -def json_dumps(data: Any, humand_readable: bool = False) -> str: - if humand_readable: - return json.dumps(data, indent=4, sort_keys=True) - else: - return json.dumps(data, separators=(",", ":")) +def json_dumps(data: Any, human_readable: bool = False) -> str: + config = ( + {"indent": 4, sort_keys: True} if human_readable else {"separators": (",", ":")} + ) + return json.dumps(data, **config) def walk( -- cgit v1.3.1 From 1b251bc803fc8fa4051a9a084fd68db5b8dee2f1 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Tue, 8 Dec 2020 19:20:56 +0100 Subject: Updated hgignore --- .hgignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.hgignore b/.hgignore index 6f5bf8f..b22e97c 100644 --- a/.hgignore +++ b/.hgignore @@ -5,6 +5,7 @@ syntax: glob *.egg-info *.tar.xz *.tar.xz.sig +*.tar.zst build/* dist/* @@ -14,3 +15,4 @@ PKGBUILD/*.zip PKGBUILD/.git/* PKGBUILD/.SRCINFO venv/* +.mypy_cache/* -- cgit v1.3.1 From 877268f12a83770fe41011dd271a6d9e86421a7e Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 10 Dec 2020 22:36:02 +0100 Subject: Add type annotation to utils.py --- patternutils/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/patternutils/utils.py b/patternutils/utils.py index d1ccacf..14d7ddb 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -31,8 +31,10 @@ def edit(data: Dict[str, str]) -> Dict[str, str]: def json_dumps(data: Any, human_readable: bool = False) -> str: config = ( - {"indent": 4, sort_keys: True} if human_readable else {"separators": (",", ":")} - ) + {"indent": 4, "sort_keys": True} + if human_readable + else {"separators": (",", ":")} + ) # type: Dict[str, Any] return json.dumps(data, **config) -- cgit v1.3.1 From 664f424d76ef2134af9513ece11d08263cff4e24 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 10 Dec 2020 22:36:32 +0100 Subject: Add splitpath and splitext filter to jinja2 engine --- patternutils/template.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/patternutils/template.py b/patternutils/template.py index 56bb0be..8dbc650 100644 --- a/patternutils/template.py +++ b/patternutils/template.py @@ -1,10 +1,11 @@ -from typing import Callable +from typing import Callable, Tuple try: import jinja2 except ImportError: jinja_feature = False else: + import os.path import shlex from datetime import datetime @@ -26,11 +27,19 @@ else: def quote(value: str) -> str: return shlex.quote(value) + def splitpath(value: str) -> Tuple[str, str]: + return os.path.split(value) + + def splitext(value: str) -> Tuple[str, str]: + return os.path.splitext(value) + jinja_env.filters["datetime"] = to_datetime jinja_env.filters["datetimeformat"] = format_datetime jinja_env.filters["int"] = to_int jinja_env.filters["float"] = to_float jinja_env.filters["quote"] = quote + jinja_env.filters["splitpath"] = splitpath + jinja_env.filters["splitext"] = splitext def get_render_function(template: str, *, engine: str = "python") -> Callable[..., str]: -- cgit v1.3.1 From 5294f1da8bd63cc5fde737baa64ca6820eed2d90 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 10 Dec 2020 22:37:13 +0100 Subject: Actually exit if feedparser is not installed --- patternutils/commands/prss.py | 1 + 1 file changed, 1 insertion(+) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index fb429a3..ec97985 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -6,6 +6,7 @@ try: import feedparser # type: ignore except ImportError: click.secho("feedparser not installed!", fg="red", err=True) + raise SystemExit from .. import utils -- cgit v1.3.1 From 62cea5cbb2de5689a244f43888369b596a30be54 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 10 Dec 2020 22:39:33 +0100 Subject: Better error handling when loading feed --- patternutils/commands/prss.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index ec97985..79b9413 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -34,7 +34,16 @@ def prss( url: str, directory: str, stream: bool, human_readable: bool, verbose: bool ) -> None: - parsed_feed = feedparser.parse(url) + try: + parsed_feed = feedparser.parse(url) + except Exception: + click.secho("Reading feed failed!", fg="red", err=True) + raise SystemExit + else: + if not parsed_feed.version: + click.secho("Unsupported feed!", fg="red", err=True) + raise SystemExit + direntries = [] filenames = [] -- cgit v1.3.1 From 4bfd24d1d4cb28f63134f7ab6525c694fcf4a69a Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 10 Dec 2020 22:40:22 +0100 Subject: Add recursive option to prss and allow specific multiple directories --- patternutils/commands/prss.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index 79b9413..2efdfae 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -1,3 +1,5 @@ +import functools +import itertools import os.path import click @@ -12,7 +14,14 @@ from .. import utils @click.command(context_settings={"help_option_names": ("-h", "--help", "-?")}) -@click.option("-d", "--directory", default="./") +@click.option("-d", "--directory", multiple=True, default=["./"]) +@click.option( + "-r", + "--recursive", + is_flag=True, + default=False, + help="search directories recursively", +) @click.option( "--stream", is_flag=True, @@ -31,7 +40,12 @@ from .. import utils @click.version_option() @click.argument("url") def prss( - url: str, directory: str, stream: bool, human_readable: bool, verbose: bool + url: str, + directory: str, + recursive: bool, + stream: bool, + human_readable: bool, + verbose: bool, ) -> None: try: @@ -44,11 +58,15 @@ def prss( click.secho("Unsupported feed!", fg="red", err=True) raise SystemExit + # Mokey patch walk function to include commandline options + walk_function = functools.partial( + utils.walk, recursive=recursive, matchdirectories=False + ) direntries = [] filenames = [] - for f in utils.walk(directory, recursive=False, match_directories=False): + for f in itertools.chain.from_iterable(map(walk_function, directory)): direntries.append(f) filenames.append(f.name) @@ -59,7 +77,6 @@ def prss( href = entry.enclosures[0]["href"] splitted_href = href.split("/") file_to_search = splitted_href[-1] - try: file_index = filenames.index(file_to_search) except ValueError: -- cgit v1.3.1 From 5e2419ccc5a10dad4476037d16f91fe73a49aa98 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 10 Dec 2020 22:40:57 +0100 Subject: Add abort-on-no-file option to prss --- patternutils/commands/prss.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index 2efdfae..bdf35a4 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -22,6 +22,12 @@ from .. import utils default=False, help="search directories recursively", ) +@click.option( + "--abort-on-no-file", + is_flag=True, + default=False, + help="exit if a file can not be found", +) @click.option( "--stream", is_flag=True, @@ -43,6 +49,7 @@ def prss( url: str, directory: str, recursive: bool, + abort_on_no_file: bool, stream: bool, human_readable: bool, verbose: bool, @@ -72,6 +79,7 @@ def prss( matches = [] + has_no_file = False for entry in parsed_feed.entries: href = entry.enclosures[0]["href"] @@ -81,6 +89,7 @@ def prss( file_index = filenames.index(file_to_search) except ValueError: click.secho(f"{file_to_search} not found!", fg="red", err=True) + has_no_file = True else: filename = filenames[file_index] direntry = direntries[file_index] @@ -105,6 +114,9 @@ def prss( } matches.append(entry_values) + if abort_on_no_file and has_no_file: + raise SystemExit + if stream: for m in matches: click.echo(utils.json_dumps(m, human_readable)) -- cgit v1.3.1 From e4e18a777b3010698bea9884a5416960154778eb Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 10 Dec 2020 23:15:41 +0100 Subject: Updated version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a67f25f..3c09295 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ URL = "https://projects.metalgamer.eu/patternutils" EMAIL = "dennis.fink@c3l.lu" AUTHOR = "Dennis Fink" -VERSION = "0.0.9" +VERSION = "0.0.10" ENTRY_POINTS = { "console_scripts": [ "pmatch=patternutils.commands.pmatch:pmatch", -- cgit v1.3.1 -- cgit v1.3.1 From 93d9203a81075d9dc35d5377e881993d69afc282 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 11 Dec 2020 11:59:39 +0100 Subject: Update PKGBUILD --- PKGBUILD/PKGBUILD | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PKGBUILD/PKGBUILD b/PKGBUILD/PKGBUILD index 13bda81..04e4a78 100644 --- a/PKGBUILD/PKGBUILD +++ b/PKGBUILD/PKGBUILD @@ -1,16 +1,16 @@ # Maintainer: Dennis Fink pkgname=patternutils -pkgver=0.0.9 -_pkghash=47eaa7719f84 +pkgver=0.0.10 +_pkghash=f33c951669cd pkgrel=1 pkgdesc="Combine regular expressions with template engines in a powerful matter." arch=('any') url="https://projects.metalgamer.eu/patternutils" license=('GPL3') depends=('python' 'python-click' 'python-jinja' 'python-pygments' 'python-feedparser') -source=('patternutils-0.0.9.zip::https://projects.metalgamer.eu/patternutils/archive/47eaa7719f848a015eff4a27300893a9e9c44e40.zip?subrepos=false') -sha512sums=('763cfe26d0d594dce4b3d7366b98990a0effcd94dd5487409f76ae6b7d82da6eeb7acb4dd46bc173fc979f217820460ddbd8a887b589aebeb649e0e051a61e0f') +source=('patternutils-0.0.10.zip::https://projects.metalgamer.eu/patternutils/archive/f33c951669cd51e527ec5e817cceb74a24400ab2.zip?subrepos=false') +sha512sums=('bfde728083917191bfd740456113f4b7c2c1cf25107bc3bc60e5d7705686b102a59a3fb28d68f3799d9026dda2da0194c9f59424148370fc4d947228a76e4616') prepare() { sed -i 's/==/>=/g' "$srcdir/$pkgname-$_pkghash/setup.py" -- cgit v1.3.1 From 544fa972523de559446db8c5daf54d71d5a8d603 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 11 Dec 2020 13:58:14 +0100 Subject: Implement real streaming in prss and pmatch --- patternutils/commands/pmatch.py | 38 ++++++++------- patternutils/commands/prss.py | 104 +++++++++++++++++++++++----------------- 2 files changed, 79 insertions(+), 63 deletions(-) diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py index 18df269..00c16e9 100644 --- a/patternutils/commands/pmatch.py +++ b/patternutils/commands/pmatch.py @@ -2,7 +2,7 @@ import functools import itertools import os.path import re -from typing import Any, Dict, Iterator, List, Pattern, Tuple +from typing import Any, Dict, Generator, Iterator, List, Optional, Pattern import click @@ -12,27 +12,25 @@ from .. import utils def apply_regex( - walk_function: Iterator[Any], regex_pattern: Pattern[str], match_full_path: bool, -) -> Tuple[List[Dict[str, str]], bool]: + walk_function: Iterator[Any], + regex_pattern: Pattern[str], + match_full_path: bool, +) -> Generator[Optional[Dict[str, str]], None, None]: - matches = [] - has_invalid_matches = False for f in walk_function: subject = f.path if match_full_path else f.name try: match = mat.apply(subject, regex_pattern) except ValueError: click.secho(f"{subject} did not match", fg="red", err=True) - has_invalid_matches = True + yield None else: match["_path"] = f.path match["_name"] = f.name match["_abspath"] = os.path.abspath(f.path) match["_realpath"] = os.path.realpath(f.path) match["_relpath"] = os.path.relpath(f.path) - matches.append(match) - - return matches, has_invalid_matches + yield match @click.command(context_settings={"help_option_names": ("-h", "--help", "-?")}) @@ -124,18 +122,22 @@ def pmatch( ) new_walk = itertools.chain.from_iterable(map(walk_function, directory)) - matches, has_invalid_matches = apply_regex( - new_walk, regex_pattern_c, match_full_path - ) + has_invalid_matches = False + matches = [] + for match in apply_regex(new_walk, regex_pattern_c, match_full_path): + if match is None: + has_invalid_matches = True + if stream and abort_on_no_match: + raise SystemExit + else: + if stream: + click.echo(utils.json_dumps(match, human_readable)) + else: + matches.append(match) if has_invalid_matches and abort_on_no_match: raise SystemExit - - if stream: - for m in matches: - click.echo(utils.json_dumps(m, human_readable)) - else: - click.echo(utils.json_dumps(matches, human_readable)) + click.echo(utils.json_dumps(matches, human_readable)) if __name__ == "__main__": diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index bdf35a4..cd3f820 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -1,6 +1,8 @@ import functools import itertools +import os import os.path +from typing import Any, Dict, Generator, Iterator, List, Optional import click @@ -13,6 +15,53 @@ except ImportError: from .. import utils +def match( + parsed_feed: feedparser.util.FeedParserDict, + walk_function: functools.partial[Generator[os.DirEntry[Any], None, None]], + directory: List[str], +) -> Generator[Optional[Dict[str, str]], None, None]: + + direntries = [] + filenames = [] + + for f in itertools.chain.from_iterable(map(walk_function, directory)): + direntries.append(f) + filenames.append(f.name) + + for entry in parsed_feed.entries: + href = entry.enclosures[0]["href"] + splitted_href = href.split("/") + file_to_search = splitted_href[-1] + try: + file_index = filenames.index(file_to_search) + except ValueError: + click.secho(f"{file_to_search} not found!", fg="red", err=True) + yield None + else: + filename = filenames[file_index] + direntry = direntries[file_index] + entry_values = { + "title": entry.get("title", None), + "link": entry.get("link", None), + "description": entry.get("description", None), + "id": entry.get("id", None), + "enclosure_href": href, + "published": entry.get("published", None), + "subtitle": entry.get("subtitle", None), + "summary": entry.get("summary", None), + "author": entry.get("author", None), + "_name": filename, + "_path": direntry.path, + "_abspath": os.path.abspath(direntry.path), + "_realpath": os.path.realpath(direntry.path), + "_relpath": os.path.relpath(direntry.path), + "feed_title": parsed_feed.feed.get("title", None), + "feed_link": parsed_feed.feed.get("link", None), + "feed_description": parsed_feed.feed.get("description", None), + } + yield entry_values + + @click.command(context_settings={"help_option_names": ("-h", "--help", "-?")}) @click.option("-d", "--directory", multiple=True, default=["./"]) @click.option( @@ -47,7 +96,7 @@ from .. import utils @click.argument("url") def prss( url: str, - directory: str, + directory: List[str], recursive: bool, abort_on_no_file: bool, stream: bool, @@ -70,58 +119,23 @@ def prss( utils.walk, recursive=recursive, matchdirectories=False ) - direntries = [] - filenames = [] - - for f in itertools.chain.from_iterable(map(walk_function, directory)): - direntries.append(f) - filenames.append(f.name) - matches = [] - has_no_file = False - for entry in parsed_feed.entries: - - href = entry.enclosures[0]["href"] - splitted_href = href.split("/") - file_to_search = splitted_href[-1] - try: - file_index = filenames.index(file_to_search) - except ValueError: - click.secho(f"{file_to_search} not found!", fg="red", err=True) + for m in match(parsed_feed, walk_function, directory): + if m is None: has_no_file = True + if abort_on_no_file and stream: + raise SystemExit else: - filename = filenames[file_index] - direntry = direntries[file_index] - entry_values = { - "title": entry.get("title", None), - "link": entry.get("link", None), - "description": entry.get("description", None), - "id": entry.get("id", None), - "enclosure_href": href, - "published": entry.get("published", None), - "subtitle": entry.get("subtitle", None), - "summary": entry.get("summary", None), - "author": entry.get("author", None), - "_name": filename, - "_path": direntry.path, - "_abspath": os.path.abspath(direntry.path), - "_realpath": os.path.realpath(direntry.path), - "_relpath": os.path.relpath(direntry.path), - "feed_title": parsed_feed.feed.get("title", None), - "feed_link": parsed_feed.feed.get("link", None), - "feed_description": parsed_feed.feed.get("description", None), - } - matches.append(entry_values) + if stream: + click.echo(utils.json_dumps(m, human_readable)) + else: + matches.append(m) if abort_on_no_file and has_no_file: raise SystemExit - if stream: - for m in matches: - click.echo(utils.json_dumps(m, human_readable)) - else: - click.echo(utils.json_dumps(matches, human_readable)) + click.echo(utils.json_dumps(matches, human_readable)) if __name__ == "__main__": -- cgit v1.3.1 From 36235072c2dff0b8148132b4f688fe559c4ad861 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 11 Dec 2020 13:58:22 +0100 Subject: Fix tln --- patternutils/commands/tln.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 8f2bd2e..51e60c0 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -97,8 +97,7 @@ def tln( key: str, stream: bool, abort_on_path_exist: bool, - dry_run, - bool, + dry_run: bool, verbose: bool, ) -> None: -- cgit v1.3.1 From a1e5594b9c663fa91d47a8a571f895be6177e3f5 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 11 Dec 2020 14:01:58 +0100 Subject: Add type parameter to annotation --- patternutils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/utils.py b/patternutils/utils.py index 14d7ddb..17e7909 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -40,7 +40,7 @@ def json_dumps(data: Any, human_readable: bool = False) -> str: def walk( directory: str, recursive: bool = False, match_directories: bool = False -) -> Generator[os.DirEntry, None, None]: +) -> Generator[os.DirEntry[Any], None, None]: for entry in os.scandir(directory): is_dir = entry.is_dir() if recursive and is_dir: -- cgit v1.3.1 From 0c850a932edd0dba9fe8c101cd99b5fd4f530409 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 11 Dec 2020 14:02:15 +0100 Subject: Remove unused type: ignore comment --- patternutils/commands/pmatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py index 00c16e9..8a2e89f 100644 --- a/patternutils/commands/pmatch.py +++ b/patternutils/commands/pmatch.py @@ -113,7 +113,7 @@ def pmatch( except re.error as e: if verbose: click.secho("Regular expression could not be compiled!", fg="red", err=True) - click.secho(e.msg, fg="red", err=True) # type: ignore + click.secho(e.msg, fg="red", err=True) raise SystemExit # Monkey patch walk function to include commandline options -- cgit v1.3.1 From ae61c220f02501d8a8ab383a211f38b65e8341b8 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 15:41:40 +0100 Subject: Fix prss --- patternutils/commands/prss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index cd3f820..6c7d88b 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -116,7 +116,7 @@ def prss( # Mokey patch walk function to include commandline options walk_function = functools.partial( - utils.walk, recursive=recursive, matchdirectories=False + utils.walk, recursive=recursive, match_directories=False ) matches = [] -- cgit v1.3.1 From e2726f2fca079516996c5ca65f4e9cc2e97c6595 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 15:41:50 +0100 Subject: Fix typo in tln --- patternutils/commands/tln.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 51e60c0..b70ce32 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -134,7 +134,7 @@ def tln( try: new_filenames = utils.edit(new_filenames) except RuntimeError: - click.secho("You edit is not parseable!", fg="red", err=True) + click.secho("Your edit is not parseable!", fg="red", err=True) raise SystemExit has_existing = False -- cgit v1.3.1 From 88057fc82b7fcc5148526eb3685f3ee0e785740e Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 15:42:09 +0100 Subject: Add json_loads to utils --- patternutils/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/patternutils/utils.py b/patternutils/utils.py index 17e7909..5a33127 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -38,6 +38,14 @@ def json_dumps(data: Any, human_readable: bool = False) -> str: return json.dumps(data, **config) +def json_loads(data: Any) -> Any: + try: + return json.loads(data) + except json.JSONDecodeError: + click.secho("JSON not valid!", fg="red", err=True) + raise SystemExit + + def walk( directory: str, recursive: bool = False, match_directories: bool = False ) -> Generator[os.DirEntry[Any], None, None]: -- cgit v1.3.1 From 0748d7011016d42c6968eb70c24a6630203b93c2 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 15:42:20 +0100 Subject: Added pjson --- patternutils/commands/pjson.py | 111 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 patternutils/commands/pjson.py diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py new file mode 100644 index 0000000..d114d4c --- /dev/null +++ b/patternutils/commands/pjson.py @@ -0,0 +1,111 @@ +import json +import re +from typing import Any, Dict, Pattern + +import click + +from .. import match as mat +from .. import utils + + +def apply_regex( + data: Dict[str, str], key: str, regex_pattern: Pattern[str] +) -> Dict[str, str]: + try: + subject = data[key] + except KeyError: + click.secho(f"{key} can not be found in data!", fg="red", err=True) + raise + + try: + match = mat.apply(data[key], regex_pattern) + except ValueError: + click.secho(f"{subject} did not match", fg="red", err=True) + raise + else: + return match + + +@click.command(context_settings={"help_option_names": ("-h", "--help", "-?")}) +@click.option("--read-from", default="-", type=click.File("r")) +@click.option( + "--stream", + is_flag=True, + default=False, + help="Input is a stream of JSON objects and output will also be a stream of JSON objects", +) +@click.option( + "--abort-on-no-key", + is_flag=True, + default=False, + help="exit if a key does not exist", +) +@click.option( + "--abort-on-no-match", + is_flag=True, + default=False, + help="exit if a value does not match the REGEX_PATTERN", +) +@click.option( + "--human-readable", + is_flag=True, + default=False, + help="output the JSON in a human readable format", +) +@click.option( + "-v", "--verbose", is_flag=True, default=False, help="explain what is being done" +) +@click.version_option() +@click.argument("key") +@click.argument("regex-pattern") +def pjson( + key: str, + regex_pattern: str, + read_from: click.File, + stream: bool, + abort_on_no_key: bool, + abort_on_no_match: bool, + human_readable: bool, + verbose: bool, +) -> None: + + try: + regex_pattern_c = re.compile(regex_pattern) + except re.error as e: + if verbose: + click.secho("Regular expression could not be compiled!", fg="red", err=True) + click.secho(e.msg, fg="red", err=True) + raise SystemExit + + has_no_key = False + has_no_match = False + + if stream: + data = map(utils.json_loads, read_from) # type: ignore + else: + data = utils.json_loads(read_from) + + matches = [] + + for line in data: + try: + match = apply_regex(line, key, regex_pattern_c) + except KeyError: + has_no_key = True + if stream and abort_on_no_key: + raise SystemExit + except ValueError: + has_no_match = True + if stream and abort_on_no_match: + raise SystemExit + else: + line.update(match) + if stream: + click.echo(utils.json_dumps(line, human_readable)) + else: + matches.append(line) + + if (abort_on_no_key and has_no_key) or (abort_on_no_match and has_no_match): + raise SystemExit + + click.echo(utils.json_dumps(matches, human_readable)) -- cgit v1.3.1 From 9939e88e16c95526c6a61db45fb0a1a31568a8a0 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 15:45:38 +0100 Subject: Use utils.json_loads in tmv, targs and tln --- patternutils/commands/targs.py | 12 ++++-------- patternutils/commands/tln.py | 12 ++++-------- patternutils/commands/tmv.py | 12 ++++-------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 6478377..5c5a063 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -80,14 +80,10 @@ def targs( verbose: bool, ) -> None: - try: - if not stream: - data = json.load(read_from) # type: ignore - else: - data = [json.loads(line) for line in read_from] # type: ignore - except json.JSONDecodeError: - click.secho("JSON not valid!", fg="red", err=True) - raise SystemExit + if stream: + data = map(utils.json_loads, read_from) + else: + data = utils.json_loads(read_from) if use_predefined_template: try: diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index b70ce32..0dec44b 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -101,14 +101,10 @@ def tln( verbose: bool, ) -> None: - try: - if not stream: - data = json.load(read_from) # type: ignore - else: - data = [json.loads(line) for line in read_from] # type: ignore - except json.JSONDecodeError: - click.secho("JSON not valid!", fg="red", err=True) - raise SystemExit + if stream: + data = map(utils.json_loads, read_from) + else: + data = utils.json_loads(read_from) if use_predefined_template: try: diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 4e93ff4..1f39cc0 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -99,14 +99,10 @@ def tmv( the templating engine to generate the new filename. """ - try: - if not stream: - data = json.load(read_from) # type: ignore - else: - data = [json.loads(line) for line in read_from] # type: ignore - except json.JSONDecodeError: - click.secho("JSON not valid!", fg="red", err=True) - raise SystemExit + if stream: + data = map(utils.json_loads, read_from) + else: + data = utils.json_loads(read_from) if use_predefined_template: try: -- cgit v1.3.1 From 33d280bd59fc29be4e077964cbb54d0fd7c9eb24 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 17:02:25 +0100 Subject: Fix json read if input is not a stream --- patternutils/commands/pjson.py | 2 +- patternutils/commands/targs.py | 2 +- patternutils/commands/tln.py | 2 +- patternutils/commands/tmv.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py index d114d4c..a7bf069 100644 --- a/patternutils/commands/pjson.py +++ b/patternutils/commands/pjson.py @@ -83,7 +83,7 @@ def pjson( if stream: data = map(utils.json_loads, read_from) # type: ignore else: - data = utils.json_loads(read_from) + data = utils.json_loads(read_from.read()) matches = [] diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 5c5a063..ae8b74d 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -83,7 +83,7 @@ def targs( if stream: data = map(utils.json_loads, read_from) else: - data = utils.json_loads(read_from) + data = utils.json_loads(read_from.read()) if use_predefined_template: try: diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 0dec44b..509f4ad 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -104,7 +104,7 @@ def tln( if stream: data = map(utils.json_loads, read_from) else: - data = utils.json_loads(read_from) + data = utils.json_loads(read_from.read()) if use_predefined_template: try: diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 1f39cc0..5ae2582 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -102,7 +102,7 @@ def tmv( if stream: data = map(utils.json_loads, read_from) else: - data = utils.json_loads(read_from) + data = utils.json_loads(read_from.read()) if use_predefined_template: try: -- cgit v1.3.1 From c3c714ae285cd42b0c7a2e102c590f316fcca835 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 17:02:52 +0100 Subject: Fix stream in pjson, pmatch and prss --- patternutils/commands/pjson.py | 7 ++++--- patternutils/commands/pmatch.py | 7 ++++--- patternutils/commands/prss.py | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py index a7bf069..66a626f 100644 --- a/patternutils/commands/pjson.py +++ b/patternutils/commands/pjson.py @@ -105,7 +105,8 @@ def pjson( else: matches.append(line) - if (abort_on_no_key and has_no_key) or (abort_on_no_match and has_no_match): - raise SystemExit + if not stream: + if (abort_on_no_key and has_no_key) or (abort_on_no_match and has_no_match): + raise SystemExit - click.echo(utils.json_dumps(matches, human_readable)) + click.echo(utils.json_dumps(matches, human_readable)) diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py index 8a2e89f..c217c36 100644 --- a/patternutils/commands/pmatch.py +++ b/patternutils/commands/pmatch.py @@ -135,9 +135,10 @@ def pmatch( else: matches.append(match) - if has_invalid_matches and abort_on_no_match: - raise SystemExit - click.echo(utils.json_dumps(matches, human_readable)) + if not stream: + if has_invalid_matches and abort_on_no_match: + raise SystemExit + click.echo(utils.json_dumps(matches, human_readable)) if __name__ == "__main__": diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index 6c7d88b..a176587 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -132,10 +132,11 @@ def prss( else: matches.append(m) - if abort_on_no_file and has_no_file: - raise SystemExit + if not stream: + if abort_on_no_file and has_no_file: + raise SystemExit - click.echo(utils.json_dumps(matches, human_readable)) + click.echo(utils.json_dumps(matches, human_readable)) if __name__ == "__main__": -- cgit v1.3.1 From c6d55b5aa7b855a850d2e9482406bf46f1508a0e Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 12 Dec 2020 17:06:40 +0100 Subject: Add --abort-on-empty-input to pjson --- patternutils/commands/pjson.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py index 66a626f..a6373ac 100644 --- a/patternutils/commands/pjson.py +++ b/patternutils/commands/pjson.py @@ -46,6 +46,12 @@ def apply_regex( default=False, help="exit if a value does not match the REGEX_PATTERN", ) +@click.option( + "--abort-on-empty-data", + is_flag=True, + default=False, + help="exit if the data is empty", +) @click.option( "--human-readable", is_flag=True, @@ -65,6 +71,7 @@ def pjson( stream: bool, abort_on_no_key: bool, abort_on_no_match: bool, + abort_on_empty_data: bool, human_readable: bool, verbose: bool, ) -> None: @@ -88,6 +95,13 @@ def pjson( matches = [] for line in data: + if not line: + if abort_on_empty_data: + click.echo(f"{line} has no input.", fg="red", err=True) + raise SystemExit + else: + continue + try: match = apply_regex(line, key, regex_pattern_c) except KeyError: -- cgit v1.3.1 From ddd741a0c78a7857446c747ed21442e9db862fa0 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 23 Jan 2021 21:20:50 +0100 Subject: Fix editor for targs --- patternutils/commands/pjson.py | 23 ++++++++++++++--------- patternutils/commands/targs.py | 2 +- patternutils/utils.py | 10 +++++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py index a6373ac..73786a4 100644 --- a/patternutils/commands/pjson.py +++ b/patternutils/commands/pjson.py @@ -84,23 +84,24 @@ def pjson( click.secho(e.msg, fg="red", err=True) raise SystemExit - has_no_key = False - has_no_match = False - if stream: data = map(utils.json_loads, read_from) # type: ignore else: - data = utils.json_loads(read_from.read()) + data = utils.json_loads(read_from.read()) # type: ignore matches = [] + has_no_key = False + has_no_match = False + has_empty_data = False for line in data: + if not line: - if abort_on_empty_data: - click.echo(f"{line} has no input.", fg="red", err=True) + has_empty_data = True + click.secho(f"{line} has no input.", fg="red", err=True) + if stream and abort_on_empty_data: raise SystemExit - else: - continue + continue try: match = apply_regex(line, key, regex_pattern_c) @@ -120,7 +121,11 @@ def pjson( matches.append(line) if not stream: - if (abort_on_no_key and has_no_key) or (abort_on_no_match and has_no_match): + if ( + (abort_on_no_key and has_no_key) + or (abort_on_no_match and has_no_match) + or (abort_on_empty_data and has_empty_data) + ): raise SystemExit click.echo(utils.json_dumps(matches, human_readable)) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index ae8b74d..b262149 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -101,7 +101,7 @@ def targs( click.secho("jinja2 not installed!", fg="red", err=True) raise SystemExit - commands = {r: render(r) for r in data} + commands = [render(r) for r in data] if editor: try: diff --git a/patternutils/utils.py b/patternutils/utils.py index 5a33127..ae8a5fa 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -1,6 +1,6 @@ import json import os -from typing import Any, Dict, Generator +from typing import Any, Dict, Generator, List, Union import click @@ -10,10 +10,14 @@ def max_procs() -> int: return 1 if cpu_count is None else cpu_count * 2 -def edit(data: Dict[str, str]) -> Dict[str, str]: +def edit(data: Union[Dict[str, str], List[str]]) -> Dict[str, str]: longest = len(max(data, key=len)) - temporary = [f"{key.ljust(longest)}\t{value}\n" for key, value in data.items()] + + if isinstance(data, dict): + temporary = [f"{key.ljust(longest)}\t{value}\n" for key, value in data.items()] + else: + temporary = [f"{value.ljust(longest)}\t{value}\n" for value in data] if (edited := click.edit("".join(temporary))) is not None: new_data = dict() -- cgit v1.3.1 From f07018175a1d4b4b3c9285b9452ae9cb0515c6b4 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 23 Jan 2021 21:21:06 +0100 Subject: Add type annotations --- patternutils/commands/targs.py | 4 ++-- patternutils/commands/tln.py | 4 ++-- patternutils/commands/tmv.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index b262149..5ca8d04 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -81,9 +81,9 @@ def targs( ) -> None: if stream: - data = map(utils.json_loads, read_from) + data = map(utils.json_loads, read_from) # type: ignore else: - data = utils.json_loads(read_from.read()) + data = utils.json_loads(read_from.read()) # type: ignore if use_predefined_template: try: diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 509f4ad..b0476b2 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -102,9 +102,9 @@ def tln( ) -> None: if stream: - data = map(utils.json_loads, read_from) + data = map(utils.json_loads, read_from) # type: ignore else: - data = utils.json_loads(read_from.read()) + data = utils.json_loads(read_from.read()) # type: ignore if use_predefined_template: try: diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 5ae2582..a82b8f7 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -100,9 +100,9 @@ def tmv( """ if stream: - data = map(utils.json_loads, read_from) + data = map(utils.json_loads, read_from) # type: ignore else: - data = utils.json_loads(read_from.read()) + data = utils.json_loads(read_from.read()) # type: ignore if use_predefined_template: try: -- cgit v1.3.1 From c571fb1cfa3630df0ba091fc4621fcb184e82914 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 23 Jan 2021 21:22:32 +0100 Subject: Add pjson command --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 3c09295..bcf4db0 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ ENTRY_POINTS = { "tln=patternutils.commands.tln:tln", "patterncfg=patternutils.commands.patterncfg:patterncfg", "prss=patternutils.commands.prss:prss", + "pjson=patternutils.commands.pjson:pjson", ], } -- cgit v1.3.1 From dbb8fc6fa073adce2592ba18504c4129a430a73f Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 23 Jan 2021 22:43:02 +0100 Subject: Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bcf4db0..adac3d9 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ URL = "https://projects.metalgamer.eu/patternutils" EMAIL = "dennis.fink@c3l.lu" AUTHOR = "Dennis Fink" -VERSION = "0.0.10" +VERSION = "0.0.11" ENTRY_POINTS = { "console_scripts": [ "pmatch=patternutils.commands.pmatch:pmatch", -- cgit v1.3.1 -- cgit v1.3.1 From a3f403d8253c8650212dc8c0f35a3f937f004211 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 23 Jan 2021 22:47:13 +0100 Subject: Updated PKGBUILD --- PKGBUILD/PKGBUILD | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PKGBUILD/PKGBUILD b/PKGBUILD/PKGBUILD index 04e4a78..5d2f325 100644 --- a/PKGBUILD/PKGBUILD +++ b/PKGBUILD/PKGBUILD @@ -1,16 +1,16 @@ # Maintainer: Dennis Fink pkgname=patternutils -pkgver=0.0.10 -_pkghash=f33c951669cd +pkgver=0.0.11 +_pkghash=845246bd20d9 pkgrel=1 pkgdesc="Combine regular expressions with template engines in a powerful matter." arch=('any') url="https://projects.metalgamer.eu/patternutils" license=('GPL3') depends=('python' 'python-click' 'python-jinja' 'python-pygments' 'python-feedparser') -source=('patternutils-0.0.10.zip::https://projects.metalgamer.eu/patternutils/archive/f33c951669cd51e527ec5e817cceb74a24400ab2.zip?subrepos=false') -sha512sums=('bfde728083917191bfd740456113f4b7c2c1cf25107bc3bc60e5d7705686b102a59a3fb28d68f3799d9026dda2da0194c9f59424148370fc4d947228a76e4616') +source=('patternutils-0.0.11.zip::https://projects.metalgamer.eu/patternutils/archive/845246bd20d99082f1809ce02426a9276bf041f9.zip?subrepos=false') +sha512sums=('77bf4e5b7f70dc29325e4b9e396f715ff6e0d346f630f3b4b7a2b485bb74c7f6d5a6c7107d52ca02611c63487c46cdc7fcc3773fde31cbe4abbf8c7c44c9df58') prepare() { sed -i 's/==/>=/g' "$srcdir/$pkgname-$_pkghash/setup.py" -- cgit v1.3.1 From 05f35fd6d7c0f11af022027c496c17e7a27e76d7 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 6 May 2021 19:18:36 +0200 Subject: Remove unused imports --- patternutils/commands/pjson.py | 6 +++--- patternutils/commands/pmatch.py | 6 +++--- patternutils/commands/prss.py | 8 ++++---- patternutils/commands/targs.py | 2 +- patternutils/config.py | 6 +++--- patternutils/match.py | 4 ++-- patternutils/template.py | 6 +++--- patternutils/utils.py | 6 +++--- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py index 73786a4..faf1be0 100644 --- a/patternutils/commands/pjson.py +++ b/patternutils/commands/pjson.py @@ -1,6 +1,6 @@ import json import re -from typing import Any, Dict, Pattern +from typing import Any, Pattern import click @@ -9,8 +9,8 @@ from .. import utils def apply_regex( - data: Dict[str, str], key: str, regex_pattern: Pattern[str] -) -> Dict[str, str]: + data: dict[str, str], key: str, regex_pattern: Pattern[str] +) -> dict[str, str]: try: subject = data[key] except KeyError: diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py index c217c36..f69df48 100644 --- a/patternutils/commands/pmatch.py +++ b/patternutils/commands/pmatch.py @@ -2,7 +2,7 @@ import functools import itertools import os.path import re -from typing import Any, Dict, Generator, Iterator, List, Optional, Pattern +from typing import Any, Generator, Iterator, Optional, Pattern import click @@ -15,7 +15,7 @@ def apply_regex( walk_function: Iterator[Any], regex_pattern: Pattern[str], match_full_path: bool, -) -> Generator[Optional[Dict[str, str]], None, None]: +) -> Generator[Optional[dict[str, str]], None, None]: for f in walk_function: subject = f.path if match_full_path else f.name @@ -87,7 +87,7 @@ def apply_regex( @click.argument("regex-pattern") def pmatch( regex_pattern: str, - directory: List[str], + directory: list[str], match_directories: bool, recursive: bool, abort_on_no_match: bool, diff --git a/patternutils/commands/prss.py b/patternutils/commands/prss.py index a176587..1ec4675 100644 --- a/patternutils/commands/prss.py +++ b/patternutils/commands/prss.py @@ -2,7 +2,7 @@ import functools import itertools import os import os.path -from typing import Any, Dict, Generator, Iterator, List, Optional +from typing import Any, Generator, Iterator, Optional import click @@ -18,8 +18,8 @@ from .. import utils def match( parsed_feed: feedparser.util.FeedParserDict, walk_function: functools.partial[Generator[os.DirEntry[Any], None, None]], - directory: List[str], -) -> Generator[Optional[Dict[str, str]], None, None]: + directory: list[str], +) -> Generator[Optional[dict[str, str]], None, None]: direntries = [] filenames = [] @@ -96,7 +96,7 @@ def match( @click.argument("url") def prss( url: str, - directory: List[str], + directory: list[str], recursive: bool, abort_on_no_file: bool, stream: bool, diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 5ca8d04..c99a6aa 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -4,7 +4,7 @@ import multiprocessing import os import shlex import subprocess -from typing import Callable, Dict, List, Union +from typing import Callable import click diff --git a/patternutils/config.py b/patternutils/config.py index 2bce26c..50566f2 100644 --- a/patternutils/config.py +++ b/patternutils/config.py @@ -1,13 +1,13 @@ import glob import os.path -from typing import List, Optional, Tuple +from typing import Optional import click CONFIG_PATH = click.get_app_dir("patternutils") -def load_template(template_name: str, command_name: Optional[str]) -> Tuple[str, str]: +def load_template(template_name: str, command_name: Optional[str]) -> tuple[str, str]: """Load a template from the config directory.""" files = find_templates(template_name, command_name) @@ -26,7 +26,7 @@ def load_template(template_name: str, command_name: Optional[str]) -> Tuple[str, return output_pattern, template_engine -def find_templates(template_name: str, command_name: Optional[str] = None) -> List[str]: +def find_templates(template_name: str, command_name: Optional[str] = None) -> list[str]: template_glob = "{}.*".format(template_name) command_glob = "*" if command_name is None else command_name command_glob = os.path.join(CONFIG_PATH, command_glob) diff --git a/patternutils/match.py b/patternutils/match.py index 1387001..fc6a805 100644 --- a/patternutils/match.py +++ b/patternutils/match.py @@ -1,7 +1,7 @@ -from typing import Dict, Pattern +from typing import Pattern -def apply(subject: str, regex_pattern: Pattern[str]) -> Dict[str, str]: +def apply(subject: str, regex_pattern: Pattern[str]) -> dict[str, str]: if (match := regex_pattern.search(subject)) is not None: groupdict = match.groupdict() groupdict["_subject"] = subject diff --git a/patternutils/template.py b/patternutils/template.py index 8dbc650..f0b3c43 100644 --- a/patternutils/template.py +++ b/patternutils/template.py @@ -1,4 +1,4 @@ -from typing import Callable, Tuple +from typing import Callable try: import jinja2 @@ -27,10 +27,10 @@ else: def quote(value: str) -> str: return shlex.quote(value) - def splitpath(value: str) -> Tuple[str, str]: + def splitpath(value: str) -> tuple[str, str]: return os.path.split(value) - def splitext(value: str) -> Tuple[str, str]: + def splitext(value: str) -> tuple[str, str]: return os.path.splitext(value) jinja_env.filters["datetime"] = to_datetime diff --git a/patternutils/utils.py b/patternutils/utils.py index ae8a5fa..d78d990 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -1,6 +1,6 @@ import json import os -from typing import Any, Dict, Generator, List, Union +from typing import Any, Generator, Union import click @@ -10,7 +10,7 @@ def max_procs() -> int: return 1 if cpu_count is None else cpu_count * 2 -def edit(data: Union[Dict[str, str], List[str]]) -> Dict[str, str]: +def edit(data: Union[dict[str, str], list[str]]) -> dict[str, str]: longest = len(max(data, key=len)) @@ -38,7 +38,7 @@ def json_dumps(data: Any, human_readable: bool = False) -> str: {"indent": 4, "sort_keys": True} if human_readable else {"separators": (",", ":")} - ) # type: Dict[str, Any] + ) # type: dict[str, Any] return json.dumps(data, **config) -- cgit v1.3.1 From 65e6e2b50a5a01efae42df1fdfb0f210210ce110 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 6 May 2021 19:18:46 +0200 Subject: Fix targs --- patternutils/commands/targs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index c99a6aa..3da6552 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -105,7 +105,7 @@ def targs( if editor: try: - commands = utils.edit(commands) + commands = list(utils.edit(commands).values()) except RuntimeError: click.secho("Your edit is not parseable!", fg="red", err=True) raise SystemExit @@ -131,7 +131,7 @@ def targs( patched_run_command(r) else: with multiprocessing.Pool(max_procs) as p: - p.map(patched_run_command, commands.values()) + p.map(patched_run_command, commands) if __name__ == "__main__": -- cgit v1.3.1 From 59af84161d88c672075c60255233271f9c042c07 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 7 May 2021 08:46:12 +0200 Subject: Catch UsageError raised from click.edit, if it is unable to open a editor --- patternutils/utils.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/patternutils/utils.py b/patternutils/utils.py index d78d990..ca07e2f 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -19,18 +19,22 @@ def edit(data: Union[dict[str, str], list[str]]) -> dict[str, str]: else: temporary = [f"{value.ljust(longest)}\t{value}\n" for value in data] - if (edited := click.edit("".join(temporary))) is not None: - new_data = dict() - for line in edited.split("\n"): - if line and "\t" in line: - old, new = line.split("\t") - new_data[old.strip()] = new - if new_data: - return new_data + try: + if (edited := click.edit("".join(temporary))) is not None: + new_data = dict() + for line in edited.split("\n"): + if line and "\t" in line: + old, new = line.split("\t") + new_data[old.strip()] = new + if new_data: + return new_data + else: + raise RuntimeError else: - raise RuntimeError - else: - return data + return data + except click.UsageError: + click.secho("The editor could not be launced!", fg="red", err=True) + raise SystemExit def json_dumps(data: Any, human_readable: bool = False) -> str: -- cgit v1.3.1 From 41bda1ad45270151b4a04f78a4d63b789f878284 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 7 May 2021 08:46:50 +0200 Subject: Use ternary expression for forcing option in tln and tmv --- patternutils/commands/tln.py | 5 +---- patternutils/commands/tmv.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index b0476b2..6d49e42 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -145,10 +145,7 @@ def tln( if has_existing and abort_on_path_exist: raise SystemExit - if force: - files_to_move = new_filenames.items() - else: - files_to_move = non_existing.items() + files_to_move = new_filenames.items() if force else non_existing.items() for old, new in files_to_move: if verbose or interactive: diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index a82b8f7..3b7f5e3 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -143,10 +143,7 @@ def tmv( if has_existing and abort_on_path_exist: raise SystemExit - if force: - files_to_move = new_filenames.items() - else: - files_to_move = non_existing.items() + files_to_move = new_filenames.items() if force else non_existing.items() for old, new in files_to_move: if verbose or interactive: -- cgit v1.3.1 From d2064b5ba008180174b55d12db707ea034863522 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 7 May 2021 08:47:08 +0200 Subject: Autoformat --- patternutils/commands/tln.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 6d49e42..0033946 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -8,7 +8,7 @@ from .. import config, template, utils def link_file(old_filename: str, new_filename: str, symbolic: bool) -> None: - if (dirs := os.path.dirname(new_filename)) : + if dirs := os.path.dirname(new_filename): os.makedirs(dirs, exist_ok=True) if symbolic: -- cgit v1.3.1 From 230662d87fe75c5a15ef2bb2ce7612af5e747d8b Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 7 May 2021 08:48:10 +0200 Subject: Set classifier to python 3.9 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index adac3d9..fd23fae 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ setup( # Trove classifiers # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers "Programming Language :: Python", - "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.9", "Programming Language :: Python :: Implementation :: CPython", ], ) -- cgit v1.3.1 From 05838fdb8d4c6ea47b2a1820a9f365fe67ed7d56 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 7 May 2021 08:54:17 +0200 Subject: Update requirements --- requirements.txt | 9 +++++---- setup.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 12a130f..83b147f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -Click==7.0 -Jinja2==2.10.3 -MarkupSafe==1.1.1 -Pygments==2.4.2 +click==7.1.2 feedparser==6.0.2 +Jinja2==2.11.3 +MarkupSafe==1.1.1 +Pygments==2.9.0 +sgmllib3k==1.0.0 diff --git a/setup.py b/setup.py index fd23fae..784bd5d 100644 --- a/setup.py +++ b/setup.py @@ -24,12 +24,12 @@ ENTRY_POINTS = { REQUIRED = [ - "click==7.0", + "click==7.1.2", ] OPTIONAL = { - "jinja2": ["Jinja2==2.10.1"], - "pygments": ["Pygments==2.4.2"], + "jinja2": ["Jinja2==2.11.3"], + "pygments": ["Pygments==2.9.0"], "prss": ["feedparser==6.0.2"], } -- cgit v1.3.1 From 51c6265f64f5c860a80b33d1679bb104973d612a Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 7 May 2021 08:54:27 +0200 Subject: Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 784bd5d..1cba86f 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ URL = "https://projects.metalgamer.eu/patternutils" EMAIL = "dennis.fink@c3l.lu" AUTHOR = "Dennis Fink" -VERSION = "0.0.11" +VERSION = "0.0.12" ENTRY_POINTS = { "console_scripts": [ "pmatch=patternutils.commands.pmatch:pmatch", -- cgit v1.3.1 From f7b1ba4140da6c644f1a692fb7e344630e6f0013 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 25 Dec 2021 10:42:26 +0100 Subject: Use assignment operator with utils.edit --- patternutils/commands/targs.py | 4 +++- patternutils/commands/tln.py | 3 ++- patternutils/commands/tmv.py | 3 ++- patternutils/utils.py | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 3da6552..317d5e1 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -105,7 +105,9 @@ def targs( if editor: try: - commands = list(utils.edit(commands).values()) + if (new_commands := utils.edit(commands)) is not None: + commands = list(new_commands.values()) + except RuntimeError: click.secho("Your edit is not parseable!", fg="red", err=True) raise SystemExit diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index 0033946..878f556 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -128,7 +128,8 @@ def tln( if editor: try: - new_filenames = utils.edit(new_filenames) + if (temporary_filenames := utils.edit(new_filenames)) is not None: + new_filenames = temporary_filenames except RuntimeError: click.secho("Your edit is not parseable!", fg="red", err=True) raise SystemExit diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 3b7f5e3..1c61b67 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -126,7 +126,8 @@ def tmv( if editor: try: - new_filenames = utils.edit(new_filenames) + if (temporary_filenames := utils.edit(new_filenames)) is not None: + new_filenames = temporary_filenames except RuntimeError: click.secho("Your edit is not parseable!", fg="red", err=True) raise SystemExit diff --git a/patternutils/utils.py b/patternutils/utils.py index ca07e2f..0395110 100644 --- a/patternutils/utils.py +++ b/patternutils/utils.py @@ -1,6 +1,6 @@ import json import os -from typing import Any, Generator, Union +from typing import Any, Generator, Optional, Union import click @@ -10,7 +10,7 @@ def max_procs() -> int: return 1 if cpu_count is None else cpu_count * 2 -def edit(data: Union[dict[str, str], list[str]]) -> dict[str, str]: +def edit(data: Union[dict[str, str], list[str]]) -> Optional[dict[str, str]]: longest = len(max(data, key=len)) @@ -31,7 +31,7 @@ def edit(data: Union[dict[str, str], list[str]]) -> dict[str, str]: else: raise RuntimeError else: - return data + return None except click.UsageError: click.secho("The editor could not be launced!", fg="red", err=True) raise SystemExit -- cgit v1.3.1 From eda74c3020404628f9a7af37a36232d95f233803 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 25 Dec 2021 10:43:38 +0100 Subject: Use abspath in pmatch if --match-full-path is used --- patternutils/commands/pmatch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patternutils/commands/pmatch.py b/patternutils/commands/pmatch.py index f69df48..3884a9d 100644 --- a/patternutils/commands/pmatch.py +++ b/patternutils/commands/pmatch.py @@ -18,7 +18,7 @@ def apply_regex( ) -> Generator[Optional[dict[str, str]], None, None]: for f in walk_function: - subject = f.path if match_full_path else f.name + subject = os.path.abspath(f.path) if match_full_path else f.name try: match = mat.apply(subject, regex_pattern) except ValueError: @@ -59,7 +59,7 @@ def apply_regex( "--match-full-path", is_flag=True, default=False, - help="match on full path instead of only filename", + help="match on full absolute path instead of only the filename", ) @click.option( "-p", -- cgit v1.3.1 From 29c367991ea7af688b77b9874e3738d64f0fe590 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 30 Dec 2021 20:43:51 +0100 Subject: Fix typo in pjson --- patternutils/commands/pjson.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py index faf1be0..8604971 100644 --- a/patternutils/commands/pjson.py +++ b/patternutils/commands/pjson.py @@ -18,7 +18,7 @@ def apply_regex( raise try: - match = mat.apply(data[key], regex_pattern) + match = mat.apply(subject, regex_pattern) except ValueError: click.secho(f"{subject} did not match", fg="red", err=True) raise -- cgit v1.3.1 From 2f20aae8a6b56e0e82fc54943c04f095f616f130 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 30 Dec 2021 20:44:24 +0100 Subject: Switch to poetry and pyproject.toml --- poetry.lock | 335 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 38 +++++++ requirements.txt | 6 - setup.py | 56 ---------- 4 files changed, 373 insertions(+), 62 deletions(-) create mode 100644 poetry.lock create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..486a87d --- /dev/null +++ b/poetry.lock @@ -0,0 +1,335 @@ +[[package]] +name = "black" +version = "21.12b0" +description = "The uncompromising code formatter." +category = "dev" +optional = false +python-versions = ">=3.6.2" + +[package.dependencies] +click = ">=7.1.2" +mypy-extensions = ">=0.4.3" +pathspec = ">=0.9.0,<1" +platformdirs = ">=2" +tomli = ">=0.2.6,<2.0.0" +typing-extensions = [ + {version = ">=3.10.0.0", markers = "python_version < \"3.10\""}, + {version = "!=3.10.0.1", markers = "python_version >= \"3.10\""}, +] + +[package.extras] +colorama = ["colorama (>=0.4.3)"] +d = ["aiohttp (>=3.7.4)"] +jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] +python2 = ["typed-ast (>=1.4.3)"] +uvloop = ["uvloop (>=0.15.2)"] + +[[package]] +name = "click" +version = "8.0.3" +description = "Composable command line interface toolkit" +category = "main" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.4" +description = "Cross-platform colored terminal text." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "feedparser" +version = "6.0.8" +description = "Universal feed parser, handles RSS 0.9x, RSS 1.0, RSS 2.0, CDF, Atom 0.3, and Atom 1.0 feeds" +category = "main" +optional = true +python-versions = ">=3.6" + +[package.dependencies] +sgmllib3k = "*" + +[[package]] +name = "isort" +version = "5.10.1" +description = "A Python utility / library to sort Python imports." +category = "dev" +optional = false +python-versions = ">=3.6.1,<4.0" + +[package.extras] +pipfile_deprecated_finder = ["pipreqs", "requirementslib"] +requirements_deprecated_finder = ["pipreqs", "pip-api"] +colors = ["colorama (>=0.4.3,<0.5.0)"] +plugins = ["setuptools"] + +[[package]] +name = "jinja2" +version = "3.0.3" +description = "A very fast and expressive template engine." +category = "main" +optional = true +python-versions = ">=3.6" + +[package.dependencies] +MarkupSafe = ">=2.0" + +[package.extras] +i18n = ["Babel (>=2.7)"] + +[[package]] +name = "markupsafe" +version = "2.0.1" +description = "Safely add untrusted strings to HTML/XML markup." +category = "main" +optional = true +python-versions = ">=3.6" + +[[package]] +name = "mypy" +version = "0.930" +description = "Optional static typing for Python" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +mypy-extensions = ">=0.4.3" +tomli = ">=1.1.0" +typing-extensions = ">=3.10" + +[package.extras] +dmypy = ["psutil (>=4.0)"] +python2 = ["typed-ast (>=1.4.0,<2)"] + +[[package]] +name = "mypy-extensions" +version = "0.4.3" +description = "Experimental type system extensions for programs checked with the mypy typechecker." +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "pathspec" +version = "0.9.0" +description = "Utility library for gitignore style pattern matching of file paths." +category = "dev" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" + +[[package]] +name = "platformdirs" +version = "2.4.1" +description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["Sphinx (>=4)", "furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx-autodoc-typehints (>=1.12)"] +test = ["appdirs (==1.4.4)", "pytest (>=6)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)"] + +[[package]] +name = "pygments" +version = "2.11.0" +description = "Pygments is a syntax highlighting package written in Python." +category = "main" +optional = true +python-versions = ">=3.5" + +[[package]] +name = "sgmllib3k" +version = "1.0.0" +description = "Py3k port of sgmllib." +category = "main" +optional = true +python-versions = "*" + +[[package]] +name = "tomli" +version = "1.2.3" +description = "A lil' TOML parser" +category = "dev" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "typing-extensions" +version = "4.0.1" +description = "Backported and Experimental Type Hints for Python 3.6+" +category = "dev" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "vermin" +version = "1.3.3" +description = "Concurrently detect the minimum Python versions needed to run code" +category = "dev" +optional = false +python-versions = ">=2.7" + +[extras] +jinja2 = ["Jinja2"] +prss = ["feedparser"] +pygments = ["Pygments"] + +[metadata] +lock-version = "1.1" +python-versions = ">=3.8,<4" +content-hash = "eedebf0b6e78c4e1fa28738ea11b5cb637b36821c647bdbc53456ab1cf477790" + +[metadata.files] +black = [ + {file = "black-21.12b0-py3-none-any.whl", hash = "sha256:a615e69ae185e08fdd73e4715e260e2479c861b5740057fde6e8b4e3b7dd589f"}, + {file = "black-21.12b0.tar.gz", hash = "sha256:77b80f693a569e2e527958459634f18df9b0ba2625ba4e0c2d5da5be42e6f2b3"}, +] +click = [ + {file = "click-8.0.3-py3-none-any.whl", hash = "sha256:353f466495adaeb40b6b5f592f9f91cb22372351c84caeb068132442a4518ef3"}, + {file = "click-8.0.3.tar.gz", hash = "sha256:410e932b050f5eed773c4cda94de75971c89cdb3155a72a0831139a79e5ecb5b"}, +] +colorama = [ + {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, + {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, +] +feedparser = [ + {file = "feedparser-6.0.8-py3-none-any.whl", hash = "sha256:1b7f57841d9cf85074deb316ed2c795091a238adb79846bc46dccdaf80f9c59a"}, + {file = "feedparser-6.0.8.tar.gz", hash = "sha256:5ce0410a05ab248c8c7cfca3a0ea2203968ee9ff4486067379af4827a59f9661"}, +] +isort = [ + {file = "isort-5.10.1-py3-none-any.whl", hash = "sha256:6f62d78e2f89b4500b080fe3a81690850cd254227f27f75c3a0c491a1f351ba7"}, + {file = "isort-5.10.1.tar.gz", hash = "sha256:e8443a5e7a020e9d7f97f1d7d9cd17c88bcb3bc7e218bf9cf5095fe550be2951"}, +] +jinja2 = [ + {file = "Jinja2-3.0.3-py3-none-any.whl", hash = "sha256:077ce6014f7b40d03b47d1f1ca4b0fc8328a692bd284016f806ed0eaca390ad8"}, + {file = "Jinja2-3.0.3.tar.gz", hash = "sha256:611bb273cd68f3b993fabdc4064fc858c5b47a973cb5aa7999ec1ba405c87cd7"}, +] +markupsafe = [ + {file = "MarkupSafe-2.0.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:d8446c54dc28c01e5a2dbac5a25f071f6653e6e40f3a8818e8b45d790fe6ef53"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:36bc903cbb393720fad60fc28c10de6acf10dc6cc883f3e24ee4012371399a38"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2d7d807855b419fc2ed3e631034685db6079889a1f01d5d9dac950f764da3dad"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:add36cb2dbb8b736611303cd3bfcee00afd96471b09cda130da3581cbdc56a6d"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:168cd0a3642de83558a5153c8bd34f175a9a6e7f6dc6384b9655d2697312a646"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:4dc8f9fb58f7364b63fd9f85013b780ef83c11857ae79f2feda41e270468dd9b"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:20dca64a3ef2d6e4d5d615a3fd418ad3bde77a47ec8a23d984a12b5b4c74491a"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:cdfba22ea2f0029c9261a4bd07e830a8da012291fbe44dc794e488b6c9bb353a"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-win32.whl", hash = "sha256:99df47edb6bda1249d3e80fdabb1dab8c08ef3975f69aed437cb69d0a5de1e28"}, + {file = "MarkupSafe-2.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:e0f138900af21926a02425cf736db95be9f4af72ba1bb21453432a07f6082134"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f9081981fe268bd86831e5c75f7de206ef275defcb82bc70740ae6dc507aee51"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:0955295dd5eec6cb6cc2fe1698f4c6d84af2e92de33fbcac4111913cd100a6ff"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:0446679737af14f45767963a1a9ef7620189912317d095f2d9ffa183a4d25d2b"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:f826e31d18b516f653fe296d967d700fddad5901ae07c622bb3705955e1faa94"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:fa130dd50c57d53368c9d59395cb5526eda596d3ffe36666cd81a44d56e48872"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:905fec760bd2fa1388bb5b489ee8ee5f7291d692638ea5f67982d968366bef9f"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bf5d821ffabf0ef3533c39c518f3357b171a1651c1ff6827325e4489b0e46c3c"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:0d4b31cc67ab36e3392bbf3862cfbadac3db12bdd8b02a2731f509ed5b829724"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:baa1a4e8f868845af802979fcdbf0bb11f94f1cb7ced4c4b8a351bb60d108145"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:deb993cacb280823246a026e3b2d81c493c53de6acfd5e6bfe31ab3402bb37dd"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-musllinux_1_1_i686.whl", hash = "sha256:63f3268ba69ace99cab4e3e3b5840b03340efed0948ab8f78d2fd87ee5442a4f"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:8d206346619592c6200148b01a2142798c989edcb9c896f9ac9722a99d4e77e6"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-win32.whl", hash = "sha256:6c4ca60fa24e85fe25b912b01e62cb969d69a23a5d5867682dd3e80b5b02581d"}, + {file = "MarkupSafe-2.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:b2f4bf27480f5e5e8ce285a8c8fd176c0b03e93dcc6646477d4630e83440c6a9"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0717a7390a68be14b8c793ba258e075c6f4ca819f15edfc2a3a027c823718567"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:6557b31b5e2c9ddf0de32a691f2312a32f77cd7681d8af66c2692efdbef84c18"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:49e3ceeabbfb9d66c3aef5af3a60cc43b85c33df25ce03d0031a608b0a8b2e3f"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:d7f9850398e85aba693bb640262d3611788b1f29a79f0c93c565694658f4071f"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:6a7fae0dd14cf60ad5ff42baa2e95727c3d81ded453457771d02b7d2b3f9c0c2"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:b7f2d075102dc8c794cbde1947378051c4e5180d52d276987b8d28a3bd58c17d"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e9936f0b261d4df76ad22f8fee3ae83b60d7c3e871292cd42f40b81b70afae85"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:2a7d351cbd8cfeb19ca00de495e224dea7e7d919659c2841bbb7f420ad03e2d6"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:60bf42e36abfaf9aff1f50f52644b336d4f0a3fd6d8a60ca0d054ac9f713a864"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:d6c7ebd4e944c85e2c3421e612a7057a2f48d478d79e61800d81468a8d842207"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:f0567c4dc99f264f49fe27da5f735f414c4e7e7dd850cfd8e69f0862d7c74ea9"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:89c687013cb1cd489a0f0ac24febe8c7a666e6e221b783e53ac50ebf68e45d86"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-win32.whl", hash = "sha256:a30e67a65b53ea0a5e62fe23682cfe22712e01f453b95233b25502f7c61cb415"}, + {file = "MarkupSafe-2.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:611d1ad9a4288cf3e3c16014564df047fe08410e628f89805e475368bd304914"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:5bb28c636d87e840583ee3adeb78172efc47c8b26127267f54a9c0ec251d41a9"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:be98f628055368795d818ebf93da628541e10b75b41c559fdf36d104c5787066"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:1d609f577dc6e1aa17d746f8bd3c31aa4d258f4070d61b2aa5c4166c1539de35"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7d91275b0245b1da4d4cfa07e0faedd5b0812efc15b702576d103293e252af1b"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:01a9b8ea66f1658938f65b93a85ebe8bc016e6769611be228d797c9d998dd298"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:47ab1e7b91c098ab893b828deafa1203de86d0bc6ab587b160f78fe6c4011f75"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:97383d78eb34da7e1fa37dd273c20ad4320929af65d156e35a5e2d89566d9dfb"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6fcf051089389abe060c9cd7caa212c707e58153afa2c649f00346ce6d260f1b"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:5855f8438a7d1d458206a2466bf82b0f104a3724bf96a1c781ab731e4201731a"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:3dd007d54ee88b46be476e293f48c85048603f5f516008bee124ddd891398ed6"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:aca6377c0cb8a8253e493c6b451565ac77e98c2951c45f913e0b52facdcff83f"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:04635854b943835a6ea959e948d19dcd311762c5c0c6e1f0e16ee57022669194"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:6300b8454aa6930a24b9618fbb54b5a68135092bc666f7b06901f897fa5c2fee"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-win32.whl", hash = "sha256:023cb26ec21ece8dc3907c0e8320058b2e0cb3c55cf9564da612bc325bed5e64"}, + {file = "MarkupSafe-2.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:984d76483eb32f1bcb536dc27e4ad56bba4baa70be32fa87152832cdd9db0833"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:2ef54abee730b502252bcdf31b10dacb0a416229b72c18b19e24a4509f273d26"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:3c112550557578c26af18a1ccc9e090bfe03832ae994343cfdacd287db6a6ae7"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:53edb4da6925ad13c07b6d26c2a852bd81e364f95301c66e930ab2aef5b5ddd8"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:f5653a225f31e113b152e56f154ccbe59eeb1c7487b39b9d9f9cdb58e6c79dc5"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:4efca8f86c54b22348a5467704e3fec767b2db12fc39c6d963168ab1d3fc9135"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:ab3ef638ace319fa26553db0624c4699e31a28bb2a835c5faca8f8acf6a5a902"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:f8ba0e8349a38d3001fae7eadded3f6606f0da5d748ee53cc1dab1d6527b9509"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c47adbc92fc1bb2b3274c4b3a43ae0e4573d9fbff4f54cd484555edbf030baf1"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:37205cac2a79194e3750b0af2a5720d95f786a55ce7df90c3af697bfa100eaac"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:1f2ade76b9903f39aa442b4aadd2177decb66525062db244b35d71d0ee8599b6"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:4296f2b1ce8c86a6aea78613c34bb1a672ea0e3de9c6ba08a960efe0b0a09047"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:9f02365d4e99430a12647f09b6cc8bab61a6564363f313126f775eb4f6ef798e"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5b6d930f030f8ed98e3e6c98ffa0652bdb82601e7a016ec2ab5d7ff23baa78d1"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-win32.whl", hash = "sha256:10f82115e21dc0dfec9ab5c0223652f7197feb168c940f3ef61563fc2d6beb74"}, + {file = "MarkupSafe-2.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:693ce3f9e70a6cf7d2fb9e6c9d8b204b6b39897a2c4a1aa65728d5ac97dcc1d8"}, + {file = "MarkupSafe-2.0.1.tar.gz", hash = "sha256:594c67807fb16238b30c44bdf74f36c02cdf22d1c8cda91ef8a0ed8dabf5620a"}, +] +mypy = [ + {file = "mypy-0.930-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:221cc94dc6a801ccc2be7c0c9fd791c5e08d1fa2c5e1c12dec4eab15b2469871"}, + {file = "mypy-0.930-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:db3a87376a1380f396d465bed462e76ea89f838f4c5e967d68ff6ee34b785c31"}, + {file = "mypy-0.930-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:1d2296f35aae9802eeb1327058b550371ee382d71374b3e7d2804035ef0b830b"}, + {file = "mypy-0.930-cp310-cp310-win_amd64.whl", hash = "sha256:959319b9a3cafc33a8185f440a433ba520239c72e733bf91f9efd67b0a8e9b30"}, + {file = "mypy-0.930-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:45a4dc21c789cfd09b8ccafe114d6de66f0b341ad761338de717192f19397a8c"}, + {file = "mypy-0.930-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:1e689e92cdebd87607a041585f1dc7339aa2e8a9f9bad9ba7e6ece619431b20c"}, + {file = "mypy-0.930-cp36-cp36m-win_amd64.whl", hash = "sha256:ed4e0ea066bb12f56b2812a15ff223c57c0a44eca817ceb96b214bb055c7051f"}, + {file = "mypy-0.930-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:a9d8dffefba634b27d650e0de2564379a1a367e2e08d6617d8f89261a3bf63b2"}, + {file = "mypy-0.930-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:b419e9721260161e70d054a15abbd50603c16f159860cfd0daeab647d828fc29"}, + {file = "mypy-0.930-cp37-cp37m-win_amd64.whl", hash = "sha256:601f46593f627f8a9b944f74fd387c9b5f4266b39abad77471947069c2fc7651"}, + {file = "mypy-0.930-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1ea7199780c1d7940b82dbc0a4e37722b4e3851264dbba81e01abecc9052d8a7"}, + {file = "mypy-0.930-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:70b197dd8c78fc5d2daf84bd093e8466a2b2e007eedaa85e792e513a820adbf7"}, + {file = "mypy-0.930-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:5feb56f8bb280468fe5fc8e6f56f48f99aa0df9eed3c507a11505ee4657b5380"}, + {file = "mypy-0.930-cp38-cp38-win_amd64.whl", hash = "sha256:2e9c5409e9cb81049bb03fa1009b573dea87976713e3898561567a86c4eaee01"}, + {file = "mypy-0.930-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:554873e45c1ca20f31ddf873deb67fa5d2e87b76b97db50669f0468ccded8fae"}, + {file = "mypy-0.930-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:0feb82e9fa849affca7edd24713dbe809dce780ced9f3feca5ed3d80e40b777f"}, + {file = "mypy-0.930-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:bc1a0607ea03c30225347334af66b0af12eefba018a89a88c209e02b7065ea95"}, + {file = "mypy-0.930-cp39-cp39-win_amd64.whl", hash = "sha256:f9f665d69034b1fcfdbcd4197480d26298bbfb5d2dfe206245b6498addb34999"}, + {file = "mypy-0.930-py3-none-any.whl", hash = "sha256:bf4a44e03040206f7c058d1f5ba02ef2d1820720c88bc4285c7d9a4269f54173"}, + {file = "mypy-0.930.tar.gz", hash = "sha256:51426262ae4714cc7dd5439814676e0992b55bcc0f6514eccb4cf8e0678962c2"}, +] +mypy-extensions = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] +pathspec = [ + {file = "pathspec-0.9.0-py2.py3-none-any.whl", hash = "sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a"}, + {file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"}, +] +platformdirs = [ + {file = "platformdirs-2.4.1-py3-none-any.whl", hash = "sha256:1d7385c7db91728b83efd0ca99a5afb296cab9d0ed8313a45ed8ba17967ecfca"}, + {file = "platformdirs-2.4.1.tar.gz", hash = "sha256:440633ddfebcc36264232365d7840a970e75e1018d15b4327d11f91909045fda"}, +] +pygments = [ + {file = "Pygments-2.11.0-py3-none-any.whl", hash = "sha256:ac8098bfc40b8e1091ad7c13490c7f4797e401d0972e8fcfadde90ffb3ed4ea9"}, + {file = "Pygments-2.11.0.tar.gz", hash = "sha256:51130f778a028f2d19c143fce00ced6f8b10f726e17599d7e91b290f6cbcda0c"}, +] +sgmllib3k = [ + {file = "sgmllib3k-1.0.0.tar.gz", hash = "sha256:7868fb1c8bfa764c1ac563d3cf369c381d1325d36124933a726f29fcdaa812e9"}, +] +tomli = [ + {file = "tomli-1.2.3-py3-none-any.whl", hash = "sha256:e3069e4be3ead9668e21cb9b074cd948f7b3113fd9c8bba083f48247aab8b11c"}, + {file = "tomli-1.2.3.tar.gz", hash = "sha256:05b6166bff487dc068d322585c7ea4ef78deed501cc124060e0f238e89a9231f"}, +] +typing-extensions = [ + {file = "typing_extensions-4.0.1-py3-none-any.whl", hash = "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"}, + {file = "typing_extensions-4.0.1.tar.gz", hash = "sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e"}, +] +vermin = [ + {file = "vermin-1.3.3-py2.py3-none-any.whl", hash = "sha256:c5bd8bf2026d87563332293a0479606954bd973d8cf72ab370e1164a019c0524"}, +] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4a340da --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[tool.poetry] +name = "patternutils" +version = "0.0.12" +description = "Combine regular expressions with template engines in a powerful matter." +authors = ["Dennis Fink "] +license = "GPL-3.0-or-later" +repository = "https://projects.metalgamer.eu/patternutils" + +[tool.poetry.scripts] +pmatch = "patternutils.commands.pmatch:pmatch" +targs = "patternutils.commands.targs:targs" +tmv = "patternutils.commands.tmv:tmv" +tln = "patternutils.commands.tln:tln" +patterncfg = "patternutils.commands.patterncfg:patterncfg" +prss = "patternutils.commands.prss:prss" +pjson = "patternutils.commands.pjson:pjson" + +[tool.poetry.dependencies] +python = ">=3.8,<4" +click = "^8.0.3" +Jinja2 = {version = "^3.0.3", optional = true} +Pygments = {version = "^2.10.0", optional = true} +feedparser = {version = "^6.0.8", optional = true} + +[tool.poetry.dev-dependencies] +mypy = "^0.930" +black = "^21.12b0" +isort = "^5.10.1" +vermin = "^1.3.2" + +[tool.poetry.extras] +jinja2 = ["Jinja2"] +pygments = ["Pygments"] +prss = ["feedparser"] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 83b147f..0000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -click==7.1.2 -feedparser==6.0.2 -Jinja2==2.11.3 -MarkupSafe==1.1.1 -Pygments==2.9.0 -sgmllib3k==1.0.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index 1cba86f..0000000 --- a/setup.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from setuptools import find_packages, setup - -NAME = "patternutils" -DESCRIPTION = "Combine regular expressions with template engines in a powerful matter." -URL = "https://projects.metalgamer.eu/patternutils" -EMAIL = "dennis.fink@c3l.lu" -AUTHOR = "Dennis Fink" - -VERSION = "0.0.12" -ENTRY_POINTS = { - "console_scripts": [ - "pmatch=patternutils.commands.pmatch:pmatch", - "targs=patternutils.commands.targs:targs", - "tmv=patternutils.commands.tmv:tmv", - "tln=patternutils.commands.tln:tln", - "patterncfg=patternutils.commands.patterncfg:patterncfg", - "prss=patternutils.commands.prss:prss", - "pjson=patternutils.commands.pjson:pjson", - ], -} - - -REQUIRED = [ - "click==7.1.2", -] - -OPTIONAL = { - "jinja2": ["Jinja2==2.11.3"], - "pygments": ["Pygments==2.9.0"], - "prss": ["feedparser==6.0.2"], -} - -setup( - name=NAME, - version=VERSION, - description=DESCRIPTION, - author=AUTHOR, - author_email=EMAIL, - url=URL, - packages=find_packages(exclude=("tests",)), - entry_points=ENTRY_POINTS, - install_requires=REQUIRED, - extras_requires=OPTIONAL, - include_package_data=True, - license="GPLv3+", - classifiers=[ - # Trove classifiers - # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers - "Programming Language :: Python", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: Implementation :: CPython", - ], -) -- cgit v1.3.1 From 231443b908823b9c10c33ed4f378d095c2e26f91 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 30 Dec 2021 20:46:39 +0100 Subject: Fail gracefully when --color is specified and pygments is not installed in patterncfg --- patternutils/commands/patterncfg.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py index 0115ed2..8f85b8f 100644 --- a/patternutils/commands/patterncfg.py +++ b/patternutils/commands/patterncfg.py @@ -136,12 +136,19 @@ def view(name: str, command: str, color: bool) -> None: click.secho("File not found!", fg="red", err=True) raise SystemExit else: - if color: + if color and has_pygments: if filename.endswith("jinja2"): lexer = DjangoLexer else: lexer = Python3Lexer text = highlight(text, lexer(), TerminalFormatter()) + elif color and not has_pygments: + click.echo( + "Pygments is not installed!. Cannot colorize output.", + fg="red", + err=True, + ) + raise SystemExit click.echo(text[:-1]) -- cgit v1.3.1 From c355ccf67385d90970d9c7c913746cf856c216b9 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 30 Dec 2021 20:57:13 +0100 Subject: Rephrase docstring in tmv --- patternutils/commands/tmv.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 1c61b67..fa7105e 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -92,11 +92,11 @@ def tmv( """Rename files based on the OUTPUT_PATTERN. - It reads a JSON list containing objects or a stream of objects - (if --stream option is defined). The object needs to have a - key named as the option KEY (default: _abspath), which points - to the file to move. The rest of the keys will be supplied to - the templating engine to generate the new filename. + It reads in a JSON list containing objects or a stream of objects (if the + --stream option is used). The object needs to contain a key, named as + the specified option KEY (default: _abspath), which points to the file to + be moved. The rest of the keys will be supplied to the templating engine to + generate the new filename. """ if stream: -- cgit v1.3.1 From f314b3ff099c30a70a4e026ad698e578ab1a9691 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 30 Dec 2021 20:57:20 +0100 Subject: Add docstring to targs --- patternutils/commands/targs.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 317d5e1..947061f 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -79,6 +79,12 @@ def targs( editor: bool, verbose: bool, ) -> None: + """Execute commands based on a template string. + + It reads in a JSON list containing objects, or a stream of objects (if the + --stream option is used), which are then supplied to the templating engine, + to generate the command to run. + """ if stream: data = map(utils.json_loads, read_from) # type: ignore -- cgit v1.3.1 From 73aa868d7a39e306a548b375b4579fdb8f8dd900 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 30 Dec 2021 21:54:47 +0100 Subject: Replace format with f-string in find_templates --- patternutils/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/config.py b/patternutils/config.py index 50566f2..c444478 100644 --- a/patternutils/config.py +++ b/patternutils/config.py @@ -27,7 +27,7 @@ def load_template(template_name: str, command_name: Optional[str]) -> tuple[str, def find_templates(template_name: str, command_name: Optional[str] = None) -> list[str]: - template_glob = "{}.*".format(template_name) + template_glob = f"{template_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)) -- cgit v1.3.1 From 29989fd5fca9e42230557d7ffd5f6849433fd99f Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Thu, 30 Dec 2021 21:55:50 +0100 Subject: Fix typo in patterncfg --- patternutils/commands/patterncfg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patternutils/commands/patterncfg.py b/patternutils/commands/patterncfg.py index 8f85b8f..3421f39 100644 --- a/patternutils/commands/patterncfg.py +++ b/patternutils/commands/patterncfg.py @@ -143,7 +143,7 @@ def view(name: str, command: str, color: bool) -> None: lexer = Python3Lexer text = highlight(text, lexer(), TerminalFormatter()) elif color and not has_pygments: - click.echo( + click.secho( "Pygments is not installed!. Cannot colorize output.", fg="red", err=True, -- cgit v1.3.1 From 4f10bd7b7b03f8ebc02e715fac38e7b5d6e6047e Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 25 Feb 2022 19:11:55 +0100 Subject: Added dry run option to targs --- patternutils/commands/targs.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 947061f..34cf018 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -64,6 +64,13 @@ def run_command( default=False, help="Open an editor before running commands to allow manual changes", ) +@click.option( + "-n", + "--dry-run", + is_flag=True, + default=False, + help="perform a trial run without actually executing the command", +) @click.version_option() @click.argument("command") def targs( @@ -78,6 +85,7 @@ def targs( stream: bool, editor: bool, verbose: bool, + dry_run: bool, ) -> None: """Execute commands based on a template string. @@ -126,11 +134,19 @@ def targs( stdout=stdout, stderr=stderr, ) - patched_run_command = functools.partial( - run_command, - run=patched_subprocess, - shell=shell, - ) + + if not dry_run: + patched_run_command = functools.partial( + run_command, + run=patched_subprocess, + shell=shell, + ) + else: + patched_run_command = functools.partial( + run_command, + run=print, + shell=True, + ) max_procs = utils.max_procs() if max_procs == 0 else max_procs -- cgit v1.3.1 -- cgit v1.3.1 From c8694bdd3753c90da88338d9f3153192d5babc0a Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 26 Feb 2022 00:57:12 +0100 Subject: Updated PKGBUILD --- PKGBUILD/PKGBUILD | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/PKGBUILD/PKGBUILD b/PKGBUILD/PKGBUILD index 5d2f325..42ca51b 100644 --- a/PKGBUILD/PKGBUILD +++ b/PKGBUILD/PKGBUILD @@ -1,27 +1,26 @@ # Maintainer: Dennis Fink pkgname=patternutils -pkgver=0.0.11 -_pkghash=845246bd20d9 +pkgver=0.0.12 pkgrel=1 pkgdesc="Combine regular expressions with template engines in a powerful matter." arch=('any') url="https://projects.metalgamer.eu/patternutils" license=('GPL3') depends=('python' 'python-click' 'python-jinja' 'python-pygments' 'python-feedparser') -source=('patternutils-0.0.11.zip::https://projects.metalgamer.eu/patternutils/archive/845246bd20d99082f1809ce02426a9276bf041f9.zip?subrepos=false') -sha512sums=('77bf4e5b7f70dc29325e4b9e396f715ff6e0d346f630f3b4b7a2b485bb74c7f6d5a6c7107d52ca02611c63487c46cdc7fcc3773fde31cbe4abbf8c7c44c9df58') +source=('https://download.metalgamer.eu/patternutils/patternutils-0.0.12.tar.gz') +sha512sums=('2d39fce29eda388436f2c11da1df8016436f0441e1c77c53aa1b7fa863e7862073629ee4dfb7d082abea0b70760c2535554fec0a0bfc6cd8674f688c6f37c771') prepare() { - sed -i 's/==/>=/g' "$srcdir/$pkgname-$_pkghash/setup.py" + sed -i 's/==/>=/g' "$srcdir/$pkgname-$pkgver/setup.py" } build() { - cd "$srcdir/$pkgname-$_pkghash" + cd "$srcdir/$pkgname-$pkgver" python setup.py build } package() { - cd "$srcdir/$pkgname-$_pkghash" + cd "$srcdir/$pkgname-$pkgver" python setup.py install --root="$pkgdir" --optimize=1 } -- cgit v1.3.1