mkdocs-document-dates 1.9.7__py3-none-any.whl → 1.9.9__py3-none-any.whl

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,3 +1,11 @@
1
1
  """MkDocs Document Dates Plugin."""
2
2
 
3
- __version__ = '1.0.0'
3
+ __version__ = '1.0.0'
4
+
5
+ from .hooks_installer import install
6
+
7
+ # 当包被导入时自动安装 hooks
8
+ try:
9
+ install()
10
+ except Exception as e:
11
+ print(f"自动安装 git hooks 失败: {e}")
@@ -8,80 +8,6 @@ import subprocess
8
8
  from datetime import datetime
9
9
  from pathlib import Path
10
10
 
11
- # 添加调试日志到项目的 docs 目录
12
- def log_debug(message):
13
- try:
14
- git_root = Path(subprocess.check_output(
15
- ['git', 'rev-parse', '--show-toplevel'],
16
- text=True
17
- ).strip())
18
-
19
- docs_dir = git_root / 'docs'
20
- if docs_dir.exists():
21
- with open(docs_dir / '.hook_debug.log', 'a') as f:
22
- f.write(f"{datetime.now()}: {message}\n")
23
- except:
24
- pass # 静默失败,不影响主流程
25
-
26
- # 配置日志
27
- def setup_logging():
28
- """设置日志"""
29
- try:
30
- # 获取当前 git 仓库根目录
31
- git_root = Path(subprocess.check_output(
32
- ['git', 'rev-parse', '--show-toplevel'],
33
- text=True
34
- ).strip())
35
-
36
- # 在 git 仓库根目录下创建日志目录
37
- log_dir = git_root / '.mkdocs_dates'
38
- log_dir.mkdir(exist_ok=True)
39
- log_file = log_dir / 'hook.log'
40
-
41
- logging.basicConfig(
42
- level=logging.INFO,
43
- format='%(asctime)s - %(levelname)s - %(message)s',
44
- handlers=[
45
- logging.FileHandler(log_file),
46
- logging.StreamHandler(sys.stderr)
47
- ]
48
- )
49
- return True
50
- except Exception as e:
51
- print(f"Failed to setup logging: {e}", file=sys.stderr)
52
- return False
53
-
54
- # 添加调试函数
55
- def debug_info():
56
- info = {
57
- 'cwd': os.getcwd(),
58
- 'python_path': sys.executable,
59
- 'env_path': os.environ.get('PATH', ''),
60
- 'script_path': __file__,
61
- 'timestamp': datetime.now().isoformat()
62
- }
63
-
64
- # 保存调试信息到固定位置
65
- debug_file = Path('/tmp/mkdocs_hook_debug.json')
66
- try:
67
- with open(debug_file, 'w') as f:
68
- json.dump(info, f, indent=2)
69
-
70
- # 同时输出到 stderr(git 会显示这些信息)
71
- print("Hook debug info:", file=sys.stderr)
72
- for k, v in info.items():
73
- print(f"{k}: {v}", file=sys.stderr)
74
- except Exception as e:
75
- print(f"Debug error: {e}", file=sys.stderr)
76
-
77
- if __name__ == "__main__":
78
- try:
79
- debug_info() # 添加调试信息
80
- update_dates_cache()
81
- except Exception as e:
82
- print(f"Hook error: {e}", file=sys.stderr)
83
- sys.exit(1)
84
-
85
11
  def find_mkdocs_projects():
86
12
  """查找当前 git 仓库中的所有 MkDocs 项目"""
87
13
  try:
@@ -121,7 +47,6 @@ def get_file_dates(file_path):
121
47
  current_time = datetime.now()
122
48
  return current_time.isoformat(), current_time.isoformat()
123
49
 
124
-
125
50
  def update_dates_cache():
126
51
  """更新文档时间缓存"""
127
52
  for project_dir in find_mkdocs_projects():
@@ -129,9 +54,6 @@ def update_dates_cache():
129
54
  if not docs_dir.exists():
130
55
  continue
131
56
 
132
- logging.info(f"Processing MkDocs project: {project_dir}")
133
- logging.info(f"Docs directory: {docs_dir}")
134
-
135
57
  dates_cache = {}
