Skip to content

Commit

Permalink
Merge branch 'release-0.0.5' into releases-0.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sinoroc committed Oct 19, 2020
2 parents 502b0a5 + 06fe35a commit 3c8eecf
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

.. Keep the current version number on line number 6
0.0.5
=====

*2020-10-19*

* Add support for URL dependencies in lockfile


0.0.4
=====

Expand Down
46 changes: 44 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Set the ``testenv`` setting ``poetry_experimental_add_locked_dependencies`` to `
# ...
poetry_experimental_add_locked_dependencies = True
If ``poetry_add_dev_dependencies`` is set as well then the development dependencies are added with the version from the *lockfile*.

``poetry_add_dev_dependencies``
-------------------------------
Expand All @@ -57,6 +55,50 @@ Set the ``testenv`` setting ``poetry_add_dev_dependencies`` to ``True`` to let T
poetry_add_dev_dependencies = True
Dependency settings combination
-------------------------------

The settings ``poetry_experimental_add_locked_dependencies`` and ``poetry_add_dev_dependencies`` are independent and can be used in combination. The following table shows the expected result for each possible combination of these two settings.

The *source file* column shows which file is used as source for the dependencies. The ``deps`` column shows an example of what dependencies are expected to be added to ``deps`` for that test environment. In that example ``Lib = '~1.0'`` is a mandatory dependency locking to ``Lib==1.2.3`` and ``Dev = '~3.0'`` is a development dependency locking to ``Dev==3.2.1``.

.. |arrow| unicode:: 0x21d2

.. list-table::
:header-rows: 1

* - ``*_locked_dependencies``
- ``*_dev_dependencies``
- |arrow|
- source file
- |arrow|
- resulting ``deps``
* - ``False``
- ``False``
-
- ``pyproject.toml``
-
- ``Lib~=1.0``
* - ``True``
- ``False``
-
- ``poetry.lock``
-
- ``Lib==1.2.3``
* - ``False``
- ``True``
-
- ``pyproject.toml``
-
- ``Lib~=1.0``, ``Dev~=3.0``
* - ``True``
- ``True``
-
- ``poetry.lock``
-
- ``Lib==1.2.3``, ``Dev==3.2.1``


``poetry_use_source_repos``
---------------------------

Expand Down
28 changes: 23 additions & 5 deletions src/tox_poetry_dev_dependencies/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"""Tox plugin hooks."""

from __future__ import annotations

import pathlib
import typing

Expand Down Expand Up @@ -37,6 +39,10 @@ class CanNotHaveMultipleDefaultSourceRepositories(_Exception):
"""Can not have multiple 'default' source repositories."""


class UnsupportedLockedDependency(_Exception):
"""Unsupported type of locked dependency."""


@tox.hookimpl # type: ignore[misc]
def tox_addoption(parser: tox.config.Parser) -> None:
"""Set hook."""
Expand Down Expand Up @@ -172,7 +178,7 @@ def _add_dev_dependencies(

def _add_index_servers(
tox_config: tox.config.Config,
index_servers: 'IndexServersT',
index_servers: IndexServersT,
) -> None:
#
for env_config in tox_config.envconfigs.values():
Expand All @@ -182,7 +188,7 @@ def _add_index_servers(

def _add_index_servers_as_pip_env_vars(
env_config: tox.config.TestenvConfig,
index_servers: 'IndexServersT',
index_servers: IndexServersT,
) -> None:
#
pip_index_server = index_servers[0]
Expand Down Expand Up @@ -238,7 +244,7 @@ def _get_dev_requirements(

def _get_index_servers(
poetry_: poetry.core.poetry.Poetry,
) -> 'IndexServersT':
) -> IndexServersT:
#
poetry_source_repos = poetry_.local_config.get('source', [])
#
Expand Down Expand Up @@ -305,14 +311,26 @@ def _get_locked_deps(
lock_document = tomlkit.parse(lock_str)
#
for dependency in lock_document['package']:
#
dep_pep_508 = None
#
dep_name = dependency['name']
dep_version = dependency['version']
#
dep_pep_508 = f'{dep_name}=={dep_version}'
dep_source = dependency.get('source', None)
if dep_source:
if dep_source['type'] == 'url':
dep_url = dep_source['url']
dep_pep_508 = f'{dep_name} @ {dep_url}'
else:
dep_pep_508 = f'{dep_name}=={dep_version}'
#
if dep_pep_508:
dep_config = tox.config.DepConfig(dep_pep_508)
else:
raise UnsupportedLockedDependency(dependency)
#
dep_category = dependency['category']
dep_config = tox.config.DepConfig(dep_pep_508)
locked_deps.setdefault(dep_category, []).append(dep_config)
#
return locked_deps
Expand Down

0 comments on commit 3c8eecf

Please sign in to comment.