mkdocs-simple-plugin 3.2.1__tar.gz → 3.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-simple-plugin
3
- Version: 3.2.1
3
+ Version: 3.2.3
4
4
  Summary: Plugin for adding simple wiki site creation from markdown files interspersed within your code with MkDocs.
5
5
  Project-URL: Documentation, http://www.althack.dev/mkdocs-simple-plugin
6
6
  Project-URL: Homepage, http://www.althack.dev/mkdocs-simple-plugin
@@ -335,11 +335,15 @@ class SimplePlugin(BasePlugin):
335
335
  # Read previous config first so updates don't get overwritten
336
336
  config_site_dir = get_config_site_dir(config.config_file_path)
337
337
 
338
- # Set the build docs dir to tmp location if not set by user
339
- if not self.config['build_dir'] and self.config['merge_docs_dir']:
340
- self.config['build_dir'] = config['docs_dir']
341
- else:
342
- self.config['build_dir'] = self.tmp_build_dir
338
+ # If the build_dir isn't set by the user,
339
+ # set it to one of the following locations:
340
+ if not self.config['build_dir']:
341
+ if self.config['merge_docs_dir']:
342
+ # the build_dir to the docs_dir if merging
343
+ self.config['build_dir'] = config['docs_dir']
344
+ else:
345
+ # or a temp directory
346
+ self.config['build_dir'] = self.tmp_build_dir
343
347
 
344
348
  utils.log.info(
345
349
  "mkdocs-simple-plugin: build_dir: %s",
@@ -392,6 +396,7 @@ class SimplePlugin(BasePlugin):
392
396
  dest_dir=config.site_dir,
393
397
  use_directory_urls=config["use_directory_urls"]
394
398
  )
399
+ file.generated_by = "mkdocs_simple_plugin"
395
400
  if file.src_uri in files.src_uris:
396
401
  files.remove(file)
397
402
  files.append(file)
@@ -3,6 +3,7 @@ import fnmatch
3
3
  import os
4
4
  import pathlib
5
5
  import stat
6
+ from typing import List, Dict
6
7
 
7
8
  from shutil import copy2 as copy
8
9
  from dataclasses import dataclass
@@ -51,68 +52,77 @@ class Simple():
51
52
  self.folders = set(folders)
52
53
  self.doc_glob = set(include)
53
54
  self.ignore_glob = set(ignore)
54
- self.ignore_hidden = ignore_hidden # to be deprecated
55
- self.hidden_prefix = set([".", "__"]) # to be deprecated
55
+ self.ignore_hidden = ignore_hidden # TODO[athackst] deprecate
56
+ self.hidden_prefix = set([".", "__"]) # TODO[athackst] deprecate
56
57
  self.ignore_paths = set(ignore_paths)
57
58
  self.semiliterate = []
58
59
  for item in semiliterate:
59
60
  self.semiliterate.append(Semiliterate(**item))
60
-
61
- def get_files(self) -> list:
61
+ self.ignore_patterns: Dict[pathlib.Path, List[str]] = {}
62
+ self.root_path: pathlib.Path = pathlib.Path()
63
+
64
+ def process_mkdocsignore_files(self):
65
+ """Process all .mkdocsignore files and update ignore_glob."""
66
+ for mkdocsignore in self.root_path.rglob('.mkdocsignore'):
67
+ relative_path = mkdocsignore.parent.relative_to(self.root_path)
68
+ patterns = []
69
+ with mkdocsignore.open(mode="r", encoding="utf-8") as txt_file:
70
+ for line in txt_file:
71
+ line = line.strip()
72
+ if line and not line.startswith('#'):
73
+ patterns.append(line)
74
+
75
+ if not patterns:
76
+ # If .mkdocsignore is empty, ignore everything in this directory
77
+ # and below
78
+ pattern = str(relative_path / '**')
79
+ self.ignore_glob.add(pattern)
80
+ else:
81
+ for pattern in patterns:
82
+ if relative_path != pathlib.Path('.'):
83
+ pattern = str(relative_path / pattern)
84
+ self.ignore_glob.add(pattern)
85
+
86
+ def process_ignore_folders(self):
87
+ """Update ignore glob to include folders."""
88
+ self.ignore_glob.update(
89
+ [f"{pattern}/**" for pattern in self.ignore_glob])
90
+
91
+ def get_files(self) -> List[str]:
62
92
  """Get a list of files to process, excluding ignored files."""
