Skip to content

Commit

Permalink
pep-710: implement provenance_url.json file
Browse files Browse the repository at this point in the history
Signed-off-by: Fridolin Pokorny <fridolin.pokorny@gmail.com>
  • Loading branch information
fridex committed Jul 29, 2024
1 parent 350a057 commit 74db0f0
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 88 deletions.
147 changes: 74 additions & 73 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-12]
# os: [ubuntu-latest, macos-12]
os: [ubuntu-latest]
python:
- "3.8"
- "3.9"
- "3.10"
# - "3.8"
# - "3.9"
# - "3.10"
- "3.11"
- "3.12"
- "3.13"
# - "3.12"
# - "3.13"

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -148,72 +149,72 @@ jobs:
--verbose --numprocesses auto --showlocals
--durations=5
tests-windows:
name: tests / ${{ matrix.python }} / ${{ matrix.os }} / ${{ matrix.group }}
runs-on: ${{ matrix.os }}-latest

needs: [packaging, determine-changes]
if: >-
needs.determine-changes.outputs.tests == 'true' ||
github.event_name != 'pull_request'
strategy:
fail-fast: true
matrix:
os: [Windows]
python:
- "3.8"
# Commented out, since Windows tests are expensively slow,
# only test the oldest and newest Python supported by pip
# - "3.9"
# - "3.10"
# - "3.11"
- "3.12" # Comment out when 3.13 is final
- "3.13"
group: [1, 2]

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
allow-prereleases: true

# We use C:\Temp (which is already available on the worker)
# as a temporary directory for all of the tests because the
# default value (under the user dir) is more deeply nested
# and causes tests to fail with "path too long" errors.
- run: pip install nox
env:
TEMP: "C:\\Temp"

# Main check
- name: Run unit tests
if: matrix.group == 1
run: >-
nox -s test-${{ matrix.python }} --
-m unit
--verbose --numprocesses auto --showlocals
env:
TEMP: "C:\\Temp"

- name: Run integration tests (group 1)
if: matrix.group == 1
run: >-
nox -s test-${{ matrix.python }} --
-m integration -k "not test_install"
--verbose --numprocesses auto --showlocals
env:
TEMP: "C:\\Temp"

- name: Run integration tests (group 2)
if: matrix.group == 2
run: >-
nox -s test-${{ matrix.python }} --
-m integration -k "test_install"
--verbose --numprocesses auto --showlocals
env:
TEMP: "C:\\Temp"
# tests-windows:
# name: tests / ${{ matrix.python }} / ${{ matrix.os }} / ${{ matrix.group }}
# runs-on: ${{ matrix.os }}-latest

# needs: [packaging, determine-changes]
# if: >-
# needs.determine-changes.outputs.tests == 'true' ||
# github.event_name != 'pull_request'

# strategy:
# fail-fast: true
# matrix:
# os: [Windows]
# python:
# - "3.8"
# # Commented out, since Windows tests are expensively slow,
# # only test the oldest and newest Python supported by pip
# # - "3.9"
# # - "3.10"
# # - "3.11"
# - "3.12" # Comment out when 3.13 is final
# - "3.13"
# group: [1, 2]

# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python }}
# allow-prereleases: true

# # We use C:\Temp (which is already available on the worker)
# # as a temporary directory for all of the tests because the
# # default value (under the user dir) is more deeply nested
# # and causes tests to fail with "path too long" errors.
# - run: pip install nox
# env:
# TEMP: "C:\\Temp"

# # Main check
# - name: Run unit tests
# if: matrix.group == 1
# run: >-
# nox -s test-${{ matrix.python }} --
# -m unit
# --verbose --numprocesses auto --showlocals
# env:
# TEMP: "C:\\Temp"

# - name: Run integration tests (group 1)
# if: matrix.group == 1
# run: >-
# nox -s test-${{ matrix.python }} --
# -m integration -k "not test_install"
# --verbose --numprocesses auto --showlocals
# env:
# TEMP: "C:\\Temp"

