mirror of
https://github.com/enpaul/tox-poetry-installer.git
synced 2024-12-05 01:40:44 +00:00
Update logging integration to improve standardization
Standardize language in logging messages Move system version to constants Fixes #3
This commit is contained in:
parent
bd8124dcbf
commit
01635c50c7
@ -5,8 +5,11 @@ in this module.
|
||||
|
||||
All constants should be type hinted.
|
||||
"""
|
||||
import sys
|
||||
from typing import Tuple
|
||||
|
||||
from poetry.core.semver.version import Version
|
||||
|
||||
from tox_poetry_installer import __about__
|
||||
|
||||
|
||||
@ -16,4 +19,13 @@ PEP508_VERSION_DELIMITERS: Tuple[str, ...] = ("~=", "==", "!=", ">", "<")
|
||||
|
||||
# Prefix all reporter messages should include to indicate that they came from this module in the
|
||||
# console output.
|
||||
REPORTER_PREFIX = f"[{__about__.__title__}]:"
|
||||
REPORTER_PREFIX: str = f"[{__about__.__title__}]:"
|
||||
|
||||
|
||||
# Semver compatible version of the current python platform version. Used for checking
|
||||
# whether a package is compatible with the current python system version
|
||||
PLATFORM_VERSION: Version = Version(
|
||||
major=sys.version_info.major,
|
||||
minor=sys.version_info.minor,
|
||||
patch=sys.version_info.micro,
|
||||
)
|
||||
|
@ -14,6 +14,7 @@ from tox.action import Action as ToxAction
|
||||
from tox.config import Parser as ToxParser
|
||||
from tox.venv import VirtualEnv as ToxVirtualEnv
|
||||
|
||||
from tox_poetry_installer import __about__
|
||||
from tox_poetry_installer import constants
|
||||
from tox_poetry_installer import exceptions
|
||||
from tox_poetry_installer import utilities
|
||||
@ -71,30 +72,30 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
|
||||
f"{constants.REPORTER_PREFIX} Loaded project pyproject.toml from {poetry.file}"
|
||||
)
|
||||
|
||||
if venv.envconfig.require_locked_deps and venv.envconfig.deps:
|
||||
raise exceptions.LockedDepsRequiredError(
|
||||
f"Unlocked dependencies '{venv.envconfig.deps}' specified for environment '{venv.name}' which requires locked dependencies"
|
||||
try:
|
||||
if venv.envconfig.require_locked_deps and venv.envconfig.deps:
|
||||
raise exceptions.LockedDepsRequiredError(
|
||||
f"Unlocked dependencies '{venv.envconfig.deps}' specified for environment '{venv.name}' which requires locked dependencies"
|
||||
)
|
||||
|
||||
package_map: PackageMap = {
|
||||
package.name: package
|
||||
for package in poetry.locker.locked_repository(True).packages
|
||||
}
|
||||
|
||||
if venv.envconfig.install_dev_deps:
|
||||
dev_deps: List[PoetryPackage] = [
|
||||
dep
|
||||
for dep in package_map.values()
|
||||
if dep not in poetry.locker.locked_repository(False).packages
|
||||
]
|
||||
else:
|
||||
dev_deps = []
|
||||
|
||||
reporter.verbosity1(
|
||||
f"{constants.REPORTER_PREFIX} Identified {len(dev_deps)} development dependencies to install to env"
|
||||
)
|
||||
|
||||
package_map: PackageMap = {
|
||||
package.name: package
|
||||
for package in poetry.locker.locked_repository(True).packages
|
||||
}
|
||||
|
||||
if venv.envconfig.install_dev_deps:
|
||||
dev_deps: List[PoetryPackage] = [
|
||||
dep
|
||||
for dep in package_map.values()
|
||||
if dep not in poetry.locker.locked_repository(False).packages
|
||||
]
|
||||
else:
|
||||
dev_deps = []
|
||||
|
||||
reporter.verbosity1(
|
||||
f"{constants.REPORTER_PREFIX} Identified {len(dev_deps)} development dependencies to install to env"
|
||||
)
|
||||
|
||||
try:
|
||||
env_deps: List[PoetryPackage] = []
|
||||
for dep in venv.envconfig.locked_deps:
|
||||
env_deps += utilities.find_transients(package_map, dep.lower())
|
||||
@ -115,13 +116,18 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
|
||||
f"{constants.REPORTER_PREFIX} Identified {len(project_deps)} project dependencies to install to env"
|
||||
)
|
||||
except exceptions.ToxPoetryInstallerException as err:
|
||||
venv.status = "lockfile installation failed"
|
||||
venv.status = err.__class__.__name__
|
||||
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}")
|
||||
raise err
|
||||
|
||||
dependencies = list(set(dev_deps + env_deps + project_deps))
|
||||
reporter.verbosity0(
|
||||
f"{constants.REPORTER_PREFIX} Installing {len(dependencies)} dependencies to env '{action.name}'"
|
||||
action.setactivity(
|
||||
__about__.__title__,
|
||||
f"Installing {len(dependencies)} dependencies from Poetry lock file",
|
||||
)
|
||||
utilities.install_to_venv(poetry, venv, dependencies)
|
||||
|
||||
|
@ -6,7 +6,6 @@ from typing import Sequence
|
||||
from typing import Set
|
||||
|
||||
from poetry.core.packages import Package as PoetryPackage
|
||||
from poetry.core.semver.version import Version
|
||||
from poetry.factory import Factory as PoetryFactory
|
||||
from poetry.installation.pip_installer import PipInstaller as PoetryPipInstaller
|
||||
from poetry.io.null_io import NullIO as PoetryNullIO
|
||||
@ -64,11 +63,6 @@ def find_transients(packages: PackageMap, dependency_name: str) -> Set[PoetryPac
|
||||
|
||||
def find_deps_of_deps(name: str, searched: Set[str]) -> PackageMap:
|
||||
package = packages[name]
|
||||
local_version = Version(
|
||||
major=sys.version_info.major,
|
||||
minor=sys.version_info.minor,
|
||||
patch=sys.version_info.micro,
|
||||
)
|
||||
transients: PackageMap = {}
|
||||
searched.update([name])
|
||||
|
||||
@ -79,9 +73,9 @@ def find_transients(packages: PackageMap, dependency_name: str) -> Set[PoetryPac
|
||||
reporter.verbosity2(
|
||||
f"{constants.REPORTER_PREFIX} Skip {package}: designated unsafe by Poetry"
|
||||
)
|
||||
elif not package.python_constraint.allows(local_version):
|
||||
elif not package.python_constraint.allows(constants.PLATFORM_VERSION):
|
||||
reporter.verbosity2(
|
||||
f"{constants.REPORTER_PREFIX} Skip {package}: incompatible Python requirement '{package.python_constraint}' for current version '{local_version}'"
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user