-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Additions + Added a basic `cli` with an optional `--path` argument defining the path generated project should reside within. + Added basic documentation for `cli` usage in `cli.py` and `README.md`. ## Removals - Removed `models`, `entry points`, and `parameter sets` from the project as they are now populated in the template. - Removed the `project-tests` from `noxfile` and updated workflow to only test the template. - Removed the entry points from `pyproject.toml` and `pybamm` as a dependency in the project. ## Usage To test this, check out this branch and inside the repository and do a local `pipx` installation on your machine. ```bash git clone https://github.com/santacodes/pybamm-cookiecutter -b cli cd pybamm-cookiecutter/ pipx install . ``` After installation, the `CLI` will be available systemwide and can be accessed using the `pybamm-cookiecutter` command. For help references add the `-h` or `--help` flag, e.g. `pybamm-cookiecutter --help` which would prompt with all the available arguments. Sub-task #26 --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
- Loading branch information
1 parent
1c21cce
commit b127ab7
Showing
46 changed files
with
182 additions
and
1,079 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
if __name__ == "__main__": | ||
from pybamm_cookiecutter.cli import pybamm_cookiecutter_cli | ||
|
||
pybamm_cookiecutter_cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import copier | ||
import argparse | ||
from pathlib import Path | ||
from colorama import Fore | ||
import os | ||
|
||
project_root = Path(__file__).resolve().parent.parent | ||
TEMPLATE = str(project_root) | ||
|
||
def pybamm_cookiecutter_cli(): | ||
""" | ||
Command Line Interface (CLI) for generating PyBaMM based projects using copier. | ||
Parameters | ||
---------- | ||
--path: pathlib.Path | ||
Examples | ||
------- | ||
$ pybamm-cookiecutter | ||
Generates a project in the current working directory of the terminal. | ||
$ pybamm-cookiecutter --path /myproject | ||
Generates a project in the `myproject` directory. | ||
""" | ||
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" | ||
) | ||
|
||
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) | ||
|
||
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) | ||
except Exception as error: | ||
print(Fore.RED + "Error caused by an exception: " + Fore.RESET, error) | ||
print(Fore.CYAN + "If you are unsure what the error is, feel free to open an issue at" + Fore.YELLOW +" - https://github.com/pybamm-team/pybamm-cookiecutter/issues" + Fore.RESET) | ||
|
||
if __name__ == '__main__': | ||
|
||
pybamm_cookiecutter_cli() |
Oops, something went wrong.