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

Initialize the agent #34

Merged
merged 12 commits into from Jan 5, 2018
Merged

Initialize the agent #34

merged 12 commits into from Jan 5, 2018

Conversation

geoffxy
Copy link
Member

@geoffxy geoffxy commented Jan 3, 2018

This initializes the agent adding the ability for it to communicate with its parent process through stdin and stdout. The code is in Python 3. The logs are written to /tmp/tandem-agent.log since we can't use stdin nor stdout because they are used for IPC. The plan is to make this location configurable in the future.

It turns out that I should actually be adding blank __init__.py files in the various packages. I avoided adding them in now to not conflict with the changes in #29.

Messages received from the editor plugin are processed in agent/tandem/protocol/editor/handler.py. Communication with the plugin is done using agent/tandem/io/std_streams.py. All the business logic in the agent should be running in the main executor to ensure that we're running on a single thread.

@geoffxy geoffxy self-assigned this Jan 3, 2018
@rageandqq
Copy link
Member

Will wait on @jamiboy16 to review #29 so I can merge it into this branch - will review this after. That way you can pull + test it with the __init__.py files I added.

@geoffxy
Copy link
Member Author

geoffxy commented Jan 3, 2018

Sounds good 👍

* Created initial vim plugin (python-supported versions of vim only)

* Use test client code in vim plugin. Spawn and communicate with agent instance

* Add python3 check
"""
def __init__(self, contents):
self.type = EditorProtocolMessageType.ApplyText
self.contents = contents
Copy link
Member

Choose a reason for hiding this comment

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

I am changing this to enforce that contents is an array of strings (each item represents a line in the buffer). Makes it easier to work with plugin APIs. Doing it in a future diff, just a heads up.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

agent/main.py Outdated
def set_up_logging():
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s %(levelname)-8s %(message)s',
Copy link
Member

Choose a reason for hiding this comment

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

We switch b/w single quotes and double quotes for strings - should we agree on one and just keep it consistent? Doesn't really matter IMO but just saying.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I'm fine with either. I think this was a result of copypasta from a code example. What is the convention for Python?

Copy link
Member

Choose a reason for hiding this comment

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

If we go by PEP 8, it doesn't matter as long as you stick with one and keep it consistent. Since we use double quotes in most places, and I used them as well, let's stick with double.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll change it over. I'll run pep8 over this too.

Copy link
Member

@rageandqq rageandqq left a comment

Choose a reason for hiding this comment

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

Noice

https://media1.tenor.com/images/d2c70f7f64587dc3b7c86ee06756fb4a/tenor.gif



def signal_handler(signal, frame):
global should_shutdown
Copy link
Member

Choose a reason for hiding this comment

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

Why do we use global here? Wouldn't it be already declared in line 6?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought that originally too, but it seems like you need to explicitly declare that you're referencing a global variable in Python (I think when making some mutating call). It didn't work for me without the global declaration.

https://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them

class StdStreams:
def __init__(self, handler_function):
self._handler_function = handler_function
self._reader = Thread(target=self._stdin_read)
Copy link
Member

Choose a reason for hiding this comment

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

I think as discussed, to avoid having to explicitly put Do not call directly on _stdin_read, we can instead make a function that returns a new Thread with the _stdin_read encapsulated within it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that's a good idea. I moved it into a _get_read_thread() function that declares _stdin_read as a nested function.

@@ -0,0 +1,77 @@
import json
Copy link
Member

Choose a reason for hiding this comment

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

I think we're going to want to split this into multiple files. In the future, it should be okay like this for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that makes sense. Since this defines messages between the agent and editor plugin, we may even want to consider using something like Protobuf/Thrift to define the messages so that they can easily be generated for different languages.

Copy link
Member

@jamiboym jamiboym left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@geoffxy
Copy link
Member Author

geoffxy commented Jan 5, 2018

I'll merge this as-is and rebase my socket changes to prevent this from growing too large.

@geoffxy geoffxy merged commit ecfbaa6 into master Jan 5, 2018
@geoffxy geoffxy deleted the gy-agent-init branch January 5, 2018 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants