MCPcopy
hub / github.com/jazzband/pip-tools / format_requirement

Function format_requirement

piptools/utils.py:99–126  ·  view source on GitHub ↗

Generic formatter for pretty printing InstallRequirements to the terminal in a less verbose way than using its ``__str__`` method.

(
    ireq: InstallRequirement,
    marker: Marker | None = None,
    hashes: set[str] | None = None,
)

Source from the content-addressed store, hash-verified

97
98
99def format_requirement(
100 ireq: InstallRequirement,
101 marker: Marker | None = None,
102 hashes: set[str] | None = None,
103) -> str:
104 """
105 Generic formatter for pretty printing InstallRequirements to the terminal
106 in a less verbose way than using its ``__str__`` method.
107 """
108 if ireq.editable:
109 line = f"-e {ireq.link.url}"
110 elif is_url_requirement(ireq):
111 line = _build_direct_reference_best_efforts(ireq)
112 else:
113 # Canonicalize the requirement name
114 # https://packaging.pypa.io/en/latest/utils.html#packaging.utils.canonicalize_name
115 req = copy.copy(ireq.req)
116 req.name = canonicalize_name(req.name)
117 line = str(req)
118
119 if marker:
120 line = f"{line} ; {marker}"
121
122 if hashes:
123 for hash_ in sorted(hashes):
124 line += f" \\\n --hash={hash_}"
125
126 return line
127
128
129def _build_direct_reference_best_efforts(ireq: InstallRequirement) -> str:

Calls 3

is_url_requirementFunction · 0.85
canonicalize_nameFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…