Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
This does not use the cache.
"""
path_st = os.stat(path)
isdir = stat.S_ISDIR(path_st.st_mode)
egg_name = osp.basename(path)
if '-' in egg_name:
name, version = egg_name.split('-')[:2]
else:
name = version = None
entrypoints = []
if isdir:
ep_path = osp.join(path, 'EGG-INFO', 'entry_points.txt')
if osp.isfile(ep_path):
cp = CaseSensitiveConfigParser()
cp.read(ep_path)
entrypoints = entrypoints_from_configparser(cp)
elif zipfile.is_zipfile(path):
z = zipfile.ZipFile(path)
try:
info = z.getinfo('EGG-INFO/entry_points.txt')
except KeyError:
return None
cp = CaseSensitiveConfigParser()
with z.open(info) as f:
fu = io.TextIOWrapper(f)
cp.read_file(fu,
source=osp.join(path, 'EGG-INFO',
'entry_points.txt'))
entrypoints = entrypoints_from_configparser(cp)
if z.filename.count('/') > 1:
continue # In a subdirectory
distro_name_version = z.filename.split('/')[0].rsplit('.', 1)[0]
if '-' in distro_name_version:
name, version = distro_name_version.split('-', 1)
else:
name, version = None, None
distro = {
'name': name, 'version': version,
'entrypoints': []
}
distributions.append(distro)
cp = CaseSensitiveConfigParser()
with z.open(info) as f:
fu = io.TextIOWrapper(f)
cp.read_file(fu, source=osp.join(path, z.filename))
distro['entrypoints'] = entrypoints_from_configparser(cp)
return {
'mtime': path_st.st_mtime,
'isdir': True,
'distributions': distributions,
}
glob.iglob(osp.join(path, '*.dist-info', 'entry_points.txt')),
glob.iglob(osp.join(path, '*.egg-info', 'entry_points.txt'))
):
distro_name_version = osp.splitext(osp.basename(osp.dirname(path)))[0]
if '-' in distro_name_version:
name, version = distro_name_version.split('-', 1)
else:
name = version = None
distro = {
'name': name, 'version': version,
'entrypoints': []
}
distributions.append(distro)
cp = CaseSensitiveConfigParser()
cp.read(path)
distro['entrypoints'] = entrypoints_from_configparser(cp)
distributions.sort(key=lambda d: "%s-%s" % (d['name'], d['version']))
return {
'mtime': path_st.st_mtime,
'isdir': True,
'distributions': distributions,
}
for folder in path:
if folder.rstrip('/\\').endswith('.egg'):
# Gah, eggs
egg_name = osp.basename(folder)
distro = Distribution.from_name_version(egg_name.split(".egg")[0])
if (repeated_distro == 'first') \
and (distro.name in distro_names_seen):
continue
distro_names_seen.add(distro.name)
if osp.isdir(folder):
ep_path = osp.join(folder, 'EGG-INFO', 'entry_points.txt')
if osp.isfile(ep_path):
cp = CaseSensitiveConfigParser(delimiters=('=',))
cp.read([ep_path])
yield cp, distro
elif zipfile.is_zipfile(folder):
z = zipfile.ZipFile(folder)
try:
info = z.getinfo('EGG-INFO/entry_points.txt')
except KeyError:
continue
cp = CaseSensitiveConfigParser(delimiters=('=',))
with z.open(info) as f:
fu = io.TextIOWrapper(f)
cp.read_file(fu, source=osp.join(
folder, 'EGG-INFO', 'entry_points.txt'))
yield cp, distro
distro_names_seen.add(distro.name)
if osp.isdir(folder):
ep_path = osp.join(folder, 'EGG-INFO', 'entry_points.txt')
if osp.isfile(ep_path):
cp = CaseSensitiveConfigParser(delimiters=('=',))
cp.read([ep_path])
yield cp, distro
elif zipfile.is_zipfile(folder):
z = zipfile.ZipFile(folder)
try:
info = z.getinfo('EGG-INFO/entry_points.txt')
except KeyError:
continue
cp = CaseSensitiveConfigParser(delimiters=('=',))
with z.open(info) as f:
fu = io.TextIOWrapper(f)
cp.read_file(fu, source=osp.join(
folder, 'EGG-INFO', 'entry_points.txt'))
yield cp, distro
# zip imports, not egg
elif zipfile.is_zipfile(folder):
with zipfile.ZipFile(folder) as zf:
for info in zf.infolist():
m = file_in_zip_pattern.match(info.filename)
if not m:
continue
distro_name_version = m.group('dist_version')
distro = Distribution.from_name_version(distro_name_version)
entrypoints = []
if isdir:
ep_path = osp.join(path, 'EGG-INFO', 'entry_points.txt')
if osp.isfile(ep_path):
cp = CaseSensitiveConfigParser()
cp.read(ep_path)
entrypoints = entrypoints_from_configparser(cp)
elif zipfile.is_zipfile(path):
z = zipfile.ZipFile(path)
try:
info = z.getinfo('EGG-INFO/entry_points.txt')
except KeyError:
return None
cp = CaseSensitiveConfigParser()
with z.open(info) as f:
fu = io.TextIOWrapper(f)
cp.read_file(fu,
source=osp.join(path, 'EGG-INFO',
'entry_points.txt'))
entrypoints = entrypoints_from_configparser(cp)
return {
'mtime': path_st.st_mtime,
'isdir': isdir,
'distributions': [{
'name': name,
'version': version,
'entrypoints': entrypoints
}],
yield cp, distro
# Regular file imports (not egg, not zip file)
for path in itertools.chain(
glob.iglob(osp.join(folder, '*.dist-info', 'entry_points.txt')),
glob.iglob(osp.join(folder, '*.egg-info', 'entry_points.txt'))
):
distro_name_version = osp.splitext(osp.basename(osp.dirname(path)))[0]
distro = Distribution.from_name_version(distro_name_version)
if (repeated_distro == 'first') \
and (distro.name in distro_names_seen):
continue
distro_names_seen.add(distro.name)
cp = CaseSensitiveConfigParser(delimiters=('=',))
cp.read([path])
yield cp, distro