Ejemplo n.º 1
0
def _get_path_stems(strings, recursive):
    """A list of any paths in strings

    If there is a "/" in the strings then it is used in the list
    Otherwise it is appended to the current working directory
    """
    strings = strings or []
    here = path('.')
    paths = ['/' in s and path(s) or here / s for s in strings]
    if not recursive:
        return paths
    return add_sub_dirs(paths)
Ejemplo n.º 2
0
 def __init__(self, that):
     self.here = path('.')
     self.home = path('~')
     self.username = get_user()
     self.host = get_host()
     self.user = '******'.join((self.username, self.host))
     self.path = self.here.relpathto(that)
     base, _ext = self.path.splitext()
     self.stem = base
     [
         self.add_ext(base, _)
         for _ in {_ext[1:], 'py', 'test', 'tests', 'fail'}
     ]
Ejemplo n.º 3
0
def todo_file():
    """Get the filename from the environment"""
    # Tell pylint not to warn that this is a todo
    # pylint: disable-msg=W0511
    if sys.argv[1:]:
        todo = path(sys.argv[1])
        if todo.isfile():
            return todo
    todo = path('~/jab') / 'todo.txt'
    if todo.isfile():
        return todo
    todo = jab / 'todo.md'
    if todo.isfile():
        return todo
    return None
Ejemplo n.º 4
0
 def remove(self, item):
     """Remove the item from sys.path"""
     directory = path(item).directory()
     if directory in self.paths:
         self.paths.remove(directory)
         if directory in sys.path:
             sys.path.remove(directory)
Ejemplo n.º 5
0
 def add(self, item):
     """Add the item to sys.path"""
     directory = path(item).directory()
     if directory not in self.paths:
         self.paths.insert(0, directory)
         if directory not in sys.path:
             sys.path.insert(0, str(directory))
Ejemplo n.º 6
0
 def add_ext(self, base, ext):
     """Add a path for base.ext as an attribute to self"""
     name = f'path_to_{ext}'
     if hasattr(self, name):
         return
     path_to_ext = path(f'{base}.{ext}')
     if path_to_ext.isfile() or ext == 'fail':
         setattr(self, name, path_to_ext)
Ejemplo n.º 7
0
def todo_file():
    """Get the filename from the environment"""
    # Tell pylint not to warn that this is a todo
    # pylint: disable-msg=W0511
    if sys.argv[1:]:
        arg = sys.argv[1]
        if os.path.isfile(arg):
            return arg
    jab = path('~/jab')
    return jab / 'todo.txt'
Ejemplo n.º 8
0
def age():
    """age of this

    >>> assert age()
    """
    from pysyte.types import paths
    from datetime import datetime

    python_file = paths.path(__file__)
    age_ = datetime.now() - datetime.fromtimestamp(python_file.stat().st_ctime)
    return age_
Ejemplo n.º 9
0
def _get_scripts_here(recursive):
    """Find all test scripts in the current working directory"""
    here = path('.')
    all_possibles = _all_possible_test_files_in(here, recursive)
    test_extensions = [
        _ for _ in all_possibles if has_python_doctest_extension(_)
    ]
    test_texts = [
        _ for _ in all_possibles
        if has_python_source_extension(_) and has_doctests(_.text())
    ]
    return test_texts + test_extensions
Ejemplo n.º 10
0
def _read():
    _path_to_csv = path(__file__).extend_by('csv')
    result = OrderedDict()
    with open(_path_to_csv) as stream:
        reader = csv.reader(stream)
        csv_rows = list(reader)
        data = csv_rows[2:]
        rows = []
        for datum in data:
            items = list(datum)
            name = items[1]
            del items[1]
            result[name] = Row(*items)
        return result
Ejemplo n.º 11
0
def _get_path_to_test_directory(strings):
    """Get a path to the root directory that we'll be testing in

    We will test in the first directory in strings
        or the directory of the first file in strings
    """
    paths = [path(s) for s in strings]
    result = first_thing_that(paths, lambda p: p.isdir())
    if not result:
        try:
            result = first_thing_that(paths,
                                      lambda p: p.parent and p.isfile()).parent
        except AttributeError:
            raise MissingFiles('No doctests found in %r' % strings)
    if not result.files('*.test*') and not result.files('*.py'):
        raise MissingFiles('No doctests found in %r' % strings)
    return result
Ejemplo n.º 12
0
def get_significant_status(path_to_directory):
    """Get the svn status for that directory

    Stop if any immediates have a significant status
        otherwise recurse into sub-directories
    """
    path_to_directory = path(path_to_directory)
    if not path_to_directory.isdir():
        return None
    if not _is_working_directory(path_to_directory):
        return None
    status = _get_immediately_significant_status(path_to_directory)
    if status:
        return status
    for path_to_dir in path_to_directory.dirs():
        if path_to_dir[0] == '.' or path_to_dir == path_to_directory:
            continue
        status = get_significant_status(path_to_dir)
        if status:
            return status
    return None
Ejemplo n.º 13
0
def _get_existing_file(path_to_file):
    result = path(path_to_file)
    if result.isfile():
        return result
    raise ValueError('%s is not a file' % result)
Ejemplo n.º 14
0
 def _paths(self):
     return [path(_) for _ in self._strings()]