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