Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_line_to_pipfile(self, line, develop):
from requirementslib import Requirement
requirement = Requirement.from_line(line)
section = self._get_pipfile_section(develop=develop)
key = requirement.normalized_name
entry = next(iter(requirement.as_pipfile().values()))
if isinstance(entry, dict):
# HACK: TOMLKit prefers to expand tables by default, but we
# always want inline tables here. Also tomlkit.inline_table
# does not have `update()`.
table = tomlkit.inline_table()
for k, v in entry.items():
table[k] = v
entry = table
section[key] = entry
The extra extraction is not comprehensive. Tt assumes the marker is NEVER
something like `extra == "foo" and extra == "bar"`. I guess this never
makes sense anyway? Markers are just terrible.
"""
extras = extras or ()
requirements = []
for entry in metadata.run_requires:
if isinstance(entry, six.text_type):
entry = {"requires": [entry]}
extra = None
else:
extra = entry.get("extra")
if extra is not None and extra not in extras:
continue
for line in entry.get("requires", []):
r = requirementslib.Requirement.from_line(line)
if r.markers:
contained = get_contained_extras(r.markers)
if (contained and not any(e in contained for e in extras)):
continue
marker = get_without_extra(r.markers)
r.markers = str(marker) if marker else None
line = r.as_line(include_hashes=False)
requirements.append(line)
return requirements
def _is_cache_broken(line, parent_name):
dep_req = requirementslib.Requirement.from_line(line)
if contains_extra(dep_req.markers):
return True # The "extra =" marker breaks everything.
elif dep_req.normalized_name == parent_name:
return True # A package cannot depend on itself.
return False
The extra extraction is not comprehensive. Tt assumes the marker is NEVER
something like `extra == "foo" and extra == "bar"`. I guess this never
makes sense anyway? Markers are just terrible.
"""
extras = extras or ()
requirements = []
for entry in metadata.run_requires:
if isinstance(entry, six.text_type):
entry = {"requires": [entry]}
extra = None
else:
extra = entry.get("extra")
if extra is not None and extra not in extras:
continue
for line in entry.get("requires", []):
r = requirementslib.Requirement.from_line(line)
if r.markers:
contained = get_contained_extras(r.markers)
if (contained and not any(e in contained for e in extras)):
continue
marker = get_without_extra(r.markers)
r.markers = str(marker) if marker else None
line = r.as_line(include_hashes=False)
requirements.append(line)
return requirements
def add_line_to_pipfile(self, line, develop):
from requirementslib import Requirement
requirement = Requirement.from_line(line)
section = self._get_pipfile_section(develop=develop)
key = requirement.normalized_name
entry = next(iter(requirement.as_pipfile().values()))
if isinstance(entry, dict):
# HACK: TOMLKit prefers to expand tables by default, but we
# always want inline tables here. Also tomlkit.inline_table
# does not have `update()`.
table = tomlkit.inline_table()
for k, v in entry.items():
table[k] = v
entry = table
section[key] = entry
def add_line_to_pipfile(self, line, develop):
from requirementslib import Requirement
requirement = Requirement.from_line(line)
section = self._get_pipfile_section(develop=develop)
key = requirement.normalized_name
entry = next(iter(requirement.as_pipfile().values()))
if isinstance(entry, dict):
# HACK: TOMLKit prefers to expand tables by default, but we
# always want inline tables here. Also tomlkit.inline_table
# does not have `update()`.
table = tomlkit.inline_table()
for k, v in entry.items():
table[k] = v
entry = table
section[key] = entry
from requirementslib import Pipfile, Requirement
from requirementslib.models.utils import make_install_requirement
from resolvelib import (
AbstractProvider, BaseReporter, Resolver,
NoVersionsAvailable, ResolutionImpossible,
)
parser = argparse.ArgumentParser()
parser.add_argument('packages', metavar='PACKAGE', nargs='*')
parser.add_argument('--project', type=os.path.abspath)
options = parser.parse_args()
requirements = [Requirement.from_line(line) for line in options.packages]
if options.project:
os.chdir(options.project)
pipfile = Pipfile.load(options.project)
requirements.extend(pipfile.packages.requirements)
requirements.extend(pipfile.dev_packages.requirements)
def _filter_needed(requirement):
if not requirement.markers:
return True
return requirement.ireq.match_markers()
class RequirementsLibProvider(AbstractProvider):
"""Provider implementation to interface with `requirementslib.Requirement`.
"""