aboutsummaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-08-13 17:38:51 +0000
committerQMK Bot <hello@qmk.fm>2021-08-13 17:38:51 +0000
commitcdba934f86717fc7618fd8a5403383d8570f524e (patch)
tree68adf6a238ebede5fb382c99898945a7a48aa8ef /lib/python
parent4adb7d2176aecdb0e493a5fd40d158722fdb35e7 (diff)
parent4742a3a48f7560ee4dd2b55d4ecad4cdf1d139cd (diff)
downloadqmk_firmware-cdba934f86717fc7618fd8a5403383d8570f524e.tar.gz
qmk_firmware-cdba934f86717fc7618fd8a5403383d8570f524e.zip
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python')
-rw-r--r--lib/python/qmk/cli/__init__.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index dea0eaeaf..b22f1c0d2 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -69,6 +69,26 @@ subcommands = [
69] 69]
70 70
71 71
72def _install_deps(requirements):
73 """Perform the installation of missing requirements.
74
75 If we detect that we are running in a virtualenv we can't write into we'll use sudo to perform the pip install.
76 """
77 command = [sys.executable, '-m', 'pip', 'install']
78
79 if sys.prefix != sys.base_prefix:
80 # We are in a virtualenv, check to see if we need to use sudo to write to it
81 if not os.access(sys.prefix, os.W_OK):
82 print('Notice: Using sudo to install modules to location owned by root:', sys.prefix)
83 command.insert(0, 'sudo')
84
85 elif not os.access(sys.prefix, os.W_OK):
86 # We can't write to sys.prefix, attempt to install locally
87 command.append('--local')
88
89 return _run_cmd(*command, '-r', requirements)
90
91
72def _run_cmd(*command): 92def _run_cmd(*command):
73 """Run a command in a subshell. 93 """Run a command in a subshell.
74 """ 94 """
@@ -172,7 +192,7 @@ safe_command = args and args[0] in safe_commands
172if not safe_command: 192if not safe_command:
173 if _broken_module_imports('requirements.txt'): 193 if _broken_module_imports('requirements.txt'):
174 if yesno('Would you like to install the required Python modules?'): 194 if yesno('Would you like to install the required Python modules?'):
175 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt') 195 _install_deps('requirements.txt')
176 else: 196 else:
177 print() 197 print()
178 print(msg_install % (str(Path('requirements.txt').resolve()),)) 198 print(msg_install % (str(Path('requirements.txt').resolve()),))
@@ -181,7 +201,7 @@ if not safe_command:
181 201
182 if cli.config.user.developer and _broken_module_imports('requirements-dev.txt'): 202 if cli.config.user.developer and _broken_module_imports('requirements-dev.txt'):
183 if yesno('Would you like to install the required developer Python modules?'): 203 if yesno('Would you like to install the required developer Python modules?'):
184 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt') 204 _install_deps('requirements-dev.txt')
185 elif yesno('Would you like to disable developer mode?'): 205 elif yesno('Would you like to disable developer mode?'):
186 _run_cmd(sys.argv[0], 'config', 'user.developer=None') 206 _run_cmd(sys.argv[0], 'config', 'user.developer=None')
187 else: 207 else: