Move non-hook function out of hooks submodule

This commit is contained in:
Ethan Paul 2020-12-04 16:05:04 -05:00
parent 4de5fea0e3
commit bd8124dcbf
No known key found for this signature in database
GPG Key ID: C5F5542B54A4D9C6
2 changed files with 38 additions and 38 deletions

View File

@ -8,7 +8,6 @@ from typing import List
from typing import Optional from typing import Optional
from poetry.core.packages import Package as PoetryPackage from poetry.core.packages import Package as PoetryPackage
from poetry.poetry import Poetry
from tox import hookimpl from tox import hookimpl
from tox import reporter from tox import reporter
from tox.action import Action as ToxAction from tox.action import Action as ToxAction
@ -104,7 +103,7 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
) )
if not venv.envconfig.skip_install and not venv.envconfig.config.skipsdist: if not venv.envconfig.skip_install and not venv.envconfig.config.skipsdist:
project_deps: List[PoetryPackage] = _find_project_dependencies( project_deps: List[PoetryPackage] = utilities.find_project_dependencies(
venv, poetry, package_map venv, poetry, package_map
) )
else: else:
@ -127,39 +126,3 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
utilities.install_to_venv(poetry, venv, dependencies) utilities.install_to_venv(poetry, venv, dependencies)
return venv.envconfig.require_locked_deps or None return venv.envconfig.require_locked_deps or None
def _find_project_dependencies(
venv: ToxVirtualEnv, poetry: Poetry, packages: PackageMap
) -> List[PoetryPackage]:
"""Install the dependencies of the project package
Install all primary dependencies of the project package.
:param venv: Tox virtual environment to install the packages to
:param poetry: Poetry object the packages were sourced from
:param packages: Mapping of package names to the corresponding package object
"""
base_dependencies: List[PoetryPackage] = [
packages[item.name]
for item in poetry.package.requires
if not item.is_optional()
]
extra_dependencies: List[PoetryPackage] = []
for extra in venv.envconfig.extras:
try:
extra_dependencies += [
packages[item.name] for item in poetry.package.extras[extra]
]
except KeyError:
raise exceptions.ExtraNotFoundError(
f"Environment '{venv.name}' specifies project extra '{extra}' which was not found in the lockfile"
) from None
dependencies: List[PoetryPackage] = []
for dep in base_dependencies + extra_dependencies:
dependencies += utilities.find_transients(packages, dep.name.lower())
return dependencies

View File

@ -1,6 +1,7 @@
"""Helper utility functions, usually bridging Tox and Poetry functionality""" """Helper utility functions, usually bridging Tox and Poetry functionality"""
import sys import sys
from pathlib import Path from pathlib import Path
from typing import List
from typing import Sequence from typing import Sequence
from typing import Set from typing import Set
@ -135,3 +136,39 @@ def check_preconditions(venv: ToxVirtualEnv, action: ToxAction) -> Poetry:
raise exceptions.SkipEnvironment( raise exceptions.SkipEnvironment(
"Project does not use Poetry for env management, skipping installation of locked dependencies" "Project does not use Poetry for env management, skipping installation of locked dependencies"
) from None ) from None
def find_project_dependencies(
venv: ToxVirtualEnv, poetry: Poetry, packages: PackageMap
) -> List[PoetryPackage]:
"""Install the dependencies of the project package
Install all primary dependencies of the project package.
:param venv: Tox virtual environment to install the packages to
:param poetry: Poetry object the packages were sourced from
:param packages: Mapping of package names to the corresponding package object
"""
base_dependencies: List[PoetryPackage] = [
packages[item.name]
for item in poetry.package.requires
if not item.is_optional()
]
extra_dependencies: List[PoetryPackage] = []
for extra in venv.envconfig.extras:
try:
extra_dependencies += [
packages[item.name] for item in poetry.package.extras[extra]
]
except KeyError:
raise exceptions.ExtraNotFoundError(
f"Environment '{venv.name}' specifies project extra '{extra}' which was not found in the lockfile"
) from None
dependencies: List[PoetryPackage] = []
for dep in base_dependencies + extra_dependencies:
dependencies += find_transients(packages, dep.name.lower())
return dependencies