diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 257829f..eb2a4f2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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' diff --git a/.travis.yml b/.travis.yml index 14baf4a..cdff45a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ dist: 'xenial' language: 'python' python: + - '3.5' - '3.6' - '3.7' - '3.8' diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bdb3d32..f5f326f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 @@ -23,7 +31,7 @@ 0.0.0 ===== -2020-09-11 +*2020-09-11* * Initial implementation diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b715fc0..24122ef 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -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 ======= @@ -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 diff --git a/README.rst b/README.rst index cb760fd..83bfa8f 100644 --- a/README.rst +++ b/README.rst @@ -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`` ------------------------------- @@ -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 diff --git a/setup.cfg b/setup.cfg index 86590d8..1bb24a7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,16 @@ strict = 1 [metadata] author = sinoroc author_email = sinoroc.code+python@gmail.com +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 @@ -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] diff --git a/src/tox_poetry_dev_dependencies/_hooks.py b/src/tox_poetry_dev_dependencies/_hooks.py index 21ecec3..5bb016d 100644 --- a/src/tox_poetry_dev_dependencies/_hooks.py +++ b/src/tox_poetry_dev_dependencies/_hooks.py @@ -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.""" @@ -48,6 +52,36 @@ 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] @@ -55,7 +89,7 @@ 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_) @@ -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) @@ -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_ diff --git a/tox.ini b/tox.ini index d67a64d..4667584 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,7 @@ [tox] envlist = + py35 py36 py37 py38 @@ -12,7 +13,9 @@ 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 = @@ -20,6 +23,7 @@ whitelist_externals = [testenv:py39] +description = Outcome is ignored since Python 3.9 is not released yet ignore_outcome = True @@ -31,6 +35,8 @@ extras = [testenv:develop] +description = Use this environment for interactive development use (activate) +# commands = extras = dev_package