mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-11 21:54:16 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,21 +1,23 @@
|
|||
"""distutils.command.sdist
|
||||
|
||||
Implements the Distutils 'sdist' command (create a source distribution)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from glob import glob
|
||||
from warnings import warn
|
||||
|
||||
from distutils.core import Command
|
||||
from distutils import archive_util
|
||||
from distutils import dir_util
|
||||
from distutils import file_util
|
||||
from distutils import archive_util
|
||||
from distutils.text_file import TextFile
|
||||
from distutils.filelist import FileList
|
||||
from distutils import log
|
||||
from distutils.core import Command
|
||||
from distutils.errors import DistutilsOptionError
|
||||
from distutils.errors import DistutilsTemplateError
|
||||
from distutils.filelist import FileList
|
||||
from distutils.text_file import TextFile
|
||||
from distutils.util import convert_path
|
||||
from distutils.errors import DistutilsTemplateError, DistutilsOptionError
|
||||
|
||||
|
||||
def show_formats():
|
||||
|
|
@ -26,16 +28,19 @@ def show_formats():
|
|||
from distutils.archive_util import ARCHIVE_FORMATS
|
||||
formats = []
|
||||
for format in ARCHIVE_FORMATS.keys():
|
||||
formats.append(("formats=" + format, None,
|
||||
ARCHIVE_FORMATS[format][2]))
|
||||
formats.append((
|
||||
'formats=' + format, None,
|
||||
ARCHIVE_FORMATS[format][2],
|
||||
))
|
||||
formats.sort()
|
||||
FancyGetopt(formats).print_help(
|
||||
"List of available source distribution formats:")
|
||||
'List of available source distribution formats:',
|
||||
)
|
||||
|
||||
|
||||
class sdist(Command):
|
||||
|
||||
description = "create a source distribution (tarball, zip file, etc.)"
|
||||
description = 'create a source distribution (tarball, zip file, etc.)'
|
||||
|
||||
def checking_metadata(self):
|
||||
"""Callable used for the check sub-command.
|
||||
|
|
@ -44,55 +49,88 @@ class sdist(Command):
|
|||
return self.metadata_check
|
||||
|
||||
user_options = [
|
||||
('template=', 't',
|
||||
"name of manifest template file [default: MANIFEST.in]"),
|
||||
('manifest=', 'm',
|
||||
"name of manifest file [default: MANIFEST]"),
|
||||
('use-defaults', None,
|
||||
"include the default file set in the manifest "
|
||||
"[default; disable with --no-defaults]"),
|
||||
('no-defaults', None,
|
||||
"don't include the default file set"),
|
||||
('prune', None,
|
||||
"specifically exclude files/directories that should not be "
|
||||
"distributed (build tree, RCS/CVS dirs, etc.) "
|
||||
"[default; disable with --no-prune]"),
|
||||
('no-prune', None,
|
||||
"don't automatically exclude anything"),
|
||||
('manifest-only', 'o',
|
||||
"just regenerate the manifest and then stop "
|
||||
"(implies --force-manifest)"),
|
||||
('force-manifest', 'f',
|
||||
"forcibly regenerate the manifest and carry on as usual. "
|
||||
"Deprecated: now the manifest is always regenerated."),
|
||||
('formats=', None,
|
||||
"formats for source distribution (comma-separated list)"),
|
||||
('keep-temp', 'k',
|
||||
"keep the distribution tree around after creating " +
|
||||
"archive file(s)"),
|
||||
('dist-dir=', 'd',
|
||||
"directory to put the source distribution archive(s) in "
|
||||
"[default: dist]"),
|
||||
('metadata-check', None,
|
||||
"Ensure that all required elements of meta-data "
|
||||
"are supplied. Warn if any missing. [default]"),
|
||||
('owner=', 'u',
|
||||
"Owner name used when creating a tar file [default: current user]"),
|
||||
('group=', 'g',
|
||||
"Group name used when creating a tar file [default: current group]"),
|
||||
]
|
||||
(
|
||||
'template=', 't',
|
||||
'name of manifest template file [default: MANIFEST.in]',
|
||||
),
|
||||
(
|
||||
'manifest=', 'm',
|
||||
'name of manifest file [default: MANIFEST]',
|
||||
),
|
||||
(
|
||||
'use-defaults', None,
|
||||
'include the default file set in the manifest '
|
||||
'[default; disable with --no-defaults]',
|
||||
),
|
||||
(
|
||||
'no-defaults', None,
|
||||
"don't include the default file set",
|
||||
),
|
||||
(
|
||||
'prune', None,
|
||||
'specifically exclude files/directories that should not be '
|
||||
'distributed (build tree, RCS/CVS dirs, etc.) '
|
||||
'[default; disable with --no-prune]',
|
||||
),
|
||||
(
|
||||
'no-prune', None,
|
||||
"don't automatically exclude anything",
|
||||
),
|
||||
(
|
||||
'manifest-only', 'o',
|
||||
'just regenerate the manifest and then stop '
|
||||
'(implies --force-manifest)',
|
||||
),
|
||||
(
|
||||
'force-manifest', 'f',
|
||||
'forcibly regenerate the manifest and carry on as usual. '
|
||||
'Deprecated: now the manifest is always regenerated.',
|
||||
),
|
||||
(
|
||||
'formats=', None,
|
||||
'formats for source distribution (comma-separated list)',
|
||||
),
|
||||
(
|
||||
'keep-temp', 'k',
|
||||
'keep the distribution tree around after creating ' +
|
||||
'archive file(s)',
|
||||
),
|
||||
(
|
||||
'dist-dir=', 'd',
|
||||
'directory to put the source distribution archive(s) in '
|
||||
'[default: dist]',
|
||||
),
|
||||
(
|
||||
'metadata-check', None,
|
||||
'Ensure that all required elements of meta-data '
|
||||
'are supplied. Warn if any missing. [default]',
|
||||
),
|
||||
(
|
||||
'owner=', 'u',
|
||||
'Owner name used when creating a tar file [default: current user]',
|
||||
),
|
||||
(
|
||||
'group=', 'g',
|
||||
'Group name used when creating a tar file [default: current group]',
|
||||
),
|
||||
]
|
||||
|
||||
boolean_options = ['use-defaults', 'prune',
|
||||
'manifest-only', 'force-manifest',
|
||||
'keep-temp', 'metadata-check']
|
||||
boolean_options = [
|
||||
'use-defaults', 'prune',
|
||||
'manifest-only', 'force-manifest',
|
||||
'keep-temp', 'metadata-check',
|
||||
]
|
||||
|
||||
help_options = [
|
||||
('help-formats', None,
|
||||
"list available distribution formats", show_formats),
|
||||
]
|
||||
(
|
||||
'help-formats', None,
|
||||
'list available distribution formats', show_formats,
|
||||
),
|
||||
]
|
||||
|
||||
negative_opt = {'no-defaults': 'use-defaults',
|
||||
'no-prune': 'prune' }
|
||||
negative_opt = {
|
||||
'no-defaults': 'use-defaults',
|
||||
'no-prune': 'prune', }
|
||||
|
||||
sub_commands = [('check', checking_metadata)]
|
||||
|
||||
|
|
@ -123,19 +161,20 @@ class sdist(Command):
|
|||
|
||||
def finalize_options(self):
|
||||
if self.manifest is None:
|
||||
self.manifest = "MANIFEST"
|
||||
self.manifest = 'MANIFEST'
|
||||
if self.template is None:
|
||||
self.template = "MANIFEST.in"
|
||||
self.template = 'MANIFEST.in'
|
||||
|
||||
self.ensure_string_list('formats')
|
||||
|
||||
bad_format = archive_util.check_archive_formats(self.formats)
|
||||
if bad_format:
|
||||
raise DistutilsOptionError(
|
||||
"unknown archive format '%s'" % bad_format)
|
||||
"unknown archive format '%s'" % bad_format,
|
||||
)
|
||||
|
||||
if self.dist_dir is None:
|
||||
self.dist_dir = "dist"
|
||||
self.dist_dir = 'dist'
|
||||
|
||||
def run(self):
|
||||
# 'filelist' contains the list of files that will make up the
|
||||
|
|
@ -161,8 +200,10 @@ class sdist(Command):
|
|||
|
||||
def check_metadata(self):
|
||||
"""Deprecated API."""
|
||||
warn("distutils.command.sdist.check_metadata is deprecated, \
|
||||
use the check command instead", PendingDeprecationWarning)
|
||||
warn(
|
||||
'distutils.command.sdist.check_metadata is deprecated, \
|
||||
use the check command instead', PendingDeprecationWarning,
|
||||
)
|
||||
check = self.distribution.get_command_obj('check')
|
||||
check.ensure_finalized()
|
||||
check.run()
|
||||
|
|
@ -189,9 +230,13 @@ class sdist(Command):
|
|||
return
|
||||
|
||||
if not template_exists:
|
||||
self.warn(("manifest template '%s' does not exist " +
|
||||
"(using default file list)") %
|
||||
self.template)
|
||||
self.warn(
|
||||
(
|
||||
"manifest template '%s' does not exist " +
|
||||
'(using default file list)'
|
||||
) %
|
||||
self.template,
|
||||
)
|
||||
self.filelist.findall()
|
||||
|
||||
if self.use_defaults:
|
||||
|
|
@ -259,8 +304,10 @@ class sdist(Command):
|
|||
break
|
||||
|
||||
if not got_it:
|
||||
self.warn("standard file not found: should have one of " +
|
||||
', '.join(alts))
|
||||
self.warn(
|
||||
'standard file not found: should have one of ' +
|
||||
', '.join(alts),
|
||||
)
|
||||
else:
|
||||
if self._cs_path_exists(fn):
|
||||
self.filelist.append(fn)
|
||||
|
|
@ -328,9 +375,11 @@ class sdist(Command):
|
|||
'self.filelist', which updates itself accordingly.
|
||||
"""
|
||||
log.info("reading manifest template '%s'", self.template)
|
||||
template = TextFile(self.template, strip_comments=1, skip_blanks=1,
|
||||
join_lines=1, lstrip_ws=1, rstrip_ws=1,
|
||||
collapse_join=1)
|
||||
template = TextFile(
|
||||
self.template, strip_comments=1, skip_blanks=1,
|
||||
join_lines=1, lstrip_ws=1, rstrip_ws=1,
|
||||
collapse_join=1,
|
||||
)
|
||||
|
||||
try:
|
||||
while True:
|
||||
|
|
@ -344,9 +393,13 @@ class sdist(Command):
|
|||
# malformed lines, or a ValueError from the lower-level
|
||||
# convert_path function
|
||||
except (DistutilsTemplateError, ValueError) as msg:
|
||||
self.warn("%s, line %d: %s" % (template.filename,
|
||||
template.current_line,
|
||||
msg))
|
||||
self.warn(
|
||||
'%s, line %d: %s' % (
|
||||
template.filename,
|
||||
template.current_line,
|
||||
msg,
|
||||
),
|
||||
)
|
||||
finally:
|
||||
template.close()
|
||||
|
||||
|
|
@ -369,9 +422,11 @@ class sdist(Command):
|
|||
else:
|
||||
seps = '/'
|
||||
|
||||
vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr',
|
||||
'_darcs']
|
||||
vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
|
||||
vcs_dirs = [
|
||||
'RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr',
|
||||
'_darcs',
|
||||
]
|
||||
vcs_ptrn = r'(^|{})({})({}).*'.format(seps, '|'.join(vcs_dirs), seps)
|
||||
self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)
|
||||
|
||||
def write_manifest(self):
|
||||
|
|
@ -380,14 +435,18 @@ class sdist(Command):
|
|||
named by 'self.manifest'.
|
||||
"""
|
||||
if self._manifest_is_not_generated():
|
||||
log.info("not writing to manually maintained "
|
||||
"manifest file '%s'" % self.manifest)
|
||||
log.info(
|
||||
'not writing to manually maintained '
|
||||
"manifest file '%s'" % self.manifest,
|
||||
)
|
||||
return
|
||||
|
||||
content = self.filelist.files[:]
|
||||
content.insert(0, '# file GENERATED by distutils, do NOT edit')
|
||||
self.execute(file_util.write_file, (self.manifest, content),
|
||||
"writing manifest file '%s'" % self.manifest)
|
||||
self.execute(
|
||||
file_util.write_file, (self.manifest, content),
|
||||
"writing manifest file '%s'" % self.manifest,
|
||||
)
|
||||
|
||||
def _manifest_is_not_generated(self):
|
||||
# check for special comment used in 3.1.3 and higher
|
||||
|
|
@ -439,13 +498,13 @@ class sdist(Command):
|
|||
|
||||
if hasattr(os, 'link'): # can make hard links on this system
|
||||
link = 'hard'
|
||||
msg = "making hard links in %s..." % base_dir
|
||||
msg = 'making hard links in %s...' % base_dir
|
||||
else: # nope, have to copy
|
||||
link = None
|
||||
msg = "copying files to %s..." % base_dir
|
||||
msg = 'copying files to %s...' % base_dir
|
||||
|
||||
if not files:
|
||||
log.warn("no files to distribute -- empty manifest?")
|
||||
log.warn('no files to distribute -- empty manifest?')
|
||||
else:
|
||||
log.info(msg)
|
||||
for file in files:
|
||||
|
|
@ -477,8 +536,10 @@ class sdist(Command):
|
|||
self.formats.append(self.formats.pop(self.formats.index('tar')))
|
||||
|
||||
for fmt in self.formats:
|
||||
file = self.make_archive(base_name, fmt, base_dir=base_dir,
|
||||
owner=self.owner, group=self.group)
|
||||
file = self.make_archive(
|
||||
base_name, fmt, base_dir=base_dir,
|
||||
owner=self.owner, group=self.group,
|
||||
)
|
||||
archive_files.append(file)
|
||||
self.distribution.dist_files.append(('sdist', '', file))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue