mirror of
				https://github.com/enpaul/tox-poetry-installer.git
				synced 2025-11-04 07:46:06 +00:00 
			
		
		
		
	Merge pull request #31 from enpaul/enp/force-fail
Add option to support forcing tox failure when Poetry is not available
This commit is contained in:
		
							
								
								
									
										10
									
								
								.github/workflows/ci.yaml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								.github/workflows/ci.yaml
									
									
									
									
										vendored
									
									
								
							@@ -40,7 +40,9 @@ jobs:
 | 
				
			|||||||
      - name: Setup:env
 | 
					      - name: Setup:env
 | 
				
			||||||
        run: .github/scripts/setup-env.sh
 | 
					        run: .github/scripts/setup-env.sh
 | 
				
			||||||
      - name: Run:${{ matrix.python.toxenv }}
 | 
					      - name: Run:${{ matrix.python.toxenv }}
 | 
				
			||||||
        run: $HOME/ci/bin/tox -e ${{ matrix.python.toxenv }}
 | 
					        run: $HOME/ci/bin/tox \
 | 
				
			||||||
 | 
					          -e ${{ matrix.python.toxenv }} \
 | 
				
			||||||
 | 
					          --require-poetry
 | 
				
			||||||
  Check:
 | 
					  Check:
 | 
				
			||||||
    runs-on: ubuntu-latest
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
@@ -63,8 +65,8 @@ jobs:
 | 
				
			|||||||
      - name: Setup:env
 | 
					      - name: Setup:env
 | 
				
			||||||
        run: .github/scripts/setup-env.sh
 | 
					        run: .github/scripts/setup-env.sh
 | 
				
			||||||
      - name: Run:static
 | 
					      - name: Run:static
 | 
				
			||||||
        run: $HOME/ci/bin/tox -e static
 | 
					        run: $HOME/ci/bin/tox -e static --require-poetry
 | 
				
			||||||
      - name: Run:static-tests
 | 
					      - name: Run:static-tests
 | 
				
			||||||
        run: $HOME/ci/bin/tox -e static-tests
 | 
					        run: $HOME/ci/bin/tox -e static-tests --require-poetry
 | 
				
			||||||
      - name: Run:security
 | 
					      - name: Run:security
 | 
				
			||||||
        run: $HOME/ci/bin/tox -e security
 | 
					        run: $HOME/ci/bin/tox -e security --require-poetry
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,6 +36,5 @@ try:
 | 
				
			|||||||
    from poetry.utils.env import VirtualEnv
 | 
					    from poetry.utils.env import VirtualEnv
 | 
				
			||||||
except ImportError:
 | 
					except ImportError:
 | 
				
			||||||
    raise exceptions.PoetryNotInstalledError(
 | 
					    raise exceptions.PoetryNotInstalledError(
 | 
				
			||||||
        f"No version of Poetry could be imported under the current environment for '{sys.executable}'",
 | 
					        f"No version of Poetry could be imported under the current environment for '{sys.executable}'"
 | 
				
			||||||
        sys.path,
 | 
					 | 
				
			||||||
    ) from None
 | 
					    ) from None
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,6 +29,13 @@ def tox_addoption(parser: ToxParser):
 | 
				
			|||||||
    dependencies should be treated as locked or not.
 | 
					    dependencies should be treated as locked or not.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    parser.add_argument(
 | 
				
			||||||
 | 
					        "--require-poetry",
 | 
				
			||||||
 | 
					        action="store_true",
 | 
				
			||||||
 | 
					        dest="require_poetry",
 | 
				
			||||||
 | 
					        help="Trigger a failure if Poetry is not available to Tox",
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    parser.add_testenv_attribute(
 | 
					    parser.add_testenv_attribute(
 | 
				
			||||||
        name="install_dev_deps",
 | 
					        name="install_dev_deps",
 | 
				
			||||||
        type="bool",
 | 
					        type="bool",
 | 
				
			||||||
@@ -65,6 +72,13 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
 | 
				
			|||||||
    try:
 | 
					    try:
 | 
				
			||||||
        poetry = utilities.check_preconditions(venv, action)
 | 
					        poetry = utilities.check_preconditions(venv, action)
 | 
				
			||||||
    except exceptions.SkipEnvironment as err:
 | 
					    except exceptions.SkipEnvironment as err:
 | 
				
			||||||
 | 
					        if (
 | 
				
			||||||
 | 
					            isinstance(err, exceptions.PoetryNotInstalledError)
 | 
				
			||||||
 | 
					            and venv.envconfig.config.option.require_poetry
 | 
				
			||||||
 | 
					        ):
 | 
				
			||||||
 | 
					            venv.status = err.__class__.__name__
 | 
				
			||||||
 | 
					            reporter.error(str(err))
 | 
				
			||||||
 | 
					            return False
 | 
				
			||||||
        reporter.verbosity1(str(err))
 | 
					        reporter.verbosity1(str(err))
 | 
				
			||||||
        return None
 | 
					        return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -114,8 +114,6 @@ def find_transients(packages: PackageMap, dependency_name: str) -> Set[PoetryPac
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def check_preconditions(venv: ToxVirtualEnv, action: ToxAction) -> "_poetry.Poetry":
 | 
					def check_preconditions(venv: ToxVirtualEnv, action: ToxAction) -> "_poetry.Poetry":
 | 
				
			||||||
    """Check that the local project environment meets expectations"""
 | 
					    """Check that the local project environment meets expectations"""
 | 
				
			||||||
    from tox_poetry_installer import _poetry
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Skip running the plugin for the packaging environment. PEP-517 front ends can handle
 | 
					    # Skip running the plugin for the packaging environment. PEP-517 front ends can handle
 | 
				
			||||||
    # that better than we can, so let them do their thing. More to the point: if you're having
 | 
					    # that better than we can, so let them do their thing. More to the point: if you're having
 | 
				
			||||||
    # problems in the packaging env that this plugin would solve, god help you.
 | 
					    # problems in the packaging env that this plugin would solve, god help you.
 | 
				
			||||||
@@ -124,6 +122,8 @@ def check_preconditions(venv: ToxVirtualEnv, action: ToxAction) -> "_poetry.Poet
 | 
				
			|||||||
            f"Skipping isolated packaging build env '{action.name}'"
 | 
					            f"Skipping isolated packaging build env '{action.name}'"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    from tox_poetry_installer import _poetry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        return _poetry.Factory().create_poetry(venv.envconfig.config.toxinidir)
 | 
					        return _poetry.Factory().create_poetry(venv.envconfig.config.toxinidir)
 | 
				
			||||||
    # Support running the plugin when the current tox project does not use Poetry for its
 | 
					    # Support running the plugin when the current tox project does not use Poetry for its
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user