Skip to content

Commit

Permalink
Add dpgui entry point and dpgen2 gui CLI (#172)
Browse files Browse the repository at this point in the history
See deepmodeling/dpgui#270 for details.

---------

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
njzjz committed Oct 9, 2023
1 parent 9ab5a87 commit 8e8bc16
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pyright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: pip install -e .
- run: pip install -e .[gui]
- uses: jakebailey/pyright-action@v1
with:
version: 1.1.318
2 changes: 2 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _cli:

Command line interface
======================

Expand Down
2 changes: 2 additions & 0 deletions docs/submit_args.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Arguments of the submit script
==============================
.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen2-submit>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen2 gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. _submitargs:
.. dargs::
Expand Down
31 changes: 31 additions & 0 deletions dpgen2/entrypoint/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""DP-GUI entrypoint."""


def start_dpgui(*, port: int, bind_all: bool, **kwargs):
"""Host DP-GUI server.
Parameters
----------
port : int
The port to serve DP-GUI on.
bind_all : bool
Serve on all public interfaces. This will expose your DP-GUI instance
to the network on both IPv4 and IPv6 (where available).
**kwargs
additional arguments
Raises
------
ModuleNotFoundError
The dpgui package is not installed
"""
try:
from dpgui import (
start_dpgui,
)
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
"To use DP-GUI, please install the dpgui package:\npip install dpgui"
) from e
start_dpgui(port=port, bind_all=bind_all)
31 changes: 31 additions & 0 deletions dpgen2/entrypoint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
download,
download_by_def,
)
from .gui import (
start_dpgui,
)
from .showkey import (
showkey,
)
Expand Down Expand Up @@ -259,6 +262,29 @@ def main_parser() -> argparse.ArgumentParser:
help="if specified, download regardless whether check points exist.",
)

##########################################
# gui
parser_gui = subparsers.add_parser(
"gui",
help="Serve DP-GUI.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser_gui.add_argument(
"-p",
"--port",
type=int,
default=6042,
help="The port to serve DP-GUI on.",
)
parser_gui.add_argument(
"--bind_all",
action="store_true",
help=(
"Serve on all public interfaces. This will expose your DP-GUI instance "
"to the network on both IPv4 and IPv6 (where available)."
),
)

# workflow subcommands
for cmd in workflow_subcommands:
add_subparser_workflow_subcommand(subparsers, cmd)
Expand Down Expand Up @@ -373,6 +399,11 @@ def main():
prefix=args.prefix,
chk_pnt=args.no_check_point,
)
elif args.command == "gui":
start_dpgui(
port=args.port,
bind_all=args.bind_all,
)
elif args.command in workflow_subcommands:
with open(args.CONFIG) as fp:
config = json.load(fp)
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ Homepage = "https://github.com/deepmodeling/dpgen2"
documentation = "https://docs.deepmodeling.com/projects/dpgen2"
repository = "https://github.com/deepmodeling/dpgen2"

[project.entry-points.console_scripts]
[project.scripts]
dpgen2 = "dpgen2.entrypoint.main:main"

[project.entry-points."dpgui"]
"DP-GEN2 Submit" = "dpgen2.entrypoint.args:submit_args"

[project.optional-dependencies]
docs = [
'sphinx',
Expand All @@ -48,6 +51,10 @@ docs = [
]
test = [
'fakegaussian>=0.0.3',
'dpgui',
]
gui = [
'dpgui',
]

[tool.setuptools.packages.find]
Expand Down
11 changes: 11 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import unittest

from dpgui import (
generate_dpgui_templates,
)


class TestDPGUI(unittest.TestCase):
def test_dpgui_entrypoints(self):
self.assertTrue(len(generate_dpgui_templates()) > 0)

0 comments on commit 8e8bc16

Please sign in to comment.