Invocation

If you cannot wait to try AvantPy before reading the rest of the documentation, here’s how you can do it:

$ python -m avantpy -h
usage: -m [-h] [-s SOURCE] [--lang LANG] [--dialect DIALECT] [--dev_py]
          [--show_converted] [--gui]

AvantPy sets up an import hook which makes it possible to run a file that
contains modified Python syntax provided the relevant source transformers can
be imported.

optional arguments:
  -h, --help            show this help message and exit
  -s SOURCE, --source SOURCE
                        Source file to be transformed and executed. It is
                        assumed that it can be imported. Format: path.to.file
                        -- Do not include an extension.
  --lang LANG           This sets the language used by AvantPy. Usually this
                        is a two-letter code such as 'fr' for French. If
                        DIALECT is not specified, this will also sets the
                        corresponding DIALECT.
  --dialect DIALECT     This sets the dialect used by AvantPy. Usually this is
                        a two-letter code such as 'pyfr' for French. If LANG
                        is not specified, this will also sets the
                        corresponding value for LANG.
  --dev_py              This disables the custom exception handling so that
                        Python tracebacks are printed.
  --show_converted      When using the console, if this flag is set, each time
                        the code entered is compaeed with the code
                        transformed. If the two are not identical, the
                        converted code is printed in the console.
  --gui                 Launches a basic GUI interface, useful for some
                        converting programs from one dialect into another or
                        into Python.

Currently, the --gui option only includes a tool to convert from one dialect (including Python) into another dialect (or Python) as illustrated below.

Repeat 10 block

The code on the left is in the “UPPERCASE” (pyupper) dialect; the code on the right has been converted to Python.

invocation.py

AvantPy sets up an import hook which makes it possible to run a file that contains modified Python syntax, provided the relevant source transformers can be imported.

Basic invocation

The simplest invocation of AvantPy sets up the import hook, collect all existing dialects, and leaves the user in a custom REPL:

python -m avantpy

This custom REPL should work in a way similar to Python’s own. Please, feel free to file issues for any unexpected behaviour.

If you want to select a particular dialect/language to be available in the console, you can use the --lang flag:

python -m avantpy --lang fr

If a source program is to be run, as described below, the --lang flag is ignored.

Running programs

The primary role of AvantPy is to run programs that have a modified syntax. This is done by one of the two following alternatives:

python -m avantpy -s path.to.file
python -m avantpy --source path.to.file

Warning

Do not include the extension in path.to.file.

You can use Python’s interactive flag, either separately, as in python -i -m ... or combined with the -m flag as done below, to execute a program to be run as “main” and continue with the console.

The following example is run from the root folder of the AvantPy repository. The file that is run ends with the pyfr extension which AvantPy uses to recognize that the French dialect is to be used:

$ python -im avantpy -s tests.pyfr.test_french
Success.
avantpy console version 0.0.5. [Python version: 3.7.0]

->> si Vrai:
...     afficher(bonjour)
...
Bonjour tout le monde !
->>