mirror of
				https://github.com/enpaul/tox-poetry-installer.git
				synced 2025-11-04 07:46:06 +00:00 
			
		
		
		
	Move install function to dedicated submodule
Fix duplicate package installs caused by using list for ordering
This commit is contained in:
		@@ -16,6 +16,7 @@ from tox.venv import VirtualEnv as ToxVirtualEnv
 | 
				
			|||||||
from tox_poetry_installer import __about__
 | 
					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 installer
 | 
				
			||||||
from tox_poetry_installer import utilities
 | 
					from tox_poetry_installer import utilities
 | 
				
			||||||
from tox_poetry_installer.datatypes import PackageMap
 | 
					from tox_poetry_installer.datatypes import PackageMap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -139,6 +140,6 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
 | 
				
			|||||||
        __about__.__title__,
 | 
					        __about__.__title__,
 | 
				
			||||||
        f"Installing {len(dependencies)} dependencies from Poetry lock file",
 | 
					        f"Installing {len(dependencies)} dependencies from Poetry lock file",
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    utilities.install_to_venv(poetry, venv, dependencies)
 | 
					    installer.install(poetry, venv, dependencies)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return venv.envconfig.require_locked_deps or None
 | 
					    return venv.envconfig.require_locked_deps or None
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										53
									
								
								tox_poetry_installer/installer.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								tox_poetry_installer/installer.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					"""Funcationality for performing virtualenv installation"""
 | 
				
			||||||
 | 
					# Silence this one globally to support the internal function imports for the proxied poetry module.
 | 
				
			||||||
 | 
					# See the docstring in 'tox_poetry_installer._poetry' for more context.
 | 
				
			||||||
 | 
					# pylint: disable=import-outside-toplevel
 | 
				
			||||||
 | 
					import typing
 | 
				
			||||||
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					from typing import Sequence
 | 
				
			||||||
 | 
					from typing import Set
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import tox
 | 
				
			||||||
 | 
					from poetry.core.packages import Package as PoetryPackage
 | 
				
			||||||
 | 
					from tox.venv import VirtualEnv as ToxVirtualEnv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from tox_poetry_installer import constants
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if typing.TYPE_CHECKING:
 | 
				
			||||||
 | 
					    from tox_poetry_installer import _poetry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def install(
 | 
				
			||||||
 | 
					    poetry: "_poetry.Poetry", venv: ToxVirtualEnv, packages: Sequence[PoetryPackage]
 | 
				
			||||||
 | 
					):
 | 
				
			||||||
 | 
					    """Install a bunch of packages to a virtualenv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    :param poetry: Poetry object the packages were sourced from
 | 
				
			||||||
 | 
					    :param venv: Tox virtual environment to install the packages to
 | 
				
			||||||
 | 
					    :param packages: List of packages to install to the virtual environment
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    from tox_poetry_installer import _poetry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    tox.reporter.verbosity1(
 | 
				
			||||||
 | 
					        f"{constants.REPORTER_PREFIX} Installing {len(packages)} packages to environment at {venv.envconfig.envdir}"
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pip = _poetry.PipInstaller(
 | 
				
			||||||
 | 
					        env=_poetry.VirtualEnv(path=Path(venv.envconfig.envdir)),
 | 
				
			||||||
 | 
					        io=_poetry.NullIO(),
 | 
				
			||||||
 | 
					        pool=poetry.pool,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    installed: Set[PoetryPackage] = set()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for dependency in packages:
 | 
				
			||||||
 | 
					        if dependency not in installed:
 | 
				
			||||||
 | 
					            tox.reporter.verbosity1(
 | 
				
			||||||
 | 
					                f"{constants.REPORTER_PREFIX} Installing {dependency}"
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            pip.install(dependency)
 | 
				
			||||||
 | 
					            installed.add(dependency)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            tox.reporter.verbosity1(
 | 
				
			||||||
 | 
					                f"{constants.REPORTER_PREFIX} Already installed {dependency}, skipping"
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
@@ -4,7 +4,6 @@
 | 
				
			|||||||
# pylint: disable=import-outside-toplevel
 | 
					# pylint: disable=import-outside-toplevel
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import typing
 | 
					import typing
 | 
				
			||||||
from pathlib import Path
 | 
					 | 
				
			||||||
from typing import List
 | 
					from typing import List
 | 
				
			||||||
from typing import Sequence
 | 
					from typing import Sequence
 | 
				
			||||||
from typing import Set
 | 
					from typing import Set
 | 
				
			||||||
@@ -22,32 +21,6 @@ if typing.TYPE_CHECKING:
 | 
				
			|||||||
    from tox_poetry_installer import _poetry
 | 
					    from tox_poetry_installer import _poetry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def install_to_venv(
 | 
					 | 
				
			||||||
    poetry: "_poetry.Poetry", venv: ToxVirtualEnv, packages: Sequence[PoetryPackage]
 | 
					 | 
				
			||||||
):
 | 
					 | 
				
			||||||
    """Install a bunch of packages to a virtualenv
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    :param poetry: Poetry object the packages were sourced from
 | 
					 | 
				
			||||||
    :param venv: Tox virtual environment to install the packages to
 | 
					 | 
				
			||||||
    :param packages: List of packages to install to the virtual environment
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    from tox_poetry_installer import _poetry
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    tox.reporter.verbosity1(
 | 
					 | 
				
			||||||
        f"{constants.REPORTER_PREFIX} Installing {len(packages)} packages to environment at {venv.envconfig.envdir}"
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    installer = _poetry.PipInstaller(
 | 
					 | 
				
			||||||
        env=_poetry.VirtualEnv(path=Path(venv.envconfig.envdir)),
 | 
					 | 
				
			||||||
        io=_poetry.NullIO(),
 | 
					 | 
				
			||||||
        pool=poetry.pool,
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for dependency in packages:
 | 
					 | 
				
			||||||
        tox.reporter.verbosity1(f"{constants.REPORTER_PREFIX} Installing {dependency}")
 | 
					 | 
				
			||||||
        installer.install(dependency)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def identify_transients(
 | 
					def identify_transients(
 | 
				
			||||||
    packages: PackageMap, dependency_name: str, allow_missing: Sequence[str] = ()
 | 
					    packages: PackageMap, dependency_name: str, allow_missing: Sequence[str] = ()
 | 
				
			||||||
) -> List[PoetryPackage]:
 | 
					) -> List[PoetryPackage]:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user