Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2023.6.0 #47

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
author = "Akshay Gupta"

# The short X.Y version
version = "2023.4.0"
version = "2023.6.0"
# The full version, including alpha/beta/rc tags
release = ""

Expand Down Expand Up @@ -69,7 +69,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
55 changes: 46 additions & 9 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,62 @@ This `edgetest` plugin runs after the test execution. If the last environment su
passes, this plugin will refresh `requirements.txt` using `pip-tools`. To use this plugin,
supply ``--export`` to your CLI call:

.. code-block:: console

$ edgetest --config setup.cfg --export
.. tabs::

.. tab:: .cfg

.. code-block:: console

$ edgetest --config setup.cfg --export

.. tab:: .toml

.. code-block:: console

$ edgetest --config pyproject.toml --export

If you want to specify a PyPI index, supply `index_url` in your configuration:

.. code-block:: ini
.. tabs::

.. tab:: .cfg

.. code-block:: ini

[edgetest.pip_tools]
index_url = https://myindex.com

.. tab:: .toml

.. code-block:: toml

[edgetest.pip_tools]
index_url = "https://myindex.com"

[edgetest.pip_tools]
index_url = ...

If you want to include extra installations in your `pip-tools` call add a newline-separated list of
extras:

.. code-block:: ini

[edgetest.pip_tools]
extras =
complete
.. tabs::

.. tab:: .cfg

.. code-block:: ini

[edgetest.pip_tools]
extras =
complete
another

.. tab:: .toml

.. code-block:: toml

[edgetest.pip_tools]
extras = "complete,another"


.. important::

Expand Down
2 changes: 1 addition & 1 deletion edgetest_pip_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Package initialization."""

__version__ = "2023.4.0"
__version__ = "2023.6.0"

__title__ = "edgetest-pip-tools"
__description__ = "pip-tools integration for edgetest"
Expand Down
10 changes: 9 additions & 1 deletion edgetest_pip_tools/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

from configparser import ConfigParser
from pathlib import Path
from typing import Dict, List
from typing import Dict, List, Any

import click
import pluggy
from edgetest.logger import get_logger
from edgetest.schema import Schema
from edgetest.utils import _run_command
from tomlkit import load

LOG = get_logger(__name__)

Expand Down Expand Up @@ -53,6 +54,7 @@ def get_reqfile(ctx: click.Context) -> Path:
Path
Path to the requirements file.
"""
parser: Any
if Path(ctx.params["config"]).name == "setup.cfg":
# Check for the install_requires
parser = ConfigParser()
Expand All @@ -61,6 +63,12 @@ def get_reqfile(ctx: click.Context) -> Path:
reqfile = Path(ctx.params["config"])
else:
reqfile = Path(ctx.params["requirements"])
elif Path(ctx.params["config"]).name == "pyproject.toml":
parser = load(open(Path(ctx.params["config"])))
if "dependencies" in parser["project"]:
reqfile = Path(ctx.params["config"])
else:
reqfile = Path(ctx.params["requirements"])
else:
reqfile = Path(ctx.params["requirements"])

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ click==8.1.3
# via
# edgetest
# pip-tools
edgetest==2023.4.0
edgetest==2023.6.0
# via edgetest-pip-tools (setup.cfg)
packaging==23.0
# via
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ edgetest =
piptools = edgetest_pip_tools.plugin

[bumpver]
current_version = "2023.4.0"
current_version = "2023.6.0"
version_pattern = "YYYY.MM.INC0"
commit_message = "Bump {old_version} to {new_version}"
commit = True
Expand Down
133 changes: 128 additions & 5 deletions tests/test_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from click.testing import CliRunner
from edgetest.interface import cli
from edgetest.schema import EdgetestValidator, Schema
from edgetest.utils import parse_cfg
from edgetest.utils import parse_cfg, parse_toml

from edgetest_pip_tools.plugin import addoption

Expand All @@ -20,6 +20,12 @@
pytest tests -m 'not integration'
"""

TOML = """
[edgetest.envs.myenv]
upgrade = ["myupgrade"]
command = "pytest tests -m 'not integration'"
"""

CFG_ART = """
[options]
install_requires =
Expand All @@ -36,6 +42,25 @@
"""


TOML_ART = """
[project]
name = "toy_edgetest_toml"
version = "0.1.0"
description = "Fake description"
requires-python = ">=3.7"

dependencies = ["myupgrade"]

[edgetest.envs.myenv]
upgrade = ["myupgrade"]
command = "pytest tests -m 'not integration'"

