Skip to content

Commit

Permalink
CLI build command (2024)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethreitz authored and amotl committed Oct 25, 2024
1 parent 68bbea0 commit 2caf792
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion responder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from . import ext
from .core import API, Request, Response
from .core import API, Request, Response, cli

__all__ = [
"cli",
"API",
"Request",
"Response",
Expand Down
42 changes: 42 additions & 0 deletions responder/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Responder.
Usage:
responder
responder run [--build] [--debug] <module>
responder build
responder --version
Options:
-h --help Show this screen.
-v --version Show version.
"""

import os

import docopt

from .__version__ import __version__


def cli():
args = docopt.docopt(__doc__, argv=None, version=__version__, options_first=False)

module = args["<module>"]
build = args["build"] or args["--build"]
run = args["run"]

if build:
os.system("npm run build") # noqa: S605, S607

if run:
split_module = module.split(":")

if len(split_module) > 1:
module = split_module[0]
prop = split_module[1]
else:
prop = "api"

app = __import__(module)
getattr(app, prop).run()
2 changes: 2 additions & 0 deletions responder/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .api import API
from .cli import cli
from .models import Request, Response

__all__ = [
"cli",
"API",
"Request",
"Response",
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
required = [
"aiofiles",
"apispec>=1.0.0b1",
"asgiref",
"chardet",
"docopt-ng",
"marshmallow",
"requests",
"requests-toolbelt",
Expand Down Expand Up @@ -75,6 +77,7 @@ def run(self):
url="https://github.com/kennethreitz/responder",
packages=find_packages(exclude=["tests"]),
package_data={},
entry_points={"console_scripts": ["responder=responder.cli:cli"]},
python_requires=">=3.6",
setup_requires=[],
install_requires=required,
Expand Down

0 comments on commit 2caf792

Please sign in to comment.