136
58
  for md_file in docs_dir.rglob("*.md"):
137
59
  rel_path = str(md_file.relative_to(docs_dir))
@@ -140,16 +62,19 @@ def update_dates_cache():
140
62
  "created": created,
141
63
  "modified": modified
142
64
  }
143
- logging.info(f"Processing file: {rel_path}")
144
65
 
145
66
  cache_file = docs_dir / '.dates_cache.json'
146
- logging.info(f"Saving cache to: {cache_file}")
147
-
148
67
  try:
149
68
  with open(cache_file, "w") as f:
150
69
  json.dump(dates_cache, f, indent=2, ensure_ascii=False)
151
70
  subprocess.run(["git", "add", str(cache_file)], check=True)
152
- logging.info(f"Added cache file to git: {cache_file}")
153
71
  except Exception as e:
154
- logging.error(f"Error handling cache file: {e}")
72
+ print(f"Error handling cache file: {e}", file=sys.stderr)
155
73
  raise
74
+
75
+ if __name__ == "__main__":
76
+ try:
77
+ update_dates_cache()
78
+ except Exception as e:
79
+ print(f"Hook error: {e}", file=sys.stderr)
80
+ sys.exit(1)
@@ -0,0 +1,49 @@
1
+ import os
2
+ import sys
3
+ import subprocess
4
+ from pathlib import Path
5
+ import site
6
+
7
+ def install():
8
+ """安装 git hooks 的入口点函数"""
9
+ print("\n正在安装 git hooks...\n")
10
+ try:
11
+ # 先清除旧的配置
12
+ subprocess.run(['git', 'config', '--global', '--unset', 'core.hooksPath'],
13
+ check=False)
14
+
15
+ # 优先使用开发目录
16
+ dev_hooks_dir = Path(__file__).parent.resolve() / 'hooks'
17
+ if dev_hooks_dir.exists():
18
+ hook_path = dev_hooks_dir / 'pre-commit'
19
+ if hook_path.exists():
20
+ if os.name != 'nt':
21
+ os.chmod(dev_hooks_dir, 0o755)
22
+ os.chmod(hook_path, 0o755)
23
+ subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(dev_hooks_dir)],
24
+ check=True)
25
+ print(f"Hooks 已安装到 (开发模式): {dev_hooks_dir}")
26
+ return True
27
+
28
+ # 如果开发目录不存在,再尝试 site-packages
29
+ for site_dir in site.getsitepackages():
30
+ hooks_dir = Path(site_dir) / 'mkdocs_document_dates' / 'hooks'
31
+ if hooks_dir.exists():
32
+ hook_path = hooks_dir / 'pre-commit'
33
+ if hook_path.exists():
34
+ if os.name != 'nt':
35
+ os.chmod(hooks_dir, 0o755)
36
+ os.chmod(hook_path, 0o755)
37
+ subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
38
+ check=True)
39
+ print(f"Hooks 已安装到: {hooks_dir}")
40
+ return True
41
+
42
+ print("错误: 未找到 hooks 目录")
43
+ return False
44
+ except Exception as e:
45
+ print(f"安装 hooks 时出错: {e}")
46
+ return False
47
+
48
+ if __name__ == '__main__':
49
+ install()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-document-dates
3
- Version: 1.9.7
3
+ Version: 1.9.9
4
4
  Summary: A MkDocs plugin for displaying accurate document creation and last modification dates.
5
5
  Home-page: https://github.com/jaywhj/mkdocs-document-dates
6
6
  Author: Aaron Wang
@@ -1,7 +1,8 @@
1
- mkdocs_document_dates/__init__.py,sha256=CZ37u8DC6kbkupKFk-VKyfKZZFAJ4rOD0aPzOzVoATc,58
1
+ mkdocs_document_dates/__init__.py,sha256=21uV4d5z91W4O-aAPrwosujLGgsR7Mh5rQUCKDoGsT8,227
2
+ mkdocs_document_dates/hooks_installer.py,sha256=dJcFQxohWnLI7gp-bxkB3Vz6E0rFw63o0xXiFEcjOw0,1868
2
3
  mkdocs_document_dates/plugin.py,sha256=zgZ9QrbfsMDAv80P11I_99urSvFolJq93Ow7P-pfS_A,9753
