@@ -87,12 +87,12 @@ def parse_requirements(
8787 comes_from_stdin : bool = False ,
8888) -> Iterator [InstallRequirement ]:
8989 # the `comes_from` data will be rewritten in different ways in different conditions
90- # each rewrite rule is expressible as a str->str function or as a static replacement
91- rewrite_comes_from : Callable [[str ], str ] | str
90+ # each rewrite rule is expressible as a str->str function
91+ rewrite_comes_from : Callable [[str ], str ]
9292
9393 if comes_from_stdin :
9494 # if data is coming from stdin, then `comes_from="-r -"`
95- rewrite_comes_from = "-r -"
95+ rewrite_comes_from = _rewrite_comes_from_to_hardcoded_stdin_value
9696 elif pathlib .Path (filename ).is_absolute ():
9797 # if the input path is absolute, just normalize paths to posix-style
9898 rewrite_comes_from = _normalize_comes_from_location
@@ -113,28 +113,32 @@ def parse_requirements(
113113 install_req .link = file_link
114114 install_req = copy_install_requirement (install_req )
115115
116- if isinstance (rewrite_comes_from , str ):
117- install_req .comes_from = rewrite_comes_from
118- else :
119- install_req .comes_from = rewrite_comes_from (install_req .comes_from )
116+ install_req .comes_from = rewrite_comes_from (install_req .comes_from )
120117
121118 yield install_req
122119
123120
121+ def _rewrite_comes_from_to_hardcoded_stdin_value (_ : str , / ) -> str :
122+ """Produce the hardcoded ``comes_from`` value for stdin."""
123+ return "-r -"
124+
125+
124126def _relativize_comes_from_location (original_comes_from : str , / ) -> str :
125127 """
128+ Convert a ``comes_from`` path to a relative posix path.
129+
126130 This is the rewrite rule used when ``-r`` or ``-c`` appears in
127131 ``comes_from`` data with an absolute path.
128132
129- The ``-r`` or ``-c`` qualifier is retained, and the path is relativized
130- with respect to the CWD.
133+ The ``-r`` or ``-c`` qualifier is retained, the path is relativized
134+ with respect to the CWD, and the path is converted to posix style .
131135 """
132136 # require `-r` or `-c` as the source
133137 if not original_comes_from .startswith (("-r " , "-c " )):
134138 return original_comes_from
135139
136140 # split on the space
137- prefix , _ , suffix = original_comes_from .partition (" " )
141+ prefix , space_sep , suffix = original_comes_from .partition (" " )
138142
139143 file_path = pathlib .Path (suffix )
140144
@@ -144,26 +148,30 @@ def _relativize_comes_from_location(original_comes_from: str, /) -> str:
144148
145149 # make it relative to the current working dir
146150 suffix = file_path .relative_to (pathlib .Path .cwd ()).as_posix ()
147- return f"{ prefix } { suffix } "
151+ return f"{ prefix } { space_sep } { suffix } "
148152
149153
150154def _normalize_comes_from_location (original_comes_from : str , / ) -> str :
151155 """
156+ Convert a ``comes_from`` path to a posix-style path.
157+
152158 This is the rewrite rule when ``-r`` or ``-c`` appears in ``comes_from``
153- data and the input path was absolute, meaning we should not relativize the locations.
159+ data and the input path was absolute, meaning we should not relativize the
160+ locations.
154161
155- Instead, we apply minimal normalization, ensuring that posix-style paths are used.
162+ The ``-r`` or ``-c`` qualifier is retained, and the path is converted to
163+ posix style.
156164 """
157165 # require `-r` or `-c` as the source
158166 if not original_comes_from .startswith (("-r " , "-c " )):
159167 return original_comes_from
160168
161169 # split on the space
162- prefix , _ , suffix = original_comes_from .partition (" " )
170+ prefix , space_sep , suffix = original_comes_from .partition (" " )
163171
164172 # convert to a posix-style path
165173 suffix = pathlib .Path (suffix ).as_posix ()
166- return f"{ prefix } { suffix } "
174+ return f"{ prefix } { space_sep } { suffix } "
167175
168176
169177def create_wheel_cache (cache_dir : str , format_control : str | None = None ) -> WheelCache :
0 commit comments