python: Add check if current python is inside virtual environment
This commit is contained in:
parent
456efd3d57
commit
0f61930872
1 changed files with 13 additions and 3 deletions
|
@ -14,9 +14,10 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
|
||||||
try:
|
try:
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -34,6 +35,13 @@ def escape_backslash(path):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def is_virtualenv():
|
||||||
|
"""Detects if current python is inside virtualenv, pyvenv (python 3.4-3.5) or venv"""
|
||||||
|
|
||||||
|
return (hasattr(sys, 'real_prefix') or
|
||||||
|
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
idf_path = os.getenv("IDF_PATH")
|
idf_path = os.getenv("IDF_PATH")
|
||||||
|
|
||||||
|
@ -79,8 +87,10 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
print('Please refer to the Get Started section of the ESP-IDF Programming Guide for setting up the required'
|
print('Please refer to the Get Started section of the ESP-IDF Programming Guide for setting up the required'
|
||||||
' packages.')
|
' packages.')
|
||||||
print('Alternatively, you can run "{} -m pip install --user -r {}" for resolving the issue.'
|
print('Alternatively, you can run "{} -m pip install {}-r {}" for resolving the issue.'
|
||||||
''.format(escape_backslash(sys.executable), escape_backslash(args.requirements)))
|
''.format(escape_backslash(sys.executable),
|
||||||
|
'' if is_virtualenv() else '--user ',
|
||||||
|
escape_backslash(args.requirements)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print('Python requirements from {} are satisfied.'.format(args.requirements))
|
print('Python requirements from {} are satisfied.'.format(args.requirements))
|
||||||
|
|
Loading…
Reference in a new issue