mkdocs-document-dates 2.0.0__tar.gz → 2.1.0__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.
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/PKG-INFO +1 -1
- mkdocs_document_dates-2.1.0/mkdocs_document_dates/__init__.py +13 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/hooks/pre-commit +6 -6
- mkdocs_document_dates-2.1.0/mkdocs_document_dates/hooks_installer.py +77 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/PKG-INFO +1 -1
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/setup.py +4 -14
- mkdocs_document_dates-2.0.0/mkdocs_document_dates/__init__.py +0 -11
- mkdocs_document_dates-2.0.0/mkdocs_document_dates/hooks_installer.py +0 -87
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/LICENSE +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/README.md +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/__init__.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ar.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/de.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/en.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/es.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/fr.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ja.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ko.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ru.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/zh.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/zh_tw.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/plugin.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/styles.py +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/SOURCES.txt +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/requires.txt +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
- {mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/setup.cfg +0 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
"""MkDocs Document Dates Plugin."""
|
2
|
+
|
3
|
+
__version__ = '2.0.0'
|
4
|
+
|
5
|
+
from .hooks_installer import install
|
6
|
+
|
7
|
+
# 在包被导入时自动执行 hooks 安装
|
8
|
+
try:
|
9
|
+
result = install()
|
10
|
+
if not result:
|
11
|
+
print("提示: Git hooks 安装被跳过(可能是因为未检测到 Git 或不在 Git 仓库中)")
|
12
|
+
except Exception as e:
|
13
|
+
print(f"警告: Git hooks 安装失败: {e}")
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/hooks/pre-commit
RENAMED
@@ -23,7 +23,7 @@ def find_mkdocs_projects():
|
|
23
23
|
|
24
24
|
return projects
|
25
25
|
except subprocess.CalledProcessError as e:
|
26
|
-
print(f"
|
26
|
+
print(f"查找 Git 仓库根目录失败: {e}", file=sys.stderr)
|
27
27
|
return []
|
28
28
|
|
29
29
|
def get_file_dates(file_path):
|
@@ -33,13 +33,13 @@ def get_file_dates(file_path):
|
|
33
33
|
modified = datetime.fromtimestamp(stat.st_mtime)
|
34
34
|
|
35
35
|
system = platform.system().lower()
|
36
|
-
if system
|
36
|
+
if system.startswith('win'): # Windows
|
37
|
+
created = datetime.fromtimestamp(stat.st_ctime)
|
38
|
+
elif system == 'darwin': # macOS
|
37
39
|
try:
|
38
40
|
created = datetime.fromtimestamp(stat.st_birthtime)
|
39
41
|
except AttributeError:
|
40
42
|
created = datetime.fromtimestamp(stat.st_ctime)
|
41
|
-
elif system == 'windows': # Windows
|
42
|
-
created = datetime.fromtimestamp(stat.st_ctime)
|
43
43
|
else: # Linux 和其他系统
|
44
44
|
created = modified
|
45
45
|
|
@@ -49,8 +49,8 @@ def get_file_dates(file_path):
|
|
49
49
|
return current_time.isoformat(), current_time.isoformat()
|
50
50
|
|
51
51
|
def update_dates_cache():
|
52
|
-
print("开始更新文档时间缓存...")
|
53
52
|
"""更新文档时间缓存"""
|
53
|
+
print("开始更新文档时间缓存...")
|
54
54
|
for project_dir in find_mkdocs_projects():
|
55
55
|
docs_dir = project_dir / 'docs'
|
56
56
|
if not docs_dir.exists():
|
@@ -89,5 +89,5 @@ if __name__ == "__main__":
|
|
89
89
|
try:
|
90
90
|
update_dates_cache()
|
91
91
|
except Exception as e:
|
92
|
-
print(f"Hook
|
92
|
+
print(f"Hook 执行出错: {e}", file=sys.stderr)
|
93
93
|
sys.exit(1)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import os
|
2
|
+
import sys
|
3
|
+
import shutil
|
4
|
+
import subprocess
|
5
|
+
from pathlib import Path
|
6
|
+
import platform
|
7
|
+
|
8
|
+
def get_config_dir():
|
9
|
+
"""获取用户配置目录"""
|
10
|
+
system = platform.system().lower()
|
11
|
+
if system.startswith('win'):
|
12
|
+
return Path(os.getenv('APPDATA', str(Path.home() / 'AppData' / 'Roaming')))
|
13
|
+
else: # macOS 和 Linux 统一使用 ~/.config
|
14
|
+
return Path.home() / '.config'
|
15
|
+
|
16
|
+
def install():
|
17
|
+
"""安装 git hooks"""
|
18
|
+
try:
|
19
|
+
# 检查 git 是否可用
|
20
|
+
try:
|
21
|
+
subprocess.run(['git', '--version'], check=True, capture_output=True, encoding='utf-8')
|
22
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
23
|
+
print("提示: 未检测到 Git,跳过 hooks 安装")
|
24
|
+
return False
|
25
|
+
|
26
|
+
# 准备配置目录
|
27
|
+
config_dir = get_config_dir() / 'mkdocs-document-dates' / 'hooks'
|
28
|
+
try:
|
29
|
+
config_dir.mkdir(parents=True, exist_ok=True)
|
30
|
+
except PermissionError:
|
31
|
+
print(f"错误: 无权限创建目录: {config_dir}")
|
32
|
+
return False
|
33
|
+
except Exception as e:
|
34
|
+
print(f"错误: 创建目录失败: {config_dir}, 原因: {e}")
|
35
|
+
return False
|
36
|
+
|
37
|
+
hook_path = config_dir / 'pre-commit'
|
38
|
+
|
39
|
+
# 复制 hook 文件
|
40
|
+
source_hook = Path(__file__).parent / 'hooks' / 'pre-commit'
|
41
|
+
if not source_hook.exists():
|
42
|
+
print(f"错误: 源 hook 文件不存在: {source_hook}")
|
43
|
+
return False
|
44
|
+
|
45
|
+
try:
|
46
|
+
shutil.copy2(source_hook, hook_path)
|
47
|
+
except PermissionError:
|
48
|
+
print(f"错误: 无权限复制文件到: {hook_path}")
|
49
|
+
return False
|
50
|
+
except Exception as e:
|
51
|
+
print(f"错误: 复制文件失败, 原因: {e}")
|
52
|
+
return False
|
53
|
+
|
54
|
+
# 设置文件权限(Unix-like 系统)
|
55
|
+
if not platform.system().lower().startswith('win'):
|
56
|
+
try:
|
57
|
+
os.chmod(config_dir, 0o755)
|
58
|
+
os.chmod(hook_path, 0o755)
|
59
|
+
except OSError as e:
|
60
|
+
print(f"警告: 设置权限时出错: {e}")
|
61
|
+
|
62
|
+
# 配置 git hooks 路径
|
63
|
+
try:
|
64
|
+
subprocess.run(['git', 'config', '--global', 'core.hooksPath',
|
65
|
+
str(config_dir)], check=True, encoding='utf-8')
|
66
|
+
print(f"Git hooks 已安装到: {config_dir}")
|
67
|
+
return True
|
68
|
+
except subprocess.CalledProcessError as e:
|
69
|
+
print(f"错误: 设置 git hooks 路径失败: {e}")
|
70
|
+
return False
|
71
|
+
|
72
|
+
except Exception as e:
|
73
|
+
print(f"安装 hooks 时出错: {e}")
|
74
|
+
return False
|
75
|
+
|
76
|
+
if __name__ == '__main__':
|
77
|
+
install()
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from setuptools import setup, find_packages
|
2
|
-
|
2
|
+
import mkdocs_document_dates
|
3
3
|
|
4
4
|
try:
|
5
5
|
with open("README.md", "r", encoding="utf-8") as fh:
|
@@ -7,14 +7,7 @@ try:
|
|
7
7
|
except FileNotFoundError:
|
8
8
|
long_description = "A MkDocs plugin for displaying accurate document creation and last modification dates."
|
9
9
|
|
10
|
-
VERSION = '2.
|
11
|
-
|
12
|
-
class PostInstallCommand(install):
|
13
|
-
"""第一个入口:通过 setuptools 的 post_install 机制,在包安装完成后自动执行 hooks 安装"""
|
14
|
-
def run(self):
|
15
|
-
install.run(self)
|
16
|
-
from mkdocs_document_dates.hooks_installer import install as install_hooks # 重命名避免冲突
|
17
|
-
result = install_hooks()
|
10
|
+
VERSION = '2.1.0'
|
18
11
|
|
19
12
|
setup(
|
20
13
|
name="mkdocs-document-dates",
|
@@ -38,15 +31,12 @@ setup(
|
|
38
31
|
'document-dates = mkdocs_document_dates.plugin:DocumentDatesPlugin',
|
39
32
|
],
|
40
33
|
'console_scripts': [
|
41
|
-
#
|
34
|
+
# 提供命令行工具,允许用户手动执行 hooks 安装
|
42
35
|
'mkdocs-document-dates-hooks=mkdocs_document_dates.hooks_installer:install'
|
43
|
-
]
|
36
|
+
],
|
44
37
|
},
|
45
38
|
package_data={
|
46
39
|
'mkdocs_document_dates': ['hooks/*'],
|
47
40
|
},
|
48
41
|
python_requires=">=3.6",
|
49
|
-
cmdclass={
|
50
|
-
'install': PostInstallCommand,
|
51
|
-
},
|
52
42
|
)
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import sys
|
3
|
-
import subprocess
|
4
|
-
from pathlib import Path
|
5
|
-
import site
|
6
|
-
import platform
|
7
|
-
|
8
|
-
def install():
|
9
|
-
"""安装 git hooks"""
|
10
|
-
try:
|
11
|
-
# 检查 git 是否可用
|
12
|
-
try:
|
13
|
-
subprocess.run(['git', '--version'], check=True, capture_output=True, encoding='utf-8')
|
14
|
-
except (subprocess.CalledProcessError, FileNotFoundError):
|
15
|
-
# 静默失败,因为用户可能在非 git 环境下安装
|
16
|
-
return False
|
17
|
-
|
18
|
-
# 检查是否在 git 仓库中
|
19
|
-
try:
|
20
|
-
subprocess.run(['git', 'rev-parse', '--git-dir'], check=True, capture_output=True, encoding='utf-8')
|
21
|
-
except subprocess.CalledProcessError:
|
22
|
-
# 静默失败,用户可能不在 git 仓库中
|
23
|
-
return False
|
24
|
-
|
25
|
-
# 检查是否是开发模式安装
|
26
|
-
def is_dev_install():
|
27
|
-
try:
|
28
|
-
import mkdocs_document_dates
|
29
|
-
pkg_path = Path(mkdocs_document_dates.__file__).resolve().parent
|
30
|
-
current_path = Path(__file__).resolve().parent
|
31
|
-
# 检查是否在开发目录中
|
32
|
-
if current_path == pkg_path:
|
33
|
-
return True
|
34
|
-
# 检查是否是 egg-link 安装
|
35
|
-
site_packages = [Path(p) for p in site.getsitepackages()]
|
36
|
-
for p in site_packages:
|
37
|
-
if (p / 'mkdocs_document_dates.egg-link').exists():
|
38
|
-
return True
|
39
|
-
return False
|
40
|
-
except (ImportError, AttributeError) as e:
|
41
|
-
print(f"开发模式检查失败: {e}")
|
42
|
-
return False
|
43
|
-
|
44
|
-
is_dev_mode = is_dev_install()
|
45
|
-
hook_path = None
|
46
|
-
|
47
|
-
if is_dev_mode:
|
48
|
-
hooks_dir = Path(__file__).parent.resolve() / 'hooks'
|
49
|
-
if hooks_dir.exists():
|
50
|
-
hook_path = hooks_dir / 'pre-commit'
|
51
|
-
else:
|
52
|
-
for site_dir in site.getsitepackages():
|
53
|
-
hooks_dir = Path(site_dir) / 'mkdocs_document_dates' / 'hooks'
|
54
|
-
if hooks_dir.exists():
|
55
|
-
hook_path = hooks_dir / 'pre-commit'
|
56
|
-
break
|
57
|
-
|
58
|
-
|
59
|
-
if not hook_path or not hook_path.exists():
|
60
|
-
print("错误: 未找到 hooks 目录或 hook 文件")
|
61
|
-
return False
|
62
|
-
|
63
|
-
# 设置文件权限(Unix-like 系统)
|
64
|
-
if platform.system() != 'Windows':
|
65
|
-
try:
|
66
|
-
os.chmod(hook_path.parent, 0o755)
|
67
|
-
os.chmod(hook_path, 0o755)
|
68
|
-
except OSError as e:
|
69
|
-
print(f"警告: 设置权限时出错: {e}")
|
70
|
-
|
71
|
-
# 配置 git hooks 路径
|
72
|
-
try:
|
73
|
-
hooks_dir = hook_path.parent
|
74
|
-
subprocess.run(['git', 'config', '--global', 'core.hooksPath',
|
75
|
-
str(hooks_dir)], check=True, encoding='utf-8')
|
76
|
-
print(f"Git hooks 已安装到: {hooks_dir}")
|
77
|
-
return True
|
78
|
-
except subprocess.CalledProcessError as e:
|
79
|
-
print(f"错误: 设置 git hooks 路径失败: {e}")
|
80
|
-
return False
|
81
|
-
|
82
|
-
except Exception as e:
|
83
|
-
print(f"安装 hooks 时出错: {e}")
|
84
|
-
return False
|
85
|
-
|
86
|
-
if __name__ == '__main__':
|
87
|
-
install()
|
File without changes
|
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/__init__.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ar.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/de.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/en.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/es.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/fr.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ja.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ko.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/ru.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/zh.py
RENAMED
File without changes
|
{mkdocs_document_dates-2.0.0 → mkdocs_document_dates-2.1.0}/mkdocs_document_dates/lang/zh_tw.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|