Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.1.1 #11

Merged
merged 2 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1.0 as of 2020-08-08 see `Changelog`_
Version v2.1.1 as of 2020-10-09 see `Changelog`_


.. include:: ./badges.rst
Expand Down
5 changes: 4 additions & 1 deletion .docs/badges.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
|travis_build| |license| |pypi|
|travis_build| |license| |pypi|

|codecov| |better_code| |cc_maintain| |cc_issues| |cc_coverage| |snyk|

Expand Down Expand Up @@ -36,3 +36,6 @@

.. |snyk| image:: https://img.shields.io/snyk/vulnerabilities/github/bitranox/rst_include
:target: https://snyk.io/test/github/bitranox/rst_include

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
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
tested on linux "bionic" with python 3.6, 3.7, 3.8, 3.9-dev, pypy3 - architectures: amd64, ppc64le, s390x, arm64

`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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ matrix:
- os: windows
if: true
language: sh
name: "Windows Python 3.8"
name: "Windows Python 3.9"

# oddly a secure password under env: global: causes that choco fails
# so we need to put the option : filter_secrets: false
Expand All @@ -71,7 +71,7 @@ matrix:
- chmod -R 0755 /usr/local/lib_bash
- chmod -R +x /usr/local/lib_bash/*.sh
- /usr/local/lib_bash/lib_retry.sh retry choco install python3
- export PATH="/c/Python38:/c/Python38/Scripts:$PATH"
- export PATH="/c/Python310:/c/Python310/Scripts:/c/Python39:/c/Python39/Scripts:/c/Python38:/c/Python38/Scripts:$PATH"
- export BUILD_DOCS="False"
- export DEPLOY_SDIST="False"
- export DEPLOY_WHEEL="False"
Expand Down Expand Up @@ -119,7 +119,7 @@ matrix:
arch: "amd64"
if: true
language: python
python: "3.8-dev"
python: "3.9-dev"
before_install:
- export BUILD_DOCS="False"
- export DEPLOY_SDIST="True"
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Changelog
- new MINOR version for added functionality in a backwards compatible manner
- new PATCH version for backwards compatible bug fixes

v2.1.1
--------
2020-10-09: service release
- update travis build matrix for linux 3.9-dev
- update travis build matrix (paths) for windows 3.9 / 3.10

v2.1.0
--------
2020-08-08: service release
Expand Down
13 changes: 11 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rst_include
===========


Version v2.1.0 as of 2020-08-08 see `Changelog`_
Version v2.1.1 as of 2020-10-09 see `Changelog`_

|travis_build| |license| |pypi|

Expand Down Expand Up @@ -43,6 +43,9 @@ Version v2.1.0 as of 2020-08-08 see `Changelog`_
.. |snyk| image:: https://img.shields.io/snyk/vulnerabilities/github/bitranox/rst_include
:target: https://snyk.io/test/github/bitranox/rst_include

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black

since 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
Expand All @@ -67,7 +70,7 @@ automated tests, Travis Matrix, Documentation, Badges, etc. are managed with `Pi

Python version required: 3.6.0 or newer

tested on linux "bionic" with python 3.6, 3.7, 3.8, 3.8-dev, pypy3 - architectures: amd64, ppc64le, s390x, arm64
tested on linux "bionic" with python 3.6, 3.7, 3.8, 3.9-dev, pypy3 - architectures: amd64, ppc64le, s390x, arm64

