PK!Y*0 pypath_setup/__init__.pyimport subprocess import platform import os.path __all__ = [ 'run', 'main', ] def run() -> int: import argparse import sys PYTHONPATH = 'PYTHONPATH' VIRTUAL_ENV = 'VIRTUAL_ENV' PYPATH_SETUP_EXECUTABLE = 'PYPATH_SETUP_EXECUTABLE' # Copying the environment variables env = os.environ.copy() # Setting up the launcher's ArgumentParser parser = argparse.ArgumentParser( prog='pypath-setup') parser.add_argument('--dry-run', dest='dryrun', action='store_true', help='only show debug information') parser.add_argument('--debug', action='store_true', help='display debug messages') parser.add_argument('--venv', type=str, help='set the virtualenv to use') parser.add_argument('--override', action='store_true', help='completely override PYTHONPATH') parser.add_argument('executable', type=str, help='path to blenderplayer to use') options, arguments = parser.parse_known_args() def debug(*args, **kargs): if options.dryrun or options.debug: print('[ PID:', os.getpid(), ']', *args, **kargs) # Check if we are running in a virtualenv virtualenv = env.get(VIRTUAL_ENV, None) # Use specified parameter if not virtualenv: virtualenv = options.venv # Use default `.venv` location if not virtualenv: if os.path.isdir('.venv'): debug('Found local virtualenv .venv folder') virtualenv = '.venv' # Nothing was found if not virtualenv: raise ValueError('--venv must be specified if not in a virtualenv') # Get python executable in the virtualenv python_executable = get_python_executable(virtualenv) # Relaunch current process in the virtualenv if needed if not os.path.samefile(python_executable, sys.executable): if PYPATH_SETUP_EXECUTABLE not in env: return subprocess.call( [python_executable, *sys.argv], env={ **env, VIRTUAL_ENV: virtualenv, PYPATH_SETUP_EXECUTABLE: python_executable }) else: # avoid fork-bomb debug('Skipped forking') # Fetch and update PYTHONPATH if options.override: path = sys.path else: path = env[PYTHONPATH].split(os.pathsep) \ if PYTHONPATH in env else [] path.extend(sys.path) # Set environment with new PYTHONPATH pythonpath = os.pathsep.join(path) debug('PYTHONPATH: "%s"' % pythonpath) env.update({ PYTHONPATH: pythonpath }) # Reconstructing the command the user wants to run in the patched environment command = '%s %s' % (options.executable, ' '.join(arguments)) debug('Command:', command) if options.dryrun: return 0 return run_in_shell(command, env=env) def main(): exit(run()) if platform.system() == 'Windows': def get_python_executable(virtualenv): return os.path.join(virtualenv, 'Scripts', 'python') def run_in_shell(command, env): return subprocess.call(command, shell=True, env=env) else: def get_python_executable(virtualenv): return os.path.join(virtualenv, 'bin', 'python') def run_in_shell(command, env): ''' Try to handle UNIX case where user can have a custom shell with aliases. ''' shell = env.get('SHELL', None) if shell: return subprocess.call([shell, '-i', '-c', command], env=env) return subprocess.call(command, shell=True, env=env) PK!O] EEpypath_setup/__main__.pyfrom pypath_setup import main if __name__ == '__main__': main() PK!Hs\ ,2-pypath_setup-0.1.3.dist-info/entry_points.txtN+I/N.,()*,H,-N-)-p<..PK!HnHTU"pypath_setup-0.1.3.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HG~%pypath_setup-0.1.3.dist-info/METADATAMN@ s ZBAb6h4MF0㩔#q.!6;{ߑx RhH=r_D|!d Q10Z" mP;N[ IN8=*._|K-6%u >_\A=(ȁ(c/=nuFhŤS wPS~Q* ƺ~`SP,&O_ܔE󓢦n*nB2dI-=DYՌJ; e_GQ֗C7~ Ju̻Ox(A t,m{Hn؜c纓ƕfhIWǠ=Ras `a&Ђ&$x1LӨ 3[ϊf=JdX=t3& -PK!Y*0 pypath_setup/__init__.pyPK!O] EE pypath_setup/__main__.pyPK!Hs\ ,2-spypath_setup-0.1.3.dist-info/entry_points.txtPK!HnHTU"pypath_setup-0.1.3.dist-info/WHEELPK!HG~%~pypath_setup-0.1.3.dist-info/METADATAPK!H v.#pypath_setup-0.1.3.dist-info/RECORDPK$