Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle(self, requester, data):
requirement = data['requirement']
wheel = Wheel(data['wheel'])
run_time_dependencies = wheel.metadata.requires_dist
for spec in run_time_dependencies:
# Packages might declare their "extras" here, so let's split it
dependency, extra = (';' in spec and spec or spec + ';').split(';')
self.emit('dependency_found', self.name,
requirement=dependency,
dependency_of=requirement)
return {'requirement': requirement}
hashes=ireq.hashes(False), progress_bar="off",
)
if ireq.is_wheel:
# If this is a wheel, use the downloaded thing.
output_dir = kwargs["wheel_download_dir"]
wheel_path = os.path.join(output_dir, ireq.link.filename)
else:
# Othereise we need to build an ephemeral wheel.
wheel_path = _build_wheel(
ireq, vistir.path.create_tracked_tempdir(prefix="ephem"),
finder, _get_wheel_cache(), kwargs,
)
if wheel_path is None or not os.path.exists(wheel_path):
raise WheelBuildError
return distlib.wheel.Wheel(wheel_path)
def __init__(self, req_string, parent=None, index_url=None, env=None, extra_index_url=None):
log = self.log = logger.bind(dist=req_string)
log.info("init johnnydist", parent=parent and str(parent.req))
self.parent = parent
self.index_url = index_url
self.env = env
self.extra_index_url = extra_index_url
self._recursed = False
if req_string.endswith(".whl") and os.path.isfile(req_string):
whl = distlib.wheel.Wheel(req_string)
self.name = canonicalize_name(whl.name)
self.specifier = "==" + canonicalize_version(whl.version)
self.req = pkg_resources.Requirement.parse(self.name + self.specifier)
self.import_names = _discover_import_names(req_string)
self.metadata = _extract_metadata(req_string)
else:
self.req = pkg_resources.Requirement.parse(req_string)
self.name = canonicalize_name(self.req.name)
self.specifier = str(self.req.specifier)
log.debug("fetching best wheel")
self.import_names, self.metadata = _get_info(
dist_name=req_string,
index_url=index_url,
env=env,
extra_index_url=extra_index_url,
)
data = venv
elif args.platform == 'linux':
sp = venv / 'lib' / python / 'site-packages'
headers = venv / 'include' / 'site' / python
scripts = venv / 'bin'
data = venv
else:
die(f'unsupported platform: {args.platform}')
maker = distlib.scripts.ScriptMaker(None, None)
for filename in os.listdir(td):
if not filename.endswith('.whl'):
continue
wheel = distlib.wheel.Wheel(os.path.join(td, filename))
paths = {
'prefix': venv,
'purelib': sp,
'platlib': sp,
'headers': headers / wheel.name,
'scripts': scripts,
'data': data
}
for dn in paths.values():
os.makedirs(dn, exist_ok=True)
# print(paths, maker)
wheel.install(paths, maker)
def handle(self, requester, data):
name = parse_requirement(data['requirement']).name
wheel = Wheel(data['wheel'])
wheel.install(get_distribution_paths(name))
return data
def parse_filename(filename, name=None):
""" Parse a name and version out of a filename """
version = None
for ext in ALL_EXTENSIONS:
if filename.endswith(ext):
if ext == ".whl":
wheel = Wheel(filename)
return wheel.name, wheel.version
trimmed = filename[: -len(ext)]
parsed = split_filename(trimmed, name)
if parsed is None:
break
else:
parsed_name, version = parsed[:2]
break
if version is None:
raise ValueError("Cannot parse package file '%s'" % filename)
if name is None:
name = parsed_name
return normalize_name(name), version
if not os.path.exists(install_folder):
os.makedirs(install_folder)
from distlib.wheel import Wheel
from distlib.scripts import ScriptMaker
paths = {
'prefix': '',
'purelib': install_folder,
'platlib': install_folder,
'scripts': '',
'headers': '',
'data': ''}
files = os.listdir(wheels_folder)
for f in [os.path.join(wheels_folder, f) for f in files]:
wheel = Wheel(f)
wheel.install(paths, ScriptMaker(None, None), lib_only=True)
# Ensure there is no top level __init__.py
os.remove(os.path.join(install_folder, 'azure', '__init__.py'))
def get_metadata_from_wheel(wheel_path):
# type: (S) -> Dict[Any, Any]
if not isinstance(wheel_path, six.string_types):
raise TypeError("Expected string instance, received {0!r}".format(wheel_path))
try:
dist = Wheel(wheel_path)
except Exception:
pass
metadata = dist.metadata
name = metadata.name
version = metadata.version
requires = []
extras_keys = getattr(metadata, "extras", []) # type: List[STRING_TYPE]
extras = {
k: [] for k in extras_keys
} # type: Dict[STRING_TYPE, List[RequirementType]]
for req in getattr(metadata, "run_requires", []):
parsed_req = init_requirement(req)
parsed_marker = parsed_req.marker
if parsed_marker:
extra = get_extra_name_from_marker(parsed_marker)
if extra is None: