fypp


Namefypp JSON
Version 3.2 PyPI version JSON
download
home_pagehttps://github.com/aradi/fypp
SummaryPython powered Fortran preprocessor
upload_time2023-08-22 08:25:26
maintainer
docs_urlNone
authorBálint Aradi
requires_python
licenseBSD
keywords fortran metaprogramming pre-processor
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            *********************************************
Fypp — Python powered Fortran metaprogramming
*********************************************

.. image:: https://travis-ci.org/aradi/fypp.svg?branch=develop
           :target: https://travis-ci.org/aradi/fypp

Fypp is a Python powered preprocessor. It can be used for any programming
languages but its primary aim is to offer a Fortran preprocessor, which helps to
extend Fortran with condititional compiling and template metaprogramming
capabilities. Instead of introducing its own expression syntax, it uses Python
expressions in its preprocessor directives, offering the consistency and
versatility of Python when formulating metaprogramming tasks. It puts strong
emphasis on robustness and on neat integration into developing toolchains.

The project is `hosted on github <https://github.com/aradi/fypp>`_.

`Detailed DOCUMENTATION <http://fypp.readthedocs.org>`_ is available on
`readthedocs.org <http://fypp.readthedocs.org>`_.

Fypp is released under the *BSD 2-clause license*.


Main features
=============

* Definition, evaluation and removal of variables::

    #:if DEBUG > 0
      print *, "Some debug information"
    #:endif

    #:set LOGLEVEL = 2
    print *, "LOGLEVEL: ${LOGLEVEL}$"

    #:del LOGLEVEL

* Macro definitions and macro calls::

    #:def ASSERT(cond)
      #:if DEBUG > 0
        if (.not. ${cond}$) then
          print *, "Assert failed in file ${_FILE_}$, line ${_LINE_}$"
          error stop
        end if
      #:endif
    #:enddef ASSERT

    ! Invoked via direct call (argument needs no quotation)
    @:ASSERT(size(myArray) > 0)

    ! Invoked as Python expression (argument needs quotation)
    $:ASSERT('size(myArray) > 0')

* Conditional output::

    program test
    #:if defined('WITH_MPI')
      use mpi
    #:elif defined('WITH_OPENMP')
      use openmp
    #:else
      use serial
    #:endif

* Iterated output (e.g. for generating Fortran templates)::

    interface myfunc
    #:for dtype in ['real', 'dreal', 'complex', 'dcomplex']
      module procedure myfunc_${dtype}$
    #:endfor
    end interface myfunc

* Inline directives::

    logical, parameter :: hasMpi = #{if defined('MPI')}# .true. #{else}# .false. #{endif}#

* Insertion of arbitrary Python expressions::

    character(*), parameter :: comp_date = "${time.strftime('%Y-%m-%d')}$"

* Inclusion of files during preprocessing::

    #:include "macrodefs.fypp"

* Using Fortran-style continutation lines in preprocessor directives::

    #:if var1 > var2 &
        & or var2 > var4
      print *, "Doing something here"
    #:endif

* Passing (unquoted) multiline string arguments to callables::

    #! Callable needs only string argument
    #:def DEBUG_CODE(code)
      #:if DEBUG > 0
        $:code
      #:endif
    #:enddef DEBUG_CODE

    #! Pass code block as first positional argument
    #:block DEBUG_CODE
      if (size(array) > 100) then
        print *, "DEBUG: spuriously large array"
      end if
    #:endblock DEBUG_CODE

    #! Callable needs also non-string argument types
    #:def REPEAT_CODE(code, repeat)
      #:for ind in range(repeat)
        $:code
      #:endfor
    #:enddef REPEAT_CODE

    #! Pass code block as positional argument and 3 as keyword argument "repeat"
    #:block REPEAT_CODE(repeat=3)
    this will be repeated 3 times
    #:endblock REPEAT_CODE

* Preprocessor comments::

    #! This will not show up in the output
    #! Also the newline characters at the end of the lines will be suppressed

* Suppressing the preprocessor output in selected regions::

    #! Definitions are read, but no output (e.g. newlines) will be produced
    #:mute
    #:include "macrodefs.fypp"
    #:endmute

* Explicit request for stopping the preprocessor::

    #:if DEBUGLEVEL < 0
      #:stop 'Negative debug level not allowed!'
    #:endif

