mirror of
				https://github.com/enpaul/tox-poetry-installer.git
				synced 2025-11-04 07:46:06 +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:
		@@ -5,8 +5,11 @@ in this module.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
All constants should be type hinted.
 | 
					All constants should be type hinted.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
from typing import Tuple
 | 
					from typing import Tuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from poetry.core.semver.version import Version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from tox_poetry_installer import __about__
 | 
					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
 | 
					# Prefix all reporter messages should include to indicate that they came from this module in the
 | 
				
			||||||
# console output.
 | 
					# 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.config import Parser as ToxParser
 | 
				
			||||||
from tox.venv import VirtualEnv as ToxVirtualEnv
 | 
					from tox.venv import VirtualEnv as ToxVirtualEnv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from tox_poetry_installer import __about__
 | 
				
			||||||
from tox_poetry_installer import constants
 | 
					from tox_poetry_installer import constants
 | 
				
			||||||
from tox_poetry_installer import exceptions
 | 
					from tox_poetry_installer import exceptions
 | 
				
			||||||
from tox_poetry_installer import utilities
 | 
					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}"
 | 
					        f"{constants.REPORTER_PREFIX} Loaded project pyproject.toml from {poetry.file}"
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if venv.envconfig.require_locked_deps and venv.envconfig.deps:
 | 
					    try:
 | 
				
			||||||
        raise exceptions.LockedDepsRequiredError(
 | 
					        if venv.envconfig.require_locked_deps and venv.envconfig.deps:
 | 
				
			||||||
            f"Unlocked dependencies '{venv.envconfig.deps}' specified for environment '{venv.name}' which requires locked dependencies"
 | 
					            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] = []
 | 
					        env_deps: List[PoetryPackage] = []
 | 
				
			||||||
        for dep in venv.envconfig.locked_deps:
 | 
					        for dep in venv.envconfig.locked_deps:
 | 
				
			||||||
            env_deps += utilities.find_transients(package_map, dep.lower())
 | 
					            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"
 | 
					            f"{constants.REPORTER_PREFIX} Identified {len(project_deps)} project dependencies to install to env"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    except exceptions.ToxPoetryInstallerException as err:
 | 
					    except exceptions.ToxPoetryInstallerException as err:
 | 
				
			||||||
        venv.status = "lockfile installation failed"
 | 
					        venv.status = err.__class__.__name__
 | 
				
			||||||
        reporter.error(f"{constants.REPORTER_PREFIX} {err}")
 | 
					        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
 | 
					        raise err
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dependencies = list(set(dev_deps + env_deps + project_deps))
 | 
					    dependencies = list(set(dev_deps + env_deps + project_deps))
 | 
				
			||||||
    reporter.verbosity0(
 | 
					    action.setactivity(
 | 
				
			||||||
        f"{constants.REPORTER_PREFIX} Installing {len(dependencies)} dependencies to env '{action.name}'"
 | 
					        __about__.__title__,
 | 
				
			||||||
 | 
					        f"Installing {len(dependencies)} dependencies from Poetry lock file",
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    utilities.install_to_venv(poetry, venv, dependencies)
 | 
					    utilities.install_to_venv(poetry, venv, dependencies)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,6 @@ from typing import Sequence
 | 
				
			|||||||
from typing import Set
 | 
					from typing import Set
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from poetry.core.packages import Package as PoetryPackage
 | 
					from poetry.core.packages import Package as PoetryPackage
 | 
				
			||||||
from poetry.core.semver.version import Version
 | 
					 | 
				
			||||||
from poetry.factory import Factory as PoetryFactory
 | 
					from poetry.factory import Factory as PoetryFactory
 | 
				
			||||||
from poetry.installation.pip_installer import PipInstaller as PoetryPipInstaller
 | 
					from poetry.installation.pip_installer import PipInstaller as PoetryPipInstaller
 | 
				
			||||||
from poetry.io.null_io import NullIO as PoetryNullIO
 | 
					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:
 | 
					        def find_deps_of_deps(name: str, searched: Set[str]) -> PackageMap:
 | 
				
			||||||
            package = packages[name]
 | 
					            package = packages[name]
 | 
				
			||||||
            local_version = Version(
 | 
					 | 
				
			||||||
                major=sys.version_info.major,
 | 
					 | 
				
			||||||
                minor=sys.version_info.minor,
 | 
					 | 
				
			||||||
                patch=sys.version_info.micro,
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
            transients: PackageMap = {}
 | 
					            transients: PackageMap = {}
 | 
				
			||||||
            searched.update([name])
 | 
					            searched.update([name])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -79,9 +73,9 @@ def find_transients(packages: PackageMap, dependency_name: str) -> Set[PoetryPac
 | 
				
			|||||||
                reporter.verbosity2(
 | 
					                reporter.verbosity2(
 | 
				
			||||||
                    f"{constants.REPORTER_PREFIX} Skip {package}: designated unsafe by Poetry"
 | 
					                    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(
 | 
					                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:
 | 
					            elif package.platform is not None and package.platform != sys.platform:
 | 
				
			||||||
                reporter.verbosity2(
 | 
					                reporter.verbosity2(
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user