annotate _postprocess-sdist.py @ 398:3beac9c85781 default

Syntax in pyproject.toml: use unescaped syntax
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 16 Feb 2026 15:36:17 +0100
parents c033f4072c14
children 669dd560f21a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
358
2acf206a8fdf Add license information to _postprocess-sdist.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 288
diff changeset
2 # :-
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
3 # SPDX-FileCopyrightText: © 2025-2026 Franz Glasner
358
2acf206a8fdf Add license information to _postprocess-sdist.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 288
diff changeset
4 # SPDX-License-Identifier: BSD-3-Clause
2acf206a8fdf Add license information to _postprocess-sdist.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 288
diff changeset
5 # :-
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
6 """Postprocress a .tar.gz-sdist to include tests/data with symlinks as symlinks.
288
57102b9d7ec9 Add some minimal docs into _postprocess-sdist.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 287
diff changeset
7
57102b9d7ec9 Add some minimal docs into _postprocess-sdist.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 287
diff changeset
8 Produce an sdist with all the data in :file:`tests/data/`::
57102b9d7ec9 Add some minimal docs into _postprocess-sdist.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 287
diff changeset
9
57102b9d7ec9 Add some minimal docs into _postprocess-sdist.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 287
diff changeset
10 rm -rf dist py_cutils.egg-info
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
11 python -m build
288
57102b9d7ec9 Add some minimal docs into _postprocess-sdist.py
Franz Glasner <fzglas.hg@dom66.de>
parents: 287
diff changeset
12 python _postprocess-sdist.py
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
13
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14 """
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 from __future__ import print_function, absolute_import
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18 try:
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
19 import tomllib
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 except ImportError:
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
21 import tomli as tomllib
285
39a19c008708 Now dynamically the version attribute from setup.cfg
Franz Glasner <fzglas.hg@dom66.de>
parents: 284
diff changeset
22 import importlib
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
23 import os
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24 import io
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 import tarfile
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
26 import gzip
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29 def main():
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
30 with open("pyproject.toml", "rb") as cfgfile:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
31 cfg = tomllib.load(cfgfile)
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
32 project_name = cfg["project"]["name"]
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
33 normalized_project_name = project_name.replace("-", "_")
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
34 project_version = cfg["project"].get("version")
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
35 if project_version is None:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
36 assert "version" in cfg["project"]["dynamic"]
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
37 project_version = cfg["tool"]["setuptools"]["dynamic"]["version"]
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
38 if "attr" in project_version:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
39 vermodname, dummy, vermodattr = (project_version["attr"]
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
40 .strip()
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
41 .rpartition('.'))
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
42 assert dummy is not None and vermodattr is not None
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
43 vermod = importlib.import_module(vermodname)
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
44 project_version = getattr(vermod, vermodattr)
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
45 else:
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
46 assert False
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
47 #
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
48 # PEP 625 requires that sdists are of the form
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
49 # <normalized_project_name>-<project_version>.tar.gz
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
50 #
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
51 archive_name = "{}-{}.tar.gz".format(
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
52 normalized_project_name, project_version)
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
53 uncompressed_archive_name = "{}-{}.tar".format(
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
54 normalized_project_name, project_version)
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
55 archive_path = "dist/" + archive_name
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
56 uncompressed_archive_path = "dist/" + uncompressed_archive_name
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
57 assert os.path.isfile(archive_path)
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
58 assert not os.path.isfile(uncompressed_archive_path)
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
59
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
60 # the directory within the archive
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
61 archive_path_prefix = "{}-{}".format(
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
62 normalized_project_name, project_version)
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
63
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
64 egg_directory = "{}.egg-info".format(normalized_project_name)
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
65 assert os.path.isdir(egg_directory)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
66 sources_txt_path = "{}/SOURCES.txt".format(egg_directory)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
67 sources_txt_arcname = "{}/{}/SOURCES.txt".format(
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
68 archive_path_prefix,
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
69 egg_directory)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
70
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
71 # Uncompress
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
72 with gzip.GzipFile(filename=archive_path, mode="rb") as ca:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
73 with open(uncompressed_archive_path, "wb") as uca:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
74 while True:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
75 data = ca.read(64*1024)
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
76 if not data:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
77 break
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
78 uca.write(data)
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
79
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
80 with tarfile.TarFile(uncompressed_archive_path, "r") as tf:
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
81 sf = tf.extractfile(sources_txt_arcname)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
82 try:
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
83 sources_txt = sf.read()
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
84 finally:
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
85 sf.close()
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
86
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
87 with tarfile.TarFile(uncompressed_archive_path, "a") as tf:
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
88 arcname = "{}/tests/data".format(archive_path_prefix)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
89 try:
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
90 info = tf.getmember(arcname)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
91 except KeyError:
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
92 pass
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
93 else:
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
94 raise RuntimeError("already postprocessed")
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
95 pre_names = set(tf.getnames())
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
96 tf.add("tests/data", arcname=arcname, recursive=True)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
97
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
98 #
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
99 # Determine the new files and symlinks that are to be added
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
100 # to SOURCES.txt. Skip directories.
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
101 #
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
102 post_names = set(tf.getnames())
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
103 new_names = list(post_names - pre_names)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
104 new_names.sort()
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
105 new_sources = []
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
106
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
107 for np in new_names:
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
108 nn = np[len(archive_path_prefix)+1:]
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
109 info = tf.getmember(np)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
110 if not info.isdir():
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
111 new_sources.append(nn)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
112
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
113 # Augment SOURCES.txt and add it to the archive
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
114 sources_info = tf.gettarinfo(
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
115 sources_txt_path, arcname=sources_txt_arcname)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
116 sf = io.BytesIO()
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
117 sf.write(sources_txt)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
118 if not sources_txt.endswith(b'\n'):
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
119 sf.write(b'\n')
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
120 sf.write(b('\n'.join(new_sources)))
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
121 sources_info.size = len(sf.getvalue())
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
122 sf.seek(0)
374
c19a21180a8f Comment
Franz Glasner <fzglas.hg@dom66.de>
parents: 358
diff changeset
123 #
c19a21180a8f Comment
Franz Glasner <fzglas.hg@dom66.de>
parents: 358
diff changeset
124 # This adds SOURCES.txt a 2nd time: this effectively overwrites
c19a21180a8f Comment
Franz Glasner <fzglas.hg@dom66.de>
parents: 358
diff changeset
125 # the "earlier" one.
c19a21180a8f Comment
Franz Glasner <fzglas.hg@dom66.de>
parents: 358
diff changeset
126 #
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
127 tf.addfile(sources_info, sf)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
128
397
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
129 # Compress
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
130 with open(uncompressed_archive_path, "rb") as uca:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
131 with open(archive_path, "wb") as ca:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
132 with gzip.GzipFile(filename=uncompressed_archive_name,
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
133 fileobj=ca,
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
134 mode="wb") as gzfile:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
135 while True:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
136 data = uca.read(64*1024)
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
137 if not data:
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
138 break
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
139 gzfile.write(data)
c033f4072c14 FIX: _postprocess-sdist now works for compressed archives and configuration in pyproject.toml.
Franz Glasner <fzglas.hg@dom66.de>
parents: 374
diff changeset
140
284
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
141
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
142 def b(buf, encoding="ascii"):
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
143 if isinstance(buf, bytes):
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
144 return buf
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
145 else:
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
146 return buf.encode(encoding)
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
147
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
148
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
149 if __name__ == "__main__":
b65d25882e44 REFACTOR: sdist generation: postprocess an sdist to include symbolic links as symbolic links.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
150 main()