Explorar el Código

Reorganize python code

main
Sindre Stephansen hace 2 años
padre
commit
0fe75c46ce
Firmado por: sindre <sindre@sindrestephansen.com> ID de clave GPG: B06FC67D17A46ADE
Se han modificado 3 ficheros con 57 adiciones y 49 borrados
  1. +1
    -0
      sync/src/maven/__init__.py
  2. +3
    -49
      sync/src/maven/fetch.py
  3. +53
    -0
      sync/src/maven/packages.py

+ 1
- 0
sync/src/maven/__init__.py Ver fichero

@@ -0,0 +1 @@
from .packages import get_effective_packages

sync/src/maven.py → sync/src/maven/fetch.py Ver fichero

@@ -1,9 +1,9 @@
import asyncio
import logging import logging
from typing import Optional, Iterable
import asyncio
from aiohttp import ClientSession from aiohttp import ClientSession
from typing import Optional, Iterable


from pom import PropertyMissing, PackagePOM, Properties
from pom import PackagePOM


logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)


@@ -12,52 +12,6 @@ class TooManyRequestsException(Exception):
pass pass




async def get_effective_packages(package: str, mirrors: Iterable[str]) -> list[str]:
"""
Get a list of packages that is required for Gradle to fetch this package.

For most packages, this just returns the package name. However, for BOMs, the full list of packages included
in the BOM is returned (including the BOM itself). This is because Gradle doesn't fetch all packages of a BOM.

This requires querying Maven and parsing the POM to check if the package is a BOM.
"""
packages = []

if pom := await fetch_pom(package, mirrors):
packages.append(package)

if pom.is_bom:
try:
packages.extend(pom.dependency_management)
except PropertyMissing as e1:
parent_props = await get_parent_props(pom.parent, mirrors)
if parent_props:
pom.set_properties(parent_props)
try:
packages.extend(pom.dependency_management)
except PropertyMissing as e2:
logger.warning(
f'{package}: Could not resolve property {e2.prop}, which is necessary for resolving dependencies'
)
else:
logger.warning(
f'{package}: Could not resolve property {e1.prop}, and could not get properties from parent'
)

return packages


async def get_parent_props(parent: Optional[str], mirrors: Iterable[str]) -> Properties:
if parent:
if pom := await fetch_pom(parent, mirrors):
pom.set_properties(await get_parent_props(pom.parent, mirrors))
return pom.properties
else:
logger.warning(f'{parent}: Error fetching pom')

return {}


async def fetch_pom(package: str, mirrors: Iterable[str]) -> Optional[PackagePOM]: async def fetch_pom(package: str, mirrors: Iterable[str]) -> Optional[PackagePOM]:
pom = await fetch_maven_file(package, 'pom', mirrors) pom = await fetch_maven_file(package, 'pom', mirrors)
return PackagePOM(package, pom) if pom else None return PackagePOM(package, pom) if pom else None

+ 53
- 0
sync/src/maven/packages.py Ver fichero

@@ -0,0 +1,53 @@
import logging
from typing import Optional, Iterable

from maven.fetch import fetch_pom
from pom import PropertyMissing, Properties

logger = logging.getLogger(__name__)


async def get_effective_packages(package: str, mirrors: Iterable[str]) -> list[str]:
"""
Get a list of packages that is required for Gradle to fetch this package.

For most packages, this just returns the package name. However, for BOMs, the full list of packages included
in the BOM is returned (including the BOM itself). This is because Gradle doesn't fetch all packages of a BOM.

This requires querying Maven and parsing the POM to check if the package is a BOM.
"""
packages = []

if pom := await fetch_pom(package, mirrors):
packages.append(package)

if pom.is_bom:
try:
packages.extend(pom.dependency_management)
except PropertyMissing as e1:
parent_props = await get_parent_props(pom.parent, mirrors)
if parent_props:
pom.set_properties(parent_props)
try:
packages.extend(pom.dependency_management)
except PropertyMissing as e2:
logger.warning(
f'{package}: Could not resolve property {e2.prop}, which is necessary for resolving dependencies'
)
else:
logger.warning(
f'{package}: Could not resolve property {e1.prop}, and could not get properties from parent'
)

return packages


async def get_parent_props(parent: Optional[str], mirrors: Iterable[str]) -> Properties:
if parent:
if pom := await fetch_pom(parent, mirrors):
pom.set_properties(await get_parent_props(pom.parent, mirrors))
return pom.properties
else:
logger.warning(f'{parent}: Error fetching pom')

return {}

Cargando…
Cancelar
Guardar