mkdocs-document-dates 1.9.7__tar.gz → 1.9.9__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.
Files changed (30) hide show
  1. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/PKG-INFO +1 -1
  2. mkdocs_document_dates-1.9.9/mkdocs_document_dates/__init__.py +11 -0
  3. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/hooks/pre-commit +8 -83
  4. mkdocs_document_dates-1.9.9/mkdocs_document_dates/hooks_installer.py +49 -0
  5. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates.egg-info/PKG-INFO +1 -1
  6. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates.egg-info/SOURCES.txt +1 -0
  7. mkdocs_document_dates-1.9.9/mkdocs_document_dates.egg-info/entry_points.txt +5 -0
  8. mkdocs_document_dates-1.9.9/setup.py +129 -0
  9. mkdocs_document_dates-1.9.7/mkdocs_document_dates/__init__.py +0 -3
  10. mkdocs_document_dates-1.9.7/mkdocs_document_dates.egg-info/entry_points.txt +0 -2
  11. mkdocs_document_dates-1.9.7/setup.py +0 -108
  12. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/LICENSE +0 -0
  13. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/README.md +0 -0
  14. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/__init__.py +0 -0
  15. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/ar.py +0 -0
  16. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/de.py +0 -0
  17. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/en.py +0 -0
  18. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/es.py +0 -0
  19. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/fr.py +0 -0
  20. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/ja.py +0 -0
  21. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/ko.py +0 -0
  22. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/ru.py +0 -0
  23. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/zh.py +0 -0
  24. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/lang/zh_tw.py +0 -0
  25. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/plugin.py +0 -0
  26. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates/styles.py +0 -0
  27. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
  28. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates.egg-info/requires.txt +0 -0
  29. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
  30. {mkdocs_document_dates-1.9.7 → mkdocs_document_dates-1.9.9}/setup.cfg +0 -0
@@ -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
@@ -0,0 +1,11 @@
1
+ """MkDocs Document Dates Plugin."""
2
+
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
@@ -2,6 +2,7 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  mkdocs_document_dates/__init__.py
5
+ mkdocs_document_dates/hooks_installer.py
5
6
  mkdocs_document_dates/plugin.py
6
7
  mkdocs_document_dates/styles.py
7
8
  mkdocs_document_dates.egg-info/PKG-INFO
