core: expand '~' in get_files & import_dir

This commit is contained in:
Dima Gerasimov 2020-05-18 21:50:36 +01:00
parent 403ec18385
commit c8bdbfd69f
3 changed files with 13 additions and 3 deletions

View file

@ -98,7 +98,7 @@ for cls, p in modules:
export_path: Paths
# path to a local clone of hypexport
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/repos/hypexport
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/hypexport
hypexport : Optional[PathIsh] = None
#+end_src
- [[file:../my/reddit.py][my.reddit]]
@ -115,7 +115,7 @@ for cls, p in modules:
export_path: Paths
# path to a local clone of rexport
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/repos/rexport
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/rexport
rexport : Optional[PathIsh] = None
#+end_src
- [[file:../my/twitter/twint.py][my.twitter.twint]]
@ -172,7 +172,7 @@ for cls, p in modules:
export_path : Paths
# path to a local clone of instapexport
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/repos/instapexport
# alternatively, you can put the repository (or a symlink) in $MY_CONFIG/my/config/repos/instapexport
instapexport: Optional[PathIsh] = None
#+end_src
:end:

View file

@ -36,6 +36,8 @@ def import_from(path: PathIsh, name: str) -> types.ModuleType:
def import_dir(path: PathIsh, extra: str='') -> types.ModuleType:
p = Path(path)
if p.parts[0] == '~':
p = p.expanduser() # TODO eh. not sure about this..
return import_from(p.parent, p.name + extra)
@ -130,6 +132,8 @@ def get_files(pp: Paths, glob: str=DEFAULT_GLOB, sort: bool=True) -> Tuple[Path,
paths: List[Path] = []
for src in sources:
if src.parts[0] == '~':
src = src.expanduser()
if src.is_dir():
gp: Iterable[Path] = src.glob(glob)
paths.extend(gp)

View file

@ -26,6 +26,12 @@ def test_single_file():
)
"if the path starts with ~, we expand it"
assert get_files('~/.bashrc') == (
Path('~').expanduser() / '.bashrc',
)
def test_multiple_files():
'''
If you pass a directory/multiple directories, it flattens the contents