# - name: Run integration tests (group 2)
# if: matrix.group == 2
# run: >-
# nox -s test-${{ matrix.python }} --
# -m integration -k "test_install"
# --verbose --numprocesses auto --showlocals
# env:
# TEMP: "C:\\Temp"

tests-zipapp:
name: tests / zipapp
Expand Down Expand Up @@ -254,7 +255,7 @@ jobs:
- docs
- packaging
- tests-unix
- tests-windows
# - tests-windows
- tests-zipapp
- vendoring

Expand Down
1 change: 1 addition & 0 deletions news/99999.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement PEP-710 for storing provenance_url.json file.
1 change: 1 addition & 0 deletions src/pip/_internal/models/direct_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
T = TypeVar("T")

DIRECT_URL_METADATA_NAME = "direct_url.json"
PROVENANCE_URL_METADATA_NAME = "provenance_url.json"
ENV_VAR_RE = re.compile(r"^\$\{[A-Za-z0-9-_]+\}(:\$\{[A-Za-z0-9-_]+\})?$")


Expand Down
25 changes: 15 additions & 10 deletions src/pip/_internal/operations/install/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
FilesystemWheel,
get_wheel_distribution,
)
from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, DirectUrl
from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, PROVENANCE_URL_METADATA_NAME, DirectUrl
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
from pip._internal.utils.filesystem import adjacent_tmp_file, replace
from pip._internal.utils.misc import StreamWrapper, ensure_dir, hash_file, partition
Expand Down Expand Up @@ -424,9 +424,10 @@ def _install_wheel( # noqa: C901, PLR0915 function is too long
wheel_zip: ZipFile,
wheel_path: str,
scheme: Scheme,
download_info: DirectUrl,
is_direct: bool,
pycompile: bool = True,
warn_script_location: bool = True,
direct_url: Optional[DirectUrl] = None,
requested: bool = False,
) -> None:
"""Install a wheel.
Expand Down Expand Up @@ -673,12 +674,14 @@ def _generate_file(path: str, **kwargs: Any) -> Generator[BinaryIO, None, None]:
installer_file.write(b"pip\n")
generated.append(installer_path)

# Record the PEP 610 direct URL reference
if direct_url is not None:
direct_url_path = os.path.join(dest_info_dir, DIRECT_URL_METADATA_NAME)
with _generate_file(direct_url_path) as direct_url_file:
direct_url_file.write(direct_url.to_json().encode("utf-8"))
generated.append(direct_url_path)
# Record the PEP 610/PEP 710 direct URL reference
reference_file_path = os.path.join(
dest_info_dir,
DIRECT_URL_METADATA_NAME if is_direct else PROVENANCE_URL_METADATA_NAME,
)
with _generate_file(reference_file_path) as reference_file:
reference_file.write(download_info.to_json().encode("utf-8"))
generated.append(reference_file_path)

# Record the REQUESTED file
if requested:
Expand Down Expand Up @@ -721,10 +724,11 @@ def install_wheel(
name: str,
wheel_path: str,
scheme: Scheme,
download_info: DirectUrl,
is_direct: bool,
req_description: str,
pycompile: bool = True,
warn_script_location: bool = True,
direct_url: Optional[DirectUrl] = None,
requested: bool = False,
) -> None:
with ZipFile(wheel_path, allowZip64=True) as z:
Expand All @@ -734,8 +738,9 @@ def install_wheel(
wheel_zip=z,
wheel_path=wheel_path,
scheme=scheme,
download_info=download_info,
is_direct=is_direct,
pycompile=pycompile,
warn_script_location=warn_script_location,
direct_url=direct_url,
requested=requested,
)
3 changes: 2 additions & 1 deletion src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,11 @@ def install(
self.req.name,
self.local_file_path,
scheme=scheme,
download_info=self.download_info,
is_direct=self.is_direct,
req_description=str(self.req),
pycompile=pycompile,
warn_script_location=warn_script_location,
direct_url=self.download_info if self.is_direct else None,
requested=self.user_supplied,
)
self.install_succeeded = True
Expand Down
Loading

0 comments on commit 74db0f0

Please sign in to comment.