Python site.__file__() Examples
The following are 30
code examples of site.__file__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
site
, or try the search function
.
Example #1
Source File: venv_update.py From mealpy with MIT License | 6 votes |
def has_system_site_packages(interpreter): # TODO: unit-test system_site_packages = check_output(( interpreter, '-c', # stolen directly from virtualenv's site.py """\ import site, os.path print( 0 if os.path.exists( os.path.join(os.path.dirname(site.__file__), 'no-global-site-packages.txt') ) else 1 )""" )) system_site_packages = int(system_site_packages) assert system_site_packages in (0, 1) return bool(system_site_packages)
Example #2
Source File: venv_update.py From venv-update with MIT License | 6 votes |
def has_system_site_packages(interpreter): # TODO: unit-test system_site_packages = check_output(( interpreter, '-c', # stolen directly from virtualenv's site.py """\ import site, os.path print( 0 if os.path.exists( os.path.join(os.path.dirname(site.__file__), 'no-global-site-packages.txt') ) else 1 )""" )) system_site_packages = int(system_site_packages) assert system_site_packages in (0, 1) return bool(system_site_packages)
Example #3
Source File: venv_update.py From venv-update with MIT License | 5 votes |
def exec_scratch_virtualenv(args): """ goals: - get any random site-packages off of the pythonpath - ensure we can import virtualenv - ensure that we're not using the interpreter that we may need to delete - idempotency: do nothing if the above goals are already met """ scratch = Scratch() if not exists(scratch.python): run(('virtualenv', scratch.venv)) if not exists(join(scratch.src, 'virtualenv.py')): scratch_python = venv_python(scratch.venv) # TODO: do we allow user-defined override of which version of virtualenv to install? # https://github.com/Yelp/venv-update/issues/231 virtualenv 20+ is not supported. tmp = scratch.src + '.tmp' run((scratch_python, '-m', 'pip.__main__', 'install', 'virtualenv<20', '--target', tmp)) from os import rename rename(tmp, scratch.src) import sys from os.path import realpath # We want to compare the paths themselves as sometimes sys.path is the same # as scratch.venv, but with a suffix of bin/.. if realpath(sys.prefix) != realpath(scratch.venv): # TODO-TEST: sometimes we would get a stale version of venv-update exec_((scratch.python, dotpy(__file__)) + args) # never returns # TODO-TEST: the original venv-update's directory was on sys.path (when using symlinking) sys.path[0] = scratch.src
Example #4
Source File: locations.py From Weapon-Detection-And-Classification with MIT License | 5 votes |
def virtualenv_no_global(): # type: () -> bool """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True else: return False
Example #5
Source File: locations.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def virtualenv_no_global(): # type: () -> bool """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True else: return False
Example #6
Source File: virtualenv.py From CogAlg with MIT License | 5 votes |
def virtualenv_no_global(): # type: () -> bool """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True else: return False
Example #7
Source File: venv_update.py From venv-update with MIT License | 5 votes |
def execfile_(filename): with open(filename) as code: code = compile(code.read(), filename, 'exec') exec(code, {'__file__': filename})
Example #8
Source File: locations.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def virtualenv_no_global(): # type: () -> bool """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True else: return False
Example #9
Source File: locations.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def virtualenv_no_global(): # type: () -> bool """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True else: return False
Example #10
Source File: locations.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def virtualenv_no_global(): # type: () -> bool """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True else: return False
Example #11
Source File: locations.py From fxxkpython with GNU General Public License v3.0 | 5 votes |
def virtualenv_no_global(): # type: () -> bool """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True else: return False
Example #12
Source File: locations.py From twitter-stock-recommendation with MIT License | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #13
Source File: locations.py From Flask with Apache License 2.0 | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ #this mirrors the logic in virtualenv.py for locating the no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #14
Source File: venv_update.py From mealpy with MIT License | 5 votes |
def exec_scratch_virtualenv(args): """ goals: - get any random site-packages off of the pythonpath - ensure we can import virtualenv - ensure that we're not using the interpreter that we may need to delete - idempotency: do nothing if the above goals are already met """ scratch = Scratch() if not exists(scratch.python): run(('virtualenv', scratch.venv)) if not exists(join(scratch.src, 'virtualenv.py')): scratch_python = venv_python(scratch.venv) # TODO: do we allow user-defined override of which version of virtualenv to install? tmp = scratch.src + '.tmp' run((scratch_python, '-m', 'pip.__main__', 'install', 'virtualenv', '--target', tmp)) from os import rename rename(tmp, scratch.src) import sys from os.path import realpath # We want to compare the paths themselves as sometimes sys.path is the same # as scratch.venv, but with a suffix of bin/.. if realpath(sys.prefix) != realpath(scratch.venv): # TODO-TEST: sometimes we would get a stale version of venv-update exec_((scratch.python, dotpy(__file__)) + args) # never returns # TODO-TEST: the original venv-update's directory was on sys.path (when using symlinking) sys.path[0] = scratch.src
Example #15
Source File: locations.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #16
Source File: locations.py From guildai with Apache License 2.0 | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #17
Source File: locations.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #18
Source File: locations.py From syntheticmass with Apache License 2.0 | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #19
Source File: locations.py From PhonePi_SampleServer with MIT License | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #20
Source File: locations.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #21
Source File: locations.py From datafari with Apache License 2.0 | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #22
Source File: locations.py From Ansible with MIT License | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #23
Source File: locations.py From python2017 with MIT License | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #24
Source File: virtualenv.py From generator-angular-flask with MIT License | 5 votes |
def relative_script(lines): "Return a script that'll work in a relocatable environment." activate = "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); execfile(activate_this, dict(__file__=activate_this)); del os, activate_this" # Find the last future statement in the script. If we insert the activation # line before a future statement, Python will raise a SyntaxError. activate_at = None for idx, line in reversed(list(enumerate(lines))): if line.split()[:3] == ['from', '__future__', 'import']: activate_at = idx + 1 break if activate_at is None: # Activate after the shebang. activate_at = 1 return lines[:activate_at] + ['', activate, ''] + lines[activate_at:]
Example #25
Source File: virtualenv.py From generator-angular-flask with MIT License | 5 votes |
def file_search_dirs(): here = os.path.dirname(os.path.abspath(__file__)) dirs = ['.', here, join(here, 'virtualenv_support')] if os.path.splitext(os.path.dirname(__file__))[0] != 'virtualenv': # Probably some boot script; just in case virtualenv is installed... try: import virtualenv except ImportError: pass else: dirs.append(os.path.join(os.path.dirname(virtualenv.__file__), 'virtualenv_support')) return [d for d in dirs if os.path.isdir(d)]
Example #26
Source File: locations.py From ImageFusion with MIT License | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #27
Source File: locations.py From ImageFusion with MIT License | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #28
Source File: virtualenv.py From rules_pip with MIT License | 5 votes |
def _no_global_under_regular_virtualenv(): # type: () -> bool """Check if "no-global-site-packages.txt" exists beside site.py This mirrors logic in pypa/virtualenv for determining whether system site-packages are visible in the virtual environment. """ site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_site_packages_file = os.path.join( site_mod_dir, 'no-global-site-packages.txt', ) return os.path.exists(no_global_site_packages_file)
Example #29
Source File: locations.py From planespotter with MIT License | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ # this mirrors the logic in virtualenv.py for locating the # no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True
Example #30
Source File: locations.py From Flask with Apache License 2.0 | 5 votes |
def virtualenv_no_global(): """ Return True if in a venv and no system site packages. """ #this mirrors the logic in virtualenv.py for locating the no-global-site-packages.txt file site_mod_dir = os.path.dirname(os.path.abspath(site.__file__)) no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt') if running_under_virtualenv() and os.path.isfile(no_global_file): return True