|
4 | 4 | import logging
|
5 | 5 | import os
|
6 | 6 | import os.path as osp
|
| 7 | +from os.path import isabs |
7 | 8 | from pathlib import Path
|
8 | 9 | import re
|
9 | 10 |
|
@@ -163,7 +164,7 @@ def prep_toml_config(d, path):
|
163 | 164 | raise ConfigError(f"{toml_key} must be a string")
|
164 | 165 |
|
165 | 166 | normp = osp.normpath(data_dir)
|
166 |
| - if osp.isabs(normp): |
| 167 | + if isabs_ish(normp): |
167 | 168 | raise ConfigError(f"{toml_key} cannot be an absolute path")
|
168 | 169 | if normp.startswith('..' + os.sep):
|
169 | 170 | raise ConfigError(
|
@@ -233,9 +234,9 @@ def _check_glob_patterns(pats, clude):
|
233 | 234 |
|
234 | 235 | normp = osp.normpath(p)
|
235 | 236 |
|
236 |
| - if osp.isabs(normp): |
| 237 | + if isabs_ish(normp): |
237 | 238 | raise ConfigError(
|
238 |
| - '{} pattern {!r} is an absolute path'.format(clude, p) |
| 239 | + f'{clude} pattern {p!r} is an absolute path' |
239 | 240 | )
|
240 | 241 | if normp.startswith('..' + os.sep):
|
241 | 242 | raise ConfigError(
|
@@ -274,7 +275,7 @@ def add_scripts(self, scripts_dict):
|
274 | 275 |
|
275 | 276 |
|
276 | 277 | def description_from_file(rel_path: str, proj_dir: Path, guess_mimetype=True):
|
277 |
| - if osp.isabs(rel_path): |
| 278 | + if isabs_ish(rel_path): |
278 | 279 | raise ConfigError("Readme path must be relative")
|
279 | 280 |
|
280 | 281 | desc_path = proj_dir / rel_path
|
@@ -708,3 +709,12 @@ def pep621_people(people, group_name='author') -> dict:
|
708 | 709 | if emails:
|
709 | 710 | res[group_name + '_email'] = ", ".join(emails)
|
710 | 711 | return res
|
| 712 | + |
| 713 | + |
| 714 | +def isabs_ish(path): |
| 715 | + """Like os.path.isabs(), but Windows paths from a drive root count as absolute |
| 716 | +
|
| 717 | + isabs() worked this way up to Python 3.12 (inclusive), and where we reject |
| 718 | + absolute paths, we also want to reject these odd halfway paths. |
| 719 | + """ |
| 720 | + return os.path.isabs(path) or path.startswith(('/', '\\')) |
0 commit comments