* Easy check for macro parameter sanity::

    #:def mymacro(RANK)
      #! Macro only works for RANK 1 and above
      #:assert RANK > 0
      :
    #:enddef mymacro

* Line numbering directives in output::

    program test
    #:if defined('MPI')
    use mpi
    #:endif
    :

  transformed to ::

    # 1 "test.fypp" 1
    program test
    # 3 "test.fypp"
    use mpi
    # 5 "test.fypp"
    :

  when variable ``MPI`` is defined and Fypp was instructed to generate line
  markers.

* Automatic folding of generated lines exceeding line length limit


Installing
==========

Fypp needs a working Python 3 interpreter (Python 3.5 or above).

When you install Fypp, you obtain the command line tool ``fypp`` and the Python
module ``fypp.py``. Latter you can import if you want to access the
functionality of Fypp directly from within your Python scripts.


Installing via conda
--------------------

The last stable release of Fypp can be easily installed as conda package by
issuing ::

  conda install -c conda-forge fypp


Installing via pip
------------------

You can also use Pythons command line installer ``pip`` in order to download the
stable release from the `Fypp page on PyPI <http://pypi.python.org/pypi/fypp>`_
and install it on your system.

If you want to install Fypp into the module system of the active Python 3
interpreter (typically the case when you are using a Python virtual
environment), issue ::

  pip3 install fypp

Alternatively, you can install Fypp into the user space (under `~/.local`) with
::

  pip3 install --user fypp


Installing via MSYS2 pacman
---------------------------

On Windows you can use the `MSYS2 toolchain <https://www.msys2.org/>`_ to install
Fypp in a MinGW terminal. To install Fypp use::

  pacman -S mingw-w64-x86_64-python-fypp

Make sure the selected architecture is matching your current MinGW terminal.
For all supporting MinGW architectures visit check the package index
`here <https://packages.msys2.org/base/mingw-w64-python-fypp>`_.


Manual install
--------------

For a manual install, you can download the source code of the **stable**
releases from the `Fypp project website
<https://github.com/aradi/fypp/releases>`_.

If you wish to obtain the latest **development** version, clone the projects
repository::

  git clone https://github.com/aradi/fypp.git

and check out the `master` branch.

The command line tool is a single stand-alone script. You can run it directly
from the source folder ::

  FYPP_SOURCE_FOLDER/bin/fypp

or after copying it from the `bin` folder to any location listed in your `PATH`
environment variable, by just issuing ::

  fypp

The python module ``fypp.py`` can be found in ``FYP_SOURCE_FOLDER/src``.


Running
=======

The Fypp command line tool reads a file, preprocesses it and writes it to
another file, so you would typically invoke it like::

  fypp source.fpp source.f90

which would process `source.fpp` and write the result to `source.f90`.  If
input and output files are not specified, information is read from stdin and
written to stdout.

