Skip to content

Commit

Permalink
Merge branch 'release-0.0.3' into releases-0.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sinoroc committed Oct 6, 2020
2 parents 211632d + 583198c commit ca53fcf
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- 'python3 -m tox'
- 'python3 -m tox -e package'

'review py35':
extends: '.review'
image: 'python:3.5'

'review py36':
extends: '.review'
image: 'python:3.6'
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist: 'xenial'
language: 'python'

python:
- '3.5'
- '3.6'
- '3.7'
- '3.8'
Expand Down
16 changes: 12 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@

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

*2020-10-06*

* Add the ``poetry_experimental_no_virtual_env`` setting to allow skipping the creation of the virtual environment (experimental feature)


0.0.2
=====

2020-09-28
*2020-09-28*

* Allow download from alternative repositories (without authentication) for pip via environment variables.
* Allow download from alternative repositories (without authentication) for pip via environment variables


0.0.1
=====

2020-09-17
*2020-09-17*

* Fix a small issue that blocked the usage under Python 3.5
* Make the dependencies mandatory
Expand All @@ -23,7 +31,7 @@
0.0.0
=====

2020-09-11
*2020-09-11*

* Initial implementation

Expand Down
31 changes: 27 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
..

Git commit messages
===================

As this project is hosted on multiple platforms (GitHub and GitLab currently), every line of the git commit messages mentioning a magic number (such as issue or pull request number for example) should be prefixed with the name of the platform. For example a line in a commit message of the form:

.. code::
Closes #XX
should be instead written as:

.. code::
GitHub: closes #XX
GitLab: refs #ZZ
GitLab: refs #YY
SomeThing: whatever #XX
Some tools (Gerrit for example) can be configured (with regexes for example) to correctly link to the items on the right platform.

* https://gerrit-review.googlesource.com/Documentation/config-gerrit.html#commentlink


Hacking
=======

Expand All @@ -10,13 +35,11 @@ This project makes extensive use of `tox`_, `pytest`_, and `GNU Make`_.
Development environment
-----------------------

Use following command to create a Python virtual environment with all
necessary dependencies::
Use following command to create a Python virtual environment with all necessary dependencies::

tox --recreate -e develop

This creates a Python virtual environment in the ``.tox/develop`` directory. It
can be activated with the following command::
This creates a Python virtual environment in the ``.tox/develop`` directory. It can be activated with the following command::

. .tox/develop/bin/activate

Expand Down
37 changes: 37 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ Source code:
Usage
=====

Installation
------------

It is a plugin for Tox and it is available on PyPI, install it however best fits the workflow. A useful thing to know though, is that starting with Tox version *3.8* it is possible to enforce the installation (in an isolated environment) of the plugin directly from within the ``tox.ini`` file, thanks to the ``requires`` setting (Tox *3.2*) and the *auto-provisioning* feature (Tox *3.8*):

.. code::
[tox]
requires =
tox-poetry-dev-dependencies
* https://tox.readthedocs.io/en/latest/config.html#conf-requires
* https://tox.readthedocs.io/en/latest/example/basic.html#tox-auto-provisioning

By default the plugin does not do anything. Use one of the following settings to activate the corresponding features.


``add_poetry_dev_dependencies``
-------------------------------

Expand Down Expand Up @@ -85,4 +103,23 @@ If pip's environment variables are already defined then they are not overwritten
PIP_INDEX_URL=https://delta.example/simple tox
``poetry_experimental_no_virtual_env``
--------------------------------------

*Experimental feature*

Set the ``testenv`` setting ``poetry_experimental_no_virtual_env`` to ``True`` to skip the creation of a virtual environment for this test environment.

.. code::
[testenv:real]
deps =
poetry_experimental_no_virtual_env = True
skip_install = True
This might be useful in cases where all the required dependencies and tools are already available, i.e. they are already installed in global or user *site packages* directory, or maybe they are already installed directly in the system (via ``apt``, ``yum``, ``pacman``, etc.).

For such environments it might be best to skip the installation of the project (``skip_install``) as well as keeping the list of dependencies empty (``deps``).

.. EOF
13 changes: 12 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ strict = 1
[metadata]
author = sinoroc
author_email = [email protected]
classifiers =
Development Status :: 2 - Pre-Alpha
Framework :: tox
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Software Development :: Testing
Typing :: Typed
description = Let Tox know about Poetry's development dependencies
license = Apache-2.0
license_file = LICENSE.txt
Expand All @@ -24,11 +34,12 @@ url = https://pypi.org/project/tox-poetry-dev-dependencies/
[options]
install_requires =
importlib-metadata
poetry-core
poetry-core ~= 1.0
tox
package_dir =
= src
packages = find:
python_requires = ~= 3.5
[options.entry_points]
Expand Down
76 changes: 67 additions & 9 deletions src/tox_poetry_dev_dependencies/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class NoPoetryFound(_Exception):
"""No poetry found."""


