29 Commits
0.5.1 ... 0.6.1

Author SHA1 Message Date
0614913cc5 Merge pull request #34 from enpaul/enp/fix-unsafe
Fix unsafe dependency handling
2020-12-16 20:37:35 -05:00
f116ffefa2 Fix special handling of unsafe dependencies as primary dependencies 2020-12-16 20:31:41 -05:00
2ce97a5349 Bump patch version 2020-12-16 19:16:38 -05:00
e77c859355 Add additional logging to dependency processing functionality
Hopefully this will help with dependency resolution errors in the future
2020-12-16 19:14:03 -05:00
c1d1ac2de1 Update handling of poetrys unsafe dependencies to avoid keyerror
Fixes #33
2020-12-16 19:01:20 -05:00
c5c5261a80 Update transient processing to more narrowly scope error catching 2020-12-16 18:47:27 -05:00
ff344c2b4b Merge pull request #32 from enpaul/enp/docs
Beta > Alpha
2020-12-05 18:37:24 -05:00
a7d9b25b62 Fix broken links in readme 2020-12-05 18:31:44 -05:00
8356d52c4f Update project project status from alpha to beta 🎉 2020-12-05 18:31:44 -05:00
1941a103d3 Update contributor, devel, and roadmap documentation 2020-12-05 18:31:44 -05:00
0ad5fb7219 Overhaul basic usage documentation to improve clarity
Add intra document links
Update to document new/updated features
Add badge for downloads per month
Update badge order
2020-12-05 18:30:09 -05:00
ea518d1201 Reorder TOC
Add garbage to email to (hopefully) avoid scraping
2020-12-05 18:30:09 -05:00
03f46d34f3 Rewrite usage reference documentation to improve clarity
Add more details to error documentation
Update error and option documentation to be referenceable via slugs
Add docs for missing --require-poetry option
Add more crosslinks to assit with navigation
2020-12-05 18:30:09 -05:00
88ca772111 Merge pull request #31 from enpaul/enp/force-fail
Add option to support forcing tox failure when Poetry is not available
2020-12-05 15:11:31 -05:00
66c1925679 Add poetry requirement to local CI to ensure proper installation 2020-12-05 15:01:39 -05:00
99edc1c24e Add runtime option for forcing error if poetry is not found 2020-12-05 15:01:39 -05:00
39439f132a Merge pull request #30 from enpaul/enp/cleanup
Misc fixes ahead of push to beta classification
2020-12-05 14:19:18 -05:00
52aaeba93c Overhaul CI to improve resilance and efficiency
Add caching for pip and poetry downloads to reduce runtime
Add pinned pip version
Add poetry installation of local project
Remove bare pip install for local project installation
2020-12-05 14:12:50 -05:00
db761d49c1 Add poetry extra install to tox config to support CI 2020-12-05 12:36:09 -05:00
5a23c05f17 Add internally proxied poetry module to support runtime in non-Poetry envs
Add the _poetry submodule to support importing Poetry internals at runtime rather
than import time. This allows the plugin to be run, and either skipped or errored,
without crashing tox
2020-12-04 22:16:36 -05:00
604e60d567 Bump feature version 2020-12-04 17:57:44 -05:00
872f6b0892 Update poetry dependency to be installed as optional extra
When running 'poetry remove tox-poetry-installer' in the same env as
poetry is installed to, poetry will uninstall itself. This is, obviously,
not ideal.

This change makes poetry an optional dependency so that the plugin can be
installed (and uninstalled) alongside poetry in the same env without
breaking the poetry installation. The intention is that the plugin can be
installed with the 'poetry' extra when being installed to an isolated environment
where poetry is not otherwise available.

This is a mitigation of Issue #2 as an alternative to vendorization of the enitre
poetry project 😬
2020-12-04 17:57:38 -05:00
afad7663f0 Fix clean target not deleting pycache 2020-12-04 17:22:52 -05:00
01635c50c7 Update logging integration to improve standardization
Standardize language in logging messages
Move system version to constants

Fixes #3
2020-12-04 17:22:41 -05:00
bd8124dcbf Move non-hook function out of hooks submodule 2020-12-04 16:09:40 -05:00
4de5fea0e3 Merge pull request #29 from enpaul/enp/fix-platform
Fix dependency installation on incompatible platforms and with invalid python versions
2020-11-26 15:08:12 -05:00
33119df752 Add missing tests __init__ file
I'm tired of fighting this. Every tool under the sun wants the tests to
be an importable module, which doesn't make much sense to me, but it's
whatever. I'm just adding this because pylint, mypy, and others get
angry when I try to use them on just a directory without globbing
2020-11-26 15:01:59 -05:00
498cb4a3d2 Bump patch version 2020-11-26 14:54:34 -05:00
0a363d1848 Fix platform and py version compatibility errors
Add check for compatible python versions during dependency determination
Add check for compatible python platforms during dependency determination
Add verbosity2 logging messages for dependency determination
2020-11-26 14:54:34 -05:00
14 changed files with 744 additions and 364 deletions

72
.github/scripts/setup-env.sh vendored Executable file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/env bash
#
# Environment setup script for the local project. Intended to be used with automation
# to create a repeatable local environment for tests to be run in. The python env
# this script creates can be accessed at the location defined by the CI_VENV variable
# below.
set -e;
# ##### Prereqs #####
#
# Set global vars for usage in the script, create the cache directory so we can rely
# on that existing, then dump some diagnostic info for later reference.
#
CI_VENV=$HOME/ci;
CI_CACHE=$HOME/.cache;
CI_CACHE_GET_POETRY="$CI_CACHE/get-poetry.py";
CI_POETRY=$HOME/.poetry/bin/poetry;
CI_VENV_PIP="$CI_VENV/bin/pip";
CI_VENV_PIP_VERSION=19.3.1;
CI_VENV_TOX="$CI_VENV/bin/tox";
mkdir --parents "$CI_CACHE";
command -v python;
python --version;
# ##### Install Poetry #####
#
# Download the poetry install script to the cache directory and then install poetry.
# After dump the poetry version for later reference.
#
curl https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py \
--output "$CI_CACHE_GET_POETRY" \
--silent \
--show-error \
--location;
python "$CI_CACHE_GET_POETRY" --yes 1>/dev/null;
python "$CI_POETRY" --version --no-ansi;
# ##### Setup Runtime Venv #####
#
# Create a virtual environment for poetry to use, upgrade pip in that venv to a pinned
# version, then install the current project to the venv.
#
# Note 1: Poetry, Tox, and this project plugin all use pip under the hood for package
# installation. This means that even though we are creating up to eight venvs
# during a given CI run they all share the same download cache.
# Note 2: The "VIRTUAL_ENV=$CI_VENV" prefix on the poetry commands below sets the venv
# that poetry will use for operations. There is no CLI flag for poetry that
# directs it to use a given environment, but if it finds itself in an existing
# environment it will use it and skip environment creation.
#
python -m venv "$CI_VENV";
$CI_VENV_PIP install "pip==$CI_VENV_PIP_VERSION" \
--upgrade \
--quiet;
VIRTUAL_ENV=$CI_VENV "$CI_POETRY" install \
--extras poetry \
--quiet \
--no-ansi \
&>/dev/null;
# ##### Print Debug Info #####
#
# Print the pip and tox versions (which will include registered plugins)
#
$CI_VENV_PIP --version;
echo "tox $($CI_VENV_TOX --version)";

View File

@@ -20,24 +20,53 @@ jobs:
- version: 3.9
toxenv: py39
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python.version }}
- name: Checkout
uses: actions/checkout@v2
- name: Setup:python${{ matrix.python.version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python.version }}
- name: Install project
run: pip install .
- name: Run tests via ${{ matrix.python.toxenv }}
run: tox -e ${{ matrix.python.toxenv }}
- name: Setup:cache
uses: actions/cache@v2
with:
path: |
~/.cache/pip
~/.cache/pypoetry/cache
~/.poetry
# Including the hashed poetry.lock in the cache slug ensures that the cache
# will be invalidated, and thus all packages will be redownloaded, if the
# lockfile is updated
key: ${{ runner.os }}-${{ matrix.python.toxenv }}-${{ hashFiles('**/poetry.lock') }}
- name: Setup:env
run: .github/scripts/setup-env.sh
- name: Run:${{ matrix.python.toxenv }}
run: $HOME/ci/bin/tox \
-e ${{ matrix.python.toxenv }} \
--require-poetry
Check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Checkout
uses: actions/checkout@v2
- name: Setup:python3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install project
run: pip install .
- name: Run meta checks
run: tox -e static -e static-tests -e security
- name: Setup:cache
uses: actions/cache@v2
with:
path: |
~/.cache/pip
~/.cache/pypoetry/cache
~/.poetry
# Hardcoded 'py38' slug here lets this cache piggyback on the 'py38' cache
# that is generated for the tests above
key: ${{ runner.os }}-py38-${{ hashFiles('**/poetry.lock') }}
- name: Setup:env
run: .github/scripts/setup-env.sh
- name: Run:static
run: $HOME/ci/bin/tox -e static --require-poetry
- name: Run:static-tests
run: $HOME/ci/bin/tox -e static-tests --require-poetry
- name: Run:security
run: $HOME/ci/bin/tox -e security --require-poetry

