Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip updates mtimes when insatlling wheels #13207

Open
1 task done
hroncok opened this issue Feb 6, 2025 · 5 comments
Open
1 task done

pip updates mtimes when insatlling wheels #13207

hroncok opened this issue Feb 6, 2025 · 5 comments
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior

Comments

@hroncok
Copy link
Contributor

hroncok commented Feb 6, 2025

Description

Hello.

When debugging a problem in RPM packaging I realized that when pip installs a wheel, the mtimes of the extracted files are set to the current timestamp.

Should installation of unmodified files preserve their mtime?

Based on #7808 I would assume installation wants to be reproducible.

Expected behavior

When a wheel is installed, I would expect the mtimes on disk to be kept as they were in the wheel.

pip version

25.0

Python version

3.13.2

OS

Linux

How to Reproduce

$ python3.13 -m venv venv
$ . venv/bin/activate
(venv)$ pip install -U pip
...
(venv)$ wget https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl
(venv)$ unzip -l six-1.17.0-py2.py3-none-any.whl
...
  Length      Date    Time    Name
---------  ---------- -----   ----
    34703  12-04-2024 17:35   six.py
...
(venv)$ pip install ./six-1.17.0-py2.py3-none-any.whl
(venv) [empty]$ LANG=C ls -l venv/lib/python3.13/site-packages/six.py 
.rw-r--r--@ 35k ...  6 Feb 14:41 venv/lib/python3.13/site-packages/six.py

Observe the mtime is 6 Feb 14:41 (a.k.a. now). I would expect it to be 12-04-2024.

As a side note, setting or not setting $SOURCE_DATE_EPOCH does not make a difference.

Code of Conduct

@hroncok hroncok added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Feb 6, 2025
@keszybz
Copy link

keszybz commented Feb 6, 2025

As additional context:

Fedora packaging guidelines say:

When adding file copying commands in the spec file, consider using a command that preserves the files' timestamps, e.g., cp -p or install -p.

In this case, the files are being copied unmodified, so that guideline applies.

Preserving timestamps is useful because it provides additional information to users when the file was really changed by the upstream and it also avoids churn between updates when packages are updated, but many files stay unchanged over many versions.

@pfmoore
Copy link
Member

pfmoore commented Feb 6, 2025

This seems like a reasonable thing to add. A PR would be welcome.

@notatallshaw
Copy link
Member

There's some discussion in #5648 about mtimes, both from unpacking from a wheel and generating pyc files.

If it's not already done, copying the mtimes from a wheel seems like a good move (assuming little negative consequences like a big performance hit).

Mtimes on generated pyc files seems is a little more tricky, but maybe there already good solutions for this.

@keszybz
Copy link

keszybz commented Feb 6, 2025

Mtimes on generated pyc files seems is a little more tricky, but maybe there already good solutions for this.

If the file is newly generated, then set the mtime to "now". (Maybe $SOURCE_DATE_EPOCH should be taken into account, not sure.) If the file is just copied, preserve the timestamp. I don't think .pyc files are different in this regard than any other file generated during build.

@hroncok
Copy link
Contributor Author

hroncok commented Feb 8, 2025

I am willing to investigate and work on this, but not in the next 2 weeks.

If anybody wants to tackle this themselves, please don't wait for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants