Skip to content

Commit ca53fcf

Browse files
committed
Merge branch 'release-0.0.3' into releases-0.0.x
2 parents 211632d + 583198c commit ca53fcf

File tree

8 files changed

+167
-19
lines changed

8 files changed

+167
-19
lines changed

.gitlab-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
- 'python3 -m tox'
99
- 'python3 -m tox -e package'
1010

11+
'review py35':
12+
extends: '.review'
13+
image: 'python:3.5'
14+
1115
'review py36':
1216
extends: '.review'
1317
image: 'python:3.6'

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dist: 'xenial'
66
language: 'python'
77

88
python:
9+
- '3.5'
910
- '3.6'
1011
- '3.7'
1112
- '3.8'

CHANGELOG.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33

44
.. Keep the current version number on line number 6
55
6+
0.0.3
7+
=====
8+
9+
*2020-10-06*
10+
11+
* Add the ``poetry_experimental_no_virtual_env`` setting to allow skipping the creation of the virtual environment (experimental feature)
12+
13+
614
0.0.2
715
=====
816

9-
2020-09-28
17+
*2020-09-28*
1018

11-
* Allow download from alternative repositories (without authentication) for pip via environment variables.
19+
* Allow download from alternative repositories (without authentication) for pip via environment variables
1220

1321

1422
0.0.1
1523
=====
1624

17-
2020-09-17
25+
*2020-09-17*
1826

1927
* Fix a small issue that blocked the usage under Python 3.5
2028
* Make the dependencies mandatory
@@ -23,7 +31,7 @@
2331
0.0.0
2432
=====
2533

26-
2020-09-11
34+
*2020-09-11*
2735

2836
* Initial implementation
2937

CONTRIBUTING.rst

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
..
22
33

4+
Git commit messages
5+
===================
6+
7+
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:
8+
9+
.. code::
10+
11+
Closes #XX
12+
13+
14+
should be instead written as:
15+
16+
.. code::
17+
18+
GitHub: closes #XX
19+
GitLab: refs #ZZ
20+
GitLab: refs #YY
21+
SomeThing: whatever #XX
22+
23+
24+
Some tools (Gerrit for example) can be configured (with regexes for example) to correctly link to the items on the right platform.
25+
26+
* https://gerrit-review.googlesource.com/Documentation/config-gerrit.html#commentlink
27+
28+
429
Hacking
530
=======
631

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

13-
Use following command to create a Python virtual environment with all
14-
necessary dependencies::
38+
Use following command to create a Python virtual environment with all necessary dependencies::
1539

1640
tox --recreate -e develop
1741

18-
This creates a Python virtual environment in the ``.tox/develop`` directory. It
19-
can be activated with the following command::
42+
This creates a Python virtual environment in the ``.tox/develop`` directory. It can be activated with the following command::
2043

2144
. .tox/develop/bin/activate
2245

README.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ Source code:
2424
Usage
2525
=====
2626

27+
Installation
28+
------------
29+
30+
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*):
31+
32+
.. code::
33+
34+
[tox]
35+
requires =
36+
tox-poetry-dev-dependencies
37+
38+
39+
* https://tox.readthedocs.io/en/latest/config.html#conf-requires
40+
* https://tox.readthedocs.io/en/latest/example/basic.html#tox-auto-provisioning
41+
42+
By default the plugin does not do anything. Use one of the following settings to activate the corresponding features.
43+
44+
2745
``add_poetry_dev_dependencies``
2846
-------------------------------
2947

@@ -85,4 +103,23 @@ If pip's environment variables are already defined then they are not overwritten
85103
PIP_INDEX_URL=https://delta.example/simple tox
86104
87105
106+
``poetry_experimental_no_virtual_env``
107+
--------------------------------------
108+
109+
*Experimental feature*
110+
111+
Set the ``testenv`` setting ``poetry_experimental_no_virtual_env`` to ``True`` to skip the creation of a virtual environment for this test environment.
112+
113+
.. code::
114+
115+
[testenv:real]
116+
deps =
117+
poetry_experimental_no_virtual_env = True
118+
skip_install = True
119+
120+
121+
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.).
122+
123+
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``).
124+
88125
.. EOF

setup.cfg

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ strict = 1
99
[metadata]
1010
author = sinoroc
1111
author_email = sinoroc.code+python@gmail.com
12+
classifiers =
13+
Development Status :: 2 - Pre-Alpha
14+
Framework :: tox
15+
Programming Language :: Python :: 3 :: Only
16+
Programming Language :: Python :: 3.5
17+
Programming Language :: Python :: 3.6
18+
Programming Language :: Python :: 3.7
19+
Programming Language :: Python :: 3.8
20+
Topic :: Software Development :: Testing
21+
Typing :: Typed
1222
description = Let Tox know about Poetry's development dependencies
1323
license = Apache-2.0
1424
license_file = LICENSE.txt
@@ -24,11 +34,12 @@ url = https://pypi.org/project/tox-poetry-dev-dependencies/
2434
[options]
2535
install_requires =
2636
importlib-metadata
27-
poetry-core
37+
poetry-core ~= 1.0
2838
tox
2939
package_dir =
3040
= src
3141
packages = find:
42+
python_requires = ~= 3.5
3243
3344
3445
[options.entry_points]