63
- files = []
64
- # Get all of the entries that match the include pattern.
65
- entries = []
93
+ # Process all .mkdocsignore files first
94
+ self.process_mkdocsignore_files()
95
+ self.process_ignore_folders() # TODO[athackst] deprecate
96
+ files = set()
66
97
  for pattern in self.folders:
67
- entries.extend(pathlib.Path().glob(pattern))
68
- # Ignore any entries that match the ignore pattern
69
- entries[:] = [
70
- entry for entry in entries
71
- if not self.is_path_ignored(str(entry))]
72
- # Add any files
73
- files[:] = [
74
- os.path.normpath(entry) for entry in entries if entry.is_file()]
75
- # Iterate through directories to get files
76
- for entry in entries:
77
- for root, directories, filenames in os.walk(entry):
78
- files.extend([os.path.join(root, f)
79
- for f in filenames if not self.is_ignored(root, f)]
80
- )
81
- directories[:] = [
82
- d for d in directories if not self.is_ignored(root, d)]
83
- return files
84
-
85
- def is_ignored(self, base_path: str, name: str) -> bool:
86
- """Check if directory and filename should be ignored."""
87
- return self.is_path_ignored(os.path.join(base_path, name))
88
-
89
- def is_path_ignored(self, path: str = None) -> bool:
98
+ for entry in pathlib.Path().glob(pattern):
99
+ if entry.is_dir():
100
+ files.update(str(f) for f in entry.rglob(
101
+ '*') if self.is_valid_file(f))
102
+ elif self.is_valid_file(entry):
103
+ files.add(str(entry))
104
+ return list(files)
105
+
106
+ def is_valid_file(self, path: pathlib.Path) -> bool:
107
+ """Check if file is valid (not ignored and matches doc_glob)."""
108
+ if self.is_ignored(path):
109
+ return False
110
+ if not path.is_file():
111
+ return False
112
+ return True
113
+
114
+ def is_ignored(self, path: pathlib.Path) -> bool:
90
115
  """Check if path should be ignored."""
91
- path = os.path.normpath(path)
92
- base_path = os.path.dirname(path)
93
-
94
- # Check if its an internally required ignore path
95
- for ignored in self.ignore_paths:
96
- if os.path.abspath(path).startswith(ignored):
97
- return True
98
-
99
- # Update ignore patterns from .mkdocsignore file
100
- mkdocsignore = os.path.join(base_path, ".mkdocsignore")
101
- if os.path.exists(mkdocsignore):
102
- ignore_list = []
103
- with open(mkdocsignore, mode="r", encoding="utf-8") as txt_file:
104
- ignore_list = txt_file.read().splitlines()
105
- # Remove all comment lines
106
- ignore_list = [x for x in ignore_list if not x.startswith('#')]
107
- if not ignore_list:
108
- ignore_list = ["*"]
109
- self.ignore_glob.update(
110
- set(os.path.join(base_path, filter) for filter in ignore_list))
111
- # Check for ignore paths in patterns
112
- if any(fnmatch.fnmatch(path, filter)
113
- for filter in self.ignore_glob):
116
+ rel_path = path.relative_to(self.root_path)
117
+
118
+ # Check ignore_paths (absolute paths)
119
+ if any(path.resolve().is_relative_to(ignored)
120
+ for ignored in self.ignore_paths):
114
121
  return True
115
- return False
122
+
123
+ # Check all ignore patterns
124
+ return any(fnmatch.fnmatch(str(rel_path), pattern)
125
+ for pattern in self.ignore_glob)
116
126
 
117
127
  def is_doc_file(self, name: str) -> bool:
118
128
  """Check if file is a desired doc file."""