]>
crepu.dev Git - config.git/blob - djavu-asus/emacs/elpy/rpc-venv/lib/python3.11/site-packages/setuptools/command/sdist.py
1 from distutils
import log
2 import distutils
.command
.sdist
as orig
7 from itertools
import chain
9 from .py36compat
import sdist_add_defaults
11 from .._importlib
import metadata
12 from .build
import _ORIGINAL_SUBCOMMANDS
14 _default_revctrl
= list
17 def walk_revctrl(dirname
=''):
18 """Find all files under revision control"""
19 for ep
in metadata
.entry_points(group
='setuptools.file_finders'):
20 for item
in ep
.load()(dirname
):
24 class sdist(sdist_add_defaults
, orig
.sdist
):
25 """Smart sdist that finds anything supported by revision control"""
29 "formats for source distribution (comma-separated list)"),
31 "keep the distribution tree around after creating " +
34 "directory to put the source distribution archive(s) in "
37 "Owner name used when creating a tar file [default: current user]"),
39 "Group name used when creating a tar file [default: current group]"),
44 README_EXTENSIONS
= ['', '.rst', '.txt', '.md']
45 READMES
= tuple('README{0}'.format(ext
) for ext
in README_EXTENSIONS
)
48 self
.run_command('egg_info')
49 ei_cmd
= self
.get_finalized_command('egg_info')
50 self
.filelist
= ei_cmd
.filelist
51 self
.filelist
.append(os
.path
.join(ei_cmd
.egg_info
, 'SOURCES.txt'))
55 for cmd_name
in self
.get_sub_commands():
56 self
.run_command(cmd_name
)
58 self
.make_distribution()
60 dist_files
= getattr(self
.distribution
, 'dist_files', [])
61 for file in self
.archive_files
:
62 data
= ('sdist', '', file)
63 if data
not in dist_files
:
64 dist_files
.append(data
)
66 def initialize_options(self
):
67 orig
.sdist
.initialize_options(self
)
69 self
._default
_to
_gztar
()
71 def _default_to_gztar(self
):
72 # only needed on Python prior to 3.6.
73 if sys
.version_info
>= (3, 6, 0, 'beta', 1):
75 self
.formats
= ['gztar']
77 def make_distribution(self
):
81 with self
._remove
_os
_link
():
82 orig
.sdist
.make_distribution(self
)
85 @contextlib.contextmanager
86 def _remove_os_link():
88 In a context, remove and restore os.link if it exists
94 orig_val
= getattr(os
, 'link', NoValue
)
102 if orig_val
is not NoValue
:
103 setattr(os
, 'link', orig_val
)
105 def add_defaults(self
):
106 super().add_defaults()
107 self
._add
_defaults
_build
_sub
_commands
()
109 def _add_defaults_optional(self
):
110 super()._add
_defaults
_optional
()
111 if os
.path
.isfile('pyproject.toml'):
112 self
.filelist
.append('pyproject.toml')
114 def _add_defaults_python(self
):
115 """getting python files"""
116 if self
.distribution
.has_pure_modules():
117 build_py
= self
.get_finalized_command('build_py')
118 self
.filelist
.extend(build_py
.get_source_files())
119 self
._add
_data
_files
(self
._safe
_data
_files
(build_py
))
121 def _add_defaults_build_sub_commands(self
):
122 build
= self
.get_finalized_command("build")
123 missing_cmds
= set(build
.get_sub_commands()) - _ORIGINAL_SUBCOMMANDS
124 # ^-- the original built-in sub-commands are already handled by default.
125 cmds
= (self
.get_finalized_command(c
) for c
in missing_cmds
)
126 files
= (c
.get_source_files() for c
in cmds
if hasattr(c
, "get_source_files"))
127 self
.filelist
.extend(chain
.from_iterable(files
))
129 def _safe_data_files(self
, build_py
):
131 Since the ``sdist`` class is also used to compute the MANIFEST
132 (via :obj:`setuptools.command.egg_info.manifest_maker`),
133 there might be recursion problems when trying to obtain the list of
134 data_files and ``include_package_data=True`` (which in turn depends on
135 the files included in the MANIFEST).
137 To avoid that, ``manifest_maker`` should be able to overwrite this
138 method and avoid recursive attempts to build/analyze the MANIFEST.
140 return build_py
.data_files
142 def _add_data_files(self
, data_files
):
144 Add data files as found in build_py.data_files.
146 self
.filelist
.extend(
147 os
.path
.join(src_dir
, name
)
148 for _
, src_dir
, _
, filenames
in data_files
149 for name
in filenames
152 def _add_defaults_data_files(self
):
154 super()._add
_defaults
_data
_files
()
156 log
.warn("data_files contains unexpected objects")
158 def check_readme(self
):
159 for f
in self
.READMES
:
160 if os
.path
.exists(f
):
164 "standard file not found: should have one of " +
165 ', '.join(self
.READMES
)
168 def make_release_tree(self
, base_dir
, files
):
169 orig
.sdist
.make_release_tree(self
, base_dir
, files
)
171 # Save any egg_info command line options used to create this sdist
172 dest
= os
.path
.join(base_dir
, 'setup.cfg')
173 if hasattr(os
, 'link') and os
.path
.exists(dest
):
174 # unlink and re-copy, since it might be hard-linked, and
175 # we don't want to change the source version
177 self
.copy_file('setup.cfg', dest
)
179 self
.get_finalized_command('egg_info').save_version_info(dest
)
181 def _manifest_is_not_generated(self
):
182 # check for special comment used in 2.7.1 and higher
183 if not os
.path
.isfile(self
.manifest
):
186 with io
.open(self
.manifest
, 'rb') as fp
:
187 first_line
= fp
.readline()
188 return (first_line
!=
189 '# file GENERATED by distutils, do NOT edit\n'.encode())
191 def read_manifest(self
):
192 """Read the manifest file (named by 'self.manifest') and use it to
193 fill in 'self.filelist', the list of files to include in the source
196 log
.info("reading manifest file '%s'", self
.manifest
)
197 manifest
= open(self
.manifest
, 'rb')
198 for line
in manifest
:
199 # The manifest must contain UTF-8. See #303.
201 line
= line
.decode('UTF-8')
202 except UnicodeDecodeError:
203 log
.warn("%r not UTF-8 decodable -- skipping" % line
)
205 # ignore comments and blank lines
207 if line
.startswith('#') or not line
:
209 self
.filelist
.append(line
)