`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

Expand Down Expand Up @@ -474,6 +477,12 @@ Changelog
- new MINOR version for added functionality in a backwards compatible manner
- new PATCH version for backwards compatible bug fixes

v2.1.1
--------
2020-10-09: service release
- update travis build matrix for linux 3.9-dev
- update travis build matrix (paths) for windows 3.9 / 3.10

v2.1.0
--------
2020-08-08: service release
Expand Down
4 changes: 2 additions & 2 deletions rst_include/__init__conf__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = 'rst_include'
title = 'commandline tool to resolve RST File includes'
version = 'v2.1.0'
version = 'v2.1.1'
url = 'https://github.com/bitranox/rst_include'
author = 'Robert Nowotny'
author_email = '[email protected]'
Expand All @@ -14,7 +14,7 @@ def print_info() -> None:

commandline tool to resolve RST File includes

Version : v2.1.0
Version : v2.1.1
Url : https://github.com/bitranox/rst_include
Author : Robert Nowotny
Email : [email protected]""")
2 changes: 1 addition & 1 deletion rst_include/libs/lib_assemble_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_block_header(block: Block) -> str:
content = ''
if block.include_file_code:
content_lines = list()
content_lines.append('.. code-block:: {code}'.format(code=block.include_file_code))
content_lines.append(f'.. code-block:: {block.include_file_code}')
content_lines = content_lines + [pass_through_option.content for pass_through_option in block.pass_through_options]
content = '\n'.join(content_lines)
return content
Expand Down
15 changes: 3 additions & 12 deletions rst_include/libs/lib_block_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,22 @@ def get_option_key_from_source_line(source_line: SourceLine) -> str:

def log_and_raise_value_error_if_option_not_in_block(option: str, block: Block) -> None:
if not is_option_in_block(option, block):
s_error = 'Error in File: "{file}", option "{option}" not found in block starting with Line: {line}'.format(
file=block.source,
option=option,
line=block.l_source_lines[0].line_number)
s_error = f'Error in File: "{block.source}", option "{option}" not found in block starting with Line: {block.l_source_lines[0].line_number}'
lib_log_utils.log_error(s_error)
raise ValueError(s_error)


def log_and_raise_if_value_of_option_in_block_is_empty(value: str, option: str, block: Block) -> None:
if not value:
line_number = get_source_line_number_for_option(option, block)
s_error = 'Error in File "{source_file}", Line {line_number}: option "{option}" has no value'.format(
source_file=block.source,
line_number=line_number,
option=option)
s_error = f'Error in File "{block.source}", Line {line_number}: option "{option}" has no value'
lib_log_utils.log_error(s_error)
raise ValueError(s_error)


def log_and_raise_if_value_of_option_in_block_must_be_int_castable_but_is_not(value: str, option: str, block: Block, value_must_be_int: bool) -> None:
if value_must_be_int and not value.isdigit():
line_number = get_source_line_number_for_option(option, block)
s_error = 'Error in File "{source_file}", Line {line_number}: option "{option}" has to be integer'.format(
source_file=block.source,
line_number=line_number,
option=option)
s_error = f'Error in File "{block.source}", Line {line_number}: option "{option}" has to be integer'
lib_log_utils.log_error(s_error)
raise TypeError(s_error)
6 changes: 3 additions & 3 deletions rst_include/libs/lib_check_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def log_and_raise_if_source_file_not_ok(source: Union[str, pathlib.Path, IO[str]

if isinstance(source, pathlib.Path):
if not source.is_file():
error_message = 'RST File "{source}" does not exist'.format(source=source)
error_message = f'RST File "{source}" does not exist'
lib_log_utils.log_error(error_message)
raise FileNotFoundError(error_message)

Expand Down Expand Up @@ -138,7 +138,7 @@ def log_and_raise_if_source_file_equals_target_file(source: Union[str, pathlib.P
"""

if isinstance(source, pathlib.Path) and source == target:
error_message = 'RST File "{source}": source and target must not be the same'.format(source=source)
error_message = f'RST File "{source}": source and target must not be the same'
lib_log_utils.log_error(error_message)
raise FileExistsError(error_message)

Expand All @@ -157,7 +157,7 @@ def log_warning_if_target_file_exist(path_target: Union[str, pathlib.Path, IO[st
"""
if isinstance(path_target, pathlib.Path):
if path_target.is_file():
lib_log_utils.log_warning('RST File "{target}" exists and will be overwritten'.format(target=path_target))
lib_log_utils.log_warning(f'RST File "{path_target}" exists and will be overwritten')


def read_input(source: Union[str, pathlib.Path, IO[str]], encoding: str = 'utf-8-sig') -> str:
Expand Down
8 changes: 2 additions & 6 deletions rst_include/libs/lib_get_include_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def get_include_filename(block: Block) -> Tuple[pathlib.Path, pathlib.Path]:
include_line = block.l_source_lines[0].content
include_filename = include_line.split('.. include::')[1].strip()
if not include_filename:
s_error = 'Error in File "{source_file}", Line {line_number}: no include filename'.format(
source_file=block.source, line_number=block.l_source_lines[0].line_number)
s_error = f'Error in File "{block.source}", Line {block.l_source_lines[0].line_number}: no include filename'
lib_log_utils.log_error(s_error)
raise FileNotFoundError(s_error)

Expand All @@ -137,10 +136,7 @@ def get_include_filename(block: Block) -> Tuple[pathlib.Path, pathlib.Path]:
path_include_file_absolut = (pathlib.Path.cwd() / path_include_file).resolve()

if not path_include_file_absolut.is_file():
s_error = 'Error in File "{source_file}", Line {line_number}: include File "{include_filename}" does not exist'.format(
source_file=block.source,
line_number=block.l_source_lines[0].line_number,
include_filename=path_include_file)
s_error = f'Error in File "{block.source}", Line {block.l_source_lines[0].line_number}: include File "{path_include_file}" does not exist'
lib_log_utils.log_error(s_error)
raise FileNotFoundError(s_error)
block.include_filename = path_include_file
Expand Down
29 changes: 10 additions & 19 deletions rst_include/libs/lib_include_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ def read_include_file(block: Block) -> List[str]:
return include_file_lines

except FileNotFoundError:
s_error = 'Error in File "{source_file}", Line {line_number}: File not found : '\
'"{include_file}"'.format(source_file=block.source,
line_number=block.l_source_lines[0].line_number,
include_file=block.include_filename_absolut)
s_error = f'Error in File "{block.source}", Line {block.l_source_lines[0].line_number}: File not found : '\
'"{block.include_filename_absolut}"'
lib_log_utils.log_traceback.log_exception_traceback(s_error)
raise IOError(s_error)

Expand Down Expand Up @@ -223,23 +221,17 @@ def slice_include_file_markers(block: Block) -> None:

def log_and_raise_if_start_after_not_found_in_string(content: str, block: Block) -> None:
if block.include_file_start_after not in content:
s_error = 'Error in File "{source_file}", Line {line_number}: include File "{include_filename}" : start-after "{start_after}" not found'.format(
source_file=block.source,
line_number=block.l_source_lines[0].line_number,
include_filename=block.include_filename,
start_after=block.include_file_start_after)
s_error = f'Error in File "{block.source}", Line {block.l_source_lines[0].line_number}: '\
f'include File "{block.include_filename}" : start-after "{block.include_file_start_after}" not found'
s_error = s_error + get_additional_error_string(block)
lib_log_utils.log_error(s_error)
raise ValueError(s_error)


def log_and_raise_if_end_before_not_found_in_string(content: str, block: Block) -> None:
if block.include_file_end_before not in content:
s_error = 'Error in File "{source_file}", Line {line_number}: include File "{include_filename}" : end-before "{end_before}" not found'.format(
source_file=block.source,
line_number=block.l_source_lines[0].line_number,
include_filename=block.include_filename,
end_before=block.include_file_end_before)
s_error = f'Error in File "{block.source}", Line {block.l_source_lines[0].line_number}: ' \
f'include File "{block.include_filename}" : end-before "{block.include_file_end_before}" not found'
s_error = s_error + get_additional_error_string(block)
s_error = s_error + get_additional_error_string_start_after(block)
lib_log_utils.log_error(s_error)
Expand All @@ -249,17 +241,16 @@ def log_and_raise_if_end_before_not_found_in_string(content: str, block: Block)
def get_additional_error_string(block: Block) -> str:
s_error = ''
if block.include_file_start_line and block.include_file_end_line:
s_error = s_error + ' between start_line: {start_line} and end_line: {end_line}'.format(
start_line=block.include_file_start_line, end_line=block.include_file_end_line)
s_error = s_error + f' between start_line: {block.include_file_start_line} and end_line: {block.include_file_end_line}'
elif block.include_file_start_line:
s_error = s_error + ' after start-line: {start_line}'.format(start_line=block.include_file_start_line)
s_error = s_error + f' after start-line: {block.include_file_start_line}'
elif block.include_file_end_line:
s_error = s_error + ' before end-line: {end_line}'.format(end_line=block.include_file_end_line)
s_error = s_error + f' before end-line: {block.include_file_end_line}'
return s_error


def get_additional_error_string_start_after(block: Block) -> str:
s_error = ''
if block.include_file_start_after:
s_error = s_error + ' after start-after: {start_after}'.format(start_after=block.include_file_start_after)
s_error = s_error + f' after start-after: {block.include_file_start_after}'
return s_error
19 changes: 6 additions & 13 deletions rst_include/libs/lib_test_compare_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,15 @@ def read_files_into_lines(expected_file: pathlib.Path,


def log_file_lengths_not_equal(expected_file: pathlib.Path, result_file: pathlib.Path, len_expected_lines: int, len_result_lines: int) -> None:
lib_log_utils.log_error('Different Size, Expected File {expected_file}: {len_expected_lines} '
'Lines, Result File {result_file}: {len_result_lines} Lines'.format(expected_file=expected_file,
len_expected_lines=len_expected_lines,
result_file=result_file,
len_result_lines=len_result_lines))
lib_log_utils.log_error(f'Different Size, Expected File {expected_file}: {len_expected_lines} '
f'Lines, Result File {result_file}: {len_result_lines} Lines')


def log_difference_expected_line(expected_file: pathlib.Path, line_number: int, expected_line: str) -> None:
lib_log_utils.log_error('Difference, Expected File {expected_file}, Line {line_number}: "{expected_line}"'.format(
expected_file=expected_file,
line_number=line_number,
expected_line=expected_line.replace('\n', '<ret>')))
expected_line = expected_line.replace('\n', '<ret>')
lib_log_utils.log_error(f'Difference, Expected File {expected_file}, Line {line_number}: "{expected_line}"')


def log_difference_result_line(result_file: pathlib.Path, line_number: int, result_line: str) -> None:
lib_log_utils.log_error('Difference, Result File {result_file}, Line {line_number}: "{result_line}"'.format(
result_file=result_file,
line_number=line_number,
result_line=result_line.replace('\n', '<ret>')))
result_line = result_line.replace('\n', '<ret>')
lib_log_utils.log_error(f'Difference, Result File {result_file}, Line {line_number}: "{result_line}"')
6 changes: 3 additions & 3 deletions rst_include/rst_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def import_module_from_file(module_fullpath: Union[pathlib.Path, str], reload: b
spec = importlib.util.spec_from_file_location(module_name, module_fullpath)
if spec is None:
sys.path.pop()
raise ImportError('can not get spec from file location "{}"'.format(module_fullpath))
raise ImportError(f'can not get spec from file location "{module_fullpath}"')

try:
mod = importlib.util.module_from_spec(spec)
sys.modules[module_name] = mod
except Exception as exc:
raise ImportError('can not load module "{}"'.format(module_name)) from exc
raise ImportError(f'can not load module "{module_name}"') from exc
finally:
sys.path.pop()
sys.path.append(str(module_fullpath.parent))
Expand All @@ -111,7 +111,7 @@ def import_module_from_file(module_fullpath: Union[pathlib.Path, str], reload: b
spec.loader.exec_module(mod) # type: ignore
except Exception as exc:
sys.path.pop()
raise ImportWarning('module "{}" reloaded, but can not be executed'.format(module_name)) from exc
raise ImportWarning(f'module "{module_name}" reloaded, but can not be executed') from exc

return mod

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_line_data(line: str) -> str:

setup_kwargs: Dict[str, Any] = dict()
setup_kwargs["name"] = "rst_include"
setup_kwargs["version"] = "v2.1.0"
setup_kwargs["version"] = "v2.1.1"
setup_kwargs["url"] = "https://github.com/bitranox/rst_include"
setup_kwargs["packages"] = find_packages()
setup_kwargs["package_data"] = {"rst_include": ["py.typed", "*.pyi", "__init__.pyi"]}
Expand Down
12 changes: 12 additions & 0 deletions tests/local_testscripts/lib_bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ function cleanup() {
}


function run_black() {
# run black for *.py files
my_banner "running black with settings from ${project_root_dir}/pyproject.toml"
if ! python3 -m black "${project_root_dir}"/**/*.py; then
my_banner_warning "black ERROR"
beep
sleep "${sleeptime_on_error}"
return 1
fi
}


function run_flake8_tests() {
# run flake8, settings from setup.cfg
my_banner "running flake8 with settings from ${project_root_dir}/setup.cfg"
Expand Down
5 changes: 5 additions & 0 deletions tests/local_testscripts/run_testloop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ project_root_dir="${project_root_dir}"
DO_FLAKE8_TESTS="True"
DO_MYPY_TESTS="True"
DO_PYTEST="True"
DO_BLACK="False"
# cleanup on cntrl-c
trap cleanup EXIT

Expand All @@ -24,6 +25,10 @@ function pytest_loop {
banner "Project Root Dir: ${project_root_dir}"
cleanup

if [ "${DO_BLACK}" == "True" ]; then
if ! run_black; then continue; fi
fi

# we prefer to run tests on its own, not within pytest, due to shaky and outdated pytest plugins
if [ "${DO_FLAKE8_TESTS}" == "True" ]; then
if ! run_flake8_tests; then continue; fi
Expand Down