Skip to content

Commit

Permalink
Merge branch 'release-3.2' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed Aug 22, 2023
2 parents 724fb01 + 021f851 commit b8dd58b
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 47 deletions.
21 changes: 21 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.10"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# We recommend specifying your dependencies to enable reproducible builds:
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
16 changes: 11 additions & 5 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ Change Log
==========


3.2
===

Added
-----

* Option ``--file-var-root`` to render file variables (``_FILE_``,
``_THIS_FILE``) as relative paths with respect to a specified root.


3.1
===

Expand All @@ -22,11 +32,7 @@ Changed

* Support for Python 2.7, 3.3 and 3.4 dropped, support for Python 3.9 added.


Fixed
-----



3.0
===

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016-2021 Bálint Aradi, Universität Bremen
Copyright (c) 2016-2023 Bálint Aradi, Universität Bremen

All rights reserved.

Expand Down
53 changes: 42 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,52 @@ Main features
Installing
==========

Fypp needs a working Python interpreter. It is compatible with Python 2 (version
2.6 and above) and Python 3 (all versions).
Fypp needs a working Python 3 interpreter (Python 3.5 or above).

Automatic install
-----------------
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.

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::

pip install fypp
Installing via conda
--------------------

This installs both, 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.
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
Expand Down
30 changes: 24 additions & 6 deletions bin/fypp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# fypp -- Python powered Fortran preprocessor
#
# Copyright (c) 2016-2021 Bálint Aradi, Universität Bremen
# Copyright (c) 2016-2023 Bálint Aradi, Universität Bremen
#
# All rights reserved.
#
Expand Down Expand Up @@ -50,7 +50,7 @@ subclasses of `FyppError`_ is raised:
* FyppStopRequest: Stop was triggered by an explicit request in the input
(by a stop- or an assert-directive).
'''

import pathlib
import sys
import types
import inspect
Expand All @@ -66,7 +66,7 @@ import builtins
# Prevent cluttering user directory with Python bytecode
sys.dont_write_bytecode = True

VERSION = '3.1'
VERSION = '3.2'

STDIN = '<stdin>'

Expand Down Expand Up @@ -1323,10 +1323,12 @@ class Renderer:
Format 'std' emits #line pragmas, 'cpp' resembles GNU cpps special
format, and 'gfortran5' adds to cpp a workaround for a bug introduced in GFortran 5.
linefolder (callable): Callable to use when folding a line.
filevarroot (str, optional): render _FILE_ and _THIS_FILE_ as paths relative to this
root directory (default: paths are not converted explicitely to relative paths)
'''

def __init__(self, evaluator=None, linenums=False, contlinenums=False,
linenumformat=None, linefolder=None):
linenumformat=None, linefolder=None, filevarroot=None):
# Evaluator to use for Python expressions
self._evaluator = Evaluator() if evaluator is None else evaluator
self._evaluator.updateglobals(_SYSTEM_=platform.system(),
Expand Down Expand Up @@ -1360,6 +1362,13 @@ class Renderer:
else:
self._linefolder = linefolder

if filevarroot is None:
self._convert_file_path = lambda path: path
else:
self._convert_file_path = (
lambda path: pathlib.Path(path).relative_to(filevarroot)
)


def render(self, tree, divert=False, fixposition=False):
'''Renders a tree.
Expand Down Expand Up @@ -1739,6 +1748,7 @@ class Renderer:


def _update_predef_globals(self, fname, linenr):
fname = self._convert_file_path(fname)
self._evaluator.updatelocals(
_DATE_=time.strftime('%Y-%m-%d'), _TIME_=time.strftime('%H:%M:%S'),
_THIS_FILE_=fname, _THIS_LINE_=linenr + 1)
Expand Down Expand Up @@ -2528,7 +2538,8 @@ class Fypp:
if inspect.signature(renderer_factory) == inspect.signature(Renderer):
renderer = renderer_factory(
evaluator, linenums=linenums, contlinenums=contlinenums,
linenumformat=options.line_marker_format, linefolder=linefolder)
linenumformat=options.line_marker_format, linefolder=linefolder,
filevarroot=options.file_var_root)
else:
raise FyppFatalError('renderer_factory has incorrect signature')
self._preprocessor = Processor(parser, builder, renderer)
Expand Down Expand Up @@ -2579,7 +2590,7 @@ class Fypp:
@staticmethod
def _apply_definitions(defines, evaluator):
for define in defines:
words = define.split('=', 2)
words = define.split('=', 1)
name = words[0]
value = None
if len(words) > 1:
Expand Down Expand Up @@ -2673,6 +2684,7 @@ class FyppOptions(optparse.Values):
self.fixed_format = False
self.encoding = 'utf-8'
self.create_parent_folder = False
self.file_var_root = None


class FortranLineFolder:
Expand Down Expand Up @@ -2893,6 +2905,12 @@ def get_option_parser():
dest='create_parent_folder',
default=defs.create_parent_folder, help=msg)

msg = 'in variables _FILE_ and _THIS_FILE_, use relative paths with DIR '\
'as root directory. Note: the input file and all included files '\
'must be in DIR or in a directory below.'
parser.add_option('--file-var-root', metavar='DIR', dest='file_var_root',
default=defs.file_var_root, help=msg)

return parser


Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@

# General information about the project.
project = 'Fypp'
copyright = '2016-2021, Bálint Aradi'
copyright = '2016-2023, Bálint Aradi'
author = 'Bálint Aradi'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '3.1'
version = '3.2'
# The full version, including alpha/beta/rc tags.
release = '3.1'
release = '3.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
Loading

0 comments on commit b8dd58b

Please sign in to comment.