The behavior of Fypp can be influenced with various command line options. A
summary of all command line options can be obtained by::

  fypp -h

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aradi/fypp",
    "name": "fypp",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "fortran metaprogramming pre-processor",
    "author": "B\u00e1lint Aradi",
    "author_email": "aradi@uni-bremen.de",
    "download_url": "https://files.pythonhosted.org/packages/01/35/0e2dfffc90201f17436d3416f8d5c8b00e2187e410ec899bb62cf2cea59b/fypp-3.2.tar.gz",
    "platform": null,
    "description": "*********************************************\nFypp \u2014 Python powered Fortran metaprogramming\n*********************************************\n\n.. image:: https://travis-ci.org/aradi/fypp.svg?branch=develop\n           :target: https://travis-ci.org/aradi/fypp\n\nFypp is a Python powered preprocessor. It can be used for any programming\nlanguages but its primary aim is to offer a Fortran preprocessor, which helps to\nextend Fortran with condititional compiling and template metaprogramming\ncapabilities. Instead of introducing its own expression syntax, it uses Python\nexpressions in its preprocessor directives, offering the consistency and\nversatility of Python when formulating metaprogramming tasks. It puts strong\nemphasis on robustness and on neat integration into developing toolchains.\n\nThe project is `hosted on github <https://github.com/aradi/fypp>`_.\n\n`Detailed DOCUMENTATION <http://fypp.readthedocs.org>`_ is available on\n`readthedocs.org <http://fypp.readthedocs.org>`_.\n\nFypp is released under the *BSD 2-clause license*.\n\n\nMain features\n=============\n\n* Definition, evaluation and removal of variables::\n\n    #:if DEBUG > 0\n      print *, \"Some debug information\"\n    #:endif\n\n    #:set LOGLEVEL = 2\n    print *, \"LOGLEVEL: ${LOGLEVEL}$\"\n\n    #:del LOGLEVEL\n\n* Macro definitions and macro calls::\n\n    #:def ASSERT(cond)\n      #:if DEBUG > 0\n        if (.not. ${cond}$) then\n          print *, \"Assert failed in file ${_FILE_}$, line ${_LINE_}$\"\n          error stop\n        end if\n      #:endif\n    #:enddef ASSERT\n\n    ! Invoked via direct call (argument needs no quotation)\n    @:ASSERT(size(myArray) > 0)\n\n    ! Invoked as Python expression (argument needs quotation)\n    $:ASSERT('size(myArray) > 0')\n\n* Conditional output::\n\n    program test\n    #:if defined('WITH_MPI')\n      use mpi\n    #:elif defined('WITH_OPENMP')\n      use openmp\n    #:else\n      use serial\n    #:endif\n\n* Iterated output (e.g. for generating Fortran templates)::\n\n    interface myfunc\n    #:for dtype in ['real', 'dreal', 'complex', 'dcomplex']\n      module procedure myfunc_${dtype}$\n    #:endfor\n    end interface myfunc\n\n* Inline directives::\n\n    logical, parameter :: hasMpi = #{if defined('MPI')}# .true. #{else}# .false. #{endif}#\n\n* Insertion of arbitrary Python expressions::\n\n    character(*), parameter :: comp_date = \"${time.strftime('%Y-%m-%d')}$\"\n\n* Inclusion of files during preprocessing::\n\n    #:include \"macrodefs.fypp\"\n\n* Using Fortran-style continutation lines in preprocessor directives::\n\n    #:if var1 > var2 &\n        & or var2 > var4\n      print *, \"Doing something here\"\n    #:endif\n\n* Passing (unquoted) multiline string arguments to callables::\n\n    #! Callable needs only string argument\n    #:def DEBUG_CODE(code)\n      #:if DEBUG > 0\n        $:code\n      #:endif\n    #:enddef DEBUG_CODE\n\n    #! Pass code block as first positional argument\n    #:block DEBUG_CODE\n      if (size(array) > 100) then\n        print *, \"DEBUG: spuriously large array\"\n      end if\n    #:endblock DEBUG_CODE\n\n    #! Callable needs also non-string argument types\n    #:def REPEAT_CODE(code, repeat)\n      #:for ind in range(repeat)\n        $:code\n      #:endfor\n    #:enddef REPEAT_CODE\n\n    #! Pass code block as positional argument and 3 as keyword argument \"repeat\"\n    #:block REPEAT_CODE(repeat=3)\n    this will be repeated 3 times\n    #:endblock REPEAT_CODE\n\n* Preprocessor comments::\n\n    #! This will not show up in the output\n    #! Also the newline characters at the end of the lines will be suppressed\n\n* Suppressing the preprocessor output in selected regions::\n\n    #! Definitions are read, but no output (e.g. newlines) will be produced\n    #:mute\n    #:include \"macrodefs.fypp\"\n    #:endmute\n\n* Explicit request for stopping the preprocessor::\n\n    #:if DEBUGLEVEL < 0\n      #:stop 'Negative debug level not allowed!'\n    #:endif\n\n* Easy check for macro parameter sanity::\n\n    #:def mymacro(RANK)\n      #! Macro only works for RANK 1 and above\n      #:assert RANK > 0\n      :\n    #:enddef mymacro\n\n* Line numbering directives in output::\n\n    program test\n    #:if defined('MPI')\n    use mpi\n    #:endif\n    :\n\n  transformed to ::\n\n    # 1 \"test.fypp\" 1\n    program test\n    # 3 \"test.fypp\"\n    use mpi\n    # 5 \"test.fypp\"\n    :\n\n  when variable ``MPI`` is defined and Fypp was instructed to generate line\n  markers.\n\n* Automatic folding of generated lines exceeding line length limit\n\n\nInstalling\n==========\n\nFypp needs a working Python 3 interpreter (Python 3.5 or above).\n\nWhen you install Fypp, you obtain the command line tool ``fypp`` and the Python\nmodule ``fypp.py``. Latter you can import if you want to access the\nfunctionality of Fypp directly from within your Python scripts.\n\n\nInstalling via conda\n--------------------\n\nThe last stable release of Fypp can be easily installed as conda package by\nissuing ::\n\n  conda install -c conda-forge fypp\n\n\nInstalling via pip\n------------------\n\nYou can also use Pythons command line installer ``pip`` in order to download the\nstable release from the `Fypp page on PyPI <http://pypi.python.org/pypi/fypp>`_\nand install it on your system.\n\nIf you want to install Fypp into the module system of the active Python 3\ninterpreter (typically the case when you are using a Python virtual\nenvironment), issue ::\n\n  pip3 install fypp\n\nAlternatively, you can install Fypp into the user space (under `~/.local`) with\n::\n\n  pip3 install --user fypp\n\n\nInstalling via MSYS2 pacman\n---------------------------\n\nOn Windows you can use the `MSYS2 toolchain <https://www.msys2.org/>`_ to install\nFypp in a MinGW terminal. To install Fypp use::\n\n  pacman -S mingw-w64-x86_64-python-fypp\n\nMake sure the selected architecture is matching your current MinGW terminal.\nFor all supporting MinGW architectures visit check the package index\n`here <https://packages.msys2.org/base/mingw-w64-python-fypp>`_.\n\n\nManual install\n--------------\n\nFor a manual install, you can download the source code of the **stable**\nreleases from the `Fypp project website\n<https://github.com/aradi/fypp/releases>`_.\n\nIf you wish to obtain the latest **development** version, clone the projects\nrepository::\n\n  git clone https://github.com/aradi/fypp.git\n\nand check out the `master` branch.\n\nThe command line tool is a single stand-alone script. You can run it directly\nfrom the source folder ::\n\n  FYPP_SOURCE_FOLDER/bin/fypp\n\nor after copying it from the `bin` folder to any location listed in your `PATH`\nenvironment variable, by just issuing ::\n\n  fypp\n\nThe python module ``fypp.py`` can be found in ``FYP_SOURCE_FOLDER/src``.\n\n\nRunning\n=======\n\nThe Fypp command line tool reads a file, preprocesses it and writes it to\nanother file, so you would typically invoke it like::\n\n  fypp source.fpp source.f90\n\nwhich would process `source.fpp` and write the result to `source.f90`.  If\ninput and output files are not specified, information is read from stdin and\nwritten to stdout.\n\nThe behavior of Fypp can be influenced with various command line options. A\nsummary of all command line options can be obtained by::\n\n  fypp -h\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Python powered Fortran preprocessor",
    "version": "3.2",
    "project_urls": {
        "Homepage": "https://github.com/aradi/fypp"
    },
    "split_keywords": [
        "fortran",
        "metaprogramming",
        "pre-processor"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd14d06b92997e66c7766e1f163f2c117248156e497f00ce6cee46ccc71c8d88",
                "md5": "e388307244b8ba579e5a05944ddbeadc",
                "sha256": "ec9d6fd0e54529e7873732be642ea9098e06cc7a1cbe0eb7faee31be6c2267fa"
            },
            "downloads": -1,
            "filename": "fypp-3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e388307244b8ba579e5a05944ddbeadc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 29170,
            "upload_time": "2023-08-22T08:25:24",
            "upload_time_iso_8601": "2023-08-22T08:25:24.144699Z",
            "url": "https://files.pythonhosted.org/packages/cd/14/d06b92997e66c7766e1f163f2c117248156e497f00ce6cee46ccc71c8d88/fypp-3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01350e2dfffc90201f17436d3416f8d5c8b00e2187e410ec899bb62cf2cea59b",
                "md5": "f071e2fb88afd1b7d1cfdafb291e2564",
                "sha256": "05c20f71dd9a7206ffe2d8688032723f97b8c2984d472ba045819d7d2b513bce"
            },
            "downloads": -1,
            "filename": "fypp-3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "f071e2fb88afd1b7d1cfdafb291e2564",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 69307,
            "upload_time": "2023-08-22T08:25:26",
            "upload_time_iso_8601": "2023-08-22T08:25:26.014773Z",
            "url": "https://files.pythonhosted.org/packages/01/35/0e2dfffc90201f17436d3416f8d5c8b00e2187e410ec899bb62cf2cea59b/fypp-3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-22 08:25:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aradi",
    "github_project": "fypp",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "fypp"
}
        
Elapsed time: 0.10245s