From 19755678dbbd7376ba5eb8b3d5d090567ebdeafe Mon Sep 17 00:00:00 2001 From: Istvan Bozso Date: Mon, 10 Feb 2020 11:53:58 +0100 Subject: [PATCH] bugfixes --- utils/__init__.py | 2 +- utils/cli.py | 4 ++-- utils/cmd.py | 2 +- utils/enforce.py | 16 +++++++++------- utils/ninja.py | 6 ++++-- utils/path.py | 2 +- utils/project.py | 2 +- utils/simpledoc.py | 8 ++++---- utils/utils.py | 38 +++++++------------------------------- 9 files changed, 30 insertions(+), 50 deletions(-) diff --git a/utils/__init__.py b/utils/__init__.py index 5ba7122..989eade 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,4 +1,4 @@ -from utils.base import * +from utils.utils import * from utils.path import * from utils.enforce import * from utils.cli import * diff --git a/utils/cli.py b/utils/cli.py index 5fef790..934ef0d 100644 --- a/utils/cli.py +++ b/utils/cli.py @@ -1,4 +1,4 @@ -import argparser +import argparse as ap def annot(**kwargs): parent = kwargs.pop("parent", None) @@ -14,7 +14,7 @@ def annotate(f): class CParse(object): def __init__(self, **kwargs): - self.argp, self.args = ArgumentParser(**kwargs), None + self.argp, self.args = ap.ArgumentParser(**kwargs), None for key, value in self.__init__.__annotations__.items(): if value.pop("kind") == "pos": diff --git a/utils/cmd.py b/utils/cmd.py index c92fdaf..4020526 100644 --- a/utils/cmd.py +++ b/utils/cmd.py @@ -64,7 +64,7 @@ def __call__(self, *args, **kwargs): return proc -def subcmommands(root, *args, **kwargs): +def subcommands(root, *args, **kwargs): p = Parser(**kwargs) return type(root, (object,), diff --git a/utils/enforce.py b/utils/enforce.py index a0baa43..4a8b391 100644 --- a/utils/enforce.py +++ b/utils/enforce.py @@ -1,11 +1,13 @@ +from functools import partial + __all__ = ( - "Enforcer", + "enforce", "type_enforce", ) -class Enforcer(object): - def enforce(self, cond, *args, **kwargs): - if not cond: - raise self(*args, **kwargs) +def enforce(cond, *args, **kwargs): + exc = kwargs.pop("exception", Exception) + + if not cond: + raise exc(*args, **kwargs) -class TypeEnforce(TypeError, Enforcer): - pass +type_enforce = partial(enforce, exception=TypeError) diff --git a/utils/ninja.py b/utils/ninja.py index 795b650..c4865ed 100644 --- a/utils/ninja.py +++ b/utils/ninja.py @@ -8,6 +8,8 @@ import re import textwrap +from utils import Path + __all__ = ( "Ninja", ) @@ -15,7 +17,7 @@ def escape_path(word): return word.replace('$ ', '$$ ').replace(' ', '$ ').replace(':', '$:') -home = pth.join("/", "home", "istvan") +home = Path.joined("/", "home", "istvan") class Ninja(object): def __init__(self, output, width=78): @@ -240,7 +242,7 @@ class HTML(Ninja): ext = ".html" - _include_dirs = {pth.join(home, "Dokumentumok", "texfiles", "gpp"),} + _include_dirs = {home.join("Dokumentumok", "texfiles", "gpp"),} def __init__(self, *args, **kwargs): include_dirs = \ diff --git a/utils/path.py b/utils/path.py index 592b0ac..40364ff 100644 --- a/utils/path.py +++ b/utils/path.py @@ -51,7 +51,7 @@ def mkdir(self): return Path(p) def join(self, *args): - return Path(pth.join(self.path, *args)) + return Path(path.join(self.path, *args)) def iglob(self): return glob.iglob(self.path) diff --git a/utils/project.py b/utils/project.py index 36003c7..e6f3582 100644 --- a/utils/project.py +++ b/utils/project.py @@ -11,7 +11,7 @@ def commit(self): pass class Git(object): - + pass class Project(object): __slots__ = ( diff --git a/utils/simpledoc.py b/utils/simpledoc.py index efffba6..53ef06b 100644 --- a/utils/simpledoc.py +++ b/utils/simpledoc.py @@ -1,5 +1,5 @@ __all__ = ( - "HTML", "libs", "JSLib", + "HTML", "jslibs", "JSLib", ) import re @@ -780,15 +780,15 @@ class CSSLib(Library): class JSLib(Library): __slots__ = ( - "async", + "_async", ) def __init__(self, *args, **kwargs): - self.async = bool(kwargs.get("async", True)) + self._async = bool(kwargs.get("async", True)) Library.__init__(self, kwargs["path"]) def add(self, doc): - if self.async: + if self._async: with doc.tag("script", "async", src=self.path): pass else: diff --git a/utils/utils.py b/utils/utils.py index 133a665..ee65765 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -1,17 +1,19 @@ +import sys +import functools as ft __all__ = ( "Seq", "flat", "new_type", "str_t", "isiter", "all_same", - "make_object", "tmp_file", "get_par", "cat", "compose", - "fs", "load", "Enum", + "make_object", "cat", "compose", + "fs", "load", "Enum", "namespace", ) -py3 = version_info[0] == 3 +py3 = sys.version_info[0] == 3 if py3: - str_t = str, + str_t = str else: - str_t = basestring, + str_t = basestring def flat(arg): @@ -53,33 +55,7 @@ def items(self): return self.__dict__.items() -class TMP(object): - tmpdir = _get_default_tempdir() - - def __init__(self): - self.tmps = [] - - def tmp_file(self, path=tmpdir, ext=None): - path = pth.join(path, next(_get_candidate_names())) - - if ext is not None: - path = "%s.%s" % (path, ext) - - self.tmps.append(path) - - return path - - def __del__(self): - for path in self.tmps: - rm(path) - - -tmp = TMP() -tmp_file = tmp.tmp_file - empty_iter = iter([]) -isfile = compose(pth.isfile, pth.join) -ls = compose(iglob, pth.join) def all_same(iterable, fun=None): if fun is not None: