diff --git a/distutils/command/bdist_rpm.py b/distutils/command/bdist_rpm.py index 649968a5..03bb0f3a 100644 --- a/distutils/command/bdist_rpm.py +++ b/distutils/command/bdist_rpm.py @@ -316,11 +316,13 @@ def run(self): # noqa: C901 source = sdist.get_archive_files()[0] source_dir = rpm_dir['SOURCES'] - self.copy_file(source, source_dir) + dest = os.path.join(source_dir, os.path.basename(source)) + self.copy_file(source, dest) if self.icon: if os.path.exists(self.icon): - self.copy_file(self.icon, source_dir) + dest = os.path.join(source_dir, os.path.basename(self.icon)) + self.copy_file(self.icon, dest) else: raise DistutilsFileError("icon file '%s' does not exist" % self.icon) diff --git a/distutils/command/install_data.py b/distutils/command/install_data.py index b63a1af2..cc6ac697 100644 --- a/distutils/command/install_data.py +++ b/distutils/command/install_data.py @@ -54,7 +54,8 @@ def run(self): "setup script did not provide a directory for " f"'{f}' -- installing right in '{self.install_dir}'" ) - (out, _) = self.copy_file(f, self.install_dir) + dst = os.path.join(self.install_dir, os.path.basename(f)) + (out, _) = self.copy_file(f, dst) self.outfiles.append(out) else: # it's a tuple with path to install to and a list of files @@ -74,7 +75,8 @@ def run(self): # Copy files, adding them to the list of output files. for data in f[1]: data = convert_path(data) - (out, _) = self.copy_file(data, dir) + dst = os.path.join(dir, os.path.basename(data)) + (out, _) = self.copy_file(data, dst) self.outfiles.append(out) def get_inputs(self): diff --git a/distutils/command/install_headers.py b/distutils/command/install_headers.py index 085272c1..b7fb4b41 100644 --- a/distutils/command/install_headers.py +++ b/distutils/command/install_headers.py @@ -3,6 +3,8 @@ Implements the Distutils 'install_headers' command, to install C/C++ header files to the Python include directory.""" +import os + from ..core import Command @@ -34,7 +36,8 @@ def run(self): self.mkpath(self.install_dir) for header in headers: - (out, _) = self.copy_file(header, self.install_dir) + dst = os.path.join(self.install_dir, os.path.basename(header)) + (out, _) = self.copy_file(header, dst) self.outfiles.append(out) def get_inputs(self): diff --git a/distutils/file_util.py b/distutils/file_util.py index 960def9c..e2239ac7 100644 --- a/distutils/file_util.py +++ b/distutils/file_util.py @@ -70,9 +70,8 @@ def copy_file( # noqa: C901 verbose=1, dry_run=0, ): - """Copy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' is - copied there with the same name; otherwise, it must be a filename. (If - the file exists, it will be ruthlessly clobbered.) If 'preserve_mode' + """Copy a file 'src' to 'dst'. + (If the file exists, it will be ruthlessly clobbered.) If 'preserve_mode' is true (the default), the file's mode (type and permission bits, or whatever is analogous on the current platform) is copied. If 'preserve_times' is true (the default), the last-modified and @@ -109,12 +108,6 @@ def copy_file( # noqa: C901 "can't copy '%s': doesn't exist or not a regular file" % src ) - if os.path.isdir(dst): - dir = dst - dst = os.path.join(dst, os.path.basename(src)) - else: - dir = os.path.dirname(dst) - if update and not newer(src, dst): if verbose >= 1: log.debug("not copying %s (output up-to-date)", src) @@ -126,10 +119,7 @@ def copy_file( # noqa: C901 raise ValueError("invalid value '%s' for 'link' argument" % link) if verbose >= 1: - if os.path.basename(dst) == os.path.basename(src): - log.info("%s %s -> %s", action, src, dir) - else: - log.info("%s %s -> %s", action, src, dst) + log.info("%s %s -> %s", action, src, dst) if dry_run: return (dst, 1) diff --git a/distutils/tests/test_dir_util.py b/distutils/tests/test_dir_util.py index 84cda619..8d4dc9fd 100644 --- a/distutils/tests/test_dir_util.py +++ b/distutils/tests/test_dir_util.py @@ -73,9 +73,10 @@ def test_copy_tree_verbosity(self, caplog): mkpath(self.target, verbose=0) a_file = path.Path(self.target) / 'ok.txt' + to_file = path.Path(self.target2) / 'ok.txt' jaraco.path.build({'ok.txt': 'some content'}, self.target) - wanted = [f'copying {a_file} -> {self.target2}'] + wanted = [f'copying {a_file} -> {to_file}'] copy_tree(self.target, self.target2, verbose=1) assert caplog.messages == wanted