Skip to content

[BUG] Setuptools copies source files to build lib even if the targets are up to date with sources #5079

@rajputa-deshaw

Description

@rajputa-deshaw

setuptools version

80.9.0

Python version

Python 3.11.8

OS

RHEL 8

Additional environment information

No response

Description

Setuptools copies the source files to build_lib even if the target files already exist and are up-to-date with the sources and force was not set to 1.

This is happening because the _newer function uses os.path.getmtime which returns a float but the copy_file function uses st[ST_MTIME] which is an int, while copying the mod time. Due to this the target file is always older than source when preserve_timestamps is true.

This should be easily fixed by using st.st_mtime in the copy function as well.

Expected behavior

Setuptools should not copy the files if targets are up to date.

How to Reproduce

Build any simple project using setuptools consecutively. The target files will be overwritten the second time even if no changes are done to source.

Output

(test) rajputa@rajputa-rh8.hdc1(hyd):/codemill/rajputa/test-project$ python setup.py build
running build
running build_py
creating build/lib
copying foo.py -> build/lib
running egg_info
writing test_project.egg-info/PKG-INFO
writing dependency_links to test_project.egg-info/dependency_links.txt
writing top-level names to test_project.egg-info/top_level.txt
reading manifest file 'test_project.egg-info/SOURCES.txt'
writing manifest file 'test_project.egg-info/SOURCES.txt'
(test) rajputa@rajputa-rh8.hdc1(hyd):/codemill/rajputa/test-project$ ll foo.py
-rw-rw-r-- 1 rajputa rajputa 0 Sep  5 18:39 foo.py
(test) rajputa@rajputa-rh8.hdc1(hyd):/codemill/rajputa/test-project$ ll build/lib/foo.py
-rw-rw-r-- 1 rajputa rajputa 0 Sep  5 18:39 build/lib/foo.py
(test) rajputa@rajputa-rh8.hdc1(hyd):/codemill/rajputa/test-project$ python setup.py build
running build
running build_py
copying foo.py -> build/lib
running egg_info
writing test_project.egg-info/PKG-INFO
writing dependency_links to test_project.egg-info/dependency_links.txt
writing top-level names to test_project.egg-info/top_level.txt
reading manifest file 'test_project.egg-info/SOURCES.txt'
writing manifest file 'test_project.egg-info/SOURCES.txt'
(test) rajputa@rajputa-rh8.hdc1(hyd):/codemill/rajputa/test-project$

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssues that need to be evaluated for severity and status.bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions