mkdocs-document-dates 2.4.0__tar.gz → 3.0.1__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.4.0 → mkdocs_document_dates-3.0.1}/PKG-INFO +37 -38
- mkdocs_document_dates-3.0.1/README.md +101 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates/hooks/pre-commit +33 -10
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates/hooks_installer.py +23 -16
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates/plugin.py +167 -77
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/document-dates.config.css +87 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/document-dates.config.js +44 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/ar.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/de.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/en.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/es.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/fr.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/ja.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/ko.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/ru.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/zh.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/languages/zh_tw.json +18 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/tippy/backdrop.css +1 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/tippy/light.css +1 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/tippy/material.css +1 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/tippy/popper.min.js +6 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/tippy/scale.css +1 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/tippy/shift-away.css +1 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/tippy/tippy.css +1 -0
- mkdocs_document_dates-3.0.1/mkdocs_document_dates/static/tippy/tippy.umd.min.js +2 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates.egg-info/PKG-INFO +37 -38
- mkdocs_document_dates-3.0.1/mkdocs_document_dates.egg-info/SOURCES.txt +33 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/setup.py +10 -4
- mkdocs_document_dates-2.4.0/README.md +0 -102
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/__init__.py +0 -22
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/ar.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/de.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/en.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/es.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/fr.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/ja.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/ko.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/ru.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/zh.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/lang/zh_tw.py +0 -19
- mkdocs_document_dates-2.4.0/mkdocs_document_dates/styles.py +0 -42
- mkdocs_document_dates-2.4.0/mkdocs_document_dates.egg-info/SOURCES.txt +0 -25
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/LICENSE +0 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates/__init__.py +0 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates.egg-info/dependency_links.txt +0 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates.egg-info/entry_points.txt +0 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates.egg-info/requires.txt +0 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates.egg-info/top_level.txt +0 -0
- {mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mkdocs-document-dates
|
3
|
-
Version:
|
4
|
-
Summary: A MkDocs plugin for displaying
|
3
|
+
Version: 3.0.1
|
4
|
+
Summary: A MkDocs plugin for displaying the exact creation date and last modification date of markdown documents.
|
5
5
|
Home-page: https://github.com/jaywhj/mkdocs-document-dates
|
6
6
|
Author: Aaron Wang
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
@@ -27,20 +27,27 @@ English | [简体中文](README_zh.md)
|
|
27
27
|
|
28
28
|
|
29
29
|
|
30
|
-
A MkDocs plugin for displaying <mark>
|
30
|
+
A MkDocs plugin for displaying the <mark>exact</mark> creation date and last modification date of markdown documents.
|
31
31
|
|
32
32
|
## Features
|
33
33
|
|
34
34
|
- **No Git dependency**, uses filesystem timestamps directly
|
35
35
|
- Supports manual date specification in `Front Matter`
|
36
|
-
- Cross-platform support (Windows, macOS, Linux)
|
37
36
|
- Support for multiple time formats (date, datetime, timeago)
|
38
|
-
- Flexible display position (top or bottom)
|
39
37
|
- Support for document exclusion mode
|
40
|
-
-
|
41
|
-
-
|
42
|
-
-
|
38
|
+
- Flexible display position (top or bottom)
|
39
|
+
- Material style icons, elegant styling (Customizable)
|
40
|
+
- Supports Tooltip Hover Tips
|
41
|
+
- Intelligent repositioning to always float optimally in view
|
42
|
+
- Supports automatic theme switching following Material's light/dark color scheme
|
43
|
+
- Support for customizing themes, styles, animations
|
44
|
+
- Compatible with mouse, keyboard and **touch** (mobile) to trigger hover
|
43
45
|
- Support for CI/CD build systems (e.g. Github Actions)
|
46
|
+
- Multi-language support, cross-platform support (Windows, macOS, Linux)
|
47
|
+
|
48
|
+
## Showcases
|
49
|
+
|
50
|
+

|
44
51
|
|
45
52
|
## Installation
|
46
53
|
|
@@ -50,7 +57,7 @@ pip install mkdocs-document-dates
|
|
50
57
|
|
51
58
|
## Configuration
|
52
59
|
|
53
|
-
Just add the plugin to your mkdocs.yml
|
60
|
+
Just add the plugin to your `mkdocs.yml`:
|
54
61
|
|
55
62
|
```yaml
|
56
63
|
plugins:
|
@@ -62,12 +69,12 @@ Or, customize the configuration:
|
|
62
69
|
```yaml
|
63
70
|
plugins:
|
64
71
|
- document-dates:
|
65
|
-
type: date # Date type: date
|
72
|
+
type: date # Date type: date datetime timeago, default: date
|
66
73
|
locale: en # Localization: zh zh_tw en es fr de ar ja ko ru, default: en
|
67
|
-
date_format: '%Y-%m-%d' # Date format
|
74
|
+
date_format: '%Y-%m-%d' # Date format, Supports all Python datetime format strings, e.g., %Y-%m-%d, %b %d, %Y, etc
|
68
75
|
time_format: '%H:%M:%S' # Time format (valid only if type=datetime)
|
69
|
-
position: bottom # Display position: top (after title)
|
70
|
-
exclude: # List of
|
76
|
+
position: bottom # Display position: top (after title) bottom (end of document), default: bottom
|
77
|
+
exclude: # List of excluded files
|
71
78
|
- temp.md # Exclude specific file
|
72
79
|
- private/* # Exclude all files in private directory, including subdirectories
|
73
80
|
- drafts/*.md # Exclude all markdown files in the current directory drafts, but not subdirectories
|
@@ -86,40 +93,32 @@ modified: 2025-02-23
|
|
86
93
|
# Document Title
|
87
94
|
```
|
88
95
|
|
89
|
-
- `created` can be replaced
|
90
|
-
- `modified` can be replaced
|
91
|
-
|
92
|
-
##
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
- **date_format** : Date format (default: `%Y-%m-%d`)
|
101
|
-
- Supports all Python datetime format strings, e.g., %Y-%m-%d, %b %d, %Y, etc.
|
102
|
-
- **time_format** : Time format (default: `%H:%M:%S`)
|
103
|
-
- **position** : Display position (default: `bottom`)
|
104
|
-
- `top` : Display after the first heading
|
105
|
-
- `bottom` : Display at the end of the document
|
106
|
-
- **exclude** : File exclusion list (default: [] )
|
107
|
-
- Supports glob patterns, e.g., ["private/\*", "temp.md", "drafts/\*.md"]
|
96
|
+
- `created` can be replaced with: `created, date, creation_date, created_at, date_created`
|
97
|
+
- `modified` can be replaced with: `modified, updated, last_modified, updated_at, date_modified, last_update`
|
98
|
+
|
99
|
+
## Customization
|
100
|
+
|
101
|
+
This plugin supports deep customization, just modify the code in the corresponding file:
|
102
|
+
|
103
|
+
- Style & Theme: `docs/assets/document_dates/document-dates.config.css`
|
104
|
+
- Properties & Animations: `docs/assets/document_dates/document-dates.config.js`
|
105
|
+
|
106
|
+
Tip: If you want to restore the default effect, just delete this file and rebuild your project
|
108
107
|
|
109
108
|
## Tips
|
110
109
|
|
111
|
-
- It still works when using CI/CD build systems (e.g. Github Actions),
|
112
|
-
1. First, you can configure the workflow like this (penultimate line) in your
|
110
|
+
- It still works when using CI/CD build systems (e.g. Github Actions), here's how it works:
|
111
|
+
1. First, you can configure the workflow like this (penultimate line) in your `.github/workflows/ci.yml`:
|
113
112
|
```
|
114
113
|
...
|
115
114
|
|
116
115
|
- run: pip install mkdocs-document-dates
|
117
116
|
- run: mkdocs gh-deploy --force
|
118
117
|
```
|
119
|
-
2. Then update your Markdown document in
|
120
|
-
3. After running git add and git commit, you will see the auto-generated cache file
|
118
|
+
2. Then update your Markdown document in `docs` as normal
|
119
|
+
3. After running git add and git commit, you will see the auto-generated cache file `.dates_cache.json` (hidden by default) in the `docs` folder
|
121
120
|
- Make sure you have installed python3 ahead of time and set environment variables
|
122
|
-
4. Finally, run git push, and you can see that
|
123
|
-
- Priority
|
121
|
+
4. Finally, run git push, and you can see that the `.dates_cache.json` file also exists in the docs directory in the GitHub repository, which means success!
|
122
|
+
- Priority for datetime reads:
|
124
123
|
- `Front Matter` > `Cache file` > `Filesystem timestamp`
|
125
124
|
- If you are using MkDocs on a Linux system, the modification time is used as the creation time because of system limitations. If you need the exact creation time, you can specify it manually in Front Matter
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# mkdocs-document-dates
|
2
|
+
|
3
|
+
English | [简体中文](README_zh.md)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
A MkDocs plugin for displaying the <mark>exact</mark> creation date and last modification date of markdown documents.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- **No Git dependency**, uses filesystem timestamps directly
|
12
|
+
- Supports manual date specification in `Front Matter`
|
13
|
+
- Support for multiple time formats (date, datetime, timeago)
|
14
|
+
- Support for document exclusion mode
|
15
|
+
- Flexible display position (top or bottom)
|
16
|
+
- Material style icons, elegant styling (Customizable)
|
17
|
+
- Supports Tooltip Hover Tips
|
18
|
+
- Intelligent repositioning to always float optimally in view
|
19
|
+
- Supports automatic theme switching following Material's light/dark color scheme
|
20
|
+
- Support for customizing themes, styles, animations
|
21
|
+
- Compatible with mouse, keyboard and **touch** (mobile) to trigger hover
|
22
|
+
- Support for CI/CD build systems (e.g. Github Actions)
|
23
|
+
- Multi-language support, cross-platform support (Windows, macOS, Linux)
|
24
|
+
|
25
|
+
## Showcases
|
26
|
+
|
27
|
+

|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
```bash
|
32
|
+
pip install mkdocs-document-dates
|
33
|
+
```
|
34
|
+
|
35
|
+
## Configuration
|
36
|
+
|
37
|
+
Just add the plugin to your `mkdocs.yml`:
|
38
|
+
|
39
|
+
```yaml
|
40
|
+
plugins:
|
41
|
+
- document-dates
|
42
|
+
```
|
43
|
+
|
44
|
+
Or, customize the configuration:
|
45
|
+
|
46
|
+
```yaml
|
47
|
+
plugins:
|
48
|
+
- document-dates:
|
49
|
+
type: date # Date type: date datetime timeago, default: date
|
50
|
+
locale: en # Localization: zh zh_tw en es fr de ar ja ko ru, default: en
|
51
|
+
date_format: '%Y-%m-%d' # Date format, Supports all Python datetime format strings, e.g., %Y-%m-%d, %b %d, %Y, etc
|
52
|
+
time_format: '%H:%M:%S' # Time format (valid only if type=datetime)
|
53
|
+
position: bottom # Display position: top (after title) bottom (end of document), default: bottom
|
54
|
+
exclude: # List of excluded files
|
55
|
+
- temp.md # Exclude specific file
|
56
|
+
- private/* # Exclude all files in private directory, including subdirectories
|
57
|
+
- drafts/*.md # Exclude all markdown files in the current directory drafts, but not subdirectories
|
58
|
+
```
|
59
|
+
|
60
|
+
## Manual Date Specification
|
61
|
+
|
62
|
+
You can also manually specify the date of a Markdown document in its `Front Matter` :
|
63
|
+
|
64
|
+
```yaml
|
65
|
+
---
|
66
|
+
created: 2023-01-01
|
67
|
+
modified: 2025-02-23
|
68
|
+
---
|
69
|
+
|
70
|
+
# Document Title
|
71
|
+
```
|
72
|
+
|
73
|
+
- `created` can be replaced with: `created, date, creation_date, created_at, date_created`
|
74
|
+
- `modified` can be replaced with: `modified, updated, last_modified, updated_at, date_modified, last_update`
|
75
|
+
|
76
|
+
## Customization
|
77
|
+
|
78
|
+
This plugin supports deep customization, just modify the code in the corresponding file:
|
79
|
+
|
80
|
+
- Style & Theme: `docs/assets/document_dates/document-dates.config.css`
|
81
|
+
- Properties & Animations: `docs/assets/document_dates/document-dates.config.js`
|
82
|
+
|
83
|
+
Tip: If you want to restore the default effect, just delete this file and rebuild your project
|
84
|
+
|
85
|
+
## Tips
|
86
|
+
|
87
|
+
- It still works when using CI/CD build systems (e.g. Github Actions), here's how it works:
|
88
|
+
1. First, you can configure the workflow like this (penultimate line) in your `.github/workflows/ci.yml`:
|
89
|
+
```
|
90
|
+
...
|
91
|
+
|
92
|
+
- run: pip install mkdocs-document-dates
|
93
|
+
- run: mkdocs gh-deploy --force
|
94
|
+
```
|
95
|
+
2. Then update your Markdown document in `docs` as normal
|
96
|
+
3. After running git add and git commit, you will see the auto-generated cache file `.dates_cache.json` (hidden by default) in the `docs` folder
|
97
|
+
- Make sure you have installed python3 ahead of time and set environment variables
|
98
|
+
4. Finally, run git push, and you can see that the `.dates_cache.json` file also exists in the docs directory in the GitHub repository, which means success!
|
99
|
+
- Priority for datetime reads:
|
100
|
+
- `Front Matter` > `Cache file` > `Filesystem timestamp`
|
101
|
+
- If you are using MkDocs on a Linux system, the modification time is used as the creation time because of system limitations. If you need the exact creation time, you can specify it manually in Front Matter
|
{mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates/hooks/pre-commit
RENAMED
@@ -5,9 +5,16 @@ import sys
|
|
5
5
|
import json
|
6
6
|
import platform
|
7
7
|
import subprocess
|
8
|
+
import logging
|
8
9
|
from datetime import datetime
|
9
10
|
from pathlib import Path
|
10
11
|
|
12
|
+
# 配置日志等级 (INFO WARNING ERROR)
|
13
|
+
logging.basicConfig(
|
14
|
+
level=logging.WARNING,
|
15
|
+
format='%(levelname)s - %(message)s'
|
16
|
+
)
|
17
|
+
|
11
18
|
def find_mkdocs_projects():
|
12
19
|
try:
|
13
20
|
git_root = Path(subprocess.check_output(
|
@@ -20,9 +27,14 @@ def find_mkdocs_projects():
|
|
20
27
|
if config_file.name.lower() in ('mkdocs.yml', 'mkdocs.yaml'):
|
21
28
|
projects.append(config_file.parent)
|
22
29
|
|
30
|
+
if not projects:
|
31
|
+
logging.info("No MkDocs projects found in the repository")
|
23
32
|
return projects
|
24
33
|
except subprocess.CalledProcessError as e:
|
25
|
-
|
34
|
+
logging.error(f"Failed to find the Git repository root: {e}")
|
35
|
+
return []
|
36
|
+
except Exception as e:
|
37
|
+
logging.error(f"Unexpected error while searching for MkDocs projects: {e}")
|
26
38
|
return []
|
27
39
|
|
28
40
|
def get_file_dates(file_path):
|
@@ -38,11 +50,14 @@ def get_file_dates(file_path):
|
|
38
50
|
created = datetime.fromtimestamp(stat.st_birthtime)
|
39
51
|
except AttributeError:
|
40
52
|
created = datetime.fromtimestamp(stat.st_ctime)
|
41
|
-
|
53
|
+
logging.warning(f"Birth time not available for {file_path}, using ctime instead")
|
54
|
+
else: # Linux and other systems
|
42
55
|
created = modified
|
56
|
+
logging.info(f"Creation time not supported on {system}, using modification time for {file_path}")
|
43
57
|
|
44
58
|
return created.isoformat(), modified.isoformat()
|
45
|
-
except (OSError, ValueError):
|
59
|
+
except (OSError, ValueError) as e:
|
60
|
+
logging.error(f"Failed to get file dates for {file_path}: {e}")
|
46
61
|
current_time = datetime.now()
|
47
62
|
return current_time.isoformat(), current_time.isoformat()
|
48
63
|
|
@@ -50,12 +65,16 @@ def update_dates_cache():
|
|
50
65
|
for project_dir in find_mkdocs_projects():
|
51
66
|
docs_dir = project_dir / 'docs'
|
52
67
|
if not docs_dir.exists():
|
53
|
-
|
68
|
+
logging.error(f"Document directory does not exist: {docs_dir}")
|
54
69
|
continue
|
55
70
|
|
56
71
|
dates_cache = {}
|
57
72
|
md_files = list(docs_dir.rglob("*.md"))
|
58
73
|
|
74
|
+
if not md_files:
|
75
|
+
logging.info(f"No markdown files found in {docs_dir}")
|
76
|
+
continue
|
77
|
+
|
59
78
|
for md_file in md_files:
|
60
79
|
try:
|
61
80
|
rel_path = str(md_file.relative_to(docs_dir))
|
@@ -65,24 +84,28 @@ def update_dates_cache():
|
|
65
84
|
"modified": modified
|
66
85
|
}
|
67
86
|
except Exception as e:
|
68
|
-
|
87
|
+
logging.error(f"Error processing file {md_file}: {e}")
|
69
88
|
|
70
89
|
if not dates_cache:
|
90
|
+
logging.warning(f"No valid dates cache generated for {project_dir}")
|
71
91
|
continue
|
72
92
|
|
73
93
|
cache_file = docs_dir / '.dates_cache.json'
|
74
94
|
try:
|
75
|
-
with open(cache_file, "w") as f:
|
95
|
+
with open(cache_file, "w", encoding='utf-8') as f:
|
76
96
|
json.dump(dates_cache, f, indent=2, ensure_ascii=False)
|
77
97
|
subprocess.run(["git", "add", str(cache_file)], check=True)
|
78
|
-
|
79
|
-
except
|
80
|
-
|
98
|
+
logging.info(f"Successfully updated cache file: {cache_file}")
|
99
|
+
except (IOError, json.JSONDecodeError) as e:
|
100
|
+
logging.error(f"Failed to write cache file {cache_file}: {e}")
|
101
|
+
raise
|
102
|
+
except subprocess.CalledProcessError as e:
|
103
|
+
logging.error(f"Failed to add cache file to git: {e}")
|
81
104
|
raise
|
82
105
|
|
83
106
|
if __name__ == "__main__":
|
84
107
|
try:
|
85
108
|
update_dates_cache()
|
86
109
|
except Exception as e:
|
87
|
-
|
110
|
+
logging.error(f"Hook execution failed: {e}")
|
88
111
|
sys.exit(1)
|
{mkdocs_document_dates-2.4.0 → mkdocs_document_dates-3.0.1}/mkdocs_document_dates/hooks_installer.py
RENAMED
@@ -1,10 +1,17 @@
|
|
1
1
|
import os
|
2
2
|
import sys
|
3
3
|
import shutil
|
4
|
+
import logging
|
4
5
|
import subprocess
|
5
6
|
from pathlib import Path
|
6
7
|
import platform
|
7
8
|
|
9
|
+
# 配置日志等级 (INFO WARNING ERROR)
|
10
|
+
logging.basicConfig(
|
11
|
+
level=logging.WARNING,
|
12
|
+
format='%(levelname)s: %(message)s'
|
13
|
+
)
|
14
|
+
|
8
15
|
def get_config_dir():
|
9
16
|
if platform.system().lower().startswith('win'):
|
10
17
|
return Path(os.getenv('APPDATA', str(Path.home() / 'AppData' / 'Roaming')))
|
@@ -17,7 +24,7 @@ def install():
|
|
17
24
|
try:
|
18
25
|
subprocess.run(['git', '--version'], check=True, capture_output=True, encoding='utf-8')
|
19
26
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
20
|
-
|
27
|
+
logging.warning("Git not detected, skip hooks installation")
|
21
28
|
return False
|
22
29
|
|
23
30
|
# 准备配置目录
|
@@ -25,27 +32,23 @@ def install():
|
|
25
32
|
try:
|
26
33
|
config_dir.mkdir(parents=True, exist_ok=True)
|
27
34
|
except PermissionError:
|
28
|
-
|
35
|
+
logging.error(f"No permission to create directory: {config_dir}")
|
29
36
|
return False
|
30
37
|
except Exception as e:
|
31
|
-
|
38
|
+
logging.error(f"Failed to create directory {config_dir}: {str(e)}")
|
32
39
|
return False
|
33
40
|
|
34
41
|
hook_path = config_dir / 'pre-commit'
|
35
|
-
|
36
|
-
# 复制 hook 文件到配置目录
|
37
42
|
source_hook = Path(__file__).parent / 'hooks' / 'pre-commit'
|
38
|
-
if not source_hook.exists():
|
39
|
-
print(f"Error: Source hook file does not exist: {source_hook}")
|
40
|
-
return False
|
41
43
|
|
44
|
+
# 复制 hook 文件到配置目录
|
42
45
|
try:
|
43
46
|
shutil.copy2(source_hook, hook_path)
|
44
47
|
except PermissionError:
|
45
|
-
|
48
|
+
logging.error(f"No permission to copy file to: {hook_path}")
|
46
49
|
return False
|
47
50
|
except Exception as e:
|
48
|
-
|
51
|
+
logging.error(f"Failed to copy file to {hook_path}: {str(e)}")
|
49
52
|
return False
|
50
53
|
|
51
54
|
# 设置文件权限
|
@@ -53,20 +56,24 @@ def install():
|
|
53
56
|
os.chmod(config_dir, 0o755)
|
54
57
|
os.chmod(hook_path, 0o755)
|
55
58
|
except OSError as e:
|
56
|
-
|
59
|
+
logging.warning(f"Failed to set file permissions: {str(e)}")
|
57
60
|
|
58
61
|
# 配置全局 git hooks 路径
|
59
62
|
try:
|
60
|
-
subprocess.run(
|
61
|
-
|
62
|
-
|
63
|
+
subprocess.run(
|
64
|
+
['git', 'config', '--global', 'core.hooksPath', str(config_dir)],
|
65
|
+
check=True,
|
66
|
+
capture_output=True,
|
67
|
+
encoding='utf-8'
|
68
|
+
)
|
69
|
+
logging.info(f"Git hooks successfully installed in: {config_dir}")
|
63
70
|
return True
|
64
71
|
except subprocess.CalledProcessError as e:
|
65
|
-
|
72
|
+
logging.error(f"Failed to set git hooks path: {str(e)}")
|
66
73
|
return False
|
67
74
|
|
68
75
|
except Exception as e:
|
69
|
-
|
76
|
+
logging.error(f"Unexpected error during hooks installation: {str(e)}")
|
70
77
|
return False
|
71
78
|
|
72
79
|
if __name__ == '__main__':
|