mirror of
				https://github.com/enpaul/tox-poetry-installer.git
				synced 2025-11-04 07:46:06 +00:00 
			
		
		
		
	Update import pattern to use tox module namespacing where possible
This commit is contained in:
		@@ -7,9 +7,8 @@ themselves manageable).
 | 
				
			|||||||
from typing import List
 | 
					from typing import List
 | 
				
			||||||
from typing import Optional
 | 
					from typing import Optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import tox
 | 
				
			||||||
from poetry.core.packages import Package as PoetryPackage
 | 
					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.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
 | 
				
			||||||
@@ -21,7 +20,7 @@ from tox_poetry_installer import utilities
 | 
				
			|||||||
from tox_poetry_installer.datatypes import PackageMap
 | 
					from tox_poetry_installer.datatypes import PackageMap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@hookimpl
 | 
					@tox.hookimpl
 | 
				
			||||||
def tox_addoption(parser: ToxParser):
 | 
					def tox_addoption(parser: ToxParser):
 | 
				
			||||||
    """Add required configuration options to the tox INI file
 | 
					    """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]:
 | 
					def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional[bool]:
 | 
				
			||||||
    """Install the dependencies for the current environment
 | 
					    """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
 | 
					            and venv.envconfig.config.option.require_poetry
 | 
				
			||||||
        ):
 | 
					        ):
 | 
				
			||||||
            venv.status = err.__class__.__name__
 | 
					            venv.status = err.__class__.__name__
 | 
				
			||||||
            reporter.error(str(err))
 | 
					            tox.reporter.error(str(err))
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
        reporter.verbosity1(str(err))
 | 
					        tox.reporter.verbosity1(str(err))
 | 
				
			||||||
        return None
 | 
					        return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    reporter.verbosity1(
 | 
					    tox.reporter.verbosity1(
 | 
				
			||||||
        f"{constants.REPORTER_PREFIX} Loaded project pyproject.toml from {poetry.file}"
 | 
					        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:
 | 
					        else:
 | 
				
			||||||
            dev_deps = []
 | 
					            dev_deps = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        reporter.verbosity1(
 | 
					        tox.reporter.verbosity1(
 | 
				
			||||||
            f"{constants.REPORTER_PREFIX} Identified {len(dev_deps)} development dependencies to install to env"
 | 
					            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(
 | 
					            env_deps += utilities.find_transients(
 | 
				
			||||||
                package_map, dep.lower(), allow_missing=[poetry.package.name]
 | 
					                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"
 | 
					            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:
 | 
					        else:
 | 
				
			||||||
            project_deps = []
 | 
					            project_deps = []
 | 
				
			||||||
            reporter.verbosity1(
 | 
					            tox.reporter.verbosity1(
 | 
				
			||||||
                f"{constants.REPORTER_PREFIX} Skipping installation of project dependencies, env does not install project package"
 | 
					                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"
 | 
					            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 = err.__class__.__name__
 | 
					        venv.status = err.__class__.__name__
 | 
				
			||||||
        reporter.error(f"{constants.REPORTER_PREFIX} {err}")
 | 
					        tox.reporter.error(f"{constants.REPORTER_PREFIX} {err}")
 | 
				
			||||||
        return False
 | 
					        return False
 | 
				
			||||||
    except Exception as err:
 | 
					    except Exception as err:
 | 
				
			||||||
        venv.status = "InternalError"
 | 
					        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
 | 
					        raise err
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dependencies = list(set(dev_deps + env_deps + project_deps))
 | 
					    dependencies = list(set(dev_deps + env_deps + project_deps))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,8 +9,8 @@ from typing import List
 | 
				
			|||||||
from typing import Sequence
 | 
					from typing import Sequence
 | 
				
			||||||
from typing import Set
 | 
					from typing import Set
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import tox
 | 
				
			||||||
from poetry.core.packages import Package as PoetryPackage
 | 
					from poetry.core.packages import Package as PoetryPackage
 | 
				
			||||||
from tox import reporter
 | 
					 | 
				
			||||||
from tox.action import Action as ToxAction
 | 
					from tox.action import Action as ToxAction
 | 
				
			||||||
from tox.venv import VirtualEnv as ToxVirtualEnv
 | 
					from tox.venv import VirtualEnv as ToxVirtualEnv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -33,7 +33,7 @@ def install_to_venv(
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
    from tox_poetry_installer import _poetry
 | 
					    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}"
 | 
					        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:
 | 
					    for dependency in packages:
 | 
				
			||||||
        reporter.verbosity1(f"{constants.REPORTER_PREFIX} Installing {dependency}")
 | 
					        tox.reporter.verbosity1(f"{constants.REPORTER_PREFIX} Installing {dependency}")
 | 
				
			||||||
        installer.install(dependency)
 | 
					        installer.install(dependency)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -70,10 +70,10 @@ def find_transients(
 | 
				
			|||||||
        searched.add(name)
 | 
					        searched.add(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if name in _poetry.Provider.UNSAFE_PACKAGES:
 | 
					        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"
 | 
					                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"
 | 
					                f"{constants.REPORTER_PREFIX} Skip {name}: designated unsafe by Poetry"
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            return dict()
 | 
					            return dict()
 | 
				
			||||||
@@ -83,33 +83,33 @@ def find_transients(
 | 
				
			|||||||
            package = packages[name]
 | 
					            package = packages[name]
 | 
				
			||||||
        except KeyError as err:
 | 
					        except KeyError as err:
 | 
				
			||||||
            if name in allow_missing:
 | 
					            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"
 | 
					                    f"{constants.REPORTER_PREFIX} Skip {name}: package is not in lockfile but designated as allowed to be missing"
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                return dict()
 | 
					                return dict()
 | 
				
			||||||
            raise err
 | 
					            raise err
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not package.python_constraint.allows(constants.PLATFORM_VERSION):
 | 
					        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}'"
 | 
					                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(
 | 
					            tox.reporter.verbosity2(
 | 
				
			||||||
                f"{constants.REPORTER_PREFIX} Skip {package}: incompatible platform requirement '{package.platform}' for current platform '{sys.platform}'"
 | 
					                f"{constants.REPORTER_PREFIX} Skip {package}: incompatible platform requirement '{package.platform}' for current platform '{sys.platform}'"
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            reporter.verbosity2(
 | 
					            tox.reporter.verbosity2(
 | 
				
			||||||
                f"{constants.REPORTER_PREFIX} Including {package} for installation"
 | 
					                f"{constants.REPORTER_PREFIX} Including {package} for installation"
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            transients[name] = package
 | 
					            transients[name] = package
 | 
				
			||||||
            for index, dep in enumerate(package.requires):
 | 
					            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}"
 | 
					                    f"{constants.REPORTER_PREFIX} Processing dependency {index + 1}/{len(package.requires)} for {package}: {dep.name}"
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                if dep.name not in searched:
 | 
					                if dep.name not in searched:
 | 
				
			||||||
                    transients.update(find_deps_of_deps(dep.name, searched))
 | 
					                    transients.update(find_deps_of_deps(dep.name, searched))
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    reporter.verbosity2(
 | 
					                    tox.reporter.verbosity2(
 | 
				
			||||||
                        f"{constants.REPORTER_PREFIX} Package with name '{dep.name}' has already been processed, skipping"
 | 
					                        f"{constants.REPORTER_PREFIX} Package with name '{dep.name}' has already been processed, skipping"
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -123,7 +123,7 @@ def find_transients(
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
    except KeyError:
 | 
					    except KeyError:
 | 
				
			||||||
        if dependency_name in _poetry.Provider.UNSAFE_PACKAGES:
 | 
					        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"
 | 
					                f"{constants.REPORTER_PREFIX} Installing package '{dependency_name}' using Poetry is not supported and will be skipped"
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            return set()
 | 
					            return set()
 | 
				
			||||||
@@ -198,7 +198,7 @@ def find_project_dependencies(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    extra_dependencies: List[PoetryPackage] = []
 | 
					    extra_dependencies: List[PoetryPackage] = []
 | 
				
			||||||
    for extra in venv.envconfig.extras:
 | 
					    for extra in venv.envconfig.extras:
 | 
				
			||||||
        reporter.verbosity1(
 | 
					        tox.reporter.verbosity1(
 | 
				
			||||||
            f"{constants.REPORTER_PREFIX} Processing project extra '{extra}'"
 | 
					            f"{constants.REPORTER_PREFIX} Processing project extra '{extra}'"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user