{"id":22278471,"url":"https://github.com/devjack/preprocess","last_synced_at":"2025-07-12T02:02:59.897Z","repository":{"id":30901395,"uuid":"34459174","full_name":"devjack/preprocess","owner":"devjack","description":"Automatically exported from code.google.com/p/preprocess","archived":false,"fork":false,"pushed_at":"2015-04-23T13:55:13.000Z","size":240,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-25T18:23:10.115Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devjack.png","metadata":{"files":{"readme":"README.txt","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-23T13:52:30.000Z","updated_at":"2015-04-23T13:53:23.000Z","dependencies_parsed_at":"2022-09-05T21:30:24.446Z","dependency_job_id":null,"html_url":"https://github.com/devjack/preprocess","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devjack/preprocess","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fpreprocess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fpreprocess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fpreprocess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fpreprocess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devjack","download_url":"https://codeload.github.com/devjack/preprocess/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fpreprocess/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264923369,"owners_count":23683735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T15:14:38.583Z","updated_at":"2025-07-12T02:02:59.862Z","avatar_url":"https://github.com/devjack.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"preprocess.py -- a portable multi-language file preprocessor\n============================================================\n\nDownload the latest preprocess.py packages from here:\n    (archive) http://preprocess.googlecode.com/files/preprocess-1.1.0.zip\n\n\nHome            : http://trentm.com/projects/preprocess/\nLicense         : MIT (see LICENSE.txt)\nPlatforms       : Windows, Linux, Mac OS X, Unix\nCurrent Version : 1.1\nDev Status      : Fairly mature, has been used in the Komodo build system for\n                  over 7 years.\nRequirements    : Python \u003e= 2.3 (http://www.activestate.com/ActivePython/)\n\n\nWhat's new?\n-----------\n\nSupport has been added for preprocessing TeX, Fortran, C#, Java, Shell\nscript and PHP files. See the [Change Log](#changelog) below for more.\n\n\nWhy preprocess.py?\n------------------\n\nThere are millions of templating systems out there (most of them\ndeveloped for the web). This isn't one of those, though it does share\nsome basics: a markup syntax for templates that are processed to give\nresultant text output.  The main difference with `preprocess.py` is\nthat its syntax is hidden in comments (whatever the syntax for comments\nmaybe in the target filetype) so that the file can still have valid\nsyntax. A comparison with the C preprocessor is more apt.\n\n`preprocess.py` is targetted at build systems that deal with many\ntypes of files. Languages for which it works include: C++, Python,\nPerl, Tcl, XML, JavaScript, CSS, IDL, TeX, Fortran, PHP, Java, Shell\nscripts (Bash, CSH, etc.) and C#. Preprocess is usable both as a\ncommand line app and as a Python module.\n\nHere is how is works: All preprocessor statements are on their own\nline. A preprocessor statement is a comment (as appropriate for the\nlanguage of the file being preprocessed). This way the preprocessor\nstatements do not make an unpreprocessed file syntactically incorrect.\nFor example:\n\n    preprocess -D FEATURES=macros,scc myapp.py\n\nwill yield this transformation:\n\n    ...                                     ...\n    # #if \"macros\" in FEATURES\n    def do_work_with_macros():              def do_work_with_macros():\n        pass                                    pass\n    # #else\n    def do_work_without_macros():\n        pass \n    # #endif\n    ...                                     ...\n\nor, with a JavaScript file:\n\n    ...                                     ...\n    // #if \"macros\" in FEATURES\n    function do_work_with_macros() {        function do_work_with_macros() {\n    }                                       }\n    // #else\n    function do_work_without_macros() {\n    }\n    // #endif\n    ...                                     ...\n\nDespite these contrived examples preprocess has proved useful for\nbuild-time code differentiation in the\n[Komodo](http://www.activestate.com/Komodo) build system -- which\nincludes source code in Python, JavaScript, XML, CSS, Perl, and C/C++.\n\nThe #if expression (`\"macros\" in FEATURES` in the example) is Python\ncode, so has Python's full comparison richness.  A number of\npreprocessor statements are implemented:\n\n    #define VAR [VALUE]\n    #undef VAR\n    #ifdef VAR\n    #ifndef VAR\n    #if EXPRESSION\n    #elif EXPRESSION\n    #else\n    #endif\n    #error ERROR_STRING\n    #include \"FILE\"\n\nAs well, preprocess will do in-line substitution of defined variables.\nAlthough this is currently off by default because substitution will occur\nin program strings, which is not ideal. When a future version of\npreprocess can lex languages being preprocessed it will NOT substitute\ninto program strings and substitution will be turned ON by default.\n\nPlease send any feedback to [Trent Mick](mailto:trentm@google's mail\nthing.com).\n\n\nInstall Notes\n-------------\n\nDownload the latest `preprocess` source package, unzip it, and run `python\nsetup.py install`:\n\n    unzip preprocess-1.1.0.zip\n    cd preprocess-1.1.0\n    python setup.py install\n\nIf your install fails then please visit [the Troubleshooting\nFAQ](http://trentm.com/faq.html#troubleshooting-python-package-installation).\n\nThis will install `preprocess.py` into your Python `site-packages` and\nalso into your Python bin directory. If you can now run `preprocess`\nand get a response then you are good to go, otherwise read on.\n\nThe *problem* is that the Python bin directory is not always on your\nPATH on some operating systems -- notably Mac OS X. To finish the\ninstall on OS X either manually move 'preprocess' to somewhere on your\nPATH:\n\n    cp preprocess.py /usr/local/bin/preprocess\n\nor create a symlink to it (try one of these depending on your Python\nversion):\n\n    ln -s /System/Library/Frameworks/Python.framework/Versions/2.3/bin/preprocess /usr/local/bin/preprocess\n    ln -s /Library/Frameworks/Python.framework/Versions/2.4/bin/preprocess /usr/local/bin/preprocess\n\n(Note: You'll probably need to prefix those commands with `sudo` and\nthe exact paths may differ on your system.)\n\n\nGetting Started\n---------------\n\nOnce you have it install, run `preprocess --help` for full usage\ninformation:\n\n    $ preprocess --help\n    Preprocess a file.\n\n    Command Line Usage:\n        preprocess [\u003coptions\u003e...] \u003cinfile\u003e\n\n    Options:\n        -h, --help      Print this help and exit.\n        -V, --version   Print the version info and exit.\n        -v, --verbose   Give verbose output for errors.\n\n        -o \u003coutfile\u003e    Write output to the given file instead of to stdout.\n        -f, --force     Overwrite given output file. (Otherwise an IOError\n                        will be raised if \u003coutfile\u003e already exists.\n        -D \u003cdefine\u003e     Define a variable for preprocessing. \u003cdefine\u003e\n                        can simply be a variable name (in which case it\n                        will be true) or it can be of the form\n                        \u003cvar\u003e=\u003cval\u003e. An attempt will be made to convert\n                        \u003cval\u003e to an integer so \"-D FOO=0\" will create a\n                        false value.\n        -I \u003cdir\u003e        Add an directory to the include path for\n                        #include directives.\n\n        -k, --keep-lines    Emit empty lines for preprocessor statement\n                        lines and skipped output lines. This allows line\n                        numbers to stay constant.\n        -s, --substitute    Substitute defines into emitted lines. By\n                        default substitution is NOT done because it\n                        currently will substitute into program strings.\n\n    Module Usage:\n        from preprocess import preprocess\n        preprocess(infile, outfile=sys.stdout, defines={}, force=0,\n                   keepLines=0, includePath=[], substitute=0)\n\n    The \u003cinfile\u003e can be marked up with special preprocessor statement lines\n    of the form:\n        \u003ccomment-prefix\u003e \u003cpreprocessor-statement\u003e \u003ccomment-suffix\u003e\n    where the \u003ccomment-prefix/suffix\u003e are the native comment delimiters for\n    that file type. \n\n\n    Examples\n    --------\n\n    HTML (*.htm, *.html) or XML (*.xml, *.kpf, *.xul) files:\n\n        \u003c!-- #if FOO --\u003e\n        ...\n        \u003c!-- #endif --\u003e\n\n    Python (*.py), Perl (*.pl), Tcl (*.tcl), Ruby (*.rb), Bash (*.sh),\n    or make ([Mm]akefile*) files:\n\n        # #if defined('FAV_COLOR') and FAV_COLOR == \"blue\"\n        ...\n        # #elif FAV_COLOR == \"red\"\n        ...\n        # #else\n        ...\n        # #endif\n\n    C (*.c, *.h), C++ (*.cpp, *.cxx, *.cc, *.h, *.hpp, *.hxx, *.hh),\n    Java (*.java), PHP (*.php) or C# (*.cs) files:\n\n        // #define FAV_COLOR 'blue'\n        ...\n        /* #ifndef FAV_COLOR */\n        ...\n        // #endif\n\n    Fortran 77 (*.f) or 90/95 (*.f90) files:\n\n        C     #if COEFF == 'var'\n              ...\n        C     #endif\n\n\n    Preprocessor Syntax\n    -------------------\n\n    - Valid statements:\n        #define \u003cvar\u003e [\u003cvalue\u003e]\n        #undef \u003cvar\u003e\n        #ifdef \u003cvar\u003e\n        #ifndef \u003cvar\u003e\n        #if \u003cexpr\u003e\n        #elif \u003cexpr\u003e\n        #else\n        #endif\n        #error \u003cerror string\u003e\n        #include \"\u003cfile\u003e\"\n      where \u003cexpr\u003e is any valid Python expression.\n    - The expression after #if/elif may be a Python statement. It is an\n      error to refer to a variable that has not been defined by a -D\n      option or by an in-content #define.\n    - Special built-in methods for expressions:\n        defined(varName)    Return true if given variable is defined.  \n\n\n    Tips\n    ----\n\n    A suggested file naming convention is to let input files to\n    preprocess be of the form \u003cbasename\u003e.p.\u003cext\u003e and direct the output\n    of preprocess to \u003cbasename\u003e.\u003cext\u003e, e.g.:\n        preprocess -o foo.py foo.p.py\n    The advantage is that other tools (esp. editors) will still\n    recognize the unpreprocessed file as the original language.\n\n\nAnd, for module usage, read the preprocess.preprocess() docstring:\n\n    pydoc preprocess.preprocess\n\n\nChange Log\n----------\n\n### v1.1.0\n- Move to code.google.com/p/preprocess for code hosting.\n- Re-org directory structure to assist with deployment to pypi and\n  better installation with setup.py.\n- Pulled the \"content.types\" file that assists with filetype\n  determination into \"preprocess.py\". This makes \"preprocess.py\" fully\n  independent and also makes the \"setup.py\" simpler. The\n  \"-c|--content-types-path\" option can be used to specify\n  addition content types information.\n\n### v1.0.9\n- Fix the 'contentType' optional arg for #include's.\n- Add cheap XML content sniffing.\n\n### v1.0.8\n- Allow for JS and CSS-style comment delims in XML/HTML. Ideally this\n  would deal with full lexing but that isn't going to happen soon.\n\n### v1.0.7\n- Allow explicit specification of content type.\n### v1.0.6\n- Add ability to include a filename mentioned in a define: '#include\n  VAR'.\n\n\n### v1.0.5\n- Make sure to use the *longest* define names first when doing\n  substitutions. This ensure that substitution in this line:\n        FOO and BAR are FOOBAR\n  will do the right thing if there are \"FOO\" and \"FOOBAR\" defines.\n\n### v1.0.4\n- Add WiX XML file extensions.\n- Add XSLT file extensions.\n\n### v1.0.3\n- TeX support (from Hans Petter Langtangen)\n\n### v1.0.2\n- Fix a bug with -k|--keep-lines and preprocessor some directives in\n  ignored if blocks (undef, define, error, include): those lines were\n  not kept. (bug noted by Eric Promislow)\n\n### v1.0.1\n- Fix documentation error for '#define' statement. The correct syntax\n  is '#define VAR [VALUE]' while the docs used to say\n  '#define VAR[=VALUE]'. (from Hans Petter Langtangen)\n- Correct '! ...' comment-style for Fortran -- the '!' can be on any\n  column in Fortran 90. (from Hans Petter Langtangen)\n- Return a non-zero exit code on error.\n\n### v1.0.0\n- Update the test suite (it had been broken for quite a while) and add\n  a Fortran test case.\n- Improve Fortran support to support any char in the first column to\n  indicate a comment. (Idea from Hans Petter Langtangen)\n- Recognize '.f90' files as Fortran. (from Hans Petter Langtangen)\n- Add Java, C#, Shell script and PHP support. (from Hans Petter\n  Langtangen)\n\n### v0.9.2\n- Add Fortran support (from Hans Petter Langtangen)\n- Ensure content.types gets written to \"bindir\" next to preprocess.py\n  there so it can be picked up (from Hans Petter Langtangen).\n\n### v0.9.1\n- Fully read in the input file before processing. This allows\n  preprocessing of a file onto itself.\n\n### v0.9.0\n- Change version attributes and semantics. Before: had a _version_\n  tuple. After: __version__ is a string, __version_info__ is a tuple.\n\n### v0.8.1\n- Mentioned #ifdef and #ifndef in documentation (these have been there\n  for a while).\n- Add preprocess.exe to source package (should fix installation on\n  Windows).\n- Incorporate Komodo changes:\n    - change 171050: add Ruby support\n    - change 160914: Only attempt to convert define strings from the\n      command-line to *int* instead of eval'ing as any Python\n      expression: which could surprise with strings that work as\n      floats.\n    - change 67962: Fix '#include' directives in preprocessed files.\n\n### v0.8.0\n- Move hosting to trentm.com. Improve the starter docs a little bit.\n\n### 0.7.0:\n- Fix bug 1: Nested #if-blocks will not be properly handled.\n- Add 'Text' type for .txt files and default (with a warn) unknown\n  filetypes to 'Text'. Text files are defined to use to '#...'-style\n  comments to allow if/else/.../endif directives as in\n  Perl/Python/Tcl files.\n\n### 0.6.1:\n- Fix a bug where preprocessor statements were not ignored when not\n  emitting. For example the following should _not_ cause an error:\n    # #if 0\n    # #error womba womba womba\n    # #endif\n- Fix a bug where multiple uses of preprocess.preprocess() in the\n  same interpreter would erroneously re-use the same list of\n  __preprocessedFiles. This could cause false detection of recursive\n  #include's.\n- Fix #include, broken in 0.6.0.\n\n### 0.6.0:\n- substitution: Variables can now replaced with their defined value\n  in preprocessed file content. This is turned OFF by default\n  because, IMO, substitution should not be done in program strings.\n  I need to add lexing for all supported languages before I can do\n  *that* properly. Substitution can be turned on with the\n  --substitute command-line option or the subst=1 module interface\n  option.\n- Add support for preprocessing HTML files.\n\n### 0.5.0:\n- Add #error, #define, #undef, #ifdef and #ifndef statements.\n- #include statement, -I command line option and 'includePath'\n  module interface option to specify an include path\n- Add __FILE__ and __LINE__ default defines.\n- More strict and more helpful error messages:\n    - Lines of the form \"#else \u003cexpr\u003e\" and \"#endif \u003cexpr\u003e\" no longer\n      match.\n    - error messages for illegal #if-block constructs\n    - error messages for use of defined(BAR) instead of\n      defined('BAR') in expressions\n- New \"keep lines\" option to output blank lines for skipped content\n  lines and preprocessor statement lines (to preserve line numbers\n  in the processed file).\n\n### 0.4.0:\n- Add #elif preprocessor statement.\n- Add defined() built-in, e.g. #if defined('FOO')\n\n### 0.3.2:\n- Make #if expressions Python code.\n- Change \"defines\" attribute of preprocess.preprocess().\n- Add -f|--force option to overwrite given output file.\n\n### 0.2.0:\n- Add content types for C/C++.\n- Better module documentation.\n- You can define *false* vars on the command line now.\n- 'python setup.py install' works.\n\n### 0.1.0:\n- First release.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevjack%2Fpreprocess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevjack%2Fpreprocess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevjack%2Fpreprocess/lists"}