Update import pattern to use tox module namespacing where possible

This commit is contained in:
Ethan Paul 2021-02-09 20:38:53 -05:00
parent ee5df2f17a
commit 52c08e9dc5
No known key found for this signature in database
GPG Key ID: C5F5542B54A4D9C6
2 changed files with 25 additions and 26 deletions

View File

@ -7,9 +7,8 @@ themselves manageable).
from typing import List
from typing import Optional
import tox
from poetry.core.packages import Package as PoetryPackage
from tox import hookimpl
from tox import reporter
from tox.action import Action as ToxAction
from tox.config import Parser as ToxParser
from tox.venv import VirtualEnv as ToxVirtualEnv
@ -21,7 +20,7 @@ from tox_poetry_installer import utilities
from tox_poetry_installer.datatypes import PackageMap
@hookimpl
@tox.hookimpl
def tox_addoption(parser: ToxParser):
"""Add required configuration options to the tox INI file
@ -57,7 +56,7 @@ def tox_addoption(parser: ToxParser):
)
@hookimpl
@tox.hookimpl
def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional[bool]:
"""Install the dependencies for the current environment
@ -77,12 +76,12 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
and venv.envconfig.config.option.require_poetry
):
venv.status = err.__class__.__name__
reporter.error(str(err))
tox.reporter.error(str(err))
return False
reporter.verbosity1(str(err))
tox.reporter.verbosity1(str(err))
return None
reporter.verbosity1(
tox.reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Loaded project pyproject.toml from {poetry.file}"
)
@ -106,7 +105,7 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
else:
dev_deps = []
reporter.verbosity1(
tox.reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Identified {len(dev_deps)} development dependencies to install to env"
)
@ -115,7 +114,7 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
env_deps += utilities.find_transients(
package_map, dep.lower(), allow_missing=[poetry.package.name]
)
reporter.verbosity1(
tox.reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Identified {len(env_deps)} environment dependencies to install to env"
)
@ -125,19 +124,19 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
)
else:
project_deps = []
reporter.verbosity1(
tox.reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Skipping installation of project dependencies, env does not install project package"
)
reporter.verbosity1(
tox.reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Identified {len(project_deps)} project dependencies to install to env"
)
except exceptions.ToxPoetryInstallerException as err:
venv.status = err.__class__.__name__
reporter.error(f"{constants.REPORTER_PREFIX} {err}")
tox.reporter.error(f"{constants.REPORTER_PREFIX} {err}")
return False
except Exception as err:
venv.status = "InternalError"
reporter.error(f"{constants.REPORTER_PREFIX} Internal plugin error: {err}")
tox.reporter.error(f"{constants.REPORTER_PREFIX} Internal plugin error: {err}")
raise err
dependencies = list(set(dev_deps + env_deps + project_deps))

View File

@ -9,8 +9,8 @@ from typing import List
from typing import Sequence
from typing import Set
import tox
from poetry.core.packages import Package as PoetryPackage
from tox import reporter
from tox.action import Action as ToxAction
from tox.venv import VirtualEnv as ToxVirtualEnv
@ -33,7 +33,7 @@ def install_to_venv(
"""
from tox_poetry_installer import _poetry
reporter.verbosity1(
tox.reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Installing {len(packages)} packages to environment at {venv.envconfig.envdir}"
)
@ -44,7 +44,7 @@ def install_to_venv(
)
for dependency in packages:
reporter.verbosity1(f"{constants.REPORTER_PREFIX} Installing {dependency}")
tox.reporter.verbosity1(f"{constants.REPORTER_PREFIX} Installing {dependency}")
installer.install(dependency)
@ -70,10 +70,10 @@ def find_transients(
searched.add(name)
if name in _poetry.Provider.UNSAFE_PACKAGES:
reporter.warning(
tox.reporter.warning(
f"{constants.REPORTER_PREFIX} Installing package '{name}' using Poetry is not supported and will be skipped"
)
reporter.verbosity2(
tox.reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Skip {name}: designated unsafe by Poetry"
)
return dict()
@ -83,33 +83,33 @@ def find_transients(
package = packages[name]
except KeyError as err:
if name in allow_missing:
reporter.verbosity2(
tox.reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Skip {name}: package is not in lockfile but designated as allowed to be missing"
)
return dict()
raise err
if not package.python_constraint.allows(constants.PLATFORM_VERSION):
reporter.verbosity2(
tox.reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Skip {package}: incompatible Python requirement '{package.python_constraint}' for current version '{constants.PLATFORM_VERSION}'"
)
elif package.platform is not None and package.platform != sys.platform:
reporter.verbosity2(
tox.reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Skip {package}: incompatible platform requirement '{package.platform}' for current platform '{sys.platform}'"
)
else:
reporter.verbosity2(
tox.reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Including {package} for installation"
)
transients[name] = package
for index, dep in enumerate(package.requires):
reporter.verbosity2(
tox.reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Processing dependency {index + 1}/{len(package.requires)} for {package}: {dep.name}"
)
if dep.name not in searched:
transients.update(find_deps_of_deps(dep.name, searched))
else:
reporter.verbosity2(
tox.reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Package with name '{dep.name}' has already been processed, skipping"
)
@ -123,7 +123,7 @@ def find_transients(
)
except KeyError:
if dependency_name in _poetry.Provider.UNSAFE_PACKAGES:
reporter.warning(
tox.reporter.warning(
f"{constants.REPORTER_PREFIX} Installing package '{dependency_name}' using Poetry is not supported and will be skipped"
)
return set()
@ -198,7 +198,7 @@ def find_project_dependencies(
extra_dependencies: List[PoetryPackage] = []
for extra in venv.envconfig.extras:
reporter.verbosity1(
tox.reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Processing project extra '{extra}'"
)
try: