Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Istvan Bozso committed Feb 10, 2020
1 parent 5e878ee commit 1975567
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 50 deletions.
2 changes: 1 addition & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from utils.base import *
from utils.utils import *
from utils.path import *
from utils.enforce import *
from utils.cli import *
Expand Down
4 changes: 2 additions & 2 deletions utils/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparser
import argparse as ap

def annot(**kwargs):
parent = kwargs.pop("parent", None)
Expand All @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion utils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,),
Expand Down
16 changes: 9 additions & 7 deletions utils/enforce.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 4 additions & 2 deletions utils/ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import re
import textwrap

from utils import Path

__all__ = (
"Ninja",
)

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):
Expand Down Expand Up @@ -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 = \
Expand Down
2 changes: 1 addition & 1 deletion utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion utils/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def commit(self):
pass

class Git(object):

pass

class Project(object):
__slots__ = (
Expand Down
8 changes: 4 additions & 4 deletions utils/simpledoc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__all__ = (
"HTML", "libs", "JSLib",
"HTML", "jslibs", "JSLib",
)

import re
Expand Down Expand Up @@ -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:
Expand Down
38 changes: 7 additions & 31 deletions utils/utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1975567

Please sign in to comment.