Skip to content

Commit

Permalink
fix pyversion
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Jan 29, 2024
1 parent 20b6dc8 commit fa51d3d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/aexpy/preprocessing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ class Preprocessor(Producer):
def preprocess(self, product: Distribution):
"""Preprocess a distribution."""
pass


PYVERSION_UPPER = 12
PYVERSION_LOWER = 8
29 changes: 19 additions & 10 deletions src/aexpy/preprocessing/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@

from ..models import Release
from .wheel import CompatibilityTag
from . import Preprocessor
from . import Preprocessor, PYVERSION_UPPER, PYVERSION_LOWER
from .. import getCacheDirectory, utils
from .pypi import INDEX_ORIGIN, INDEX_TSINGHUA, FILE_ORIGIN, FILE_TSINGHUA, getReleases

PYVERSIONS = [f"3.{i}" for i in range(8, 13)]
PYVERSIONS = [f"3.{i}" for i in range(PYVERSION_UPPER, PYVERSION_LOWER - 1, -1)]


def wheelByPip(
release: Release, path: Path, logger: Logger | None, mirror: bool = False
release: Release,
path: Path,
pyversions: list[str] | None = None,
logger: Logger | None = None,
mirror: bool = False,
) -> tuple[Path, str]:
logger = logger or logging.getLogger("pre-download-pip")
index = INDEX_TSINGHUA if mirror else INDEX_ORIGIN
pyversions = pyversions or PYVERSIONS

def glob(suffix: str):
prefix = f"{release.project}-{release.version}".lower()
Expand All @@ -46,7 +51,7 @@ def check(s: str):
logger.warning(f"Remove downloaded {item}.")
os.remove(item)

for pyversion in PYVERSIONS:
for pyversion in pyversions:
logger.info(f"Download wheel distribution for Python {pyversion}.")
try:
subres = subprocess.run(
Expand Down Expand Up @@ -214,17 +219,17 @@ def getDownloadInfo(

py3.append((item, tag))

py37 = []
supportedPy = []
for item, tag in py3:
for i in range(7, 13):
for i in range(PYVERSION_UPPER, PYVERSION_LOWER - 1, -1):
if f"py3{i}" in tag.python or f"cp3{i}" in tag.python:
py37.append(item)
supportedPy.append(item)
break

result = None

if len(py37) > 0:
result = py37[0]
if len(supportedPy) > 0:
result = supportedPy[0]

if len(py3) > 0:
result = py3[0][0]
Expand Down Expand Up @@ -284,8 +289,12 @@ def __init__(

@override
def preprocess(self, product):
if product.pyversion:
pyversions = [product.pyversion] + PYVERSIONS
else:
pyversions = None
wheelFile, pyversion = wheelByPip(
product.release, self.cacheDir, logger=self.logger
product.release, self.cacheDir, pyversions, logger=self.logger
)
product.pyversion = pyversion
product.wheelFile = wheelFile
12 changes: 6 additions & 6 deletions src/aexpy/preprocessing/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path

from aexpy import getCacheDirectory, utils
from . import Preprocessor
from . import PYVERSION_LOWER, PYVERSION_UPPER, Preprocessor

FILE_ORIGIN = "https://files.pythonhosted.org/"
FILE_TSINGHUA = "https://pypi.tuna.tsinghua.edu.cn/"
Expand Down Expand Up @@ -54,7 +54,7 @@ def version(self):
def dependencies(self):
dist = self.metadata.get_all("requires-dist")
if dist:
return [str(t) for t in dist]
return [str(t).split(maxsplit=1)[0] for t in dist]
else:
return []

Expand All @@ -73,17 +73,17 @@ def pyversion(self) -> str | None:
if item.startswith(">="):
version = item.removeprefix(">=").strip()
if version.startswith("3."):
return "3.12"
return f"3.{PYVERSION_UPPER}"
else:
continue
elif item.startswith("<="):
return item.removeprefix("<=").strip()
return "3.12"
return f"3.{PYVERSION_UPPER}"
else:
for i in range(12, 7, -1):
for i in range(PYVERSION_UPPER, PYVERSION_LOWER - 1, -1):
if f"py3{i}" in tag.python or f"cp3{i}" in tag.python:
return f"3.{i}"
return "3.12"
return f"3.{PYVERSION_UPPER}"

@classmethod
def fromdir(cls, path: Path, project: str = ""):
Expand Down

0 comments on commit fa51d3d

Please sign in to comment.