Returns `(from_, (to_abs, to_rel))`. If `p` is a string we convert to `(p, p)`. Otherwise we assert that `p` is a tuple `(from_, to_)` where `from_` is str/bytes and `to_` is str. If `from_` is a bytes it is contents of file to add, otherwise the path of an
(self, p)
| 1537 | return p, p_rel |
| 1538 | |
| 1539 | def _fromto(self, p): |
| 1540 | ''' |
| 1541 | Returns `(from_, (to_abs, to_rel))`. |
| 1542 | |
| 1543 | If `p` is a string we convert to `(p, p)`. Otherwise we assert that |
| 1544 | `p` is a tuple `(from_, to_)` where `from_` is str/bytes and `to_` is |
| 1545 | str. If `from_` is a bytes it is contents of file to add, otherwise the |
| 1546 | path of an existing file; non-absolute paths are assumed to be relative |
| 1547 | to `self.root`. |
| 1548 | |
| 1549 | If `to_` is empty or `/` we set it to the leaf of `from_` (which must |
| 1550 | be a str) - i.e. we place the file in the root directory of the wheel; |
| 1551 | otherwise if `to_` ends with `/` we append the leaf of `from_` (which |
| 1552 | must be a str). |
| 1553 | |
| 1554 | If `to_` starts with `$dist-info/`, we replace this with |
| 1555 | `self._dist_info_dir()`. |
| 1556 | |
| 1557 | If `to_` starts with `$data/`, we replace this with |
| 1558 | `{self.name}-{self.version}.data/`. |
| 1559 | |
| 1560 | We assert that `to_abs` is `within self.root`. |
| 1561 | |
| 1562 | `to_rel` is derived from the `to_abs` and is relative to self.root`. |
| 1563 | ''' |
| 1564 | ret = None |
| 1565 | if isinstance(p, str): |
| 1566 | p = p, p |
| 1567 | assert isinstance(p, tuple) and len(p) == 2 |
| 1568 | |
| 1569 | from_, to_ = p |
| 1570 | assert isinstance(from_, (str, bytes)) |
| 1571 | assert isinstance(to_, str) |
| 1572 | if to_ == '/' or to_ == '': |
| 1573 | to_ = os.path.basename(from_) |
| 1574 | elif to_.endswith('/'): |
| 1575 | to_ += os.path.basename(from_) |
| 1576 | prefix = '$dist-info/' |
| 1577 | if to_.startswith( prefix): |
| 1578 | to_ = f'{self._dist_info_dir()}/{to_[ len(prefix):]}' |
| 1579 | prefix = '$data/' |
| 1580 | if to_.startswith( prefix): |
| 1581 | to_ = f'{_normalise2(self.name)}-{self.version}.data/{to_[ len(prefix):]}' |
| 1582 | if isinstance(from_, str): |
| 1583 | from_, _ = self._path_relative_to_root( from_, assert_within_root=False) |
| 1584 | to_ = self._path_relative_to_root(to_) |
| 1585 | assert isinstance(from_, (str, bytes)) |
| 1586 | log2(f'returning {from_=} {to_=}') |
| 1587 | return from_, to_ |
| 1588 | |
| 1589 | _extensions_to_py_limited_api = dict() |
| 1590 |
no test coverage detected