Package: rst-include
rst_includeVersion v2.1.3 as of 2023-07-21 seeChangelogsince You can not include files into RST files on github or PyPi, You can resolve such imports with this software.That means You can locally write Your RST documents (for instance with pycharm) and use there
the.. include:option to include other RST Files or code snippets into Your Document.
Afterwards You can run this software to create a monolithic README.rst that can be viewed on Github or PypiYou might also include Text/Code from Jupyter Notebooks (sorry, no pictures at the moment, but it is not very hard to do that)This has many advantages like :dont repeat Yourself, create standard blocks to include into Your documentationinclude tested code snippets from Your code files into Your documentation, to avoid untested or outdated documentationinclude other RST Filesvery simple usage, throwing exit codes to detect errors on documentation at travis build-timecommandline or programmatic interface, You can even use it in the travis.ymlcommandline interface supporting shellscript, cmd, pipes, config-filesautomated tests, Github Actions, Documentation, Badges, etc. are managed withPizzaCutter(cookiecutter on steroids)Python version required: 3.8.0 or newertested on recent linux with python 3.8, 3.9, 3.10, 3.11, 3.12-dev, pypy-3.9, pypy-3.10 - architectures: amd64100% code coverage, flake8 style checking ,mypy static type checking ,tested underLinux, macOS, Windows, automatic daily builds and monitoringUsageUsage from CommandlineInstallation and UpgradeRequirementsAcknowledgementsContributeReport IssuesPull RequestCode of ConductLicenseChangelogUsageYo might use rst_include from the commandline (Windows, Linux and MacOs is supported) or import the module to Your python script and use it from there. You
can also use it from Bash Scripts and Windows Batch Files - See Examples.use rst_include from commandline# replace the include statements on shell or windows commandline
# path can be relative or absolute path
# examples :# relativ path$>rst_includeinclude./source.rst./target.rst# absolute path$>rst_includeinclude/project/docs/source.rst/project/docs/target.rst# on linux via pipe - You need to change to the source directory first because of relative include paths$>cd/project/docs$>cat./source.rst|rst_includeinclude-->/project/docs/target.rst# on Windows via pipe - You need to change to the source directory first because of relative include paths$>cd/project/docs$>type./source.rst|rst_includeinclude-->/project/docs/target.rstmultiline text replacementAdditional You can easily replace (also multiline) text strings :# replace text strings easily
# examples :$>rst_includereplace./source.rst./target.rst"{{template_string}}""new content"# multiline example
# note ${IFS} is the standard bash seperator$>rst_include--inplacereplace./source.txt-"line1${IFS}line2""line1${IFS}something_between${IFS}line2"piping under Linux:# piping examples$>rst_includeinclude./source.rst-|rst_includereplace-./target.rst"{{pattern}}""new content"# same result$>cat./source.rst|rst_includeinclude--|rst_includereplace--"{template_string}""new content">./target.rst# multiline example$>cat./text.txt|rst_includereplace--"line1${IFS}line2""line1${IFS}something_between${IFS}line2">./text.txtExamplesExample Python# STDLIBimportsubprocess# OWNfromrst_includeimport*defmain():rst_inc(source='./.docs/README_template.rst',target='./README.rst')rst_str_replace(source='./README.rst',target='',str_pattern='{{some pattern}}',str_replace='some text',inplace=True)if__name__=='__main':main()Example Shellscript#!/bin/bashsudo_askpass="$(command-vssh-askpass)"exportSUDO_ASKPASS="${sudo_askpass}"exportNO_AT_BRIDGE=1# get rid of (ssh-askpass:25930): dbind-WARNING **: 18:46:12.019: Couldn't register with accessibility bus: Did not receive a reply.echo"import the include blocks"rst_includeinclude./.docs/README_template.rst./README.rstecho"replace some patterns"# example for pipingcat./README.rst\|rst_include--inplacereplace--"{{pattern1}}""some_text_1"\|rst_include--inplacereplace--"{{pattern2}}""some_text_2"\|rst_include--inplacereplace--"{{pattern3}}""some_text_3"\>./README.rstExample BatchREMREM rst_include needs to be installed and python paths set correctly@echooffclsrst_include include ./.docs/README_template.rst ./README.rst
rst_include --inplace replace ./.docs/README_template.rst -"{{pattern}}""replace string 1"echo'finished'rst file examplessimple code include# simple text include, empty line after..include::./include1.py:code:python:number-lines:10:start-line:6:end-line:23:start-after:# start marker:end-before:# end-marker:encoding:utf-8text or RST file include# simple text include, without code setting - it is imported as normal textfile, as it is.
# You might also include other rst files..include::include3.py:start-line:0# working, also end-line, etc ... all others suppressed.:number-lines:# not working without :code: settinginclude jupyter notebooksjupyter notebooks can be first converted to rst via nbconvert, see :https://nbconvert.readthedocs.io/en/latest/usage.html#convert-rstpandoc is a requirement for nbconvert, see :https://pandoc.org/# convert the attached test.ipynb to test.rst$jupyternbconvert--torsttest.ipynbunfortunately the pictures are not shown and needed to be extracted - a first hint might be :https://gist.github.com/sglyon/5687b8455a0107afc6f4c60b5f313670I would prefer to exctract the pictures after the conversion to RST, and make it a module in rst_include.
Filenames can be a hash of the picture data, in order to avoid web caching issues.rst file include parameterstaken from :http://docutils.sourceforge.net/docs/ref/rst/directives.htmlStandard data files intended for inclusion in reStructuredText documents are distributed with the Docutils source code, located in the “docutils” package in the docutils/parsers/rst/include directory.
To access these files, use the special syntax for standard “include” data files, angle brackets around the file name:..include::<isonum.txt># not supported nowThe current set of standard “include” data files consists of sets of substitution definitions. See reStructuredText Standard Definition Files for details.The following options are recognized:# Only the content starting from this line will be included.
# (As usual in Python, the first line has index 0 and negative values count from the end.)
# Combining start/end-line and start-after/end-before is possible.
# The text markers will be searched in the specified lines (further limiting the included content).start-line:integer# Only the content up to (but excluding) this line will be included.
# Combining start/end-line and start-after/end-before is possible.
# The text markers will be searched in the specified lines (further limiting the included content).end-line:integer# Only the content after the first occurrence of the specified text will be included.
# Combining start/end-line and start-after/end-before is possible.
# The text markers will be searched in the specified lines (further limiting the included content).start-after:texttofindintheexternaldatafile# Only the content before the first occurrence of the specified text (but after any after text) will be included.
# Combining start/end-line and start-after/end-before is possible.
# The text markers will be searched in the specified lines (further limiting the included content).end-before:texttofindintheexternaldatafile# The entire included text is inserted into the document as a single literal block.literal:flag(empty)# The argument and the content of the included file are passed to the code directive (useful for program listings).
# (New in Docutils 0.9)code:formallanguage(optional)# Precede every code line with a line number. The optional argument is the number of the first line (default 1).
# Works only with code or literal. (New in Docutils 0.9)number-lines:[startlinenumber]# The text encoding of the external data file. Defaults to the document's input_encoding.encoding:nameoftextencoding# Number of spaces for hard tab expansion. A negative value prevents expansion of hard tabs.
# Defaults to the tab_width configuration setting.tab-width:integerWithcodeorliteralthecommonoptions:class:and:name:arerecognizedaswell.allotheroptionintheformat:<option>:arejustpassedthroughthecodeblockUsage from CommandlineUsage: rst_include [OPTIONS] COMMAND [ARGS]...

  commandline tool to resolve RST File includes

