Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Apr 27, 2023
1 parent 0c030bb commit 678f07b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 69 deletions.
91 changes: 46 additions & 45 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ jobs:
fail-fast: false
matrix:
py:
- "3.11"
- "3.10"
- "3.9"
- "3.8"
- "3.7"
- pypy-3.9
- pypy-3.8
- pypy-3.7
- "3.12.0-alpha.7"
# - "3.11"
# - "3.10"
# - "3.9"
# - "3.8"
# - "3.7"
# - pypy-3.9
# - pypy-3.8
# - pypy-3.7
os:
- ubuntu-22.04
- macos-12
- windows-2022
include:
- { os: macos-12, py: "[email protected]" }
- { os: macos-12, py: "[email protected]" }
# include:
# - { os: macos-12, py: "[email protected]" }
# - { os: macos-12, py: "[email protected]" }
steps:
- uses: taiki-e/install-action@cargo-binstall
- name: Install OS dependencies
Expand Down Expand Up @@ -90,37 +91,37 @@ jobs:
PYTEST_ADDOPTS: "-vv --durations=20"
CI_RUN: "yes"
DIFF_AGAINST: HEAD

check:
name: ${{ matrix.tox_env }} - ${{ matrix.os }}
if: github.event_name != 'schedule' || github.repository_owner == 'pypa'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- windows-2022
tox_env:
- dev
- docs
- readme
- upgrade
- zipapp
exclude:
- { os: windows-2022, tox_env: readme }
- { os: windows-2022, tox_env: docs }
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python "3.11"
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install tox
run: python -m pip install tox
- name: Run check for ${{ matrix.tox_env }}
run: python -m tox -e ${{ matrix.tox_env }}
env:
UPGRADE_ADVISORY: "yes"
#
# check:
# name: ${{ matrix.tox_env }} - ${{ matrix.os }}
# if: github.event_name != 'schedule' || github.repository_owner == 'pypa'
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os:
# - ubuntu-22.04
# - windows-2022
# tox_env:
# - dev
# - docs
# - readme
# - upgrade
# - zipapp
# exclude:
# - { os: windows-2022, tox_env: readme }
# - { os: windows-2022, tox_env: docs }
# steps:
# - uses: actions/checkout@v3
# with:
# fetch-depth: 0
# - name: Setup Python "3.11"
# uses: actions/setup-python@v4
# with:
# python-version: "3.11"
# - name: Install tox
# run: python -m pip install tox
# - name: Run check for ${{ matrix.tox_env }}
# run: python -m tox -e ${{ matrix.tox_env }}
# env:
# UPGRADE_ADVISORY: "yes"
22 changes: 12 additions & 10 deletions src/virtualenv/seed/embed/base_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ def __init__(self, options):
self.enabled = False

@classmethod
def distributions(cls):
def distributions(cls) -> dict[str, Version]:
return {
"pip": Version.bundle,
"setuptools": Version.bundle,
"wheel": Version.bundle,
}

def distribution_to_versions(self):
def distribution_to_versions(self) -> dict[str, str]:
return {
distribution: getattr(self, f"{distribution}_version")
for distribution in self.distributions()
if getattr(self, f"no_{distribution}") is False
if getattr(self, f"no_{distribution}") is False and getattr(self, f"{distribution}_version") != "none"
}

@classmethod
Expand Down Expand Up @@ -71,11 +71,13 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
default=[],
)
for distribution, default in cls.distributions().items():
if interpreter.version_info > (3, 11) and distribution in {"wheel", "setuptools"}:
default = "none"
parser.add_argument(
f"--{distribution}",
dest=distribution,
metavar="version",
help=f"version of {distribution} to install as seed: embed, bundle or exact version",
help=f"version of {distribution} to install as seed: embed, bundle, none or exact version",
default=default,
)
for distribution in cls.distributions():
Expand All @@ -84,10 +86,7 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
dest=f"no_{distribution}",
action="store_true",
help=f"do not install {distribution}",
default=True
if (float(interpreter.version.split(" ")[0].rsplit(".", 1)[0]) >= 12)
and (distribution in {"wheel", "setuptools"})
else False,
default=False,
)
parser.add_argument(
"--no-periodic-update",
Expand All @@ -97,7 +96,7 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
default=not PERIODIC_UPDATE_ON_BY_DEFAULT,
)

def __repr__(self):
def __repr__(self) -> str:
result = self.__class__.__name__
result += "("
if self.extra_search_dir:
Expand All @@ -106,7 +105,10 @@ def __repr__(self):
for distribution in self.distributions():
if getattr(self, f"no_{distribution}"):
continue
ver = f"={getattr(self, f'{distribution}_version', None) or 'latest'}"
version = getattr(self, f"{distribution}_version", None)
if version == "none":
continue
ver = f"={version or 'latest'}"
result += f" {distribution}{ver},"
return result[:-1] + ")"

Expand Down
23 changes: 9 additions & 14 deletions tests/unit/seed/embed/test_base_embed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
from pathlib import Path

import pytest

Expand All @@ -16,17 +17,11 @@ def test_download_cli_flag(args, download, tmp_path):
assert session.seeder.download is download


@pytest.mark.parametrize(
("args", "install"),
[([], True)],
)
def test_embed_optional_wheels(args, install, tmp_path):
session = session_via_cli(args + [str(tmp_path)])
if float(sys.version.split(" ")[0].rsplit(".", 1)[0]) >= 12:
assert session.seeder.no_setuptools is install
assert session.seeder.no_wheel is install
assert session.seeder.no_pip is not install
else:
assert session.seeder.no_setuptools is not install
assert session.seeder.no_wheel is not install
assert session.seeder.no_pip is not install
def test_embed_wheel_versions(tmp_path: Path) -> None:
session = session_via_cli([str(tmp_path)])
expected = (
{"pip": "bundle"}
if sys.version_info[:2] >= (3, 12)
else {"pip": "bundle", "setuptools": "bundle", "wheel": "bundle"}
)
assert session.seeder.distribution_to_versions() == expected

0 comments on commit 678f07b

Please sign in to comment.