abingham / traad

An JSON+HTTP server for the rope Python refactoring library
MIT License
107 stars 20 forks source link

Automatically starting traad server on-demand #70

Closed abingham closed 6 years ago

abingham commented 10 years ago

It would be cool if we could find a way to automatically start a traad server when needed. We would need to start a server when a Python file is opened, and presumably kill it when it's no longer needed.

There are a number of issues to consider. First, on which directory do we open the server? One approach is to scan up the filesystem hierarchy to find the top of the package containing the file being visited. Or, if the file isn't in a package (i.e. there are no __init__.py files) then we might just start the server on the directory containing the file.

The other obvious issue is determining which version of the server to start. Sometime you need a Python 2 server, sometimes you need a Python 3 server. We may be able to sidestep this problem by making a smarter server that somehow handles/detects both version and does the right thing. Maybe not. This needs some thought.

abingham commented 10 years ago

regarding detecting python versions: The consensus seems to be to either a) use 2to3 and see if it produces and suggested changes or b) compile the code with one version or the other and see if that produces any error. I suppose that 2to3 has the benefit that it will be more robust in the face of programmer errors, i.e. compilation problems that have nothing to do with 2/3 differences.

This might help: https://github.com/abingham/python-version-probe

PythonNut commented 9 years ago

Perhaps one way to solve the directory problem is to ask the user where the root directory is if traad can't automatically find it. After that, traversing upward to .ropeproject would work automatically, and the user would not need to specify again.

abingham commented 9 years ago

I like the sound of that approach. In the absence of .ropeproject we could also look for things like setup.py, __init__.py, .git, etc. as clues for a default value when we query the user. A similar system seems to work really well for e.g. projectile.

abingham commented 6 years ago

We've got a version of this in the emacs client now. It seems to work well, though I'm sure it could use some polish (e.g. looking for .git in the absence of .ropeproject would be a good start).