Skip to content

Commit 07f0cb7

Browse files
authored
apply ruff format
1 parent 21bc7ca commit 07f0cb7

File tree

8 files changed

+223
-257
lines changed

8 files changed

+223
-257
lines changed

src/mkdocs_git_revision_date_localized_plugin/dates.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,49 +43,49 @@ def get_date_formats(
4343
def strftime_to_babel_format(fmt: str) -> str:
4444
"""
4545
Convert strftime format string to Babel format pattern.
46-
46+
4747
Args:
4848
fmt (str): strftime format string
49-
49+
5050
Returns:
5151
str: Babel format pattern
5252
"""
5353
# Dictionary mapping strftime directives to Babel format patterns
5454
mapping = {
55-
'%a': 'EEE', # Weekday abbreviated
56-
'%A': 'EEEE', # Weekday full
57-
'%b': 'MMM', # Month abbreviated
58-
'%B': 'MMMM', # Month full
59-
'%c': '', # Locale's date and time (not directly mappable)
60-
'%d': 'dd', # Day of month zero-padded
61-
'%-d': 'd', # Day of month
62-
'%e': 'd', # Day of month space-padded
63-
'%f': 'SSSSSS', # Microsecond
64-
'%H': 'HH', # Hour 24h zero-padded
65-
'%-H': 'H', # Hour 24h
66-
'%I': 'hh', # Hour 12h zero-padded
67-
'%-I': 'h', # Hour 12h
68-
'%j': 'DDD', # Day of year
69-
'%m': 'MM', # Month zero-padded
70-
'%-m': 'M', # Month
71-
'%M': 'mm', # Minute zero-padded
72-
'%-M': 'm', # Minute
73-
'%p': 'a', # AM/PM
74-
'%S': 'ss', # Second zero-padded
75-
'%-S': 's', # Second
76-
'%w': 'e', # Weekday as number
77-
'%W': 'w', # Week of year
78-
'%x': '', # Locale's date (not directly mappable)
79-
'%X': '', # Locale's time (not directly mappable)
80-
'%y': 'yy', # Year without century
81-
'%Y': 'yyyy', # Year with century
82-
'%z': 'Z', # UTC offset
83-
'%Z': 'z', # Timezone name
84-
'%%': '%' # Literal %
55+
"%a": "EEE", # Weekday abbreviated
56+
"%A": "EEEE", # Weekday full
57+
"%b": "MMM", # Month abbreviated
58+
"%B": "MMMM", # Month full
59+
"%c": "", # Locale's date and time (not directly mappable)
60+
"%d": "dd", # Day of month zero-padded
61+
"%-d": "d", # Day of month
62+
"%e": "d", # Day of month space-padded
63+
"%f": "SSSSSS", # Microsecond
64+
"%H": "HH", # Hour 24h zero-padded
65+
"%-H": "H", # Hour 24h
66+
"%I": "hh", # Hour 12h zero-padded
67+
"%-I": "h", # Hour 12h
68+
"%j": "DDD", # Day of year
69+
"%m": "MM", # Month zero-padded
70+
"%-m": "M", # Month
71+
"%M": "mm", # Minute zero-padded
72+
"%-M": "m", # Minute
73+
"%p": "a", # AM/PM
74+
"%S": "ss", # Second zero-padded
75+
"%-S": "s", # Second
76+
"%w": "e", # Weekday as number
77+
"%W": "w", # Week of year
78+
"%x": "", # Locale's date (not directly mappable)
79+
"%X": "", # Locale's time (not directly mappable)
80+
"%y": "yy", # Year without century
81+
"%Y": "yyyy", # Year with century
82+
"%z": "Z", # UTC offset
83+
"%Z": "z", # Timezone name
84+
"%%": "%", # Literal %
8585
}
86-
86+
8787
result = fmt
8888
for strftime_code, babel_code in mapping.items():
8989
result = result.replace(strftime_code, babel_code)
90-
91-
return result
90+
91+
return result

src/mkdocs_git_revision_date_localized_plugin/plugin.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def on_config(self, config: config_options.Config, **kwargs) -> Dict[str, Any]:
144144

145145
return config
146146

147-
148147
def parallel_compute_commit_timestamps(self, files, original_source: Optional[Dict] = None, is_first_commit=False):
149148
pool = multiprocessing.Pool(processes=min(10, multiprocessing.cpu_count()))
150149
results = []
@@ -154,9 +153,7 @@ def parallel_compute_commit_timestamps(self, files, original_source: Optional[Di
154153
# Support plugins like monorep that might have moved the files from the original source that is under git
155154
if original_source and abs_src_path in original_source:
156155
abs_src_path = original_source[abs_src_path]
157-
result = pool.apply_async(
158-
self.util.get_git_commit_timestamp, args=(abs_src_path, is_first_commit)
159-
)
156+
result = pool.apply_async(self.util.get_git_commit_timestamp, args=(abs_src_path, is_first_commit))
160157
results.append((abs_src_path, result))
161158
pool.close()
162159
pool.join()
@@ -173,10 +170,10 @@ def on_files(self, files: Files, config: MkDocsConfig):
173170
"""
174171
if not self.config.get("enabled") or not self.config.get("enable_parallel_processing"):
175172
return
176-
173+
177174
# Support monorepo/techdocs, which copies the docs_dir to a temporary directory
178-
if "monorepo" in config.get('plugins', {}):
179-
original_source = config.get('plugins').get('monorepo').merger.files_source_dir
175+
if "monorepo" in config.get("plugins", {}):
176+
original_source = config.get("plugins").get("monorepo").merger.files_source_dir
180177
else:
181178
original_source = None
182179

@@ -185,7 +182,6 @@ def on_files(self, files: Files, config: MkDocsConfig):
185182
if not self.created_commits:
186183
self.parallel_compute_commit_timestamps(files=files, original_source=original_source, is_first_commit=True)
187184

188-
189185
def on_page_markdown(self, markdown: str, page: Page, config: config_options.Config, files, **kwargs) -> str:
190186
"""
191187
Replace jinja2 tags in markdown and templates with the localized dates.
@@ -240,7 +236,9 @@ def on_page_markdown(self, markdown: str, page: Page, config: config_options.Con
240236
if getattr(page.file, "generated_by", None):
241237
last_revision_hash, last_revision_timestamp = "", int(time.time())
242238
else:
243-
last_revision_hash, last_revision_timestamp = self.last_revision_commits.get(page.file.abs_src_path, (None, None))
239+
last_revision_hash, last_revision_timestamp = self.last_revision_commits.get(
240+
page.file.abs_src_path, (None, None)
241+
)
244242
if last_revision_timestamp is None:
245243
last_revision_hash, last_revision_timestamp = self.util.get_git_commit_timestamp(
246244
path=page.file.abs_src_path,
@@ -314,8 +312,10 @@ def on_page_markdown(self, markdown: str, page: Page, config: config_options.Con
314312
if getattr(page.file, "generated_by", None):
315313
first_revision_hash, first_revision_timestamp = "", int(time.time())
316314
else:
317-
first_revision_hash, first_revision_timestamp = self.created_commits.get(page.file.abs_src_path, (None, None))
318-
if first_revision_timestamp is None:
315+
first_revision_hash, first_revision_timestamp = self.created_commits.get(
316+
page.file.abs_src_path, (None, None)
317+
)
318+
if first_revision_timestamp is None:
319319
first_revision_hash, first_revision_timestamp = self.util.get_git_commit_timestamp(
320320
path=page.file.abs_src_path,
321321
is_first_commit=True,

tests/fixtures/mkdocs-gen-files/gen_pages.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
with mkdocs_gen_files.open("foo.md", "w") as f:
44
print("Hello, world!", file=f)
5-

tests/fixtures/with_mknotebooks/docs/demo.ipynb

Lines changed: 46 additions & 45 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)