Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command for opening a shell for Thrift services #161

Merged
merged 6 commits into from
Feb 21, 2018

Conversation

bradengroom
Copy link
Member

@bradengroom bradengroom commented Feb 20, 2018

This adds a tshell command which will provide a way for Thrift services to open an interactive shell similar to pshell:

$ tshell example.ini
Baseplate Interactive Shell
Python 2.7.6 (default, Nov 23 2017, 15:49:48) 
[GCC 4.8.4]

Available Objects:

  app          This project's app instance
  context      The context for this shell instance's span
>>> 

Services may expose additional variables to the shell environment by providing a setup function in their .ini file.

config file:

...
[tshell]
setup = my_service:tshell_setup

setup function:

def tshell_setup(env, env_banner):
    from my_service import models
    env['models'] = models
    env_banner['models'] = 'Models module'
$ tshell example.ini
Baseplate Interactive Shell
Python 2.7.6 (default, Nov 23 2017, 15:49:48) 
[GCC 4.8.4]

Available Objects:

  app          This project's app instance
  context      The context for this shell instance's span
  models       Models module
>>> 


args = parser.parse_args(sys.argv[1:])
config = read_config(args.config_file, server_name=None, app_name=args.app_name)
configure_logging(config, args.debug)
Copy link
Member Author

@bradengroom bradengroom Feb 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I delete this line?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want fileConfig taking over, so it might be best to just manually set up a logging.basicConfig(level=logging.INFO) with a simple formatter or something? Not sure how much logging we'd want to see while trying to interact with the REPL.

setup.py Outdated
@@ -89,6 +89,7 @@ def run(self):
scripts=[
"bin/baseplate-serve{:d}".format(sys.version_info.major),
"bin/baseplate-script{:d}".format(sys.version_info.major),
"bin/tshell",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need a tshell2 and tshell3 similar to the serve and script commands?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that makes most sense for consistency.

Should this be baseplate- prefixed? It's almost a generic thrift shell but it does tie into baseplate's span stuff (as it should) so it's definitely custom.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be baseplate- prefixed?

Sounds reasonable. It also doesn't have to be called tshell if you have some other name that you would prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tshell seems pretty nice to be consistent with pshell

@bradengroom
Copy link
Member Author

👓 @bsimpson63

@spladug spladug self-requested a review February 20, 2018 22:03
Copy link
Contributor

@spladug spladug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great and will be super useful. Thank you!

I think it might be nice to add some documentation of this (and pshell tbh). That'd mean adding some new .rst files to docs/ (see CONTRIBUTING.md for how to add new stuff and test it out).

@@ -66,12 +67,16 @@ def read_config(config_file, server_name, app_name):
if server_name else None)
app_config = dict(parser.items("app:" + app_name))
has_logging_config = parser.has_section("loggers")
tshell_config = dict()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None might be a little more obvious here.


args = parser.parse_args(sys.argv[1:])
config = read_config(args.config_file, server_name=None, app_name=args.app_name)
configure_logging(config, args.debug)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want fileConfig taking over, so it might be best to just manually set up a logging.basicConfig(level=logging.INFO) with a simple formatter or something? Not sure how much logging we'd want to see while trying to interact with the REPL.

# try to use IPython if possible
try:
try:
# 1.0 <= ipython
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be OK dropping the old IPython support?

IPython 1.0 was released on August 8, 2013 (http://ipython.org/news.html)

In general we should probably be writing the minimal version of what we need here rather than just copying pylons; they have many more cases (and much longer history) to deal with.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Yeah, this was copied from r2 which was copied from pylons.

shell(local_ns=env, global_ns={})
except ImportError:
import code
py_prefix = sys.platform.startswith('java') and 'J' or 'P'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha let's drop this too. we're never gonna run in Jython.

setup.py Outdated
@@ -89,6 +89,7 @@ def run(self):
scripts=[
"bin/baseplate-serve{:d}".format(sys.version_info.major),
"bin/baseplate-script{:d}".format(sys.version_info.major),
"bin/tshell",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that makes most sense for consistency.

Should this be baseplate- prefixed? It's almost a generic thrift shell but it does tie into baseplate's span stuff (as it should) so it's definitely custom.

@bradengroom
Copy link
Member Author

💇

Copy link
Contributor

@spladug spladug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pulled this down and played with it and it's great! This is gonna be super useful and make a lot of people happy, thank you!

One request: can you make it clearer in the argparse banner and the sphinx docs that tshell is just for thrift apps?

@bradengroom
Copy link
Member Author

One request: can you make it clearer in the argparse banner and the sphinx docs that tshell is just for thrift apps?

8dabc50

@bradengroom bradengroom merged commit 6541842 into reddit:master Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants