Skip to main content

Interactive MacroPy - IPython REPL, generic bootstrapper.

Project description

Imacropy is interactive macropy.

We provide some agile-development addons for MacroPy, namely a generic macro-enabling bootstrapper, and an IPython extension to macro-enable its REPL.

Bootstrapper:

The bootstrapper imports the specified file or module, pretending its __name__ is "__main__". This allows your main program to use macros.

For example, some_program.py:

from simplelet import macros, let

def main():
    x = let((y, 21))[2*y]
    assert x == 42
    print("All OK")

if __name__ == "__main__":
    main()

Start it as:

macropy3 some_program.py

or:

macropy3 -m some_program

The only command-line switch the bootstrapper supports is -m module_name. If you need to set other Python command-line options:

python3 <your options here> -m macropy3 -m some_program

The first -m goes to Python itself, the second to the macropy3 bootstrapper.

IPython extension:

The extension allows to use macros in the IPython REPL. (Defining macros in the REPL is currently not supported.)

For example:

In [1]: from simplelet import macros, let

In [2]: let((x, 21))[2*x]
Out[2]: 42

A from-import of macros from a given module clears from the REPL session all current macros loaded from that module, and loads the latest definitions of only the specified macros from disk. This allows interactive testing when editing macros.

The most recent definition of any given macro remains alive until the next macro from-import from the same module, or until the IPython session is terminated.

Macro docstrings and source code can be viewed using ? and ??, as usual.

To load the extension once, %load_ext imacropy.console.

To autoload it when IPython starts, add "imacropy.console" to the list c.InteractiveShellApp.extensions in your ipython_config.py. To find the config file, ipython profile locate.

When the extension loads, it imports macropy into the REPL session. You can use this to debug whether it is loaded, if necessary.

Currently no startup banner is printed, because extension loading occurs after IPython has already printed its own banner. We cannot manually print a banner, because some tools (notably importmagic.el for Emacs, included in Spacemacs) treat the situation as a fatal error in Python interpreter startup if anything is printed (and ipython3 --no-banner is rather convenient to have as the python-shell, to run IPython in Emacs’s inferior-shell mode).

For more details, see the docstring of imacropy.console.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imacropy-0.2.2.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imacropy-0.2.2-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file imacropy-0.2.2.tar.gz.

File metadata

  • Download URL: imacropy-0.2.2.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

File hashes

Hashes for imacropy-0.2.2.tar.gz
Algorithm Hash digest
SHA256 87cb6dae41e3dae78a878c7743c3b058e98582cc839edaa3b46728da735e275b
MD5 2f7a2d569fb58c1698779d054cb4245f
BLAKE2b-256 830c4ec6fd605265adc39279fc6c0c27c4de940843b0c56d1f9654242203d79c

See more details on using hashes here.

File details

Details for the file imacropy-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: imacropy-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

File hashes

Hashes for imacropy-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2e89802f0636b2212537a9a767941b22a02338839f0679734e747ddf5fb3424b
MD5 9eba9cf8394668f7f0ed373098d18d23
BLAKE2b-256 e8c3e6c7f414061eabaef5bf72beeead303a5690a5cb58ef4802ea3eda601e42

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page