View File

@@ -19,7 +19,7 @@ clean-py:
rm --recursive --force ./dist
rm --recursive --force ./build
rm --recursive --force ./*.egg-info
rm --recursive --force __pycache__/
rm --recursive --force ./**/__pycache__/
clean: clean-tox clean-py; ## Clean temp build/cache files and directories

557
README.md
View File

@@ -3,24 +3,26 @@
A plugin for [Tox](https://tox.readthedocs.io/en/latest/) that allows test environment
dependencies to be installed using [Poetry](https://python-poetry.org/) from its lockfile.
⚠️ **This project is alpha software and should not be used in production environments** ⚠️
⚠️ **This project is beta software and is under active development** ⚠️
[![ci-status](https://github.com/enpaul/tox-poetry-installer/workflows/CI/badge.svg?event=push)](https://github.com/enpaul/tox-poetry-installer/actions)
[![license](https://img.shields.io/pypi/l/tox-poetry-installer)](https://opensource.org/licenses/MIT)
[![pypi-version](https://img.shields.io/pypi/v/tox-poetry-installer)](https://pypi.org/project/tox-poetry-installer/)
[![pypi-downloads](https://img.shields.io/pypi/dm/tox-poetry-installer)](https://libraries.io/pypi/tox-poetry-installer)
[![license](https://img.shields.io/pypi/l/tox-poetry-installer)](https://opensource.org/licenses/MIT)
[![python-versions](https://img.shields.io/pypi/pyversions/tox-poetry-installer)](https://www.python.org)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
**Documentation**
* [Installation](#installation)
* [Quick Start](#quick-start)
* [Reference and Usage](#reference-and-usage)
* [Config Option Reference](#config-option-reference)
* [Error Reference](#error-reference)
* [Example Config](#example-config)
* [Known Drawbacks and Problems](#known-drawbacks-and-problems)
* [Why would I use this?](#why-would-i-use-this) (What problems does this solve?)
* [Introduction](#introduction)
* [Install](#install)
* [Quick Start](#quick-start)
* [Why would I use this?](#why-would-i-use-this) (What problems does this solve?)
* [Reference](#reference)
* [Configuration Options](#configuration-options)
* [Command-line Arguments](#command-line-arguments)
* [Errors](#errors)
* [Advanced Usage](#advanced-usage)
* [Developing](#developing)
* [Contributing](#contributing)
* [Roadmap](#roadmap)
@@ -30,49 +32,95 @@ dependencies to be installed using [Poetry](https://python-poetry.org/) from its
Related resources:
* [Poetry Python Project Manager](https://python-poetry.org/)
* [Tox Automation Project](https://tox.readthedocs.io/en/latest/)
* [Poetry Dev-Dependencies Tox Plugin](https://github.com/sinoroc/tox-poetry-dev-dependencies)
* [Poetry Tox Plugin](https://github.com/tkukushkin/tox-poetry)
* [Other Tox plugins](https://tox.readthedocs.io/en/latest/plugins.html)
Similar projects:
* [Poetry Dev-Dependencies Tox Plugin](https://github.com/sinoroc/tox-poetry-dev-dependencies)
* [Poetry Tox Plugin](https://github.com/tkukushkin/tox-poetry)
## Installation
Add the plugin as a development dependency of a Poetry project:
## Introduction
```
~ $: poetry add tox-poetry-installer --dev
This is a plugin to unify two great projects in the Python ecosystem: the
[Tox](https://tox.readthedocs.io/en/latest/) automation project and the
[Poetry](https://python-poetry.org) project/dependency manager. Specifically it allows
the repeatable dependency resolution and installation tools that Poetry uses to benefit
the isolated environments that Tox uses to run automated tests. The motivation to write
this plugin came from a need for a single source of truth for the versions of all
packages that should be installed to an environment.
When in use this plugin will allow a Tox environment to install its required
dependencies using the versions specified in the Poetry lockfile. This eliminates
needing to specify package versions in multiple places as well as ensures that the Tox
environment has the exact same versions of a given package as the Poetry environment.
This reduces (or hopefully eliminates) hard to debug problems caused by subtle
differences in the dependency graph of the active development environment (the one managed
by Poetry) and the automated test environment(s) created by Tox.
To learn more about the problems this plugin aims to solve jump ahead to
[What problems does this solve?](#why-would-i-use-this).
Otherwise keep reading to get started.
### Install
The recommended way to install the plugin is to add it to a project's `pyproject.toml`
and lockfile using Poetry:
```bash
poetry add tox-poetry-installer[poetry] --dev
```
Confirm that the plugin is installed, and Tox recognizes it, by checking the Tox version:
**WARNING:** The below installation methods are vulnerable to the
[transient dependency issues this plugin aims to avoid](#why-would-i-use-this). It is
always recommended to install dependencies using Poetry whenever possible.
The plugin can also be installed with pip directly, though it is recommended to always
install to a virtual environment and pin to a specific version:
```bash
source my-venv/bi/activate
pip install tox-poetry-installer[poetry] == 0.6.0
```
The plugin can also be installed using the Tox
[`requires`]((https://tox.readthedocs.io/en/latest/config.html#conf-requires))
configuration option. Note however that dependencies installed via the `requires` option
are not handled by the plugin and will be installed the same way as a `pip install ...`
above. For this reason it is also recommended to always pin to a specific version when
using this installation method:
```ini
# tox.ini
[tox]
requires
tox-poetry-installer[poetry] == 0.6.0
```
Check that the plugin is registered by checking the Tox version:
```
~ $: poetry run tox --version
3.20.0 imported from .venv/lib64/python3.8/site-packages/tox/__init__.py
registered plugins:
tox-poetry-installer-0.5.0 at .venv/lib64/python3.8/site-packages/tox_poetry_installer.py
tox-poetry-installer-0.6.0 at .venv/lib64/python3.8/site-packages/tox_poetry_installer.py
```
If using Pip, ensure that the plugin is installed to the same environment as Tox:
**NOTE:** Installing the `tox-poetry-installer[poetry]` extra will add the `poetry`
package as a managed environment dependency which can cause problems when the Poetry
installation is externally managed (such as in a CI or container environment). See
[Advanced Usage](#installing-alongside-an-existing-poetry-installation) for more
information on this use case.
```
# Calling the virtualenv's 'pip' binary directly will cause pip to install to that virtualenv
~ $: /path/to/my/automation/virtualenv/bin/pip install tox
~ $: /path/to/my/automation/virtualenv/bin/pip install tox-poetry-installer
```
### Quick Start
**Note:** While it is possible to install this plugin using Tox's
[`requires`](https://tox.readthedocs.io/en/latest/config.html#conf-requires)
configuration option, it is not recommended. Dependencies from the `requires` option are
installed using the default Tox installation backend which opens up the
[possibility of transient dependency problems](#why-would-i-use-this) in your automation
environment.
Before making any changes to `tox.ini` the project is already benefiting from having
the plugin installed: all dependencies of the root project package are installed using
the Poetry backend to all Tox environments that install the root package without any
configuration changes.
## Quick Start
To add dependencies from the lockfile to a Tox environment, add the option `locked_deps`
to the environment configuration and list names of dependencies (with no version
specifier) under it:
To add dependencies from the lockfile to a Tox environment, add the option
[`locked_deps`](#locked_deps) to the environment configuration and list names of
dependencies (with no version specifier) under it:
```ini
[testenv]
@@ -84,9 +132,9 @@ locked_deps =
commands = ...
```
The standard `deps` option can be used in parallel with the `locked_deps` option to
install unlocked dependencies (dependencies not in the lockfile) alongside locked
dependencies:
The standard [`deps`](https://tox.readthedocs.io/en/latest/config.html#conf-deps) option
can be used in parallel with the `locked_deps` option to install unlocked dependencies
(dependencies not in the lockfile) alongside locked dependencies:
```ini
[testenv]
@@ -102,170 +150,37 @@ commands = ...
```
Alternatively, to quickly install all Poetry dev-dependencies to a Tox environment, add the
`install_dev_deps = true` option to the environment configuration.
**Note:** Regardless of the settings outlined above, all dependencies of the project package (the
one Tox is testing) will always be installed from the lockfile.
## Reference and Usage
### Config Option Reference
All options listed below are Tox environment options and can be applied to one or more
environment sections of the `tox.ini` file. They cannot be applied to the global Tox
configuration section.
**NOTE:** Environment settings applied to the main `testenv` environment will be
inherited by child environments (i.e. `testenv:foo`) unless they are explicitly
overridden by the child environment's configuration.
| Option | Type | Default | Usage |
|:----------------------|:----------------|:--------|:-----------------------------------------------|
| `locked_deps` | Multi-line list | `[]` | Names of packages in the Poetry lockfile to install to the Tox environment. All dependencies specified here (and their dependencies) will be installed to the Tox environment using the version the Poetry lockfile specifies for them. |
| `require_locked_deps` | Bool | `false` | Indicates whether the environment should allow unlocked dependencies (dependencies not in the Poetry lockfile) to be installed alongside locked dependencies. If `true` then installation of unlocked dependencies will be blocked and an error will be raised if the `deps` option specifies any values. |
| `install_dev_deps` | Bool | `false` | Indicates whether all Poetry development dependencies should be installed to the environment. Provides a quick and easy way to install all dev-dependencies without needing to specify them individually. |
### Error Reference
* `LockedDepVersionConflictError` - Indicates that a locked dependency included a PEP-508 version
specifier (i.e. `pytest >=6.0, <6.1`). Locked dependencies always take their version from the
Poetry lockfile so specifying a specific version for a locked dependency is not supported.
* `LockedDepNotFoundError` - Indicates that a locked dependency could not be found in the Poetry
lockfile. This can be solved by [adding the dependency using Poetry](https://python-poetry.org/docs/cli/#add).
* `ExtraNotFoundError` - Indicates that the Tox `extras` option specified a project extra that
Poetry does not know about. This may be due to a misconfigured `pyproject.toml` or out of date
lockfile.
* `LockedDepsRequiredError` - Indicates that an environment with `require_locked_deps = true` also
specified unlocked dependencies using Tox's `deps` option. This can be solved by either setting
`require_locked_deps = false` (the default) or removing the `deps` option from the environment
configuration.
### Example Config
[`install_dev_deps`](#install_dev_deps) option to the environment configuration:
```ini
[tox]
envlist = py, foo, bar, baz
isolated_build = true
# The base testenv will always use locked dependencies and only ever installs the project package
# (and its dependencies) and the two pytest dependencies listed below
[testenv]
description = Some very cool tests
require_locked_deps = true
locked_deps =
pytest
pytest-cov
commands = ...
# This environment also requires locked dependencies, but the "skip_install" setting means that
# the project dependencies will not be installed to the environment from the lockfile
[testenv:foo]
description = FOObarbaz
skip_install = true
require_locked_deps = true
locked_deps =
requests
toml
ruamel.yaml
commands = ...
# This environment allows unlocked dependencies to be installed ad-hoc. Below, the "mypy" and
# "pylint" dependencies (and their dependencies) will be installed from the Poetry lockfile but the
# "black" dependency will be installed using the default Tox backend. Note, this environment does
# not specify "require_locked_deps = true" to allow the unlocked "black" dependency without raising
# an error.
[testenv:bar]
description = fooBARbaz
locked_deps =
mypy
pylint
deps =
black
commands = ...
# This environment requires locked dependencies but does not specify any. Instead it specifies the
# "install_dev_deps = true" option which will cause all of the Poetry dev-dependencies to be
# installed from the lockfile.
[testenv:baz]
description = foobarBAZ
install_dev_deps = true
require_locked_deps = true
commands = ...
```
See the [Reference](#reference) section for more details on available
configuration options and the [Advanced Usage](#advanced-usage) section for some
unusual use cases.
## Known Drawbacks and Problems
* The following `tox.ini` configuration options have no effect on the dependencies installed from
the Poetry lockfile (note that they will still affect unlocked dependencies):
* [`install_command`](https://tox.readthedocs.io/en/latest/config.html#conf-install_command)
* [`pip_pre`](https://tox.readthedocs.io/en/latest/config.html#conf-pip_pre)
* [`downloadcache`](https://tox.readthedocs.io/en/latest/config.html#conf-downloadcache) (deprecated)
* [`download`](https://tox.readthedocs.io/en/latest/config.html#conf-download)
* [`indexserver`](https://tox.readthedocs.io/en/latest/config.html#conf-indexserver)
* [`usedevelop`](https://tox.readthedocs.io/en/latest/config.html#conf-indexserver)
* Tox will not automatically detect changes to the locked dependencies and so
environments will not be automatically rebuilt when locked dependencies are changed.
When changing the locked dependencies (or their versions) the environments will need to
be manually rebuilt using either the `-r`/`--recreate` CLI option or the
`recreate = true` option in `tox.ini`.
* There are a handful of packages that cannot be installed from the lockfile, whether as specific
dependencies or as transient dependencies (dependencies of dependencies). This is due to
[an ongoing discussion in the Poetry project](https://github.com/python-poetry/poetry/issues/1584);
the list of dependencies that cannot be installed from the lockfile can be found
[here](https://github.com/python-poetry/poetry/blob/cc8f59a31567f806be868aba880ae0642d49b74e/poetry/puzzle/provider.py#L55).
This plugin will skip these dependencies entirely, but log a warning when they are encountered.
## Why would I use this?
**Introduction**
The lockfile is a file generated by a package manager for a project that records what
dependencies are installed, the versions of those dependencies, and any additional metadata that
the package manager needs to recreate the local project environment. This allows developers
to have confidence that a bug they are encountering that may be caused by one of their
dependencies will be reproducible on another device. In addition, installing a project
environment from a lockfile gives confidence that automated systems running tests or performing
builds are using the same environment as a developer.
[Poetry](https://python-poetry.org/) is a project dependency manager for Python projects, and
so it creates and manages a lockfile so that its users can benefit from all the features
described above. [Tox](https://tox.readthedocs.io/en/latest/#what-is-tox) is an automation tool
that allows Python developers to run tests suites, perform builds, and automate tasks within
self-contained [Python virtual environments](https://docs.python.org/3/tutorial/venv.html).
To make these environments useful Tox supports installing dependencies in each environment.
However, since these environments are created on the fly and Tox does not maintain a lockfile,
there can be subtle differences between the dependencies a developer is using and the
dependencies Tox uses.
This is where this plugin comes into play.
By default Tox uses [Pip](https://docs.python.org/3/tutorial/venv.html) to install the
PEP-508 compliant dependencies to a test environment. This plugin extends the default
Tox dependency installation behavior to support installing dependencies using a Poetry-based
installation method that makes use of the dependency metadata from Poetry's lockfile.
### Why would I use this?
**The Problem**
By default Tox uses Pip to install the [PEP-508](https://www.python.org/dev/peps/pep-0508/)
compliant dependencies to a test environment. This plugin extends the default Tox
dependency installation behavior to support installing dependencies using a Poetry-based
installation method that makes use of the dependency metadata from Poetry's lockfile.
Environment dependencies for a Tox environment are usually specified in PEP-508 format, like
the below example:
```ini
# from tox.ini
...
[testenv]
description = Some very cool tests
deps =
foo == 1.2.3
bar >=1.3,<2.0
baz
...
```
Let's assume these dependencies are also useful during development, so they can be added to the
@@ -319,9 +234,6 @@ less stable than the one presented above because it does not specify any version
dependencies:
```ini
# from tox.ini
...
[testenv]
description = Some very cool tests
require_locked_deps = true
@@ -329,22 +241,247 @@ locked_deps =
foo
bar
baz
...
```
However with the `tox-poetry-installer` plugin installed the `require_locked_deps = true`
setting means that Tox will install these dependencies from the Poetry lockfile so that the
version installed to the Tox environment exactly matches the version Poetry is managing. When
`poetry update` updates the lockfile with new versions of these dependencies, Tox will
automatically install these new versions without needing any changes to the configuration.
However with the `tox-poetry-installer` plugin installed Tox will install these
dependencies from the Poetry lockfile so that the version installed to the Tox
environment exactly matches the version Poetry is managing. When `poetry update` updates
the lockfile with new versions of these dependencies, Tox will automatically install
these new versions without needing any changes to the configuration.
## Reference
### Configuration Options
All options listed below are Tox environment options and can be applied to one or more
environment sections of the `tox.ini` file. They cannot be applied to the global Tox
configuration section.
**NOTE:** Environment settings applied to the main `testenv` environment will be
inherited by child environments (i.e. `testenv:foo`) unless they are explicitly
overridden by the child environment's configuration.
#### `locked_deps`
* **Type:** multi-line list
* **Default:** `[]`
Names of packages in the Poetry lockfile to install to the Tox environment. All
dependencies specified here will be installed to the Tox environment using the details
given by the Poetry lockfile.
#### `require_locked_deps`
* **Type:** boolean
* **Default:** `false`
Whether the environment should allow unlocked dependencies (dependencies not in the
Poetry lockfile) to be installed alongside locked dependencies. If `true` then an error
will be raised if the environment specifies unlocked dependencies to install and the
plugin will block any other plugins from using the
[`tox_testenv_install_deps`](https://tox.readthedocs.io/en/latest/plugins.html#tox.hookspecs.tox_testenv_install_deps)
hook.
#### `install_dev_deps`
* **Type:** boolean
* **Default:** `false`
Whether all Poetry dev-dependencies should be installed to the environment. If `true`
then all dependencies specified in the
[`dev-dependencies`](https://python-poetry.org/docs/pyproject/#dependencies-and-dev-dependencies)
section of `pyproject.toml` will be installed automatically.
### Command-line Arguments
All arguments listed below can be passed to the `tox` command to modify runtime behavior
of the plugin.
#### `--require-poetry`
Indicates that Poetry is expected to be available to Tox and, if it is not, then the Tox
run should fail. If provided and the `poetry` package is not installed to the same
environment as the `tox` package then Tox will fail.
**NOTE:** See [Advanced Usage](#installing-alongside-an-existing-poetry-installation)
for more information.
### Errors
If the plugin encounters an error while processing a Tox environment then it will mark
the environment as failed and set the environment status to one of the values below:
**NOTE:** In addition to the reasons noted below, the plugin can encounter errors if the
Poetry lockfile is not up-to-date with `pyproject.toml`. To resynchronize the
lockfile with the `pyproject.toml` run one of
[`poetry update`](https://python-poetry.org/docs/cli/#update) or
[`poetry lock`](https://python-poetry.org/docs/cli/#lock)
#### Poetry Not Installed Error
* **Status value:** `PoetryNotInstalledError`
* **Cause:** Indicates that the `poetry` module could not be imported from the same
environment as the running `tox` module and the runtime flags specified
[`--require-poetry`](#--require-poetry).
* **Resolution options:**
* Install Poetry: ensure that `poetry` is installed to the same environment as `tox`.
* Skip running the plugin: remove the `--require-poetry` flag from the runtime options.
**NOTE:** See [Advanced Usage](#installing-alongside-an-existing-poetry-installation)
for more information.
#### Locked Dependency Version Conflict Error
* **Status value:** `LockedDepVersionConflictError`
* **Cause:** Indicates that a dependency specified in the [`locked_deps`](#locked_deps)
configuration option in `tox.ini` includes a
[PEP-508 version specifier](https://www.python.org/dev/peps/pep-0508/#grammar)
(i.e. `pytest >=6.0, <6.1`).
* **Resolution options:**
* Use the dependency version from the lockfile: remove any/all version specifiers
from the item in the `locked_deps` list in `tox.ini`.
* Do not install the dependency: remove the item from the `locked_deps` list in
`tox.ini`.
#### Locked Dependency Not Found Error
* **Status value:** `LockedDepNotFoundError`
* **Cause:** Indicates that a dependency specified in the [`locked_deps`](#locked_deps)
configuration option in `tox.ini` could not be found in the Poetry lockfile.
* **Resolution options:**
* Add the dependency to the lockfile: run
[`poetry add <dependency>`](https://python-poetry.org/docs/cli/#add).
* Do not install the dependency: remove the item from the `locked_deps` list in
`tox.ini`.
#### Extra Not Found Error
* **Status value:** `ExtraNotFoundError`
* **Cause:** Indicates that the [`extras`](https://tox.readthedocs.io/en/latest/config.html#conf-extras)
configuration option specified a setuptools extra that is not configured by Poetry in
`pyproject.toml`
* **Resolution options:**
* Configure the extra: add a section for the named extra to the
[`extras`](https://python-poetry.org/docs/pyproject/#extras) section of
`pyproject.toml` and optionally assign dependencies to the named extra using the
[`--optional`](https://python-poetry.org/docs/cli/#options_3) dependency setting.
* Remove the extra: remove the item from the `extras` list in `tox.ini`.
#### Locked Dependencies Required Error
* **Status value:** `LockedDepsRequiredError`
* **Cause:** Indicates that an environment with the [`require_locked_deps`](#require_locked_deps)
configuration option also specified unlocked dependencies using
[`deps`](https://tox.readthedocs.io/en/latest/config.html#conf-deps) option in
`tox.ini`.
* **Resolution options:**
* Remove all unlocked dependencies: remove the `deps` configuration option in
`tox.ini`.
* Allow unlocked dependencies: remove the `require_locked_deps` configuration option
in `tox.ini` or explicitly set `require_locked_deps = false`.
### Advanced Usage
#### Unsupported Tox configuration options
The `tox.ini` configuration options listed below have no effect on the dependencies
installed by this plugin the Poetry lockfile. Note that these settings will still be
applied by the default Tox installation backend when installing unlocked dependencies
using the built-in `deps` option.
* [`install_command`](https://tox.readthedocs.io/en/latest/config.html#conf-install_command)
* [`pip_pre`](https://tox.readthedocs.io/en/latest/config.html#conf-pip_pre)
* [`download`](https://tox.readthedocs.io/en/latest/config.html#conf-download)
* [`indexserver`](https://tox.readthedocs.io/en/latest/config.html#conf-indexserver)
* [`usedevelop`](https://tox.readthedocs.io/en/latest/config.html#conf-indexserver)
All of these options are obsoleted by using the Poetry backend. If a given package
installs successfully using Poetry (using either `poetry add <package>` or
`poetry install`) then the required configuration options are already properly set in
the Poetry configuration and the plugin will automatically use the same settings when
installing the package.
#### Reinstalling locked dependencies to a Tox environment
Updating the `poetry.lock` file will not automatically cause Tox to install the updated
lockfile specifications to the Tox environments that specify them.
The Tox environment(s) with updated locked dependencies must be deleted and recreated
using the [`--recreate`](https://tox.readthedocs.io/en/latest/config.html#cmdoption-tox-r)
runtime flag. Alternatively Tox can be configured to always recreate an environment by
setting the [`recreate`](https://tox.readthedocs.io/en/latest/config.html#conf-recreate)
option in `tox.ini`.
#### Installing Poetry's unsafe dependencies
There are several packages that cannot be installed from the lockfile because they are
excluded by Poetry itself. As a result these packages cannot be installed by this plugin
either as environment dependencies (passed directly to [`locked_deps`](#locked_deps)) or
as transient dependencies (a dependency of a locked dependency).
As of [Poetry-1.1.4](https://github.com/python-poetry/poetry/releases/tag/1.1.4) there
are four packages classified as "unsafe" by Poetry and excluded from the lockfile:
* `setuptools`
* `distribute`
* `pip`
* `wheel`
When one of these packages is encountered by the plugin a warning will be logged and
_**the package will not be installed to the environment**_. If the unsafe package
is required for the environment then it will need to be specified as an unlocked
dependency using the [`deps`](https://tox.readthedocs.io/en/latest/config.html#conf-deps)
configuration option in `tox.ini`, ideally with an exact pinned version.
* The set of packages excluded from the Poetry lockfile can be found in
[`poetry.puzzle.provider.Provider.UNSAFE_DEPENDENCIES`](https://github.com/python-poetry/poetry/blob/master/poetry/puzzle/provider.py)
* There is an ongoing discussion of Poetry's handling of these packages at
[python-poetry/poetry#1584](https://github.com/python-poetry/poetry/issues/1584)
#### Installing alongside an existing Poetry installation
The plugin specifies the `poetry` package as an optional dependency to support an
externally managed Poetry installation such as in a container or CI environment. This
gives greater flexibility when using Poetry arguments like `--no-root`, `--no-dev`, or
`--remove-untracked` which can cause Poetry to uninstall itself if Poetry is specified
as a dependency of one of the packages it is managing (like this plugin).
To have the plugin use the externally-managed Poetry package simply do not install the
`poetry` extra when installing this plugin:
```bash
# Installing Poetry as a dependency with the plugin
poetry add tox-poetry-installer[poetry]
# Relying on an externally managed Poetry installation
poetry add tox-poetry-installer
```
Note that Poetry is an optional dependency to support this use case _only_: Poetry must
be installed to the same environment as Tox for the plugin to function. To check that
the local environment has all of the required modules in scope run the below command:
```bash
python -c '\
import tox;\
import tox_poetry_installer;\
from poetry.poetry import Poetry;\
'
```
**NOTE:** To force Tox to fail if Poetry is not installed, run the `tox` command with
the [`--require-poetry`](#--require-poetry) option.
## Developing
This project requires a developer to have Poetry version 1.0+ installed on their workstation, see
This project requires Poetry version 1.0+ on the development workstation, see
the [installation instructions here](https://python-poetry.org/docs/#installation).
Local environment setup instructions:
```bash
# Clone the repository...
# ...over HTTPS
@@ -354,7 +491,7 @@ git clone git@github.com:enpaul/tox-poetry-installer.git
# Create a the local project virtual environment and install dependencies
cd tox-poetry-installer
poetry install
poetry install -E poetry
# Install pre-commit hooks
poetry run pre-commit install
@@ -363,11 +500,18 @@ poetry run pre-commit install
poetry run tox
```
**NOTE:** Because the pre-commit hooks require dependencies in the Poetry environment it
is recommend to [launch an environment shell](https://python-poetry.org/docs/cli/#shell)
when developing the project. Alternatively, many `git` commands will need to be run from
outside of the environment shell by prefacing the command with
[`poetry run`](https://python-poetry.org/docs/cli/#run).
## Contributing
All project contributors and participants are expected to adhere to the
[Contributor Covenant Code of Conduct, Version 2](CODE_OF_CONDUCT.md).
[Contributor Covenant Code of Conduct, v2](CODE_OF_CONDUCT.md)
([external link](https://www.contributor-covenant.org/version/2/0/code_of_conduct/)).
The `devel` branch has the latest (potentially unstable) changes. The
[tagged versions](https://github.com/enpaul/tox-poetry-installer/releases) correspond to the
@@ -376,7 +520,7 @@ releases on PyPI.
* To report a bug, request a feature, or ask for assistance, please
[open an issue on the Github repository](https://github.com/enpaul/tox-poetry-installer/issues/new).
* To report a security concern or code of conduct violation, please contact the project author
directly at **ethan dot paul at enp dot one**.
directly at **me [at] enp dot one**.
* To submit an update, please
[fork the repository](https://docs.github.com/en/enterprise/2.20/user/github/getting-started-with-github/fork-a-repo)
and
@@ -385,10 +529,10 @@ releases on PyPI.
## Roadmap
This project is under active development and is classified as alpha software, not yet ready
for usage in production environments.
This project is under active development and is classified as beta software, ready for
production environments on a provisional basis only.
* Beta classification will be assigned when the initial feature set is finalized
* Beta classification was assigned with [v0.6.0](https://github.com/enpaul/tox-poetry-installer/releases/tag/0.6.0)
* Stable classification will be assigned when the test suite covers an acceptable number of
use cases
@@ -400,24 +544,25 @@ for usage in production environments.
Tox configuration option ([#4](https://github.com/enpaul/tox-poetry-installer/issues/4))
- [X] Add per-environment Tox configuration option to fall back to default installation
backend.
- [ ] Add warnings when an unsupported Tox configuration option is detected while using the
Poetry backend. ([#5](https://github.com/enpaul/tox-poetry-installer/issues/5))
- [ ] ~Add warnings when an unsupported Tox configuration option is detected while using the
Poetry backend. ([#5](https://github.com/enpaul/tox-poetry-installer/issues/5))~
- [X] Add trivial tests to ensure the project metadata is consistent between the pyproject.toml
and the module constants.
- [X] Update to use [poetry-core](https://github.com/python-poetry/poetry-core) and
improve robustness of the Tox and Poetry module imports
to avoid potentially breaking API changes in upstream packages. ([#2](https://github.com/enpaul/tox-poetry-installer/issues/2))
- [ ] Find and implement a way to mitigate the [UNSAFE_DEPENDENCIES issue](https://github.com/python-poetry/poetry/issues/1584) in Poetry.
([#6](https://github.com/enpaul/tox-poetry-installer/issues/6))
- [ ] Fix logging to make proper use of Tox's logging reporter infrastructure ([#3](https://github.com/enpaul/tox-poetry-installer/issues/3))
- [ ] ~Find and implement a way to mitigate the [UNSAFE_DEPENDENCIES issue](https://github.com/python-poetry/poetry/issues/1584) in Poetry.
([#6](https://github.com/enpaul/tox-poetry-installer/issues/6))~
- [X] Fix logging to make proper use of Tox's logging reporter infrastructure ([#3](https://github.com/enpaul/tox-poetry-installer/issues/3))
- [X] Add configuration option for installing all dev-dependencies to a testenv ([#14](https://github.com/enpaul/tox-poetry-installer/issues/14))
### Path to Stable
Everything in Beta plus...
- [ ] Add tests for each feature version of Tox between 2.3 and 3.20
- [ ] Add tests for Python-3.6, 3.7, and 3.8
- [ ] Add comprehensive unit tests
- [ ] Add tests for each feature version of Tox between 3.0 and 3.20
- [ ] Add tests for Python-3.6, 3.7, 3.8, and 3.9
- [X] Add Github Actions based CI
- [ ] Add CI for CPython, PyPy, and Conda
- [ ] Add CI for Linux and Windows

106
poetry.lock generated
View File

@@ -8,8 +8,8 @@ python-versions = "*"
[[package]]
name = "appnope"
version = "0.1.0"
description = "Disable App Nap on OS X 10.9"
version = "0.1.2"
description = "Disable App Nap on macOS >= 10.9"
category = "dev"
optional = false
python-versions = "*"
@@ -123,7 +123,7 @@ name = "cachecontrol"
version = "0.12.6"
description = "httplib2 caching for requests"
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[package.dependencies]
@@ -148,7 +148,7 @@ name = "cachy"
version = "0.3.0"
description = "Cachy provides a simple yet effective caching library."
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[package.extras]
@@ -169,7 +169,7 @@ name = "cffi"
version = "1.14.4"
description = "Foreign Function Interface for Python calling C code."
category = "main"
optional = false
optional = true
python-versions = "*"
[package.dependencies]
@@ -196,7 +196,7 @@ name = "cleo"
version = "0.8.1"
description = "Cleo allows you to create beautiful and testable command-line interfaces."
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[package.dependencies]
@@ -215,7 +215,7 @@ name = "clikit"
version = "0.6.2"
description = "CliKit is a group of utilities to build beautiful and testable command line interfaces."
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[package.dependencies]
@@ -247,7 +247,7 @@ name = "crashtest"
version = "0.3.1"
description = "Manage Python errors with ease"
category = "main"
optional = false
optional = true
python-versions = ">=3.6,<4.0"
[[package]]
@@ -255,7 +255,7 @@ name = "cryptography"
version = "3.2.1"
description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers."
category = "main"
optional = false
optional = true
python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*"
[package.dependencies]
@@ -263,11 +263,11 @@ cffi = ">=1.8,<1.11.3 || >1.11.3"
six = ">=1.4.1"
[package.extras]
docs = ["sphinx (>=1.6.5,<1.8.0 || >1.8.0,<3.1.0 || >3.1.0,<3.1.1 || >3.1.1)", "sphinx-rtd-theme"]
docs = ["sphinx (>=1.6.5,!=1.8.0,!=3.1.0,!=3.1.1)", "sphinx-rtd-theme"]
docstest = ["doc8", "pyenchant (>=1.6.11)", "twine (>=1.12.0)", "sphinxcontrib-spelling (>=4.0.1)"]
pep8test = ["black", "flake8", "flake8-import-order", "pep8-naming"]
ssh = ["bcrypt (>=3.1.5)"]
test = ["pytest (>=3.6.0,<3.9.0 || >3.9.0,<3.9.1 || >3.9.1,<3.9.2 || >3.9.2)", "pretend", "iso8601", "pytz", "hypothesis (>=1.11.4,<3.79.2 || >3.79.2)"]
test = ["pytest (>=3.6.0,!=3.9.0,!=3.9.1,!=3.9.2)", "pretend", "iso8601", "pytz", "hypothesis (>=1.11.4,!=3.79.2)"]
[[package]]
name = "dataclasses"
@@ -344,7 +344,7 @@ name = "html5lib"
version = "1.1"
description = "HTML parser based on the WHATWG HTML specification"
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[package.dependencies]
@@ -477,7 +477,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
parso = ">=0.7.0,<0.8.0"
[package.extras]
qa = ["flake8 (3.7.9)"]
qa = ["flake8 (==3.7.9)"]
testing = ["Django (<3.1)", "colorama", "docopt", "pytest (>=3.9.0,<5.0.0)"]
[[package]]
@@ -485,7 +485,7 @@ name = "jeepney"
version = "0.6.0"
description = "Low-level, pure Python DBus protocol wrapper."
category = "main"
optional = false
optional = true
python-versions = ">=3.6"
[package.extras]
@@ -496,7 +496,7 @@ name = "keyring"
version = "21.5.0"
description = "Store and access your passwords safely."
category = "main"
optional = false
optional = true
python-versions = ">=3.6"
[package.dependencies]
@@ -507,7 +507,7 @@ SecretStorage = {version = ">=3.2", markers = "sys_platform == \"linux\""}
[package.extras]
docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"]
testing = ["pytest (>=3.5,<3.7.3 || >3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "pytest-black (>=0.3.7)", "pytest-mypy"]
testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "pytest-black (>=0.3.7)", "pytest-mypy"]
[[package]]
name = "lazy-object-proxy"
@@ -522,7 +522,7 @@ name = "lockfile"
version = "0.12.2"
description = "Platform-independent file locking module"
category = "main"
optional = false
optional = true
python-versions = "*"
[[package]]
@@ -538,7 +538,7 @@ name = "msgpack"
version = "1.0.0"
description = "MessagePack (de)serializer."
category = "main"
optional = false
optional = true
python-versions = "*"
[[package]]
@@ -575,7 +575,7 @@ python-versions = "*"
[[package]]
name = "packaging"
version = "20.4"
version = "20.7"
description = "Core utilities for Python packages"
category = "main"
optional = false
@@ -583,7 +583,6 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[package.dependencies]
pyparsing = ">=2.0.2"
six = "*"
[[package]]
name = "parso"
@@ -601,7 +600,7 @@ name = "pastel"
version = "0.2.1"
description = "Bring colors to your terminal."
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
@@ -644,7 +643,7 @@ name = "pkginfo"
version = "1.6.1"
description = "Query metadatdata from sdists / bdists / installed packages."
category = "main"
optional = false
optional = true
python-versions = "*"
[package.extras]
@@ -669,7 +668,7 @@ name = "poetry"
version = "1.1.4"
description = "Python dependency management and packaging made easy."
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[package.dependencies]
@@ -764,7 +763,7 @@ name = "pycparser"
version = "2.20"
description = "C parser in Python"
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
@@ -780,7 +779,7 @@ name = "pylev"
version = "1.3.0"
description = "A pure Python Levenshtein implementation that's not freaking GPL'd."
category = "main"
optional = false
optional = true
python-versions = "*"
[[package]]
@@ -826,7 +825,7 @@ py = ">=1.8.2"
toml = "*"
[package.extras]
checkqa_mypy = ["mypy (0.780)"]
checkqa_mypy = ["mypy (==0.780)"]
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"]
[[package]]
@@ -842,14 +841,14 @@ coverage = ">=4.4"
pytest = ">=4.6"
[package.extras]
testing = ["fields", "hunter", "process-tests (2.0.2)", "six", "pytest-xdist", "virtualenv"]
testing = ["fields", "hunter", "process-tests (==2.0.2)", "six", "pytest-xdist", "virtualenv"]
[[package]]
name = "pywin32-ctypes"
version = "0.2.0"
description = ""
category = "main"
optional = false
optional = true
python-versions = "*"
[[package]]
@@ -895,14 +894,14 @@ urllib3 = ">=1.21.1,<1.27"
[package.extras]
security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"]
socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7)", "win-inet-pton"]
socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]
[[package]]
name = "requests-toolbelt"
version = "0.9.1"
description = "A utility belt for advanced users of python-requests"
category = "main"
optional = false
optional = true
python-versions = "*"
[package.dependencies]
@@ -950,7 +949,7 @@ name = "secretstorage"
version = "3.3.0"
description = "Python bindings to FreeDesktop.org Secret Service API"
category = "main"
optional = false
optional = true
python-versions = ">=3.6"
[package.dependencies]
@@ -962,7 +961,7 @@ name = "shellingham"
version = "1.3.2"
description = "Tool to Detect Surrounding Shell"
category = "main"
optional = false
optional = true
python-versions = "!=3.0,!=3.1,!=3.2,!=3.3,>=2.6"
[[package]]
@@ -983,7 +982,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
name = "stevedore"
version = "3.2.2"
version = "3.3.0"
description = "Manage dynamic plugins for Python applications"
category = "dev"
optional = false
@@ -1006,7 +1005,7 @@ name = "tomlkit"
version = "0.7.0"
description = "Style preserving TOML library"
category = "main"
optional = false
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[[package]]
@@ -1073,7 +1072,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
[package.extras]
brotli = ["brotlipy (>=0.6.0)"]
secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"]
socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"]
socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
[[package]]
name = "virtualenv"
@@ -1108,7 +1107,7 @@ name = "webencodings"
version = "0.5.1"
description = "Character encoding aliases for legacy web content"
category = "main"
optional = false
optional = true
python-versions = "*"
[[package]]
@@ -1129,12 +1128,15 @@ python-versions = ">=3.6"
[package.extras]
docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"]
testing = ["pytest (>=3.5,<3.7.3 || >3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"]
testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"]
[extras]
poetry = ["poetry"]
[metadata]
lock-version = "1.1"
python-versions = "^3.6.1"
content-hash = "8eea42cb6c60df03376bb264b444ccd0a63a211122edc6625284d57204295273"
content-hash = "a5ba6181fc3728d85a60b2e089b9afe2d5bf75f361526e6972d48a42e5075c32"
[metadata.files]
appdirs = [
@@ -1142,8 +1144,8 @@ appdirs = [
{file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"},
]
appnope = [
{file = "appnope-0.1.0-py2.py3-none-any.whl", hash = "sha256:5b26757dc6f79a3b7dc9fab95359328d5747fcb2409d331ea66d0272b90ab2a0"},
{file = "appnope-0.1.0.tar.gz", hash = "sha256:8b995ffe925347a2138d7ac0fe77155e4311a0ea6d6da4f5128fe4b3cbe5ed71"},
{file = "appnope-0.1.2-py2.py3-none-any.whl", hash = "sha256:93aa393e9d6c54c5cd570ccadd8edad61ea0c4b9ea7a01409020c9aa019eb442"},
{file = "appnope-0.1.2.tar.gz", hash = "sha256:dd83cd4b5b460958838f6eb3000c660b1f9caf2a5b1de4264e941512f603258a"},
]
"aspy.refactor-imports" = [
{file = "aspy.refactor_imports-2.1.1-py2.py3-none-any.whl", hash = "sha256:9df76bf19ef81620068b785a386740ab3c8939fcbdcebf20c4a4e0057230d782"},
@@ -1468,8 +1470,8 @@ nodeenv = [
{file = "nodeenv-1.5.0.tar.gz", hash = "sha256:ab45090ae383b716c4ef89e690c41ff8c2b257b85b309f01f3654df3d084bd7c"},
]
packaging = [
{file = "packaging-20.4-py2.py3-none-any.whl", hash = "sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181"},
{file = "packaging-20.4.tar.gz", hash = "sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8"},
{file = "packaging-20.7-py2.py3-none-any.whl", hash = "sha256:eb41423378682dadb7166144a4926e443093863024de508ca5c9737d6bc08376"},
{file = "packaging-20.7.tar.gz", hash = "sha256:05af3bb85d320377db281cf254ab050e1a7ebcbf5410685a9a407e18a1f81236"},
]
parso = [
{file = "parso-0.7.1-py2.py3-none-any.whl", hash = "sha256:97218d9159b2520ff45eb78028ba8b50d2bc61dcc062a9682666f2dc4bd331ea"},
@@ -1643,29 +1645,22 @@ requests-toolbelt = [
{file = "ruamel.yaml.clib-0.2.2-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:73b3d43e04cc4b228fa6fa5d796409ece6fcb53a6c270eb2048109cbcbc3b9c2"},
{file = "ruamel.yaml.clib-0.2.2-cp35-cp35m-macosx_10_6_intel.whl", hash = "sha256:53b9dd1abd70e257a6e32f934ebc482dac5edb8c93e23deb663eac724c30b026"},
{file = "ruamel.yaml.clib-0.2.2-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:839dd72545ef7ba78fd2aa1a5dd07b33696adf3e68fae7f31327161c1093001b"},
{file = "ruamel.yaml.clib-0.2.2-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:1236df55e0f73cd138c0eca074ee086136c3f16a97c2ac719032c050f7e0622f"},
{file = "ruamel.yaml.clib-0.2.2-cp35-cp35m-win32.whl", hash = "sha256:b1e981fe1aff1fd11627f531524826a4dcc1f26c726235a52fcb62ded27d150f"},
{file = "ruamel.yaml.clib-0.2.2-cp35-cp35m-win_amd64.whl", hash = "sha256:4e52c96ca66de04be42ea2278012a2342d89f5e82b4512fb6fb7134e377e2e62"},
{file = "ruamel.yaml.clib-0.2.2-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:a873e4d4954f865dcb60bdc4914af7eaae48fb56b60ed6daa1d6251c72f5337c"},
{file = "ruamel.yaml.clib-0.2.2-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:ab845f1f51f7eb750a78937be9f79baea4a42c7960f5a94dde34e69f3cce1988"},
{file = "ruamel.yaml.clib-0.2.2-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:2fd336a5c6415c82e2deb40d08c222087febe0aebe520f4d21910629018ab0f3"},
{file = "ruamel.yaml.clib-0.2.2-cp36-cp36m-win32.whl", hash = "sha256:e9f7d1d8c26a6a12c23421061f9022bb62704e38211fe375c645485f38df34a2"},
{file = "ruamel.yaml.clib-0.2.2-cp36-cp36m-win_amd64.whl", hash = "sha256:2602e91bd5c1b874d6f93d3086f9830f3e907c543c7672cf293a97c3fabdcd91"},
{file = "ruamel.yaml.clib-0.2.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:44c7b0498c39f27795224438f1a6be6c5352f82cb887bc33d962c3a3acc00df6"},
{file = "ruamel.yaml.clib-0.2.2-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:8e8fd0a22c9d92af3a34f91e8a2594eeb35cba90ab643c5e0e643567dc8be43e"},
{file = "ruamel.yaml.clib-0.2.2-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:75f0ee6839532e52a3a53f80ce64925ed4aed697dd3fa890c4c918f3304bd4f4"},
{file = "ruamel.yaml.clib-0.2.2-cp37-cp37m-win32.whl", hash = "sha256:464e66a04e740d754170be5e740657a3b3b6d2bcc567f0c3437879a6e6087ff6"},
{file = "ruamel.yaml.clib-0.2.2-cp37-cp37m-win_amd64.whl", hash = "sha256:52ae5739e4b5d6317b52f5b040b1b6639e8af68a5b8fd606a8b08658fbd0cab5"},
{file = "ruamel.yaml.clib-0.2.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:4df5019e7783d14b79217ad9c56edf1ba7485d614ad5a385d1b3c768635c81c0"},
{file = "ruamel.yaml.clib-0.2.2-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:5254af7d8bdf4d5484c089f929cb7f5bafa59b4f01d4f48adda4be41e6d29f99"},
{file = "ruamel.yaml.clib-0.2.2-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:8be05be57dc5c7b4a0b24edcaa2f7275866d9c907725226cdde46da09367d923"},
{file = "ruamel.yaml.clib-0.2.2-cp38-cp38-win32.whl", hash = "sha256:74161d827407f4db9072011adcfb825b5258a5ccb3d2cd518dd6c9edea9e30f1"},
{file = "ruamel.yaml.clib-0.2.2-cp38-cp38-win_amd64.whl", hash = "sha256:058a1cc3df2a8aecc12f983a48bda99315cebf55a3b3a5463e37bb599b05727b"},
{file = "ruamel.yaml.clib-0.2.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c6ac7e45367b1317e56f1461719c853fd6825226f45b835df7436bb04031fd8a"},
{file = "ruamel.yaml.clib-0.2.2-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:b4b0d31f2052b3f9f9b5327024dc629a253a83d8649d4734ca7f35b60ec3e9e5"},
{file = "ruamel.yaml.clib-0.2.2-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:1f8c0a4577c0e6c99d208de5c4d3fd8aceed9574bb154d7a2b21c16bb924154c"},
{file = "ruamel.yaml.clib-0.2.2-cp39-cp39-win32.whl", hash = "sha256:46d6d20815064e8bb023ea8628cfb7402c0f0e83de2c2227a88097e239a7dffd"},
{file = "ruamel.yaml.clib-0.2.2-cp39-cp39-win_amd64.whl", hash = "sha256:6c0a5dc52fc74eb87c67374a4e554d4761fd42a4d01390b7e868b30d21f4b8bb"},
{file = "ruamel.yaml.clib-0.2.2.tar.gz", hash = "sha256:2d24bd98af676f4990c4d715bcdc2a60b19c56a3fb3a763164d2d8ca0e806ba7"},
]
safety = [
@@ -1689,8 +1684,8 @@ smmap = [
{file = "smmap-3.0.4.tar.gz", hash = "sha256:9c98bbd1f9786d22f14b3d4126894d56befb835ec90cef151af566c7e19b5d24"},
]
stevedore = [
{file = "stevedore-3.2.2-py3-none-any.whl", hash = "sha256:5e1ab03eaae06ef6ce23859402de785f08d97780ed774948ef16c4652c41bc62"},
{file = "stevedore-3.2.2.tar.gz", hash = "sha256:f845868b3a3a77a2489d226568abe7328b5c2d4f6a011cc759dfa99144a521f0"},
{file = "stevedore-3.3.0-py3-none-any.whl", hash = "sha256:50d7b78fbaf0d04cd62411188fa7eedcb03eb7f4c4b37005615ceebe582aa82a"},
{file = "stevedore-3.3.0.tar.gz", hash = "sha256:3a5bbd0652bf552748871eaa73a4a8dc2899786bc497a2aa1fcb4dcdb0debeee"},
]
toml = [
{file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
@@ -1716,19 +1711,28 @@ typed-ast = [
{file = "typed_ast-1.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75"},
{file = "typed_ast-1.4.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652"},
{file = "typed_ast-1.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7"},
{file = "typed_ast-1.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:fcf135e17cc74dbfbc05894ebca928ffeb23d9790b3167a674921db19082401f"},
{file = "typed_ast-1.4.1-cp36-cp36m-win32.whl", hash = "sha256:4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1"},
{file = "typed_ast-1.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa"},
{file = "typed_ast-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614"},
{file = "typed_ast-1.4.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41"},
{file = "typed_ast-1.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b"},
{file = "typed_ast-1.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:f208eb7aff048f6bea9586e61af041ddf7f9ade7caed625742af423f6bae3298"},
{file = "typed_ast-1.4.1-cp37-cp37m-win32.whl", hash = "sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe"},
{file = "typed_ast-1.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355"},
{file = "typed_ast-1.4.1-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6"},
{file = "typed_ast-1.4.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c31defeb059a907"},
{file = "typed_ast-1.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d"},
{file = "typed_ast-1.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:7e4c9d7658aaa1fc80018593abdf8598bf91325af6af5cce4ce7c73bc45ea53d"},
{file = "typed_ast-1.4.1-cp38-cp38-win32.whl", hash = "sha256:715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895af64a77a8c852c"},
{file = "typed_ast-1.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4"},
{file = "typed_ast-1.4.1-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34"},
{file = "typed_ast-1.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:92c325624e304ebf0e025d1224b77dd4e6393f18aab8d829b5b7e04afe9b7a2c"},
{file = "typed_ast-1.4.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:d648b8e3bf2fe648745c8ffcee3db3ff903d0817a01a12dd6a6ea7a8f4889072"},
{file = "typed_ast-1.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:fac11badff8313e23717f3dada86a15389d0708275bddf766cca67a84ead3e91"},
{file = "typed_ast-1.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:0d8110d78a5736e16e26213114a38ca35cb15b6515d535413b090bd50951556d"},
{file = "typed_ast-1.4.1-cp39-cp39-win32.whl", hash = "sha256:b52ccf7cfe4ce2a1064b18594381bccf4179c2ecf7f513134ec2f993dd4ab395"},
{file = "typed_ast-1.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:3742b32cf1c6ef124d57f95be609c473d7ec4c14d0090e5a5e05a15269fb4d0c"},
{file = "typed_ast-1.4.1.tar.gz", hash = "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b"},
]
typing-extensions = [

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "tox-poetry-installer"
version = "0.5.1"
version = "0.6.1"
license = "MIT"
authors = ["Ethan Paul <24588726+enpaul@users.noreply.github.com>"]
description = "Tox plugin to install Tox environment dependencies using the Poetry backend and lockfile"
@@ -15,7 +15,7 @@ include = [
keywords = ["tox", "poetry", "plugin"]
readme = "README.md"
classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Environment :: Plugins",
"Framework :: tox",
"Intended Audience :: Developers",
@@ -32,11 +32,14 @@ classifiers = [
[tool.poetry.plugins.tox]
poetry_installer = "tox_poetry_installer"
[tool.poetry.extras]
poetry = ["poetry"]
[tool.poetry.dependencies]
python = "^3.6.1"
poetry = "^1.0.0"
poetry = {version = "^1.0.0", optional = true}
poetry-core = "^1.0.0"
tox = "^2.3.0 || ^3.0.0"
tox = "^3.0.0"
[tool.poetry.dev-dependencies]
bandit = "^1.6.2"

0
tests/__init__.py Normal file
View File

View File

@@ -6,6 +6,8 @@ skip_missing_interpreters = true
[testenv]
description = Run the tests
require_locked_deps = true
extras =
poetry
locked_deps =
pytest
pytest-cov

View File

@@ -1,7 +1,7 @@
# pylint: disable=missing-docstring
__title__ = "tox-poetry-installer"
__summary__ = "Tox plugin to install Tox environment dependencies using the Poetry backend and lockfile"
__version__ = "0.5.1"
__version__ = "0.6.1"
__url__ = "https://github.com/enpaul/tox-poetry-installer/"
__license__ = "MIT"
__authors__ = ["Ethan Paul <24588726+enpaul@users.noreply.github.com>"]

View File

@@ -0,0 +1,40 @@
"""You've heard of vendoirization, now get ready for internal namespace shadowing
Poetry is an optional dependency of this package explicitly to support the use case of having the
plugin and the `poetry` package installed to the same python environment; this is most common in
containers and/or CI. In this case there are two potential problems that can arise in this case:
* The installation of the plugin overwrites the installed version of Poetry resulting in
compatibility issues.
* Running `poetry install --no-dev`, when this plugin is in the dev-deps, results in poetry being
uninstalled from the environment.
To support these edge cases, and more broadly to support not messing with a system package manager,
the `poetry` package dependency is listed as optional dependency. This allows the plugin to be
installed to the same environment as Poetry and import that same Poetry installation here.
However, simply importing Poetry on the assumption that it is installed breaks another valid use
case: having this plugin installed alongside Tox when not using a Poetry-based project. To account
for this the imports in this module are isolated and the resultant import error that would result
is converted to an internal error that can be caught by callers. Rather than importing this module
at the module scope it is imported into function scope wherever Poetry components are needed. This
moves import errors from load time to runtime which allows the plugin to be skipped if Poetry isn't
installed and/or a more helpful error be raised within the Tox framework.
"""
# pylint: disable=unused-import
import sys
from tox_poetry_installer import exceptions
try:
from poetry.factory import Factory
from poetry.installation.pip_installer import PipInstaller
from poetry.io.null_io import NullIO
from poetry.poetry import Poetry
from poetry.puzzle.provider import Provider
from poetry.utils.env import VirtualEnv
except ImportError:
raise exceptions.PoetryNotInstalledError(
f"No version of Poetry could be imported under the current environment for '{sys.executable}'"
) from None

View File

@@ -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,
)

View File

@@ -6,6 +6,7 @@ All exceptions should inherit from the common base exception :exc:`ToxPoetryInst
ToxPoetryInstallerException
+-- SkipEnvironment
| +-- PoetryNotInstalledError
+-- LockedDepVersionConflictError
+-- LockedDepNotFoundError
+-- ExtraNotFoundError
@@ -22,6 +23,10 @@ class SkipEnvironment(ToxPoetryInstallerException):
"""Current environment does not meet preconditions and should be skipped by the plugin"""
class PoetryNotInstalledError(SkipEnvironment):
"""No version of Poetry could be imported from the current Python environment"""
class LockedDepVersionConflictError(ToxPoetryInstallerException):
"""Locked dependencies cannot specify an alternate version for installation"""

View File

@@ -8,13 +8,13 @@ from typing import List
from typing import Optional
from poetry.core.packages import Package as PoetryPackage
from poetry.poetry import Poetry
from tox import hookimpl
from tox import reporter
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
@@ -29,6 +29,13 @@ def tox_addoption(parser: ToxParser):
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(
name="install_dev_deps",
type="bool",
@@ -65,6 +72,13 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
try:
poetry = utilities.check_preconditions(venv, action)
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))
return None
@@ -72,6 +86,7 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
f"{constants.REPORTER_PREFIX} Loaded project pyproject.toml from {poetry.file}"
)
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"
@@ -95,7 +110,6 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
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())
@@ -104,7 +118,7 @@ def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional
)
if not venv.envconfig.skip_install and not venv.envconfig.config.skipsdist:
project_deps: List[PoetryPackage] = _find_project_dependencies(
project_deps: List[PoetryPackage] = utilities.find_project_dependencies(
venv, poetry, package_map
)
else:
@@ -116,50 +130,19 @@ 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)
return venv.envconfig.require_locked_deps or None
def _find_project_dependencies(
venv: ToxVirtualEnv, poetry: Poetry, packages: PackageMap
) -> List[PoetryPackage]:
"""Install the dependencies of the project package
Install all primary dependencies of the project package.
:param venv: Tox virtual environment to install the packages to
:param poetry: Poetry object the packages were sourced from
:param packages: Mapping of package names to the corresponding package object
"""
base_dependencies: List[PoetryPackage] = [
packages[item.name]
for item in poetry.package.requires
if not item.is_optional()
]
extra_dependencies: List[PoetryPackage] = []
for extra in venv.envconfig.extras:
try:
extra_dependencies += [
packages[item.name] for item in poetry.package.extras[extra]
]
except KeyError:
raise exceptions.ExtraNotFoundError(
f"Environment '{venv.name}' specifies project extra '{extra}' which was not found in the lockfile"
) from None
dependencies: List[PoetryPackage] = []
for dep in base_dependencies + extra_dependencies:
dependencies += utilities.find_transients(packages, dep.name.lower())
return dependencies

View File

@@ -1,15 +1,15 @@
"""Helper utility functions, usually bridging Tox and Poetry functionality"""
# 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 sys
import typing
from pathlib import Path
from typing import List
from typing import Sequence
from typing import Set
from poetry.core.packages import Package as PoetryPackage
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
from poetry.poetry import Poetry
from poetry.puzzle.provider import Provider as PoetryProvider
from poetry.utils.env import VirtualEnv as PoetryVirtualEnv
from tox import reporter
from tox.action import Action as ToxAction
from tox.venv import VirtualEnv as ToxVirtualEnv
@@ -18,9 +18,12 @@ from tox_poetry_installer import constants
from tox_poetry_installer import exceptions
from tox_poetry_installer.datatypes import PackageMap
if typing.TYPE_CHECKING:
from tox_poetry_installer import _poetry
def install_to_venv(
poetry: Poetry, venv: ToxVirtualEnv, packages: Sequence[PoetryPackage]
poetry: "_poetry.Poetry", venv: ToxVirtualEnv, packages: Sequence[PoetryPackage]
):
"""Install a bunch of packages to a virtualenv
@@ -28,14 +31,15 @@ def install_to_venv(
: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
reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Installing {len(packages)} packages to environment at {venv.envconfig.envdir}"
)
installer = PoetryPipInstaller(
env=PoetryVirtualEnv(path=Path(venv.envconfig.envdir)),
io=PoetryNullIO(),
installer = _poetry.PipInstaller(
env=_poetry.VirtualEnv(path=Path(venv.envconfig.envdir)),
io=_poetry.NullIO(),
pool=poetry.pool,
)
@@ -56,25 +60,62 @@ def find_transients(packages: PackageMap, dependency_name: str) -> Set[PoetryPac
.. note:: The package corresponding to the dependency named by ``dependency_name`` is included
in the list of returned packages.
"""
from tox_poetry_installer import _poetry
try:
def find_deps_of_deps(name: str, searched: Set[str]) -> PackageMap:
searched.add(name)
def find_deps_of_deps(name: str, transients: PackageMap):
if name in PoetryProvider.UNSAFE_PACKAGES:
if name in _poetry.Provider.UNSAFE_PACKAGES:
reporter.warning(
f"{constants.REPORTER_PREFIX} Installing package '{name}' using Poetry is not supported; skipping installation of package '{name}'"
f"{constants.REPORTER_PREFIX} Installing package '{name}' using Poetry is not supported and will be skipped"
)
else:
transients[name] = packages[name]
for dep in packages[name].requires:
if dep.name not in transients.keys():
find_deps_of_deps(dep.name, transients)
reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Skip {name}: designated unsafe by Poetry"
)
return dict()
transients: PackageMap = {}
find_deps_of_deps(packages[dependency_name].name, transients)
package = packages[name]
return set(transients.values())
if 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 '{constants.PLATFORM_VERSION}'"
)
elif package.platform is not None and package.platform != sys.platform:
reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Skip {package}: incompatible platform requirement '{package.platform}' for current platform '{sys.platform}'"
)
else:
reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Including {package} for installation"
)
transients[name] = package
for index, dep in enumerate(package.requires):
reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Processing dependency {index + 1}/{len(package.requires)} for {package}: {dep.name}"
)
if dep.name not in searched:
transients.update(find_deps_of_deps(dep.name, searched))
else:
reporter.verbosity2(
f"{constants.REPORTER_PREFIX} Package with name '{dep.name}' has already been processed, skipping"
)
return transients
searched: Set[str] = set()
try:
transients: PackageMap = find_deps_of_deps(
packages[dependency_name].name, searched
)
except KeyError:
if dependency_name in _poetry.Provider.UNSAFE_PACKAGES:
reporter.warning(
f"{constants.REPORTER_PREFIX} Installing package '{dependency_name}' using Poetry is not supported and will be skipped"
)
return set()
if any(
delimiter in dependency_name
for delimiter in constants.PEP508_VERSION_DELIMITERS
@@ -82,12 +123,15 @@ def find_transients(packages: PackageMap, dependency_name: str) -> Set[PoetryPac
raise exceptions.LockedDepVersionConflictError(
f"Locked dependency '{dependency_name}' cannot include version specifier"
) from None
raise exceptions.LockedDepNotFoundError(
f"No version of locked dependency '{dependency_name}' found in the project lockfile"
) from None
return set(transients.values())
def check_preconditions(venv: ToxVirtualEnv, action: ToxAction) -> Poetry:
def check_preconditions(venv: ToxVirtualEnv, action: ToxAction) -> "_poetry.Poetry":
"""Check that the local project environment meets expectations"""
# 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
@@ -97,8 +141,10 @@ def check_preconditions(venv: ToxVirtualEnv, action: ToxAction) -> Poetry:
f"Skipping isolated packaging build env '{action.name}'"
)
from tox_poetry_installer import _poetry
try:
return PoetryFactory().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
# environment/dependency management.
#
@@ -108,3 +154,42 @@ def check_preconditions(venv: ToxVirtualEnv, action: ToxAction) -> Poetry:
raise exceptions.SkipEnvironment(
"Project does not use Poetry for env management, skipping installation of locked dependencies"
) from None
def find_project_dependencies(
venv: ToxVirtualEnv, poetry: "_poetry.Poetry", packages: PackageMap
) -> List[PoetryPackage]:
"""Install the dependencies of the project package
Install all primary dependencies of the project package.
:param venv: Tox virtual environment to install the packages to
:param poetry: Poetry object the packages were sourced from
:param packages: Mapping of package names to the corresponding package object
"""
base_dependencies: List[PoetryPackage] = [
packages[item.name]
for item in poetry.package.requires
if not item.is_optional()
]
extra_dependencies: List[PoetryPackage] = []
for extra in venv.envconfig.extras:
reporter.verbosity1(
f"{constants.REPORTER_PREFIX} Processing project extra '{extra}'"
)
try:
extra_dependencies += [
packages[item.name] for item in poetry.package.extras[extra]
]
except KeyError:
raise exceptions.ExtraNotFoundError(
f"Environment '{venv.name}' specifies project extra '{extra}' which was not found in the lockfile"
) from None
dependencies: List[PoetryPackage] = []
for dep in base_dependencies + extra_dependencies:
dependencies += find_transients(packages, dep.name.lower())
return dependencies