Skip to main content

Python EPC server component for reddel. It provides an easy way to send (python) source code from Emacs to the server, inspect or transform it via Redbaron and send the result back.

An example on how to expose a simple function to add arguments:

# file: myprovidermod.py
import reddel_server

class MyProvider(reddel_server.ProviderBase)
    @reddel_server.red_src()
    @reddel_server.red_validate([reddel_server.OptionalRegionValidator(),
                                 reddel_server.SingleNodeValidator(),
                                 reddel_server.TypeValidator(["def"])])
    def add_arg(self, red, start, end, index, arg):
        red.arguments.insert(index, arg)
        return red

Start the reddel server from Emacs:

>>> (require 'epc)

>>> (defvar my-epc (epc:start-epc "reddel" nil))

>>> ;; make sure myprovidermod is in a directory within the PYTHONPATH
>>> (epc:call-sync my-epc 'add_provider '("myprovidermod.MyProvider"))

>>> (message (epc:call-sync my-epc 'add_arg '("def foo(arg1, arg3): pass" nil nil 1 "arg2")))
"def foo(arg1, arg2, arg3): pass"

Redbaron provides a lossless format, so even formatting and comments are preserved.

Installation

At the command line:

pip install reddel-server

Usage

You can start a reddel server from within Emacs like shown above or start it from the command line. A executable reddel is provided by this project, which should suitable for most use cases.

$ reddel --help
Usage: reddel [OPTIONS]

Options:
  --address TEXT       address to bind the server to
  --port INTEGER       address to bind the server to
  -p, --provider TEXT  dotted path to a provider class
  -v, --verbosity LVL  Either CRITICAL, ERROR, WARNING, INFO or DEBUG
  --debug              Show tracebacks when erroring.
  --help               Show this message and exit.

--address TEXT

Default is localhost. Can be an IP or domain name.

--port INTEGER

Defaults to a random free port.

-p, --provider TEXT

Example: mypkg.mymod.MyProviderClass You can provide this multiple times. Defines additional providers that are available from the start. More providers can be added at runtime via reddel_server.ChainedProvider.add_provider.

-v, --verbosity LVL

Define the logging level.

--debug

By default all expected exceptions are only logged without the traceback. If this flag is set, the traceback is printed as well.

--help

Show the help message and exit.

Calling a function from within Emacs is very simple thanks to epc:

>>> (progn
...   (require 'epc)
...   (defvar my-epc (epc:start-epc "reddel" nil))
...   ;; list all methods compatible with the given source
...   (message (epc:call-sync my-epc 'list_methods '("def foo(arg1, arg3): pass"))))

(epc:start-epc "reddel" nil) starts the server by executing reddel without any arguments (nil). Then you can make calls to that server by referring to the manager returned from epc:start-epc. To execute a call, you can use (epc:call-sync <manager> <method> <arguments>), where <manager> is the manager returned by epc:start-epc, <method> is the function and <arguments> is a list of arguments passed to <method>.

The Builtin Functions section in the documentation provides a guide through all functions that ship with this package. If you need advanced features check the reference documentation for help on how to write your own server.

Documentation

https://reddel-server.readthedocs.io/

Bugs/Requests

Please use the GitHub issue tracker to submit bugs or request features.

Development

To run the all tests run:

tox

Note, to combine the coverage data from all the tox environments run:

Windows

set PYTEST_ADDOPTS=--cov-append
tox

Other

PYTEST_ADDOPTS=--cov-append tox

License

Copyright David Zuber, 2016.

Distributed under the terms of the GNU General Public License version 3, reddel-server is free and open source software.

Changelog

0.2.0 (2017-01-02)

  • You can optionally specify regions for methods that take in source code.

  • Restructure the validators into several small classes.

0.1.0 (2016-11-17)

  • First release on PyPI.

Metadata

Release files for reddel-server 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reddel-server 0.2.0
File Size Uploaded
reddel-server-0.2.0.tar.gz 44.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for reddel-server 0.2.0
File Interpreter ABI Platform
reddel_server-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 68.0 kB

Release files / reddel-server-0.2.0.tar.gz

Download URL reddel-server-0.2.0.tar.gz
Size 44.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4a6e65833e123fbfe14204f52df808c2c0d7c15d51efea2d0b3dd3c16be3151d
BLAKE2b-256 checksum
How to use checksums
420c55ec823738ae1e6e8beb1c179e5d1459c5cd86561daec310d8e50fcb19f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / reddel_server-0.2.0-py2.py3-none-any.whl

Download URL reddel_server-0.2.0-py2.py3-none-any.whl
Size 23.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a89b19411e1989d227fd2775df9a5cbc06d87ec9e357700a92ffd99701675a09
BLAKE2b-256 checksum
How to use checksums
a20a648a61dab66267e25574221f8c8a49acf37fb09e886c7608c55d6bbaa0aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page