[edgetest.pip_tools]
index_url = "myindexurl"
extras = "complete,another"
"""


CFG_EXTRAS = """
[edgetest.envs.myenv]
upgrade =
Expand All @@ -49,6 +74,16 @@
"""


TOML_EXTRAS = """
[edgetest.envs.myenv]
upgrade = ["myupgrade"]
command = "pytest tests -m 'not integration'"

[edgetest.pip_tools]
extras = "complete,another"
"""


PIP_LIST = """
[{"name": "myupgrade", "version": "0.2.0"}]
"""
Expand All @@ -65,7 +100,7 @@


@pytest.mark.parametrize("config", [CFG, CFG_ART, CFG_EXTRAS])
def test_addoption(config, tmpdir):
def test_addoption_cfg(config, tmpdir):
"""Test the addoption hook."""
location = tmpdir.mkdir("mylocation")
conf_loc = Path(str(location), "myconfig.cfg")
Expand All @@ -82,10 +117,28 @@ def test_addoption(config, tmpdir):
assert validator.validate(cfg)


@pytest.mark.parametrize("config", [TOML, TOML_ART, TOML_EXTRAS])
def test_addoption_toml(config, tmpdir):
"""Test the addoption hook."""
location = tmpdir.mkdir("mylocation")
conf_loc = Path(str(location), "pyproject.toml")
with open(conf_loc, "w") as outfile:
outfile.write(config)

schema = Schema()
addoption(schema=schema)

cfg = parse_toml(filename=conf_loc)

validator = EdgetestValidator(schema=schema.schema)

assert validator.validate(cfg)


@patch("edgetest.lib.EnvBuilder", autospec=True)
@patch("edgetest.core.Popen", autospec=True)
@patch("edgetest.utils.Popen", autospec=True)
def test_update_reqs(mock_popen, mock_cpopen, mock_builder):
def test_update_reqs_cfg(mock_popen, mock_cpopen, mock_builder):
"""Test calling ``pip-tools``."""
mock_popen.return_value.communicate.return_value = (PIP_LIST, "error")
type(mock_popen.return_value).returncode = PropertyMock(return_value=0)
Expand All @@ -102,9 +155,9 @@ def test_update_reqs(mock_popen, mock_cpopen, mock_builder):

env_loc = Path(loc) / ".edgetest" / "myenv"
if platform.system() == "Windows":
py_loc = str(Path(env_loc) / "Scripts" / "python")
py_loc = str(Path(env_loc) / "Scripts" / "python")
else:
py_loc = str(Path(env_loc) / "bin" / "python")
py_loc = str(Path(env_loc) / "bin" / "python")

assert result.exit_code == 0
assert mock_popen.call_args_list == [
Expand Down Expand Up @@ -150,3 +203,73 @@ def test_update_reqs(mock_popen, mock_cpopen, mock_builder):
universal_newlines=True,
),
]


@patch("edgetest.lib.EnvBuilder", autospec=True)
@patch("edgetest.core.Popen", autospec=True)
@patch("edgetest.utils.Popen", autospec=True)
def test_update_reqs_toml(mock_popen, mock_cpopen, mock_builder):
"""Test calling ``pip-tools``."""
mock_popen.return_value.communicate.return_value = (PIP_LIST, "error")
type(mock_popen.return_value).returncode = PropertyMock(return_value=0)
mock_cpopen.return_value.communicate.return_value = ("output", "error")
type(mock_cpopen.return_value).returncode = PropertyMock(return_value=0)

runner = CliRunner()

with runner.isolated_filesystem() as loc:
with open("pyproject.toml", "w") as outfile:
outfile.write(TOML_ART)
result = runner.invoke(cli, [f"--config=pyproject.toml", "--export"])

env_loc = Path(loc) / ".edgetest" / "myenv"
if platform.system() == "Windows":
py_loc = str(Path(env_loc) / "Scripts" / "python")
else:
py_loc = str(Path(env_loc) / "bin" / "python")

assert result.exit_code == 0
assert mock_popen.call_args_list == [
call(
(f"{str(py_loc)}", "-m", "pip", "install", "."),
stdout=-1,
universal_newlines=True,
),
call(
(
f"{str(py_loc)}",
"-m",
"pip",
"install",
"myupgrade",
"--upgrade",
),
stdout=-1,
universal_newlines=True,
),
call(
(f"{str(py_loc)}", "-m", "pip", "list", "--format", "json"),
stdout=-1,
universal_newlines=True,
),
call(
(f"{str(py_loc)}", "-m", "pip", "list", "--format", "json"),
stdout=-1,
universal_newlines=True,
),
call(
(
f"{str(py_loc)}",
"-m",
"piptools",
"compile",
"-U",
"--extra=complete,another",
"--index-url=myindexurl",
"--output-file=requirements.txt",
"pyproject.toml",
),
stdout=-1,
universal_newlines=True,
),
]