Options:
  --version                     Show the version and exit.
  --traceback / --no-traceback  return traceback information on cli
  -h, --help                    Show this message and exit.

Commands:
  include  include the include files, use "-" for stdin as SOURCE and "-"...
  info     get program informations
  replace  replace <str_pattern> with <str_replace> <count> timesInstallation and UpgradeBefore You start, its highly recommended to update pip and setup tools:python -m pip --upgrade pip
python -m pip --upgrade setuptoolsto install the latest release from PyPi via pip (recommended):python -m pip install --upgrade rst_includeto install the latest release from PyPi via pip, including test dependencies:python -m pip install --upgrade rst_include[test]to install the latest version from github via pip:python -m pip install --upgrade git+https://github.com/bitranox/rst_include.gitinclude it into Your requirements.txt:# Insert following line in Your requirements.txt:
# for the latest Release on pypi:
rst_include

# for the latest development version :
rst_include @ git+https://github.com/bitranox/rst_include.git

# to install and upgrade all modules mentioned in requirements.txt:
python -m pip install --upgrade -r /<path>/requirements.txtto install the latest development version, including test dependencies from source code:# cd ~
$ git clone https://github.com/bitranox/rst_include.git
$ cd rst_include
python -m pip install -e .[test]via makefile:
makefiles are a very convenient way to install. Here we can do much more,
like installing virtual environments, clean caches and so on.# from Your shell's homedirectory:$gitclonehttps://github.com/bitranox/rst_include.git$cdrst_include# to run the tests:$maketest# to install the package$makeinstall# to clean the package$makeclean# uninstall the package$makeuninstallRequirementsfollowing modules will be automatically installed :## Project Requirementsclickcli_exit_toolslib_listlib_log_utilspathlib3xAcknowledgementsspecial thanks to “uncle bob” Robert C. Martin, especially for his books on “clean code” and “clean architecture”ContributeI would love for you to fork and send me pull request for this project.
-please ContributeLicenseThis software is licensed under theMIT license—Changelognew MAJOR version for incompatible API changes,new MINOR version for added functionality in a backwards compatible mannernew PATCH version for backwards compatible bug fixesv2.1.32023-07-21:require minimum python 3.8remove python 3.7 testsintroduce PEP517 packaging standardintroduce pyproject.toml build-systemremove mypy.iniremove pytest.iniremove setup.cfgremove setup.pyremove .bettercodehub.ymlremove .travis.ymlupdate black configclean ./tests/test_cli.pyadd codeql badgemove 3rd_party_stubs outside the src directory to./.3rd_party_stubsadd pypy 3.10 testsadd python 3.12-dev testsv2.1.2.22022-06-02: setup github actions v3, python3.10 test matrixv2.1.12020-10-09: service releaseupdate travis build matrix for linux 3.9-devupdate travis build matrix (paths) for windows 3.9 / 3.10v2.1.02020-08-08: service releasefix documentationfix travisdeprecate pycodestyleimplement flake8v2.0.92020-08-07: implement flake8 - transitionalv2.0.82020-08-01: fix pypi deployv2.0.72020-07-31: fix travis buildv2.0.62020-07-31: fix environ.pop issue in doctestv2.0.52020-07-29: feature releaseuse the new pizzacutter templateuse cli_exit_toolsv2.0.42020-07-23: patch releaseadopt lib_log_utils 0.3.0v2.0.32020-07-16: feature releasefix cli testenable traceback option on cli errorsv2.0.22020-07-16: patch releasefix cli testenable traceback option on cli errorsv2.0.12020-07-05patch releasefix typosmanage project with PizzaCutterrestructured cli entry pointsv2.0.02020-06-19new CLI Interfaceavoid recursive importsmanage the project with lib_travis_templatev1.0.9drop support for configfilesupdate documentationimplement –version on commandlinetest commandline registrationstrict mypy typechecking1.0.8drop python 2.7 / 3.4 supportimplement –inplace optionimplement –quiet optionimplement multiline string replacementextend documentation1.0.22019-04-28: fix import errors1.0.12019-04-28: add empty line at the end of the assembled documentation, to be able to add CHANGES.rst with setup.py1.0.02019-04-19: Initial public release, PyPi Release