Skip to content

Commit

Permalink
[feature] Add a main script to print neuralprophet version (#974)
Browse files Browse the repository at this point in the history
* add a main script to run python -m neuralprophet and print version

* rewrite main cli with proper argument parsing

* add test case for cli to improve test coverage

* fix isort warnings

* improve test case and wrap code in function

* Rename -v to -V

Co-authored-by: Kevin Chen <[email protected]>
  • Loading branch information
noxan and Kevin-Chen0 authored Dec 2, 2022
1 parent af98e9d commit 9237bfd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions neuralprophet/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Invokes neuralprophet when module is run as a script.
"""
import argparse

from neuralprophet._version import __version__


def parse_args(args=None):
parser = argparse.ArgumentParser(description="NeuralProphet")
parser.add_argument("-V", "--version", action="version", version="%(prog)s " + __version__)
return parser.parse_args(args)


if __name__ == "__main__":
parse_args()
13 changes: 13 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from neuralprophet.__main__ import parse_args
from neuralprophet._version import __version__


def test_main_file(capsys):
with pytest.raises(SystemExit) as exit_info:
parse_args(["--version"])

out, _ = capsys.readouterr()
assert exit_info.value.code == 0
assert __version__ in out

0 comments on commit 9237bfd

Please sign in to comment.