##// END OF EJS Templates
skip submodule check in package managers...
MinRK -
Show More
@@ -1,92 +1,102 b''
1 1 """utilities for checking submodule status"""
2 2
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (C) 2013 The IPython Development Team
5 5 #
6 6 # Distributed under the terms of the BSD License. The full license is in
7 7 # the file COPYING, distributed as part of this software.
8 8 #-----------------------------------------------------------------------------
9 9
10 10 #-----------------------------------------------------------------------------
11 11 # Imports
12 12 #-----------------------------------------------------------------------------
13 13
14 14 import os
15 15 import subprocess
16 16 import sys
17 17
18 18 #-----------------------------------------------------------------------------
19 19 # Globals
20 20 #-----------------------------------------------------------------------------
21 21
22 22 pjoin = os.path.join
23 23
24 24 #-----------------------------------------------------------------------------
25 25 # Code
26 26 #-----------------------------------------------------------------------------
27 27
28 28 def ipython_parent():
29 29 """return IPython's parent (i.e. root if run from git)"""
30 30 from IPython.utils.path import get_ipython_package_dir
31 31 return os.path.abspath(os.path.dirname(get_ipython_package_dir()))
32 32
33 33 def ipython_submodules(root):
34 34 """return IPython submodules relative to root"""
35 35 return [
36 36 pjoin(root, 'IPython', 'frontend', 'html', 'notebook', 'static', 'components'),
37 37 ]
38 38
39 39 def is_repo(d):
40 40 """is d a git repo?"""
41 41 return os.path.exists(pjoin(d, '.git'))
42 42
43 def is_package():
44 """Is a package manager responsible for the static files path?"""
45 from IPython.utils.path import get_ipython_package_dir
46 from IPython.frontend.html.notebook import DEFAULT_STATIC_FILES_PATH
47 return not DEFAULT_STATIC_FILES_PATH.startswith(get_ipython_package_dir())
48
43 49 def check_submodule_status(root=None):
44 50 """check submodule status
45 51
46 52 Has three return values:
47 53
48 54 'missing' - submodules are absent
49 55 'unclean' - submodules have unstaged changes
50 56 'clean' - all submodules are up to date
51 57 """
52 58
53 59 if hasattr(sys, "frozen"):
54 # frozen via py2exe or similar, don't bother
55 return 'clean'
60 # frozen via py2exe or similar, don't bother
61 return 'clean'
62
63 if is_package():
64 # package manager is responsible for static files, don't bother
65 return 'clean'
56 66
57 67 if not root:
58 68 root = ipython_parent()
59 69
60 70 submodules = ipython_submodules(root)
61 71
62 72 for submodule in submodules:
63 73 if not os.path.exists(submodule):
64 74 return 'missing'
65 75
66 76 if not is_repo(root):
67 77 # not in git, assume clean
68 78 return 'clean'
69 79
70 80 # check with git submodule status
71 81 proc = subprocess.Popen('git submodule status',
72 82 stdout=subprocess.PIPE,
73 83 stderr=subprocess.PIPE,
74 84 shell=True,
75 85 cwd=root,
76 86 )
77 87 status, _ = proc.communicate()
78 88 status = status.decode("ascii")
79 89
80 90 for line in status.splitlines():
81 91 if status.startswith('-'):
82 92 return 'missing'
83 93 elif status.startswith('+'):
84 94 return 'unclean'
85 95
86 96 return 'clean'
87 97
88 98 def update_submodules(repo_dir):
89 99 """update submodules in a repo"""
90 100 subprocess.check_call("git submodule init", cwd=repo_dir, shell=True)
91 101 subprocess.check_call("git submodule update --recursive", cwd=repo_dir, shell=True)
92 102
General Comments 0
You need to be logged in to leave comments. Login now