def create( cls, venv_dir, # type: str interpreter=None, # type: Optional[PythonInterpreter] force=False, # type: bool ): # type: (...) -> Virtualenv venv_dir = os.path.abspath(venv_dir) safe_mkdir(venv_dir, clean=force) interpreter = interpreter or PythonInterpreter.get() if interpreter.is_venv: base_interpreter = interpreter.resolve_base_interpreter() TRACER.log( "Ignoring enclosing venv {} and using its base interpreter {} to create venv at {}" " instead.".format(interpreter.prefix, base_interpreter.binary, venv_dir), V=3, ) interpreter = base_interpreter if interpreter.version[0] >= 3 and not interpreter.identity.interpreter == "PyPy": # N.B.: PyPy3 comes equipped with a venv module but it does not seem to work. interpreter.execute(args=["-m", "venv", "--without-pip", venv_dir]) else: virtualenv_py = resource_string(__name__, "virtualenv_16.7.10_py") with named_temporary_file(mode="wb") as fp: fp.write(virtualenv_py) fp.close() interpreter.execute( args=[fp.name, "--no-pip", "--no-setuptools", "--no-wheel", venv_dir], ) return cls(venv_dir)
def walk_zipped_assets(static_module_name, static_path, asset_path, temp_dir): for asset in resource_listdir(static_module_name, asset_path): asset_target = os.path.normpath( os.path.join(os.path.relpath(asset_path, static_path), asset)) if resource_isdir(static_module_name, os.path.join(asset_path, asset)): safe_mkdir(os.path.join(temp_dir, asset_target)) walk_zipped_assets(static_module_name, static_path, os.path.join(asset_path, asset), temp_dir) else: with open(os.path.join(temp_dir, asset_target), 'wb') as fp: path = os.path.join(static_path, asset_target) file_data = resource_string(static_module_name, path) fp.write(file_data)
def walk_zipped_assets(static_module_name, static_path, asset_path, temp_dir): for asset in resource_listdir(static_module_name, asset_path): asset_target = os.path.normpath( os.path.join(os.path.relpath(asset_path, static_path), asset)) if resource_isdir(static_module_name, os.path.join(asset_path, asset)): safe_mkdir(os.path.join(temp_dir, asset_target)) walk_zipped_assets(static_module_name, static_path, os.path.join(asset_path, asset), temp_dir) else: with open(os.path.join(temp_dir, asset_target), 'wb') as fp: path = os.path.join(static_path, asset_target) file_data = resource_string(static_module_name, path) fp.write(file_data)
def walk_zipped_assets(static_module_name, static_path, asset_path, temp_dir): for asset in resource_listdir(static_module_name, asset_path): if not asset: # The `resource_listdir` function returns a '' asset for the directory entry # itself if it is either present on the filesystem or present as an explicit # zip entry. Since we only care about files and subdirectories at this point, # skip these assets. continue asset_target = os.path.normpath( os.path.join(os.path.relpath(asset_path, static_path), asset) ) if resource_isdir(static_module_name, os.path.join(asset_path, asset)): safe_mkdir(os.path.join(temp_dir, asset_target)) walk_zipped_assets( static_module_name, static_path, os.path.join(asset_path, asset), temp_dir ) else: with open(os.path.join(temp_dir, asset_target), "wb") as fp: path = os.path.join(static_path, asset_target) file_data = resource_string(static_module_name, path) fp.write(file_data)