Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit b3ca163

Browse files
committed
Rename baseplate-tshell to baseplate-shell
It turns out that since Apache Thrift, we're standardized on how the application object works so we can use this shell for both kinds of services. Not only is this simpler to think about, but it also means we're not using different configuration parsing for Pyramid shells which fixes #367.
1 parent 2c36387 commit b3ca163

File tree

6 files changed

+42
-27
lines changed

6 files changed

+42
-27
lines changed

baseplate/server/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Configuration(NamedTuple):
8787
server: Optional[Dict[str, str]]
8888
app: Dict[str, str]
8989
has_logging_options: bool
90-
tshell: Optional[Dict[str, str]]
90+
shell: Optional[Dict[str, str]]
9191

9292

9393
def read_config(config_file: TextIO, server_name: Optional[str], app_name: str) -> Configuration:
@@ -100,11 +100,13 @@ def read_config(config_file: TextIO, server_name: Optional[str], app_name: str)
100100
server_config = dict(parser.items("server:" + server_name)) if server_name else None
101101
app_config = dict(parser.items("app:" + app_name))
102102
has_logging_config = parser.has_section("loggers")
103-
tshell_config = None
104-
if parser.has_section("tshell"):
105-
tshell_config = dict(parser.items("tshell"))
103+
shell_config = None
104+
if parser.has_section("shell"):
105+
shell_config = dict(parser.items("shell"))
106+
elif parser.has_section("tshell"):
107+
shell_config = dict(parser.items("tshell"))
106108

107-
return Configuration(filename, server_config, app_config, has_logging_config, tshell_config)
109+
return Configuration(filename, server_config, app_config, has_logging_config, shell_config)
108110

109111

110112
def configure_logging(config: Configuration, debug: bool) -> None:
@@ -313,7 +315,7 @@ def _fn_accepts_additional_args(script_fn: Callable[..., Any], fn_args: Sequence
313315
return allows_additional_args
314316

315317

316-
def load_and_run_tshell() -> None:
318+
def load_and_run_shell() -> None:
317319
"""Launch a shell for a thrift service."""
318320

319321
sys.path.append(os.getcwd())
@@ -355,8 +357,8 @@ def load_and_run_tshell() -> None:
355357
span = baseplate.make_server_span(context, "shell")
356358
env["context"] = span.context
357359

358-
if config.tshell and "setup" in config.tshell:
359-
setup = _load_factory(config.tshell["setup"])
360+
if config.shell and "setup" in config.shell:
361+
setup = _load_factory(config.shell["setup"])
360362
setup(env, env_banner)
361363

362364
# generate banner text

bin/baseplate-shell

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
3+
# this is here and not just a console_script entry point because we want the
4+
# gevent monkeypatching to happen before any pieces of baseplate are imported
5+
# at all, as would happen if we were to have this code be in the baseplate
6+
# package.
7+
8+
from gevent.monkey import patch_all
9+
10+
patch_all()
11+
12+
from baseplate.server import load_and_run_shell
13+
14+
load_and_run_shell()

bin/baseplate-tshell

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ from gevent.monkey import patch_all
99

1010
patch_all()
1111

12-
from baseplate.server import load_and_run_tshell
12+
from baseplate.server import load_and_run_shell
1313

14-
load_and_run_tshell()
14+
print("baseplate-tshell has been renamed to baseplate-shell. Please use that in the future!")
15+
print()
16+
17+
load_and_run_shell()

docs/cli/index.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@ CLI Tools
77
baseplate-healthcheck: Check if your service is alive <healthcheck>
88
baseplate-serve: The application server <serve>
99
baseplate-script: Run backend scripts <script>
10-
baseplate-tshell: Begin an interactive shell for a Thrift service <tshell>
11-
12-
HTTP services can use Pyramid's pshell_ in order to get an interactive shell.
13-
14-
.. _pshell: https://docs.pylonsproject.org/projects/pyramid/en/latest/pscripts/pshell.html
10+
baseplate-shell: Begin an interactive shell for a service <shell>

docs/cli/tshell.rst renamed to docs/cli/shell.rst

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
``baseplate-tshell``
1+
``baseplate-shell``
22
====================
33

4-
This command allows you to run an interactive Python shell for a Thrift service
4+
This command allows you to run an interactive Python shell for Baseplate.py services
55
with the application configuration and context loaded. The command is
6-
``baseplate-tshell``.
6+
``baseplate-shell``.
77

8-
HTTP services can use Pyramid's pshell_ in order to get an interactive shell.
9-
10-
.. _pshell: https://docs.pylonsproject.org/projects/pyramid/en/latest/pscripts/pshell.html
8+
This shell can be used for any kind of Baseplate.py service: Thrift, HTTP, etc.
119

1210
Command Line
1311
------------
@@ -19,7 +17,8 @@ default. This can be overridden with the ``--app-name`` option.
1917

2018
By default, the shell will have variables containing the application and the
2119
context exposed. Additional variables can be exposed by providing a ``setup``
22-
function in the ``tshell`` section of the configuration file.
20+
function in the ``shell`` (or ``tshell`` for backwards compatibility) section
21+
of the configuration file.
2322

2423
Example
2524
-------
@@ -31,14 +30,14 @@ Given a configuration file, ``example.ini``:
3130
[app:main]
3231
factory = baseplate.server.thrift
3332
34-
[tshell]
35-
setup = my_service:tshell_setup
33+
[shell]
34+
setup = my_service:shell_setup
3635
3736
and a small setup function, ``my_service.py``:
3837

3938
.. code-block:: python
4039
41-
def tshell_setup(env, env_banner):
40+
def shell_setup(env, env_banner):
4241
from my_service import models
4342
env['models'] = models
4443
env_banner['models'] = 'Models module'
@@ -47,7 +46,7 @@ You can begin a shell with the models module exposed:
4746

4847
.. code-block:: console
4948
50-
$ tshell example.ini
49+
$ baseplate-shell example.ini
5150
Baseplate Interactive Shell
5251
Python 2.7.6 (default, Nov 23 2017, 15:49:48)
5352
[GCC 4.8.4]

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
"zookeeper": ["kazoo>=2.5.0"],
3333
},
3434
scripts=[
35-
"bin/baseplate-serve",
3635
"bin/baseplate-script",
36+
"bin/baseplate-serve",
37+
"bin/baseplate-shell",
3738
"bin/baseplate-tshell",
3839
"bin/baseplate-healthcheck",
3940
],

0 commit comments

Comments
 (0)