@@ -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
@@ -0,0 +1,129 @@
1
+ from setuptools import setup, find_packages
2
+ from setuptools.command.install_egg_info import install_egg_info
3
+ from setuptools.command.develop import develop
4
+ from setuptools.command.install import install
5
+ from setuptools.command.build_py import build_py
6
+ import os
7
+ import sys
8
+ import subprocess
9
+ from pathlib import Path
10
+ import site
11
+
12
+ def install_git_hooks():
13
+ print("\n...Starting hooks installation...\n")
14
+ try:
15
+ # 先清除旧的配置
16
+ subprocess.run(['git', 'config', '--global', '--unset', 'core.hooksPath'],
17
+ check=False)
18
+
19
+ # 使用 site-packages 路径
20
+ for site_dir in site.getsitepackages():
21
+ hooks_dir = Path(site_dir) / 'mkdocs_document_dates' / 'hooks'
22
+ print(f"Checking hooks in: {hooks_dir}")
23
+ if hooks_dir.exists():
24
+ hook_path = hooks_dir / 'pre-commit'
25
+ if hook_path.exists():
26
+ if os.name != 'nt':
27
+ os.chmod(hooks_dir, 0o755)
28
+ os.chmod(hook_path, 0o755)
29
+ subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
30
+ check=True)
31
+ print(f"Hooks installed at: {hooks_dir}")
32
+
33
+ # 验证配置
34
+ result = subprocess.run(['git', 'config', '--global', 'core.hooksPath'],
35
+ capture_output=True, text=True)
36
+ print(f"Verified hooks path: {result.stdout.strip()}")
37
+ return True
38
+
39
+ # 如果在 site-packages 中没找到,尝试开发目录
40
+ dev_hooks_dir = Path(__file__).parent.resolve() / 'mkdocs_document_dates' / 'hooks'
41
+ if dev_hooks_dir.exists():
42
+ hook_path = dev_hooks_dir / 'pre-commit'
43
+ if hook_path.exists():
44
+ if os.name != 'nt':
45
+ os.chmod(dev_hooks_dir, 0o755)
46
+ os.chmod(hook_path, 0o755)
47
+ subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(dev_hooks_dir)],
48
+ check=True)
49
+ print(f"Hooks installed at (dev mode): {dev_hooks_dir}")
50
+ return True
51
+
52
+ print("Error: Hooks directory not found in any location")
53
+ return False
54
+ except Exception as e:
55
+ print(f"Error installing hooks: {e}")
56
+ return False
57
+
58
+ class CustomInstallEggInfo(install_egg_info):
59
+
60
+ def run(self):
61
+ print("\n=== Starting CustomInstallEggInfo run ===\n")
62
+ print(f"Installation mode: {'Development' if '-e' in sys.argv else 'Production'}")
63
+ print(f"Current directory: {os.getcwd()}")
64
+ print(f"Setup file location: {__file__}")
65
+ print(f"Command line args: {sys.argv}")
66
+
67
+ install_egg_info.run(self)
68
+ install_git_hooks()
69
+
70
+ class CustomInstall(install):
71
+ def run(self):
72
+ print("\n=== Starting CustomInstall run ===\n")
73
+ print(f"Current directory: {os.getcwd()}")
74
+ install.run(self)
75
+ install_git_hooks()
76
+
77
+ class CustomDevelop(develop):
78
+ def run(self):
79
+ print("\n=== Starting CustomDevelop run ===\n")
80
+ develop.run(self)
81
+ install_git_hooks()
82
+
83
+ class CustomBuildPy(build_py):
84
+ def run(self):
85
+ print("\n=== Starting CustomBuildPy run ===\n")
86
+ print(f"Current directory: {os.getcwd()}")
87
+ print(f"Build lib dir: {self.build_lib}")
88
+ build_py.run(self)
89
+ install_git_hooks()
90
+
91
+ try:
92
+ with open("README.md", "r", encoding="utf-8") as fh:
93
+ long_description = fh.read()
94
+ except FileNotFoundError:
95
+ long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
96
+
97
+ VERSION = '1.9.9'
98
+
99
+ setup(
100
+ name="mkdocs-document-dates",
101
+ version=VERSION,
102
+ author="Aaron Wang",
103
+ description="A MkDocs plugin for displaying accurate document creation and last modification dates.",
104
+ long_description=long_description,
105
+ long_description_content_type="text/markdown",
106
+ url="https://github.com/jaywhj/mkdocs-document-dates",
107
+ packages=find_packages(),
108
+ install_requires=[
109
+ 'mkdocs>=1.0.0',
110
+ ],
111
+ classifiers=[
112
+ "Programming Language :: Python :: 3",
113
+ "License :: OSI Approved :: MIT License",
114
+ "Operating System :: OS Independent",
115
+ ],
116
+ entry_points={
117
+ 'mkdocs.plugins': [
118
+ 'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
119
+ ],
120
+ 'console_scripts': [
121
+ 'install-mkdocs-hooks=mkdocs_document_dates.hooks_installer:install'
122
+ ]
123
+ },
124
+
125
+ package_data={
126
+ 'mkdocs_document_dates': ['hooks/*'],
127
+ },
128
+ python_requires=">=3.6",
129
+ )
@@ -1,3 +0,0 @@
1
- """MkDocs Document Dates Plugin."""
2
-
3
- __version__ = '1.0.0'
@@ -1,2 +0,0 @@
1
- [mkdocs.plugins]
2
- document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin
@@ -1,108 +0,0 @@
1
- from setuptools import setup, find_packages
2
- from setuptools.command.install import install
3
- from setuptools.command.develop import develop
4
- from setuptools.command.build_py import build_py
5
- import os
6
- import sys
7
- import subprocess
8
- from pathlib import Path
9
-
10
- def install_git_hooks():
11
- try:
12
- # 先等待包安装完成并打印调试信息
13
- print("Starting hooks installation...")
14
-
15
- # 使用 pkg_resources 获取已安装包的位置
16
- import pkg_resources
17
- dist = pkg_resources.get_distribution('mkdocs-document-dates')
18
- hooks_dir = Path(dist.location) / 'mkdocs_document_dates' / 'hooks'
19
-
20
- print(f"Looking for hooks in: {hooks_dir}")
21
-
22
- if not hooks_dir.exists():
23
- print(f"Error: Hooks directory not found at {hooks_dir}")
24
- return
25
-
26
- hook_path = hooks_dir / 'pre-commit'
27
- if not hook_path.exists():
28
- print(f"Error: pre-commit hook not found at {hook_path}")
29
- return
30
-
31
- # 设置权限
32
- if os.name != 'nt':
33
- print(f"Setting permissions for {hooks_dir}")
34
- os.chmod(hooks_dir, 0o755)
35
- os.chmod(hook_path, 0o755)
36
-
37
- # 设置 git hooks 路径
38
- print(f"Configuring git hooks path to: {hooks_dir}")
39
- result = subprocess.run(['git', 'config', '--global', 'core.hooksPath', str(hooks_dir)],
40
- capture_output=True,
41
- text=True)
42
-
43
- if result.returncode != 0:
44
- print(f"Error setting git hooks path: {result.stderr}")
45
- return
46
-
47
- print(f"Git hooks installed successfully at: {hooks_dir}")
48
-
49
- except Exception as e:
50
- print(f"Error installing git hooks: {e}")
51
- import traceback
52
- print(traceback.format_exc())
53
-
54
- class CustomInstall(install):
55
- def run(self):
56
- install.run(self)
57
- install_git_hooks()
58
-
59
- class CustomDevelop(develop):
60
- def run(self):
61
- develop.run(self)
62
- install_git_hooks()
63
-
64
- class CustomBuildPy(build_py):
65
- def run(self):
66
- build_py.run(self)
67
- install_git_hooks()
68
-
69
- try:
70
- with open("README.md", "r", encoding="utf-8") as fh:
71
- long_description = fh.read()
72
- except FileNotFoundError:
73
- long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
74
-
75
- VERSION = '1.9.7'
76
-
77
- setup(
78
- name="mkdocs-document-dates",
79
- version=VERSION,
80
- author="Aaron Wang",
81
- description="A MkDocs plugin for displaying accurate document creation and last modification dates.",
82
- long_description=long_description,
83
- long_description_content_type="text/markdown",
84
- url="https://github.com/jaywhj/mkdocs-document-dates",
85
- packages=find_packages(),
86
- install_requires=[
87
- 'mkdocs>=1.0.0',
88
- ],
89
- classifiers=[
90
- "Programming Language :: Python :: 3",
91
- "License :: OSI Approved :: MIT License",
92
- "Operating System :: OS Independent",
93
- ],
94
- entry_points={
95
- 'mkdocs.plugins': [
96
- 'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
97
- ]
98
- },
99
- cmdclass={
100
- 'install': CustomInstall,
101
- 'develop': CustomDevelop,
102
- 'build_py': CustomBuildPy,
103
- },
104
- package_data={
105
- 'mkdocs_document_dates': ['hooks/*'],
106
- },
107
- python_requires=">=3.6",
108
- )