Package: imacropy
ImacropyImacropy is interactive macropy.We provide some agile-development addons for MacroPy, namely:imacropy.iconsole, IPython extension.Use macros in the IPython REPL.imacropy.console.MacroConsole, a macro-enabled equivalent ofcode.InteractiveConsole.Embed a REPL that supports macros.macropy3, a generic bootstrapper for macro-enabled Python programs.Use macros in your main program.Changed in v0.2.0.Due to the addition ofMacroConsole, which is more deserving of the module nameimacropy.console, the IPython extension has been renamed toimacropy.iconsole(note the secondi). Please update your IPython profile. This is a permanent rename,iconsolewill not be renamed again.IPython extensionThe extension allows touse macros in the IPython REPL. (Definingmacros 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]: 42A from-import of macros from a given module clears from the REPL sessionallcurrent macros loaded from that module, and loads the latest definitionsof only the specifiedmacros 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.Added in v0.3.1.The line magic%macrosnow prints a human-readable list of macros that are currently imported into the REPL session (or says that no macros are imported, if so).Loading the extensionTo load the extension once,%load_ext imacropy.iconsole.To autoload it when IPython starts, add the string"imacropy.iconsole"to the listc.InteractiveShellApp.extensionsin youripython_config.py. To find the config file,ipython profile locate.When the extension loads, it importsmacropyinto the REPL session. You can use this to debug whether it is loaded, if necessary.Currentlyno 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 (notablyimportmagic.elfor Emacs, included inSpacemacs) treat the situation as a fatal error in Python interpreter startup if anything is printed (andipython3 --no-banneris rather convenient to have as the python-shell, to run IPython in Emacs's inferior-shell mode).MacroConsoleThis is a derivative of, and drop-in replacement for,code.InteractiveConsole, which allows you toembed a REPL that supports macros. The difference tomacropy.core.console.MacroConsoleis that this one offers the same semantics as the IPython extension. We also offer the?and??syntax to view docstrings and source code.fromimacropy.consoleimportMacroConsolem=MacroConsole()m.interact()Now we're inside a macro-enabled REPL:fromunpythonic.syntaximportmacros,letx=let[((a,21))in2*a]assertx==42Just like incode.InteractiveConsole, exiting the REPL (Ctrl+D) returns from theinteract()call.Macro docstrings and source code can be viewed like in IPython:let?let??If the information is available, these operations also print the filename and the starting line number of the definition of the queried object in that file.Theobj?syntax is shorthand forimacropy.doc(obj), andobj??is shorthand forimacropy.sourcecode(obj).Note that just like in IPython, for some reasonhelp(some_macro)sees only the generic docstring ofWrappedMacro, not that of the actual macro stub object. So use the?syntax to view macro docstrings, as you would in IPython.Added in v0.3.1.The literal commandmacros?now prints a human-readable list of macros that are currently imported into the REPL session (or says that no macros are imported, if so). This shadows theobj?docstring lookup syntax for the MacroPy special objectmacros, but that's likely not needed. That can still be invoked manually, usingimacropy.doc(macros).BootstrapperThe 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:fromsimpleletimportmacros,letdefmain():x=let((y,21))[2*y]assertx==42print("All OK")if__name__=="__main__":main()Start it as:macropy3some_program.pyA relative path is ok, as long as it is under the current directory. Relative paths including..arenotsupported. We also support the-m module_namevariant:macropy3-msome_programA dotted module path under the current directory is ok.If you need to set other Python command-line options:python3<youroptionshere>$(whichmacropy3)-msome_programThis way the rest of the options go to the Python interpreter itself, and the-m some_programto themacropy3bootstrapper.InstallationFrom PyPIInstall as user:pipinstallimacropy--userInstall as admin:sudopipinstallimacropyFrom GitHubAs user:gitclonehttps://github.com/Technologicat/imacropy.gitcdimacropy
pythonsetup.pyinstall--userAs admin, change the last command tosudopythonsetup.pyinstallDependenciesMacroPy3.LicenseBSD. Copyright 2019-2020 Juha Jeronen and University of Jyväskylä.