3
4
  mkdocs_document_dates/styles.py,sha256=ujhlKgDWsOo5sHiYtf3XekuGg4C5Yjol8RzP3W9Wzjo,578
4
- mkdocs_document_dates/hooks/pre-commit,sha256=k9HOjyfAsywkc4CugqzssLe6l9KyBn1VLk4ckCalEPg,5004
5
+ mkdocs_document_dates/hooks/pre-commit,sha256=YoNwuoT2NxMbpzwxMctH4EFB5ex_LdzG5xDxKjl93LQ,2601
5
6
  mkdocs_document_dates/lang/__init__.py,sha256=M1BLjCOA3HHKeAitk45YAgzxxNpnxFUvVAk6-FO_QSA,690
6
7
  mkdocs_document_dates/lang/ar.py,sha256=BsZlxz54U_spOZ5SBiKt73ywoLKbR54cZNkKAs86OxM,632
7
8
  mkdocs_document_dates/lang/de.py,sha256=B0Ffrn4lVSvcxFpGho7SiMm16GXYEmpjcVAR-k4UgSI,585
@@ -13,9 +14,9 @@ mkdocs_document_dates/lang/ko.py,sha256=GwY6yrKYAOj6S6feq9yqNxr2XpyGHC0XeenO541v
13
14
  mkdocs_document_dates/lang/ru.py,sha256=fK5s4mQKCoP6KI3jf6eqqmqB3YVn39q81U7Cw1QWNNg,721
14
15
  mkdocs_document_dates/lang/zh.py,sha256=OrLElrSTZhHSwxBzuUtUj7NpQb7wm0s83viimpk2ynM,519
15
16
  mkdocs_document_dates/lang/zh_tw.py,sha256=t3qu-a7UOzgcmYDkLFiosJZCcpfMU4xiKTJfu1ZHoHA,519
16
- mkdocs_document_dates-1.9.7.dist-info/LICENSE,sha256=1YKfCs5WKSk-bON8a68WZE5to1B2klCrHBYiuaVCThM,514
17
- mkdocs_document_dates-1.9.7.dist-info/METADATA,sha256=H6taAMRA5v1jAW-XDcuyx0mnsMghb1tHW_vYBO8LuA4,3908
18
- mkdocs_document_dates-1.9.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
19
- mkdocs_document_dates-1.9.7.dist-info/entry_points.txt,sha256=gI-OFLGjDG6-oLEfyevl3Gwwj2GcqVFQeX3bvL1IF8o,83
20
- mkdocs_document_dates-1.9.7.dist-info/top_level.txt,sha256=yWkKQdNuAJJVqUQ9uLa5xD4x_Gux4IfOUpy8Ryagdwc,22
21
- mkdocs_document_dates-1.9.7.dist-info/RECORD,,
17
+ mkdocs_document_dates-1.9.9.dist-info/LICENSE,sha256=1YKfCs5WKSk-bON8a68WZE5to1B2klCrHBYiuaVCThM,514
18
+ mkdocs_document_dates-1.9.9.dist-info/METADATA,sha256=Q8Oqd5iOcL1-r7v993WwCf9HoZnV2TH5a-XMp8rSZA8,3908
19
+ mkdocs_document_dates-1.9.9.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
20
+ mkdocs_document_dates-1.9.9.dist-info/entry_points.txt,sha256=4JFXqAAay470D6qgPzAAhDC-lwXVSF7THDBRFJE0yYQ,171
21
+ mkdocs_document_dates-1.9.9.dist-info/top_level.txt,sha256=yWkKQdNuAJJVqUQ9uLa5xD4x_Gux4IfOUpy8Ryagdwc,22
22
+ mkdocs_document_dates-1.9.9.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ install-mkdocs-hooks = mkdocs_document_dates.hooks_installer:install
3
+
4
+ [mkdocs.plugins]
5
+ document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin
@@ -1,2 +0,0 @@
1
- [mkdocs.plugins]
2
- document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin