PEP 610: should metadata be updated for re-installations?

Essentially, I have logic to check whether defined dependencies are in sync with a given environment and if not then pip install <dependencies>.

I noticed that when changing a component of a direct URL reference like the commit hash pip will re-install as expected but the direct_url.json file does not get updated so it will appear as though the environment always needs to be synced.

Is this the expected behavior?

If the package is indeed reinstalled, this sounds like a bug to me. pip could choose to not reinstall, but if it does, it should also update metadata.

It looks like pip only updates the file if the version changes:

ofek@OZONE C:\Users\ofek\Desktop
$ virtualenv testenv
created virtual environment CPython3.8.1.final.0-64 in 379ms
  creator CPython3Windows(dest=C:\Users\ofek\Desktop\testenv, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\ofek\AppData\Local\pypa\virtualenv)
    added seed packages: pip==21.3.1, setuptools==58.3.0, wheel==0.37.0
  activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

ofek@OZONE C:\Users\ofek\Desktop
$ testenv\Scripts\activate.bat

(testenv) ofek@OZONE C:\Users\ofek\Desktop
$ python -c "from importlib.metadata import distribution;d=distribution('wheel');print(d.read_text('direct_url.json'))"
None

(testenv) ofek@OZONE C:\Users\ofek\Desktop
$ pip install "wheel @ git+https://github.com/pypa/wheel.git@88320ee9c2441d4df5aa004bd751bcd7d52ad983"
Collecting wheel@ git+https://github.com/pypa/wheel.git@88320ee9c2441d4df5aa004bd751bcd7d52ad983
  Cloning https://github.com/pypa/wheel.git (to revision 88320ee9c2441d4df5aa004bd751bcd7d52ad983) to c:\users\ofek\appdata\local\temp\pip-install-4iuudyjg\wheel_214b1f72e1ac4c5fbad6b38ae8a47712
  Running command git clone --filter=blob:none -q https://github.com/pypa/wheel.git 'C:\Users\ofek\AppData\Local\Temp\pip-install-4iuudyjg\wheel_214b1f72e1ac4c5fbad6b38ae8a47712'
  Running command git rev-parse -q --verify 'sha^88320ee9c2441d4df5aa004bd751bcd7d52ad983'
  Running command git fetch -q https://github.com/pypa/wheel.git 88320ee9c2441d4df5aa004bd751bcd7d52ad983
  Running command git checkout -q 88320ee9c2441d4df5aa004bd751bcd7d52ad983
  Resolved https://github.com/pypa/wheel.git to commit 88320ee9c2441d4df5aa004bd751bcd7d52ad983
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: wheel
  Building wheel for wheel (setup.py) ... done
  Created wheel for wheel: filename=wheel-0.36.2-py2.py3-none-any.whl size=35181 sha256=3dd673eed4721e779bd93262a52ae0f1c4f52f09ef3bbf36f0b40209d2d2c70a
  Stored in directory: c:\users\ofek\appdata\local\pip\cache\wheels\01\45\70\eb54ea2eb99b7cbb414ff22fa114ed62478ae13cdd2460d09c
Successfully built wheel
Installing collected packages: wheel
  Attempting uninstall: wheel
    Found existing installation: wheel 0.37.0
    Uninstalling wheel-0.37.0:
      Successfully uninstalled wheel-0.37.0
Successfully installed wheel-0.36.2

(testenv) ofek@OZONE C:\Users\ofek\Desktop
$ python -c "from importlib.metadata import distribution;d=distribution('wheel');print(d.read_text('direct_url.json'))"
{"url": "https://github.com/pypa/wheel.git", "vcs_info": {"commit_id": "88320ee9c2441d4df5aa004bd751bcd7d52ad983", "requested_revision": "88320ee9c2441d4df5aa004bd751bcd7d52ad983", "vcs": "git"}}

(testenv) ofek@OZONE C:\Users\ofek\Desktop
$ pip install "wheel @ git+https://github.com/pypa/wheel.git@b8c4aa055cea0132776e7e53edce3538710d5b68"
Collecting wheel@ git+https://github.com/pypa/wheel.git@b8c4aa055cea0132776e7e53edce3538710d5b68
  Cloning https://github.com/pypa/wheel.git (to revision b8c4aa055cea0132776e7e53edce3538710d5b68) to c:\users\ofek\appdata\local\temp\pip-install-la9rc_8f\wheel_c95253cb16db4493af0ab0338e08a275
  Running command git clone --filter=blob:none -q https://github.com/pypa/wheel.git 'C:\Users\ofek\AppData\Local\Temp\pip-install-la9rc_8f\wheel_c95253cb16db4493af0ab0338e08a275'
  Running command git rev-parse -q --verify 'sha^b8c4aa055cea0132776e7e53edce3538710d5b68'
  Running command git fetch -q https://github.com/pypa/wheel.git b8c4aa055cea0132776e7e53edce3538710d5b68
  Running command git checkout -q b8c4aa055cea0132776e7e53edce3538710d5b68
  Resolved https://github.com/pypa/wheel.git to commit b8c4aa055cea0132776e7e53edce3538710d5b68
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: wheel
  Building wheel for wheel (setup.py) ... done
  Created wheel for wheel: filename=wheel-0.37.0-py2.py3-none-any.whl size=35180 sha256=e69adee9413eb274ad427a1a7aec071f7e75985ce0268c0b22807629fc1716a7
  Stored in directory: c:\users\ofek\appdata\local\pip\cache\wheels\0f\ae\0a\bd1937bab1d842b0109421d9e46e9eeeb2b4492f51593e9dcf
Successfully built wheel
Installing collected packages: wheel
  Attempting uninstall: wheel
    Found existing installation: wheel 0.36.2
    Uninstalling wheel-0.36.2:
      Successfully uninstalled wheel-0.36.2
Successfully installed wheel-0.37.0

(testenv) ofek@OZONE C:\Users\ofek\Desktop
$ python -c "from importlib.metadata import distribution;d=distribution('wheel');print(d.read_text('direct_url.json'))"
{"url": "https://github.com/pypa/wheel.git", "vcs_info": {"commit_id": "b8c4aa055cea0132776e7e53edce3538710d5b68", "requested_revision": "b8c4aa055cea0132776e7e53edce3538710d5b68", "vcs": "git"}}

(testenv) ofek@OZONE C:\Users\ofek\Desktop
$ pip install "wheel @ git+https://github.com/pypa/wheel.git@3f1a73a2b282ed55044541d3c28e0618d8b1de14"
Collecting wheel@ git+https://github.com/pypa/wheel.git@3f1a73a2b282ed55044541d3c28e0618d8b1de14
  Cloning https://github.com/pypa/wheel.git (to revision 3f1a73a2b282ed55044541d3c28e0618d8b1de14) to c:\users\ofek\appdata\local\temp\pip-install-dgqfac56\wheel_d18d8f4607fe4cc68c0fb9dbc9708fe5
  Running command git clone --filter=blob:none -q https://github.com/pypa/wheel.git 'C:\Users\ofek\AppData\Local\Temp\pip-install-dgqfac56\wheel_d18d8f4607fe4cc68c0fb9dbc9708fe5'
  Running command git rev-parse -q --verify 'sha^3f1a73a2b282ed55044541d3c28e0618d8b1de14'
  Running command git fetch -q https://github.com/pypa/wheel.git 3f1a73a2b282ed55044541d3c28e0618d8b1de14
  Running command git checkout -q 3f1a73a2b282ed55044541d3c28e0618d8b1de14
  Resolved https://github.com/pypa/wheel.git to commit 3f1a73a2b282ed55044541d3c28e0618d8b1de14
  Preparing metadata (setup.py) ... done

(testenv) ofek@OZONE C:\Users\ofek\Desktop
$ python -c "from importlib.metadata import distribution;d=distribution('wheel');print(d.read_text('direct_url.json'))"
{"url": "https://github.com/pypa/wheel.git", "vcs_info": {"commit_id": "b8c4aa055cea0132776e7e53edce3538710d5b68", "requested_revision": "b8c4aa055cea0132776e7e53edce3538710d5b68", "vcs": "git"}}

It looks like the wheel package is not reinstalled when the version does not change. So to answer the question in the topic: yes, metadata should be updated for reinstallations. But since pip is not doing a reinstallation in this particular case, it should not update metadata. (Whether it should reinstall—and also update metadata as a result—is another discussion; I believe there is already an issue in GitHub tracking this topic).