Skip to content

Commit

Permalink
add --version to pkgmt setup (ploomber#74)
Browse files Browse the repository at this point in the history
* add specify python version to cli

* update changelog.md

* test multiple version values
  • Loading branch information
bryannho authored Sep 15, 2023
1 parent 2912d8f commit 1aabfd3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CHANGELOG

## 0.7.5dev
* [Feature] Added `--version` option to `pkgmt setup` to specify Python version

## 0.7.4 (2023-09-08)

Expand Down
10 changes: 8 additions & 2 deletions src/pkgmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ def release(tag, production, yes):
default=False,
help="Install documentation dependencies",
)
def setup(doc):
@click.option(
"--version",
default=None,
type=str,
help="Select a Python version, default is 3.10",
)
def setup(version, doc):
"""Setup development environment
Create conda environment and install dependencies:
Expand All @@ -150,7 +156,7 @@ def setup(doc):
$ pkgmt setup --doc
"""
try:
dev.setup(Context(), doc=doc)
dev.setup(Context(), version=version, doc=doc)
except UnexpectedExit as e:
raise SystemExit(f"Error running: {e.result.command}") from e

Expand Down
24 changes: 24 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from pkgmt import cli
from invoke import Context


@pytest.mark.parametrize(
Expand Down Expand Up @@ -262,3 +263,26 @@ def test_lint_black_pyproj(pyproject, command, output, tmp_empty):
result = runner.invoke(cli.cli, command)

assert output in result.output


@pytest.mark.parametrize(
"command, version, doc",
[
[["setup"], None, False],
[["setup", "--version", "2.7"], "2.7", False],
[["setup", "--version", "3.7"], "3.7", False],
[["setup", "--version", "3.8"], "3.8", False],
[["setup", "--version", "3.9"], "3.9", False],
[["setup", "--version", "3.10"], "3.10", False],
[["setup", "--version", "3.11"], "3.11", False],
[["setup", "--version", "3.9", "--doc"], "3.9", True],
],
)
def test_setup_with_python_version(monkeypatch, command, version, doc):
mock = Mock()
monkeypatch.setattr(cli.dev, "setup", mock)

runner = CliRunner()
runner.invoke(cli.cli, command)

mock.assert_called_once_with(Context(), version=version, doc=doc)

0 comments on commit 1aabfd3

Please sign in to comment.