src/tox_poetry_dev_dependencies/_hooks.py

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class NoPoetryFound(_Exception):
2626
"""No poetry found."""
2727

2828

29+
class NoPyprojectTomlFound(_Exception):
30+
"""No 'pyproject.toml' file found."""
31+
32+
2933
class CanNotHaveMultipleDefaultSourceRepositories(_Exception):
3034
"""Can not have multiple 'default' source repositories."""
3135

@@ -48,14 +52,44 @@ def tox_addoption(parser: tox.config.Parser) -> None:
4852
"'PIP_EXTRA_INDEX_URL')."
4953
),
5054
)
55+
parser.add_testenv_attribute(
56+
'poetry_experimental_no_virtual_env',
57+
'bool',
58+
"Do not create a virtual environment.",
59+
default=False,
60+
)
61+
62+
63+
def _is_test_env(env_config: tox.config.TestenvConfig) -> bool:
64+
#
65+
is_test_env = False
66+
#
67+
tox_config = env_config.config
68+
env_name = env_config.envname
69+
#
70+
known_private_env_names = []
71+
#
72+
provision_tox_env = getattr(tox_config, 'provision_tox_env', None)
73+
if provision_tox_env:
74+
known_private_env_names.append(provision_tox_env)
75+
#
76+
isolated_build_env = getattr(tox_config, 'isolated_build_env', None)
77+
if isolated_build_env:
78+
known_private_env_names.append(isolated_build_env)
79+
#
80+
if env_name not in known_private_env_names:
81+
if env_name in tox_config.envlist:
82+
is_test_env = True
83+
#
84+
return is_test_env
5185

5286

5387
@tox.hookimpl # type: ignore[misc]
5488
def tox_configure(config: tox.config.Config) -> None:
5589
"""Set hook."""
5690
try:
5791
poetry_ = _get_poetry(config.setupdir)
58-
except NoPoetryFound:
92+
except (NoPoetryFound, NoPyprojectTomlFound):
5993
pass
6094
else:
6195
dev_deps = _get_dev_requirements(poetry_)
@@ -65,18 +99,40 @@ def tox_configure(config: tox.config.Config) -> None:
6599
_add_index_servers(config, index_servers)
66100

67101

102+
@tox.hookimpl # type: ignore[misc]
103+
def tox_testenv_create(
104+
venv: tox.venv.VirtualEnv,
105+
action: tox.action.Action, # pylint: disable=unused-argument
106+
) -> typing.Any:
107+
"""Set hook."""
108+
#
109+
result = None
110+
#
111+
if _is_test_env(venv.envconfig):
112+
if venv.envconfig.poetry_experimental_no_virtual_env is True:
113+
#
114+
tox.venv.cleanup_for_venv(venv)
115+
#
116+
python_link_name = venv.envconfig.get_envpython()
117+
python_link_path = pathlib.Path(python_link_name)
118+
python_link_path.parent.mkdir(parents=True)
119+
python_link_target = (
120+
tox.interpreters.tox_get_python_executable(venv.envconfig)
121+
)
122+
pathlib.Path(python_link_name).symlink_to(python_link_target)
123+
#
124+
result = True # anything but None
125+
#
126+
return result
127+
128+
68129
def _add_dev_dependencies(
69130
tox_config: tox.config.Config,
70131
dev_dep_configs: typing.Iterable[tox.config.DepConfig],
71132
) -> None:
72-
#
73-
skip_envs = [
74-
tox_config.isolated_build_env,
75-
tox_config.provision_tox_env,
76-
]
77133
#
78134
for env_config in tox_config.envconfigs.values():
79-
if env_config.envname not in skip_envs:
135+
if _is_test_env(env_config):
80136
if env_config.add_poetry_dev_dependencies is True:
81137
for dep_config in dev_dep_configs:
82138
env_config.deps.append(dep_config)
@@ -115,8 +171,10 @@ def _get_poetry(project_root_path: pathlib.Path) -> poetry.core.poetry.Poetry:
115171
poetry_factory = poetry.core.factory.Factory()
116172
try:
117173
poetry_ = poetry_factory.create_poetry(str(project_root_path))
118-
except RuntimeError as runtime_error:
119-
raise NoPoetryFound from runtime_error
174+
except RuntimeError as exc:
175+
raise NoPyprojectTomlFound from exc
176+
except poetry.core.pyproject.exceptions.PyProjectException as exc:
177+
raise NoPoetryFound from exc
120178
return poetry_
121179

122180

tox.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
[tox]
55
envlist =
6+
py35
67
py36
78
py37
89
py38
@@ -12,14 +13,17 @@ isolated_build = True
1213

1314
[testenv]
1415
commands =
15-
make review
16+
# Run review under Python 3.8 as it also includes linting and type checking
17+
py38: make review
18+
!py38: make test
1619
extras =
1720
dev_test
1821
whitelist_externals =
1922
make
2023

2124

2225
[testenv:py39]
26+
description = Outcome is ignored since Python 3.9 is not released yet
2327
ignore_outcome = True
2428

2529

@@ -31,6 +35,8 @@ extras =
3135

3236

3337
[testenv:develop]
38+
description = Use this environment for interactive development use (activate)
39+
#
3440
commands =
3541
extras =
3642
dev_package

0 commit comments

Comments
 (0)