Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5338552

Browse files
kamilkrzyskowsquidfunk
authored andcommitted
Fixed handling of inconsistent drive letter case
1 parent6d4f756 commit5338552

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

‎material/plugins/info/plugin.py‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,22 @@ def on_config(self, config):
151151
ifnotisinstance(loaded_configs,list):
152152
loaded_configs= [loaded_configs]
153153

154+
# It can happen that the drive letter case is inconsistent on Windows.
155+
# Therefore, assure first character to be uppercase for the following
156+
# checks. See: https://t.ly/9t1SU
157+
site_prefixes=list(map(capitalize,site.PREFIXES))
158+
cwd=capitalize(os.getcwd())
159+
154160
# We need to make sure the user put every file in the current working
155161
# directory. To assure the reproduction inside the ZIP file can be run,
156162
# validate that the MkDocs paths are children of the current root.
157-
paths_to_validate= [
163+
paths_to_validate=list(map(capitalize,[
158164
config.config_file_path,
159165
config.docs_dir,
160166
abs_custom_dir,
161167
abs_projects_dir,
162168
*[cfg.get("INHERIT","")forcfginloaded_configs]
163-
]
169+
]))
164170

165171
# Convert relative hook paths to absolute path
166172
forhookinconfig.hooks:
@@ -169,7 +175,7 @@ def on_config(self, config):
169175

170176
# Remove valid paths from the list
171177
forpathinlist(paths_to_validate):
172-
ifnotpathorpath.startswith(os.getcwd()):
178+
ifnotpathorpath.startswith(cwd):
173179
paths_to_validate.remove(path)
174180

175181
# Report the invalid paths to the user
@@ -191,14 +197,14 @@ def on_config(self, config):
191197
self.excluded_entries= []
192198

193199
# Exclude the site_dir at project root
194-
ifconfig.site_dir.startswith(os.getcwd()):
200+
ifcapitalize(config.site_dir).startswith(cwd):
195201
self.exclusion_patterns.append(_resolve_pattern(config.site_dir))
196202

197203
# Exclude the Virtual Environment directory. site.getsitepackages() has
198204
# inconsistent results across operating systems, and relies on the
199205
# PREFIXES that will contain the absolute path to the activated venv.
200-
forpathinsite.PREFIXES:
201-
ifpath.startswith(os.getcwd()):
206+
forpathinsite_prefixes:
207+
ifpath.startswith(cwd):
202208
self.exclusion_patterns.append(_resolve_pattern(path))
203209

204210
# Guess other Virtual Environment paths in case we forget to activate
@@ -209,9 +215,9 @@ def on_config(self, config):
209215
iffilename.lower()!="pyvenv.cfg":
210216
continue
211217

212-
path=abs_root[0].upper()+abs_root[1:]
218+
path=capitalize(abs_root)
213219

214-
ifpathnotinsite.PREFIXES:
220+
ifpathnotinsite_prefixes:
215221
print(f"Possible inactive venv:{path}")
216222
self.exclusion_patterns.append(_resolve_pattern(path))
217223

@@ -509,7 +515,7 @@ def _load_yaml(abs_src_path: str):
509515
# in the pattern creation for files and directories. The patterns are matched
510516
# using the search function, so they are prefixed with ^ for specificity.
511517
def_resolve_pattern(abspath:str,return_path:bool=False):
512-
path=abspath.replace(os.getcwd(),"",1)
518+
path=capitalize(abspath).replace(capitalize(os.getcwd()),"",1)
513519
path=path.replace(os.sep,"/").rstrip("/")
514520

515521
ifnotpath:
@@ -543,6 +549,11 @@ def _is_dotpath(path: str, log_warning: bool = False) -> bool:
543549
returnTrue
544550
returnFalse
545551

552+
# It can happen that the drive letter case is inconsistent on Windows.
553+
# Capitalize the first character keeping the rest the same for comparison.
554+
# See: https://t.ly/9t1SU
555+
defcapitalize(path:str):
556+
returnpath[0].upper()+path[1:]ifpathelsepath
546557

