-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from bitranox/development
v2.1.0
- Loading branch information
Showing
35 changed files
with
495 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
tested on linux "bionic" with python 3.6, 3.7, 3.8, 3.8-dev, pypy3 - architectures: amd64, ppc64le, s390x, arm64 | ||
|
||
`100% code coverage <https://codecov.io/gh/bitranox/rst_include>`_, codestyle checking ,mypy static type checking ,tested under `Linux, macOS, Windows <https://travis-ci.org/bitranox/rst_include>`_, automatic daily builds and monitoring | ||
`100% code coverage <https://codecov.io/gh/bitranox/rst_include>`_, flake8 style checking ,mypy static type checking ,tested under `Linux, macOS, Windows <https://travis-ci.org/bitranox/rst_include>`_, automatic daily builds and monitoring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
Yo 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. | ||
|
||
.. include:: ./parts/include_from_commandline.rst | ||
.. include:: ./usage_include_from_commandline.rst | ||
|
||
----------------------------------------------------------------- | ||
|
||
.. include:: ./parts/multiline_text_replacement.rst | ||
.. include:: ./usage_multiline_text_replacement.rst | ||
|
||
----------------------------------------------------------------- | ||
|
||
.. include:: ./parts/examples.rst | ||
.. include:: ./usage_examples.rst | ||
|
||
----------------------------------------------------------------- | ||
|
||
.. include:: ./parts/rst_file_examples.rst | ||
.. include:: ./usage_rst_file_examples.rst | ||
|
||
----------------------------------------------------------------- | ||
|
||
.. include:: ./parts/rst_file_include_parameters.rst | ||
.. include:: ./usage_rst_file_include_parameters.rst | ||
|
||
----------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Commandline Parameter | ||
===================== | ||
|
||
.. code-block:: bash | ||
STUB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Examples | ||
======== | ||
|
||
.. include:: ./usage_examples_python.rst | ||
|
||
---- | ||
|
||
.. include:: ./usage_examples_shellscript.rst | ||
|
||
---- | ||
|
||
.. include:: ./usage_examples_batch.rst | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Example Batch | ||
============= | ||
|
||
.. code-block:: bat | ||
REM | ||
REM rst_include needs to be installed and python paths set correctly | ||
@echo off | ||
cls | ||
rst_include include ./.docs/README_template.rst ./README.rst | ||
rst_include --inplace replace ./.docs/README_template.rst - "{{pattern}}" "replace string 1" | ||
echo 'finished' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Example Python | ||
============== | ||
|
||
.. code-block:: python | ||
# STDLIB | ||
import subprocess | ||
# OWN | ||
from rst_include import * | ||
def main(): | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Example Shellscript | ||
=================== | ||
|
||
.. code-block:: bash | ||
#!/bin/bash | ||
sudo_askpass="$(command -v ssh-askpass)" | ||
export SUDO_ASKPASS="${sudo_askpass}" | ||
export NO_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_include include ./.docs/README_template.rst ./README.rst | ||
echo "replace some patterns" | ||
# example for piping | ||
cat ./README.rst \ | ||
| rst_include --inplace replace - - "{{pattern1}}" "some_text_1" \ | ||
| rst_include --inplace replace - - "{{pattern2}}" "some_text_2" \ | ||
| rst_include --inplace replace - - "{{pattern3}}" "some_text_3" \ | ||
> ./README.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use rst_include from commandline | ||
-------------------------------- | ||
|
||
.. code-block:: bash | ||
# replace the include statements on shell or windows commandline | ||
# path can be relative or absolute path | ||
# examples : | ||
# relativ path | ||
$> rst_include include ./source.rst ./target.rst | ||
# absolute path | ||
$> rst_include include /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_include include - - > /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_include include - - > /project/docs/target.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
multiline text replacement | ||
-------------------------- | ||
|
||
Additional You can easily replace (also multiline) text strings : | ||
|
||
.. code-block:: bash | ||
# replace text strings easily | ||
# examples : | ||
$> rst_include replace ./source.rst ./target.rst "{{template_string}}" "new content" | ||
# multiline example | ||
# note ${IFS} is the standard bash seperator | ||
$> rst_include --inplace replace ./source.txt - "line1${IFS}line2" "line1${IFS}something_between${IFS}line2" | ||
piping under Linux: | ||
|
||
.. code-block:: bash | ||
# piping examples | ||
$> rst_include include ./source.rst - | rst_include replace - ./target.rst "{{pattern}}" "new content" | ||
# same result | ||
$> cat ./source.rst | rst_include include - - | rst_include replace - - "{template_string}" "new content" > ./target.rst | ||
# multiline example | ||
$> cat ./text.txt | rst_include replace - - "line1${IFS}line2" "line1${IFS}something_between${IFS}line2" > ./text.txt | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
rst file examples | ||
================= | ||
|
||
.. include:: ./usage_rst_file_examples_simple_code_include.rst | ||
|
||
|
||
.. include:: ./usage_rst_file_examples_txt_or_rst_include.rst | ||
|
||
|
||
.. include:: ./usage_rst_file_examples_jupyter_include.rst | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
include jupyter notebooks | ||
========================= | ||
|
||
jupyter notebooks can be first converted to rst via nbconvert, see : https://nbconvert.readthedocs.io/en/latest/usage.html#convert-rst | ||
|
||
pandoc is a requirement for nbconvert, see : https://pandoc.org/ | ||
|
||
|
||
.. code-block:: bash | ||
# convert the attached test.ipynb to test.rst | ||
$ jupyter nbconvert --to rst test.ipynb | ||
unfortunately the pictures are not shown and needed to be extracted - a first hint might be : https://gist.github.com/sglyon/5687b8455a0107afc6f4c60b5f313670 | ||
|
||
I 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
simple code include | ||
=================== | ||
|
||
.. code-block:: bash | ||
# 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-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
text or RST file include | ||
======================== | ||
.. code-block:: bash | ||
# 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: setting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
rst file include parameters | ||
=========================== | ||
|
||
taken from : http://docutils.sourceforge.net/docs/ref/rst/directives.html | ||
|
||
Standard 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: | ||
|
||
|
||
.. code-block:: bash | ||
.. include:: <isonum.txt> # not supported now | ||
The 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: | ||
|
||
.. code-block:: bash | ||
# 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 | ||
.. code-block:: bash | ||
# 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 | ||
.. code-block:: bash | ||
# 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 : text to find in the external data file | ||
.. code-block:: bash | ||
# 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 : text to find in the external data file | ||
.. code-block:: bash | ||
# The entire included text is inserted into the document as a single literal block. | ||
literal : flag (empty) | ||
.. code-block:: bash | ||
# 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 : formal language (optional) | ||
.. code-block:: bash | ||
# 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 : [start line number] | ||
.. code-block:: bash | ||
# The text encoding of the external data file. Defaults to the document's input_encoding. | ||
encoding : name of text encoding | ||
.. code-block:: bash | ||
# Number of spaces for hard tab expansion. A negative value prevents expansion of hard tabs. | ||
# Defaults to the tab_width configuration setting. | ||
tab-width : integer | ||
.. code-block:: bash | ||
With code or literal the common options :class: and :name: are recognized as well. | ||
all other option in the format :<option>: are just passed through the codeblock |
Oops, something went wrong.