Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check all file parts for hidden attributes #395

Merged
merged 1 commit into from Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mkdocs_simple_plugin/semiliterate.py
Expand Up @@ -229,7 +229,7 @@ def write(self, arg: str):
def close(self):
"""Finish the file."""
if self.file_object is not None:
utils.log.debug(
utils.log.info(
" ... extracted %s",
os.path.join(
self.file_directory,
Expand Down
13 changes: 8 additions & 5 deletions mkdocs_simple_plugin/simple.py
Expand Up @@ -147,9 +147,14 @@ def has_hidden_attribute(filepath):
return False

def has_hidden_prefix(filepath):
name = os.path.basename(os.path.abspath(filepath))
return any(name.startswith(pattern)
for pattern in self.hidden_prefix)
parts = filepath.split(os.path.sep)

def hidden_prefix(name):
if name == ".":
return False
return any(name.startswith(pattern)
for pattern in self.hidden_prefix)
return any(hidden_prefix(part) for part in parts)

return has_hidden_prefix(filepath) or has_hidden_attribute(filepath)

Expand Down Expand Up @@ -202,8 +207,6 @@ def try_copy_file(self, from_dir: str, name: str, to_dir: str) -> bool:
new_file = os.path.join(to_dir, name)

if not self.should_copy_file(name):
utils.log.debug(
"mkdocs-simple-plugin: skip copying file %s", original)
return False
try:
os.makedirs(to_dir, exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions tests/test_simple.py
Expand Up @@ -49,6 +49,7 @@ def test_is_hidden(self, os_stat):
self.assertFalse(simple_test.is_hidden('./folder/test.md'))
self.assertTrue(simple_test.is_hidden('__pycache__'))
self.assertTrue(simple_test.is_hidden('.mkdocsignore'))
self.assertTrue(simple_test.is_hidden(".git/objects/34/49807110bdc8"))
# Check hidden file attribute
os_stat.return_value.st_file_attributes = stat.FILE_ATTRIBUTE_HIDDEN
self.assertTrue(simple_test.is_hidden('/test/file'))
Expand Down