Skip to main content

Standalone Package Generator

Project description

AdHoc consists of a single python source file, which can be used as a program (see Script Usage) as well as a module (see adhoc.AdHoc). itself is distributed as a compiled adhoc script.

After installation of the binary package, run --explode to obtain the full source in directory __adhoc__.


AdHoc provides python scripts with

  • template facilities
  • default file generation
  • standalone module inclusion


adhoc.AdHoc parses text for tagged lines and processes them as instructions.

The minimal parsed entity is a tagged line, which is any line containing a recognized AdHoc tag.

Tagged lines come in two flavors, namely flags and section delimiters.

All AdHoc tags are enclosed in @: and :@. E.g:


Flags are tagged lines, which denote a single option or command (see Flags). E.g.:

import module # @:adhoc:@
# @:adhoc_self:@ my_module_name

Sections are tagged line pairs, which delimit a block of text. The first tagged line opens the section, the second tagged line closes the section (see Sections). E.g.:

# @:adhoc_enable:@
# disabled_command()
# @:adhoc_enable:@

The implementation is realized as class adhoc.AdHoc which is mainly used as a namespace. The run time part of adhoc.AdHoc which handles module import and file export is included verbatim as class RtAdHoc in the generated output.



The place where the AdHoc run time code is added. This flag must be present in files, which use the @:adhoc:@ import feature. It is not needed for the enable/disable features.


Mark import line for run-time compilation.

This flag is ignored, if the line is commented out. E.g.:

# import module # @:adhoc:@
@:adhoc_include:@ file_spec, …:

Include files for unpacking. file_spec is one of

file:file is used for both input and output.
file from default-file:
 file is used for input and output. if file does not exist, default-file is used for input.
source-file as output-file:
 source-file is used for input. output-file is used for output.

This flag is ignored, if double commented. E.g.:

# # @:adhoc_include:@ file
@:adhoc_verbatim:@ [flags] file_spec, …:

Include files for verbatim extraction. See adhoc_include for file_spec.

The files are included as @:adhoc_template_v:@ sections. file is used as export_file mark. If file is --, the template disposition becomes standard output.

Optional flags can be any combination of [+|-]NUM for indentation and # for commenting. E.g.:

# @:adhoc_verbatim:@ +4# my_file from /dev/null

my_file (or /dev/null) is read, commented and indented 4 spaces.

If the @:adhoc_verbatim:@ tag is already indented, the specified indentation is subtracted.

This flag is ignored, if double commented. E.g.:

# # @:adhoc_verbatim:@ file
@:adhoc_self:@ name …:

Mark name(s) as currently compiling. This is useful, if imports other module parts. E.g:

import pyjsmo # @:adhoc:@

where pyjsmo/ contains:

# @:adhoc_self:@ pyjsmo
from pyjsmo.base import * # @:adhoc:@

If present, no compilation is done on this file. This flag is added by the compiler to the run-time version.



Leading comment char and exactly one space are removed from lines in these sections.


A comment char and exactly one space are added to lines in these sections.

@:adhoc_template:@ -mark | export_file:

If mark starts with -, the output disposition is standard output and the template is ignored, when exporting.

Otherwise, the template is written to output_file during export.

All template parts with the same mark/export_file are concatenated to a single string.

@:adhoc_template_v:@ export_file:

Variation of @:adhoc_template:@. Automatically generated by @:adhoc_verbatim:@.


Treated like @:adhoc_enable:@ before template output.

@:adhoc_indent:@ [+|-]NUM:

Add or remove indentation before template output.


Imported files are marked as such by the compiler. There is no effect during compilation.


Included files are marked as such by the compiler. There is no effect during compilation.


Added sections are marked as such by the compiler. The flag is renamed to @:adhoc_remove_:@ during compilation. Which in turn is renamed to @:adhoc_remove:@ during export.


 Marks the beginning of the run-time class. This is only recognized in the AdHoc programm/module.
 All sections are concatenated and used as run-time code. This is only recognized in the AdHoc programm/module.

|:todo:| make enable/disable RX configurable

AdHoc Script/Module - Python ad hoc compiler.

usage: [OPTIONS] [file …]
or import adhoc


-c, –compile compile arguments. (default)
-q, –quiet suppress warnings
-v, –verbose verbose test output
-d, –debug[=NUM] show debug information
-h, –help display this help message
–documentation display module documentation.
–template list show available templates.
–template[=NAME] extract named template to standard output. Default NAME is -.
–extract[=DIR] extract adhoc files to directory DIR (default: .)
–explode[=DIR] explode script with adhoc in directory DIR (default __adhoc__)
–implode implode script with adhoc
–install install script
-t, –test run doc tests is compatible with Python 2.5+ and Python 3. (For Python 2.5 the packages stringformat and argparse are needed and included.)

Script Examples


Sections marked by @:adhoc_template:@ can be retrieved as templates on standard output.

Additionally, all other files compiled into an adhoc file with one of

@:adhoc:@ ==> @:adhoc_import:@
@:adhoc_verbatim:@ ==> @:adhoc_template_v:@
@:adhoc_include:@ ==> @:adhoc_unpack:@

are accessible as templates.

python --template list provides a list of templates:

>>> ign = main(' --template list'.split())
============================================== ============================= ================
                   Command                               Template                  Type
============================================== ============================= ================ --template adhoc_test                 # !adhoc_test                 adhoc_import --template adhoc_test.sub             # !adhoc_test.sub             adhoc_import --template argparse_local             # !argparse_local             adhoc_import --template namespace_dict             # !namespace_dict             adhoc_import --template stringformat_local         # !stringformat_local         adhoc_import --template docutils.conf              # docutils.conf               adhoc_template_v --template                            # -                           adhoc_template --template col-param-closure          # -col-param-closure          adhoc_template --template doc/index.rst              # doc/index.rst               adhoc_template --template max-width-class            # -max-width-class            adhoc_template --template rst-to-ascii               # -rst-to-ascii               adhoc_template --template test                       # -test                       adhoc_template --template                # !                adhoc_unpack --template Makefile                   # !Makefile                   adhoc_unpack --template README.css                 # !README.css                 adhoc_unpack --template doc/Makefile               # !doc/Makefile               adhoc_unpack --template doc/                # !doc/                adhoc_unpack --template doc/make.bat               # !doc/make.bat               adhoc_unpack --template                   # !                   adhoc_unpack --template # ! adhoc_unpack
============================================== ============================= ================

python --template prints the standard template -:

>>> ign = main('./ --template'.split())
Standard template.

python --template test prints the template named -test. the leading - signifies disposition to standard output:

>>> ign = main('./ --template test'.split())
Test template.


The default destination for extracting files is the current working directory.

Files extracted include packed files generated by @:adhoc_include:@, templates generated by @:adhoc_verbatim:@ and templates with a file destination other than standard output.

python --extract __adhoc_extract__ unpacks the following files into directory __adhoc_extract__:

>>> import shutil
>>> ign = main('./ --extract __adhoc_extract__'.split())
>>> for dir, subdirs, files in os.walk('__adhoc_extract__'):
...     for file in sorted(files):
...         printf(os.path.join(dir, file))
>>> shutil.rmtree('__adhoc_extract__')


The default destination for exporting files is the subdirectory __adhoc__.

Files exported include imported modules generated by @:adhoc:@ and all files covered in section Extract.

python --explode __adhoc_explode__ unpacks the following files into directory __adhoc_explode__:

>>> import shutil
>>> ign = main('./ --explode __adhoc_explode__'.split())
>>> for dir, subdirs, files in os.walk('__adhoc_explode__'):
...     for file in sorted(files):
...         printf(os.path.join(dir, file))
>>> shutil.rmtree('__adhoc_explode__')

Download files

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

Files for AdHoc, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size AdHoc-0.1.5.tar.gz (88.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page