Skip to content

Commit

Permalink
added defaults and version flag in cli along with a cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
santacodes committed Aug 13, 2024
1 parent 0fc714a commit 3bcfd44
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Set up Git
run: |
git config --global user.name "pybamm user"
git config --global user.email "[email protected]"
- name: Set up uv
uses: yezz123/setup-uv@v4
with:
Expand Down
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def install_and_run_tests(session, test_dir):
"""Install dependencies and run tests in the specified directory."""
session.install("setuptools", silent=False)
session.install("-e", ".[dev]", silent=False)
session.run("pipx", "install", ".", "--force", silent=False)
session.run("pytest", test_dir)

@nox.session(name="template-tests")
Expand Down
4 changes: 2 additions & 2 deletions src/pybamm_cookiecutter/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '0.1.dev139+g5e08eb6.d20240813'
__version_tuple__ = version_tuple = (0, 1, 'dev139', 'g5e08eb6.d20240813')
__version__ = version = '0.1.dev142+g0fc714a.d20240813'
__version_tuple__ = version_tuple = (0, 1, 'dev142', 'g0fc714a.d20240813')
25 changes: 21 additions & 4 deletions src/pybamm_cookiecutter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,30 @@ def pybamm_cookiecutter_cli():
"""
try:
parser = argparse.ArgumentParser(description = "A copier template generator for PyBaMM based projects")
parser.add_argument("--path", type = str, required = False, default = os.getcwd(),
help = "The destination path for project generation. The default is the current working directory")

parser.add_argument(
"--path", type = str,
required = False,
default = os.getcwd(),
help = "The destination path for project generation. The default is the current working directory"
)

from pybamm_cookiecutter import __version__ as version
parser.add_argument(
'--version',
action='version',
version=f'PyBaMM Cookiecutter CLI Version - {version}'
)

parser.add_argument(
"--defaults",
action="store_true",
help="Whether to use default options for generating the template"
)
args = parser.parse_args()
destination_path = Path(args.path)

copier.run_copy(src_path = TEMPLATE, dst_path = destination_path, unsafe=True)
with copier.Worker(src_path = TEMPLATE, dst_path = destination_path, unsafe = True, defaults = args.defaults) as worker:
worker.run_copy()

except KeyboardInterrupt:
print(Fore.RED + "Execution stopped by the user" + Fore.RESET)
Expand Down
12 changes: 12 additions & 0 deletions tests/template_tests/test_project_generation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pybamm_cookiecutter as m
import pytest
import os
import subprocess
import shutil

def test_version() -> None:
assert m.__version__
Expand Down Expand Up @@ -36,3 +39,12 @@ def test_template_with_extra_answers(copie): # codespell:ignore copie
assert result.project_dir.is_dir(), f"Project directory {result.project_dir} not found"
with open(result.project_dir / extra_context["project_name"] / "README.md") as f:
assert f.readline() == f"# {extra_context['project_name']}\n", f"{f.readline()} is not the same as {extra_context['project_name']}\n"

def test_cli():
"""
Testing if the CLI works and returns a successful exit code on execution
"""
os.mkdir("testcli")
return_code = subprocess.run(["pybamm-cookiecutter", "--defaults"], cwd = "./testcli")
shutil.rmtree("testcli")
assert return_code

0 comments on commit 3bcfd44

Please sign in to comment.