Esempio n. 1
0
def _find_suite():
    root = os.environ.get("JSON_SCHEMA_TEST_SUITE")
    if root is not None:
        return FilePath(root)

    root = FilePath(jsonschema.__file__).parent().sibling("json")
    if not root.isdir():
        raise ValueError(
            ("Can't find the JSON-Schema-Test-Suite directory. "
             "Set the 'JSON_SCHEMA_TEST_SUITE' environment "
             "variable or run the tests from alongside a checkout "
             "of the suite."), )
    return root
Esempio n. 2
0
def run(
    paths,
    output=_I_STILL_HATE_EVERYTHING,
    recurse=core.flat,
    sort_by=lambda x: x,
    ls=core.ls,
    stdout=stdout,
):
    """
    Project-oriented directory and file information lister.

    """

    if output is _I_STILL_HATE_EVERYTHING:
        output = core.columnized if stdout.isatty() else core.one_per_line

    def _sort_by(thing):
        return not getattr(thing, "_always_sorts_first", False), sort_by(thing)

    contents = [
        path_and_children
        for path in paths or (project.from_path(FilePath(".")), )
        for path_and_children in recurse(path=path, ls=ls)
    ]
    for line in output(contents, sort_by=_sort_by):
        stdout.write(line)
        stdout.write("\n")
Esempio n. 3
0
def run(
    paths,
    output=_I_STILL_HATE_EVERYTHING,
    recurse=core.flat,
    sort_by=None,
    ls=core.ls,
    stdout=stdout,
):
    """
    Project-oriented directory and file information lister.

    """

    if output is _I_STILL_HATE_EVERYTHING:
        output = core.columnized if stdout.isatty() else core.one_per_line
    if sort_by is None:
        if output == core.as_tree:

            def sort_by(thing):
                return (
                    thing.parent(),
                    thing.basename().lstrip(string.punctuation).lower(),
                )
        else:

            def sort_by(thing):
                return thing

    def _sort_by(thing):
        return not getattr(thing, "_always_sorts_first", False), sort_by(thing)

    contents = [
        path_and_children
        for path in paths or (project.from_path(FilePath(".")), )
        for path_and_children in recurse(path=path, ls=ls)
    ]
    for line in output(contents, sort_by=_sort_by):
        stdout.write(line)
        stdout.write("\n")
Esempio n. 4
0
 def test_it_works(self):
     self.cycy.interpret(
         [FilePath(__file__).sibling("example.c").getContent()],
     )
     self.assertEqual(self.stdout.getvalue(), "Hello, world!\n")
Esempio n. 5
0
 def convert(self, value, param, context):
     return project.from_path(FilePath(value))
Esempio n. 6
0
 def getStatusChangeTime(self):
     """
     Return the archive file's status change time.
     """
     return FilePath(self.zipfile.filename).getStatusChangeTime()
Esempio n. 7
0
 def getModificationTime(self):
     """
     Return the archive file's modification time.
     """
     return FilePath(self.zipfile.filename).getModificationTime()
Esempio n. 8
0
 def getAccessTime(self):
     """
     Return the archive file's last access time.
     """
     return FilePath(self.zipfile.filename).getAccessTime()
Esempio n. 9
0
 def exists(self):
     """
     Returns whether the underlying archive exists.
     """
     return FilePath(self.zipfile.filename).exists()
Esempio n. 10
0
    $ pypy example.py ~/Desktop/haarcascade_frontalface_default.xml

"""

from time import time
import sys

from bp.filepath import FilePath

from opencv_cffi.core import Color, invert
from opencv_cffi.imaging import Camera
from opencv_cffi.gui import ESCAPE, Window
from opencv_cffi.object_detection import HaarClassifier


cascade_filepath = FilePath(sys.argv[1])
classifier = HaarClassifier.from_path(cascade_filepath, canny_pruning=True)


def uglify(frame, facetangle):
    with frame.region_of_interest(facetangle.right_half):
        invert(frame)


def prettify(frame, facetangle):
    with frame.region_of_interest(facetangle.right_half):
        prettified = frame.flipped_vertical()

    with frame.region_of_interest(facetangle.left_half):
        prettified.write_into(frame)
Esempio n. 11
0
#!/usr/bin/env python
"""
A performance benchmark using the example from issue #232:

https://github.com/Julian/jsonschema/pull/232

"""
from bp.filepath import FilePath
from perf import Runner
from pyrsistent import m

from jsonschema.tests._suite import Collection
import jsonschema

collection = Collection(
    path=FilePath(__file__).sibling("issue232"),
    remotes=m(),
    name="issue232",
    validator=jsonschema.Draft7Validator,
)

if __name__ == "__main__":
    collection.benchmark(runner=Runner())
Esempio n. 12
0
 def children(self):
     return [FilePath(path) for path in self.listdir()]