### Install fprettify from source Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Installs fprettify from its source code, requiring Python Setuptools. The `--user` option can be used for local installation. ```sh pip install . ``` -------------------------------- ### fprettify Configuration File Example Source: https://context7.com/fortran-lang/fprettify/llms.txt Example of a configuration file (.fprettify.rc) for fprettify. This file can be placed in the home directory or parent directories of input files to set formatting options. ```ini # ~/.fprettify.rc or ./.fprettify.rc indent=4 line-length=100 whitespace=2 strict-indent=false enable-decl=true strip-comments=true comment-spacing=1 case=1 1 0 0 ``` -------------------------------- ### Install fprettify using pip Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Installs the latest release of fprettify using the pip package manager. This is the recommended method for most users. ```sh pip install --upgrade fprettify ``` -------------------------------- ### Install fprettify using Conda Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Installs fprettify using the Conda package manager from the conda-forge channel. This is an alternative installation method for users who prefer Conda. ```sh conda install -c conda-forge fprettify ``` -------------------------------- ### Fortran Code Formatting Example Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Demonstrates the transformation of unformatted Fortran code into a strictly formatted version using fprettify. This showcases the auto-indentation, spacing around operators, and alignment of line continuations. ```Fortran program demo integer :: endif, if, elseif integer, DIMENSION(2) :: function endif = 3; if = 2 if (endif == 2) then endif = 5 elseif = if + 4*(endif + & 2**10) elseif (endif == 3) then function(if) = endif/elseif print *, endif endif end program ``` -------------------------------- ### Configure fprettify with In-File Directives (Fortran) Source: https://context7.com/fortran-lang/fprettify/llms.txt fprettify allows overriding command-line formatting options directly within a Fortran source file using special comments. Lines starting with `! fprettify:` followed by arguments (e.g., `--indent 4`) enable specific formatting rules for that file. ```fortran ! fprettify: --indent 4 --whitespace 3 --enable-decl program myprogram integer :: x x = 1 end program ``` -------------------------------- ### Line Length and Comment Options (CLI) Source: https://context7.com/fortran-lang/fprettify/llms.txt Control line length and comment formatting with fprettify. Set the maximum line length, disable line length limits, strip whitespace before comments, and configure spacing between code and trailing comments. ```bash # Set maximum line length (default 132) fprettify --line-length 80 mycode.f90 # Unlimited line length fprettify --line-length 0 mycode.f90 # Strip whitespace before comments fprettify --strip-comments mycode.f90 # Set comment spacing (spaces between code and trailing comment) fprettify --strip-comments --comment-spacing 2 mycode.f90 ``` -------------------------------- ### Preprocessor and Editor Integration (CLI) Source: https://context7.com/fortran-lang/fprettify/llms.txt Handle preprocessor directives and integrate fprettify with editors. Options include disabling fypp preprocessor indentation, enabling silent mode for editors, and activating debug mode for verbose output. ```bash # Disable fypp preprocessor indentation fprettify --disable-fypp mycode.f90 # Silent mode for editor integration (suppress warnings) fprettify --silent mycode.f90 # Debug mode (verbose output) fprettify --debug mycode.f90 ``` -------------------------------- ### Strip comments and control spacing Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Command-line options for fprettify to remove whitespace before comment markers (`--strip-comments`) and to control the number of spaces between code and trailing comments (`--comment-spacing N`). ```sh fprettify --strip-comments --comment-spacing N ``` -------------------------------- ### Configure Integration Tests in INI format Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Configuration format for adding external code bases as integration test suites in fprettify. This INI-style configuration specifies how to obtain the test code, its relative path, and the test suite it belongs to (`regular` or `cron`). ```ini [...] # arbitrary unique section name identifying test code obtain: ... # Python command to obtain test code base path: ... # relative path pointing to test code location suite: ... # which suite this test code should belong to ``` -------------------------------- ### Format Fortran Files (CLI) Source: https://context7.com/fortran-lang/fprettify/llms.txt Format one or more Fortran files in-place using the fprettify command-line tool. Supports formatting single files, multiple files, from standard input, outputting to standard output, and showing diffs without modification. ```bash # Format single file fprettify mycode.f90 # Format multiple files fprettify file1.f90 file2.f90 file3.f90 # Format from stdin cat mycode.f90 | fprettify - # Output to stdout instead of in-place fprettify --stdout mycode.f90 # Show diff without modifying file fprettify --diff mycode.f90 ``` -------------------------------- ### Pre-commit Hook Configuration for fprettify Source: https://context7.com/fortran-lang/fprettify/llms.txt Integrate fprettify as a pre-commit hook to automatically format Fortran code before commits. This requires specifying the repository, revision, and the hook ID, along with any desired arguments. ```yaml # .pre-commit-config.yaml repos: - repo: https://github.com/pseewald/fprettify rev: v0.3.7 hooks: - id: fprettify args: ['--indent', '4', '--whitespace', '2'] ``` -------------------------------- ### VS Code Configuration for fprettify Source: https://context7.com/fortran-lang/fprettify/llms.txt Configure VS Code to use fprettify as the Fortran formatter. This involves setting the 'fortran.formatting.formatter' to 'fprettify' and optionally providing arguments like indentation and whitespace. ```json { "fortran.formatting.formatter": "fprettify", "fortran.formatting.fprettifyArgs": [ "--indent", "4", "--whitespace", "2" ] } ``` -------------------------------- ### Relational Operator and Case Conversion (CLI) Source: https://context7.com/fortran-lang/fprettify/llms.txt Manage Fortran and C-style relational operators and intrinsic case conversion using fprettify. Enable replacements, convert between styles, and set case for keywords, procedures, operators, and constants. ```bash # Enable relational operator replacement fprettify --enable-replacements mycode.f90 # Convert to C-style operators (.lt. -> <, .eq. -> ==) fprettify --enable-replacements --c-relations mycode.f90 # Convert to Fortran-style operators (< -> .lt., == -> .eq.) fprettify --enable-replacements mycode.f90 # Case conversion: [keywords, procedures, operators, constants] # 0=unchanged, 1=lowercase, 2=uppercase fprettify --case 1 1 1 1 mycode.f90 # all lowercase fprettify --case 2 2 2 2 mycode.f90 # all uppercase fprettify --case 1 0 0 0 mycode.f90 # only keywords lowercase ``` -------------------------------- ### Recursive Directory Formatting (CLI) Source: https://context7.com/fortran-lang/fprettify/llms.txt Recursively format all Fortran files within a directory tree using fprettify. Options include specifying indent width, excluding specific files or directories, custom file extensions, and excluding files based on line count. ```bash # Format all Fortran files in project directory fprettify -r ./src # Recursive with custom indent and exclusions fprettify -r ./src --indent 4 --exclude "*.bak" --exclude "build/*" # Recursive with custom extensions fprettify -r ./src -f .F90 -f .fpp # Exclude files larger than 1000 lines fprettify -r ./src --exclude-max-lines 1000 ``` -------------------------------- ### Recursively format Fortran project Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Applies fprettify formatting recursively to an entire Fortran project directory using the `-r` option. This is useful for batch formatting a whole codebase. ```sh fprettify -r ``` -------------------------------- ### Whitespace Formatting Options (CLI) Source: https://context7.com/fortran-lang/fprettify/llms.txt Configure whitespace around operators and delimiters with fprettify. Supports preset levels, disabling whitespace formatting, and fine-grained control over specific elements like commas, assignments, and relational operators. ```bash # Whitespace presets (0=minimal, 1-4=increasing amounts) fprettify --whitespace 0 mycode.f90 # minimal fprettify --whitespace 2 mycode.f90 # default: operators, print/read, plus/minus fprettify --whitespace 4 mycode.f90 # maximum: all operators including type selector # Disable whitespace formatting entirely fprettify --disable-whitespace mycode.f90 # Fine-grained whitespace control fprettify --whitespace-comma true --whitespace-assignment true mycode.f90 fprettify --whitespace-relational false mycode.f90 fprettify --whitespace-logical true --whitespace-plusminus false mycode.f90 fprettify --whitespace-multdiv true --whitespace-type true mycode.f90 # Enable declaration formatting (:: operator) fprettify --enable-decl mycode.f90 ``` -------------------------------- ### Read Fortran Lines with Continuations (Python) Source: https://context7.com/fortran-lang/fprettify/llms.txt The InputStream class reads Fortran code from a file-like object, intelligently handling line continuations ('&'). It yields logical lines of Fortran code, preserving comments and separating parts of the line. This is crucial for accurate parsing of multi-line Fortran statements. ```python import io from fprettify.fparse_utils import InputStream code = """program test x = 1 + 2 + & 3 + 4 end program """ infile = io.StringIO(code) stream = InputStream(infile, filter_fypp=True) while True: joined_line, comments, lines = stream.next_fortran_line() if not lines: break print(f"Line {stream.line_nr}:") print(f" Joined: {repr(joined_line)}") print(f" Parts: {lines}") ``` -------------------------------- ### Handle fprettify Exceptions (Python) Source: https://context7.com/fortran-lang/fprettify/llms.txt fprettify defines custom exception classes to handle specific errors during code formatting. FprettifyParseException is for syntax errors, FprettifyInternalException for unexpected internal issues, and FprettifyException as a base class. These exceptions aid in robust error handling. ```python from fprettify.fparse_utils import ( FprettifyException, FprettifyParseException, FprettifyInternalException ) try: # Formatting code that might have issues from fprettify import reformat_inplace reformat_inplace("broken.f90") except FprettifyParseException as e: print(f"Parse error in {e.filename} at line {e.line_nr}: {e}") except FprettifyInternalException as e: print(f"Internal error in {e.filename} at line {e.line_nr}: {e}") except FprettifyException as e: print(f"General fprettify error: {e}") ``` -------------------------------- ### Format Fortran Code Programmatically (Python) Source: https://context7.com/fortran-lang/fprettify/llms.txt The reformat_ffile function allows programmatic formatting of Fortran code from an input stream to an output stream. It accepts various options to control indentation, whitespace, and line length. This is useful for integrating fprettify into larger Python applications. ```python import io from fprettify import reformat_ffile # Format Fortran code from string input_code = """program test integer::x,y x=1;y=2 if(x==1)then y=3 endif end program """ infile = io.StringIO(input_code) outfile = io.StringIO() reformat_ffile( infile, outfile, impose_indent=True, indent_size=3, impose_whitespace=True, whitespace=2, llength=132, orig_filename="test.f90" ) print(outfile.getvalue()) ``` -------------------------------- ### Add Unit Test Skeleton in Python Source: https://github.com/fortran-lang/fprettify/blob/master/README.md A Python skeleton for adding a new unit test to fprettify. This involves defining a test method, specifying input and expected output Fortran code, and listing fprettify command-line arguments. It utilizes a helper function `assert_fprettify_result` for verification. ```python def test_something(self): """short description""" in = "Some Fortran code" out = "Same Fortran code after fprettify formatting" # selected fprettify command line arguments, as documented in "fprettify.py -h": opt = ["arg 1", "value for arg 1", "arg2", ...] # helper function checking that fprettify output is equal to "out": self.assert_fprettify_result(opt, in, out) ``` -------------------------------- ### Vim editor integration for fprettify Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Configuration for Vim to use fprettify as the external formatting program for Fortran files. This allows fprettify to be invoked using Vim's `gq` command. ```vim autocmd Filetype fortran setlocal formatprg=fprettify\ --silent ``` -------------------------------- ### Format Fortran files inplace Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Command-line usage of fprettify to format one or more Fortran files in place. The `--indent` option allows customization of the indentation level. ```sh fprettify file1, file2, ... ``` ```sh fprettify --indent n ``` -------------------------------- ### Indentation Options (CLI) Source: https://context7.com/fortran-lang/fprettify/llms.txt Control code block indentation in fprettify. Options include setting the indent width, disabling auto-indentation, enforcing strict indentation for nested loops, and disabling indentation after module/program statements. ```bash # Set indent width to 4 spaces (default is 3) fprettify --indent 4 mycode.f90 # Disable auto-indentation entirely fprettify --disable-indent mycode.f90 # Strict indentation for nested loops (ignores existing alignment) fprettify --strict-indent mycode.f90 # Disable indentation after module/program statements fprettify --disable-indent-mod mycode.f90 ``` -------------------------------- ### Format Fortran Files In-Place or to Stdout (Python) Source: https://context7.com/fortran-lang/fprettify/llms.txt The reformat_inplace function formats a specified Fortran file. It can modify the file directly, output the formatted content to standard output, or generate a diff. This function provides a comprehensive set of options for fine-tuning the formatting process. ```python from fprettify import reformat_inplace # Format file in-place reformat_inplace("mycode.f90", indent_size=4, whitespace=2) # Output to stdout instead reformat_inplace("mycode.f90", stdout=True, indent_size=3) # Generate diff only reformat_inplace("mycode.f90", diffonly=True) # Full options reformat_inplace( "mycode.f90", stdout=False, diffonly=False, impose_indent=True, indent_size=4, strict_indent=False, impose_whitespace=True, whitespace=2, whitespace_dict={ 'comma': True, 'assignments': True, 'relational': True, 'logical': True, 'plusminus': True, 'multdiv': False, 'print': True, 'type': False, 'intrinsics': True, 'decl': True, 'concat': False }, llength=132, strip_comments=True, comment_spacing=1, format_decl=True, indent_fypp=True, indent_mod=True ) ``` -------------------------------- ### Deactivate fprettify with inline comments Source: https://github.com/fortran-lang/fprettify/blob/master/README.md Demonstrates how to temporarily deactivate fprettify's auto-formatting for specific lines or blocks of code using special inline comments (`!&`, `!&<`, `!&>`). This is useful for manual alignment or when dealing with non-standard syntax. ```Fortran A = [-1, 10, 0, & !& 0, 1000, 0, & !& 0, -1, 1] !& ``` ```Fortran !&< A = [-1, 10, 0, & 0, 1000, 0, & 0, -1, 1] !&> ``` -------------------------------- ### Configure Vim for fprettify Formatting (Vimscript) Source: https://context7.com/fortran-lang/fprettify/llms.txt Vim can be configured to use fprettify for automatic code formatting. By setting the `formatprg` option in `.vimrc` to `fprettify --silent`, users can format code using standard Vim commands like `ggVGgq` for the entire file or `gq` for selections. ```vimscript " Add to .vimrc autocmd Filetype fortran setlocal formatprg=fprettify\ --silent " Format entire file: ggVGgq " Format selection: visual select then gq " Format paragraph: gqap ``` -------------------------------- ### Disable Formatting with Inline Comments (Fortran) Source: https://context7.com/fortran-lang/fprettify/llms.txt Fortran code can use specific inline comments to disable fprettify's automatic formatting for individual lines or blocks. The `!&` suffix disables formatting for a line, while `!&<` and `!&>` delimit blocks where formatting is suspended, useful for manual alignment. ```fortran ! Disable formatting for individual lines with !& suffix my_integer = 2 !& i = 3 !& j = 5 !& ! Disable formatting for a block with !&< and !&> !&< matrix = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] !&> ! Disable auto-alignment for array continuations big_arr = [ 1, 2, 3, 4, 5, & !& 6, 7, 8, 9, 10, & !& 11, 12, 13, 14, 15] !& ``` -------------------------------- ### Filter Fortran Code Characters (Python) Source: https://context7.com/fortran-lang/fprettify/llms.txt The CharFilter class is an iterator that processes Fortran code character by character, filtering out comments, strings, and preprocessor directives. It can be used to iterate over code elements or to obtain a filtered string, with options to disable specific filtering behaviors. ```python from fprettify.fparse_utils import CharFilter code = 'x = 1 + 2 ! comment here' # Iterate over code, filtering comments and strings for pos, char in CharFilter(code): print(f"Position {pos}: '{char}'") # Get filtered string filtered = CharFilter(code).filter_all() print(filtered) # Disable comment filtering for pos, char in CharFilter(code, filter_comments=False): print(f"Position {pos}: '{char}'") # Disable string filtering code_with_string = 'x = "hello world"' for pos, char in CharFilter(code_with_string, filter_strings=False): print(f"Position {pos}: '{char}'") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.