547558
# -----------------------------------------------------------------------------
548559
# Data

‎src/plugins/info/plugin.py‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,22 @@ def on_config(self, config):
151151
ifnotisinstance(loaded_configs,list):
152152
loaded_configs= [loaded_configs]
153153

154+
# It can happen that the drive letter case is inconsistent on Windows.
155+
# Therefore, assure first character to be uppercase for the following
156+
# checks. See: https://t.ly/9t1SU
157+
site_prefixes=list(map(capitalize,site.PREFIXES))
158+
cwd=capitalize(os.getcwd())
159+
154160
# We need to make sure the user put every file in the current working
155161
# directory. To assure the reproduction inside the ZIP file can be run,
156162
# validate that the MkDocs paths are children of the current root.
157-
paths_to_validate= [
163+
paths_to_validate=list(map(capitalize,[
158164
config.config_file_path,
159165
config.docs_dir,
160166
abs_custom_dir,
161167
abs_projects_dir,
162168
*[cfg.get("INHERIT","")forcfginloaded_configs]
163-
]
169+
]))
164170

165171
# Convert relative hook paths to absolute path
166172
forhookinconfig.hooks:
@@ -169,7 +175,7 @@ def on_config(self, config):
169175

170176
# Remove valid paths from the list
171177
forpathinlist(paths_to_validate):
172-
ifnotpathorpath.startswith(os.getcwd()):
178+
ifnotpathorpath.startswith(cwd):
173179
paths_to_validate.remove(path)
174180

175181
# Report the invalid paths to the user
@@ -191,14 +197,14 @@ def on_config(self, config):
191197
self.excluded_entries= []
192198

193199
# Exclude the site_dir at project root
194-
ifconfig.site_dir.startswith(os.getcwd()):
200+
ifcapitalize(config.site_dir).startswith(cwd):
195201
self.exclusion_patterns.append(_resolve_pattern(config.site_dir))
196202

197203
# Exclude the Virtual Environment directory. site.getsitepackages() has
198204
# inconsistent results across operating systems, and relies on the
199205
# PREFIXES that will contain the absolute path to the activated venv.
200-
forpathinsite.PREFIXES:
201-
ifpath.startswith(os.getcwd()):
206+
forpathinsite_prefixes:
207+
ifpath.startswith(cwd):
202208
self.exclusion_patterns.append(_resolve_pattern(path))
203209

204210
# Guess other Virtual Environment paths in case we forget to activate
@@ -209,9 +215,9 @@ def on_config(self, config):
209215
iffilename.lower()!="pyvenv.cfg":
210216
continue
211217

212-
path=abs_root[0].upper()+abs_root[1:]
218+
path=capitalize(abs_root)
213219

214-
ifpathnotinsite.PREFIXES:
220+
ifpathnotinsite_prefixes:
215221
print(f"Possible inactive venv:{path}")
216222
self.exclusion_patterns.append(_resolve_pattern(path))
217223

@@ -509,7 +515,7 @@ def _load_yaml(abs_src_path: str):
509515
# in the pattern creation for files and directories. The patterns are matched
510516
# using the search function, so they are prefixed with ^ for specificity.
511517
def_resolve_pattern(abspath:str,return_path:bool=False):
512-
path=abspath.replace(os.getcwd(),"",1)
518+
path=capitalize(abspath).replace(capitalize(os.getcwd()),"",1)
513519
path=path.replace(os.sep,"/").rstrip("/")
514520

515521
ifnotpath:
@@ -543,6 +549,11 @@ def _is_dotpath(path: str, log_warning: bool = False) -> bool:
543549
returnTrue
544550
returnFalse
545551

552+
# It can happen that the drive letter case is inconsistent on Windows.
553+
# Capitalize the first character keeping the rest the same for comparison.
554+
# See: https://t.ly/9t1SU
555+
defcapitalize(path:str):
556+
returnpath[0].upper()+path[1:]ifpathelsepath
546557

547558
# -----------------------------------------------------------------------------
548559
# Data

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp