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 26, 2024
1 parent 68bbea0 commit 5be3422
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ jobs:
- name: Install package and run software tests (Python 3.6)
if: matrix.python-version == '3.6'
run: |
pip install '.[graphql,develop,test]'
pip install '.[cli,graphql,develop,test]'
poe test
- name: Install and completely validate package (Python >=3.6)
if: matrix.python-version != '3.6'
run: |
uv pip install '.[graphql,develop,test]' --system
uv pip install '.[cli,graphql,develop,test]' --system
poe check
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ for more details on features available in Responder.

Install the most recent stable release:

pip install --upgrade responder
pip install --upgrade 'responder'

Install package including CLI interface and GraphQL extension:

pip install --upgrade 'responder[cli,graphql]'

Or, install directly from the repository:

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 setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ 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,
extras_require={
"cli": ["docopt-ng"],
"develop": [
"poethepoet",
"pyproject-fmt; python_version>='3.7'",
Expand Down
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 subprocess

import pytest

from responder.__version__ import __version__

pytest.importorskip("docopt", reason="docopt-ng package not installed")


def test_cli_version(capfd):
subprocess.check_call(["responder", "--version"]) # noqa: S603, S607
stdout = capfd.readouterr().out.strip()
assert stdout == __version__

0 comments on commit 5be3422

Please sign in to comment.