-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdeveloper-setup.py
More file actions
45 lines (32 loc) · 953 Bytes
/
developer-setup.py
File metadata and controls
45 lines (32 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Setup for git hooks.
"""
import sys
from pathlib import Path
def get_project_path() -> Path:
"""
Get the absolute project path.
Thereby, this script can be called from any location in
the filesystem.
Returns:
the absolute ELVA project path.
"""
script = sys.argv[0]
return Path(script).absolute().parent
def create_hook_symlinks(project: Path):
"""
Create symlinked hooks in the local .git directory.
Arguments:
project: the absolute ELVA project path
"""
git_hooks = project / "git/hooks/"
dotgit_hooks = project / ".git/hooks/"
for target in git_hooks.iterdir():
link = dotgit_hooks / target.name
target = target.relative_to(dotgit_hooks, walk_up=True)
if not link.exists():
link.symlink_to(target)
print(f"✓ {link}")
if __name__ == "__main__":
project = get_project_path()
create_hook_symlinks(project)