Skip to content

Commit

Permalink
Merge pull request #10 from bitranox/development
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
bitranox authored Aug 8, 2020
2 parents c8b2596 + a458717 commit a2c6acf
Show file tree
Hide file tree
Showing 35 changed files with 495 additions and 339 deletions.
2 changes: 1 addition & 1 deletion .docs/README_template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rst_include
===========


Version v2.0.8 as of 2020-08-01 see `Changelog`_
Version v2.1.0 as of 2020-08-08 see `Changelog`_


.. include:: ./badges.rst
Expand Down
17 changes: 2 additions & 15 deletions .docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@
python -m pip --upgrade pip
python -m pip --upgrade setuptools
python -m pip --upgrade wheel
.. include:: ./installation_via_pypi.rst

- to install the latest development version from github via pip:
- to install the latest version from github via pip:


.. code-block:: bash
# normal install
python -m pip install --upgrade git+https://github.com/bitranox/rst_include.git
# to test without installing (can be skipped)
python -m pip install git+https://github.com/bitranox/rst_include.git --install-option test
# to install and upgrade all dependencies regardless of version number
python -m pip install --upgrade git+https://github.com/bitranox/rst_include.git --upgrade-strategy eager
- include it into Your requirements.txt:

Expand All @@ -39,19 +32,13 @@
python -m pip install --upgrade -r /<path>/requirements.txt
- to install the latest development version from source code:

.. code-block:: bash
# cd ~
$ git clone https://github.com/bitranox/rst_include.git
$ cd rst_include
# to test without installing (can be skipped)
python setup.py test
# normal install
python setup.py install
Expand Down
4 changes: 0 additions & 4 deletions .docs/installation_via_pypi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

.. code-block:: bash
# install latest release from PyPi
python -m pip install --upgrade rst_include
# test latest release from PyPi without installing (can be skipped)
python -m pip install rst_include --install-option test
2 changes: 1 addition & 1 deletion .docs/tested_under.rst
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
10 changes: 5 additions & 5 deletions .docs/usage.rst
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

-----------------------------------------------------------------
6 changes: 6 additions & 0 deletions .docs/usage_commandline_parameter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Commandline Parameter
=====================

.. code-block:: bash
STUB
13 changes: 13 additions & 0 deletions .docs/usage_examples.rst
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

14 changes: 14 additions & 0 deletions .docs/usage_examples_batch.rst
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'
17 changes: 17 additions & 0 deletions .docs/usage_examples_python.rst
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()
22 changes: 22 additions & 0 deletions .docs/usage_examples_shellscript.rst
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
22 changes: 22 additions & 0 deletions .docs/usage_include_from_commandline.rst
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
29 changes: 29 additions & 0 deletions .docs/usage_multiline_text_replacement.rst
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
11 changes: 11 additions & 0 deletions .docs/usage_rst_file_examples.rst
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

17 changes: 17 additions & 0 deletions .docs/usage_rst_file_examples_jupyter_include.rst
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.
14 changes: 14 additions & 0 deletions .docs/usage_rst_file_examples_simple_code_include.rst
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
9 changes: 9 additions & 0 deletions .docs/usage_rst_file_examples_txt_or_rst_include.rst
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
79 changes: 79 additions & 0 deletions .docs/usage_rst_file_include_parameters.rst
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
Loading

0 comments on commit a2c6acf

Please sign in to comment.