class NoPyprojectTomlFound(_Exception):
"""No 'pyproject.toml' file found."""


class CanNotHaveMultipleDefaultSourceRepositories(_Exception):
"""Can not have multiple 'default' source repositories."""

Expand All @@ -48,14 +52,44 @@ def tox_addoption(parser: tox.config.Parser) -> None:
"'PIP_EXTRA_INDEX_URL')."
),
)
parser.add_testenv_attribute(
'poetry_experimental_no_virtual_env',
'bool',
"Do not create a virtual environment.",
default=False,
)


def _is_test_env(env_config: tox.config.TestenvConfig) -> bool:
#
is_test_env = False
#
tox_config = env_config.config
env_name = env_config.envname
#
known_private_env_names = []
#
provision_tox_env = getattr(tox_config, 'provision_tox_env', None)
if provision_tox_env:
known_private_env_names.append(provision_tox_env)
#
isolated_build_env = getattr(tox_config, 'isolated_build_env', None)
if isolated_build_env:
known_private_env_names.append(isolated_build_env)
#
if env_name not in known_private_env_names:
if env_name in tox_config.envlist:
is_test_env = True
#
return is_test_env


@tox.hookimpl # type: ignore[misc]
def tox_configure(config: tox.config.Config) -> None:
"""Set hook."""
try:
poetry_ = _get_poetry(config.setupdir)
except NoPoetryFound:
except (NoPoetryFound, NoPyprojectTomlFound):
pass
else:
dev_deps = _get_dev_requirements(poetry_)
Expand All @@ -65,18 +99,40 @@ def tox_configure(config: tox.config.Config) -> None:
_add_index_servers(config, index_servers)


@tox.hookimpl # type: ignore[misc]
def tox_testenv_create(
venv: tox.venv.VirtualEnv,
action: tox.action.Action, # pylint: disable=unused-argument
) -> typing.Any:
"""Set hook."""
#
result = None
#
if _is_test_env(venv.envconfig):
if venv.envconfig.poetry_experimental_no_virtual_env is True:
#
tox.venv.cleanup_for_venv(venv)
#
python_link_name = venv.envconfig.get_envpython()
python_link_path = pathlib.Path(python_link_name)
python_link_path.parent.mkdir(parents=True)
python_link_target = (
tox.interpreters.tox_get_python_executable(venv.envconfig)
)
pathlib.Path(python_link_name).symlink_to(python_link_target)
#
result = True # anything but None
#
return result


def _add_dev_dependencies(
tox_config: tox.config.Config,
dev_dep_configs: typing.Iterable[tox.config.DepConfig],
) -> None:
#
skip_envs = [
tox_config.isolated_build_env,
tox_config.provision_tox_env,
]
#
for env_config in tox_config.envconfigs.values():
if env_config.envname not in skip_envs:
if _is_test_env(env_config):
if env_config.add_poetry_dev_dependencies is True:
for dep_config in dev_dep_configs:
env_config.deps.append(dep_config)
Expand Down Expand Up @@ -115,8 +171,10 @@ def _get_poetry(project_root_path: pathlib.Path) -> poetry.core.poetry.Poetry:
poetry_factory = poetry.core.factory.Factory()
try:
poetry_ = poetry_factory.create_poetry(str(project_root_path))
except RuntimeError as runtime_error:
raise NoPoetryFound from runtime_error
except RuntimeError as exc:
raise NoPyprojectTomlFound from exc
except poetry.core.pyproject.exceptions.PyProjectException as exc:
raise NoPoetryFound from exc
return poetry_


Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

[tox]
envlist =
py35
py36
py37
py38
Expand All @@ -12,14 +13,17 @@ isolated_build = True

[testenv]
commands =
make review
# Run review under Python 3.8 as it also includes linting and type checking
py38: make review
!py38: make test
extras =
dev_test
whitelist_externals =
make


[testenv:py39]
description = Outcome is ignored since Python 3.9 is not released yet
ignore_outcome = True


Expand All @@ -31,6 +35,8 @@ extras =


[testenv:develop]
description = Use this environment for interactive development use (activate)
#
commands =
extras =
dev_package
Expand Down

0 comments on commit ca53fcf

Please sign in to comment.