Fixes #10. Hidden files and directories are ignored when trying to find metadata.
This commit is contained in:
parent
2158c666c6
commit
adb4cf7442
2 changed files with 19 additions and 5 deletions
12
circup.py
12
circup.py
|
|
@ -375,8 +375,16 @@ def get_modules(path):
|
|||
:param str path: The directory in which to find modules.
|
||||
:return: A dictionary containing metadata about the found modules.
|
||||
"""
|
||||
single_file_mods = glob.glob(os.path.join(path, "*.py"))
|
||||
directory_mods = glob.glob(os.path.join(path, "*", ""))
|
||||
single_file_mods = [
|
||||
f
|
||||
for f in glob.glob(os.path.join(path, "*.py"))
|
||||
if not os.path.basename(f).startswith(".")
|
||||
]
|
||||
directory_mods = [
|
||||
d
|
||||
for d in glob.glob(os.path.join(path, "*", ""))
|
||||
if not os.path.basename(os.path.normpath(d)).startswith(".")
|
||||
]
|
||||
result = {}
|
||||
for sfm in single_file_mods:
|
||||
with open(sfm, encoding="utf-8") as source_file:
|
||||
|
|
|
|||
|
|
@ -399,10 +399,13 @@ def test_get_modules_that_are_files():
|
|||
(mocked) results of glob and open on file based Python modules.
|
||||
"""
|
||||
path = "tests" # mocked away in function.
|
||||
mods = [os.path.join("tests", "local_module.py")]
|
||||
mods = [
|
||||
os.path.join("tests", "local_module.py"),
|
||||
os.path.join("tests", ".hidden_module.py"),
|
||||
]
|
||||
with mock.patch("circup.glob.glob", side_effect=[mods, []]):
|
||||
result = circup.get_modules(path)
|
||||
assert len(result) == 1
|
||||
assert len(result) == 1 # Hidden files are ignored.
|
||||
assert "local_module.py" in result
|
||||
assert result["local_module.py"]["path"] == os.path.join(
|
||||
"tests", "local_module.py"
|
||||
|
|
@ -420,7 +423,10 @@ def test_get_modules_that_are_directories():
|
|||
(mocked) results of glob and open, on directory based Python modules.
|
||||
"""
|
||||
path = "tests" # mocked away in function.
|
||||
mods = [os.path.join("tests", "dir_module", "")]
|
||||
mods = [
|
||||
os.path.join("tests", "dir_module", ""),
|
||||
os.path.join("tests", ".hidden_dir", ""),
|
||||
]
|
||||
mod_files = [
|
||||
"tests/dir_module/my_module.py",
|
||||
"tests/dir_module/__init__.py",
|
||||
|
|
|
|||
Loading…
Reference in a new issue