diff --git a/.gitignore b/.gitignore index 3831f63..53739d4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.MD !README.md !CONTRIBUTING.md +!SECURITY.md benchmark.csv # Byte-compiled / optimized / DLL files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d813ab..1b45ce2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,45 +1,49 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.5.0' - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - - id: check-added-large-files - - id: destroyed-symlinks - - id: detect-private-key - - id: check-ast - - id: check-case-conflict - - id: debug-statements - - id: fix-encoding-pragma - - id: forbid-submodules - - id: check-symlinks - - id: check-shebang-scripts-are-executable - - id: check-case-conflict - - id: check-added-large-files - args: ['--maxkb=4096'] - - id: destroyed-symlinks +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: 'v4.5.0' + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: destroyed-symlinks + - id: detect-private-key + - id: check-ast + - id: check-case-conflict + - id: debug-statements + # Add <# -*- coding: utf-8 -*-> to the top of python files. + - id: fix-encoding-pragma + # https://github.com/asottile/pyupgrade/issues/748 + # https://github.com/asottile/pyupgrade/issues/89 + args: ['--remove'] + - id: forbid-submodules + - id: check-symlinks + - id: check-shebang-scripts-are-executable + - id: check-case-conflict + - id: check-added-large-files + args: ['--maxkb=4096'] + - id: destroyed-symlinks # YAPF and flake8 need to remain pinned. -- repo: https://github.com/pre-commit/mirrors-yapf - rev: 'v0.32.0' # frozen: v0.32.0 - hooks: - - id: yapf - additional_dependencies: [toml] +- repo: https://github.com/pre-commit/mirrors-yapf + rev: 'v0.32.0' # frozen: v0.32.0 + hooks: + - id: yapf + additional_dependencies: [toml] -- repo: https://github.com/pycqa/flake8 - rev: '6.0.0' # frozen: 6.0.0 - hooks: - - id: flake8 - additional_dependencies: [flake8-docstrings] +- repo: https://github.com/pycqa/flake8 + rev: '6.0.0' # frozen: 6.0.0 + hooks: + - id: flake8 + additional_dependencies: [flake8-docstrings] -- repo: https://github.com/PyCQA/bandit - rev: '1.7.5' # Use the sha / tag you want to point at - hooks: - - id: bandit - args: ['--skip', 'B404,B506,B410,B603,B324', '--level', 'LOW'] +- repo: https://github.com/PyCQA/bandit + rev: '1.7.5' # Use the sha / tag you want to point at + hooks: + - id: bandit + args: ['--skip', 'B404,B506,B410,B603,B324', '--level', 'LOW'] # - repo: https://github.com/pre-commit/mirrors-mypy # rev: 'v0.991' @@ -47,10 +51,15 @@ repos: # - id: mypy # args: ['--no-strict-optional', '--ignore-missing-imports', '--show-error-context', '--show-error-codes', '--follow-imports', 'silent'] -- repo: https://github.com/pycqa/isort - rev: '5.12.0' - hooks: - - id: isort +- repo: https://github.com/pycqa/isort + rev: '5.12.0' + hooks: + - id: isort + +- repo: https://github.com/asottile/pyupgrade + rev: 'v3.15.0' + hooks: + - id: pyupgrade # - repo: https://codeberg.org/frnmst/licheck # rev: '1.0.0' @@ -58,35 +67,41 @@ repos: # - id: licheck # args: ['--configuration-file', '.allowed_licenses.yml'] -- repo: https://codeberg.org/frnmst/md-toc - rev: '8.2.0' # or a specific git tag from md-toc - hooks: - - id: md-toc - args: [-p, 'cmark', '-l6'] # CLI options +- repo: https://codeberg.org/frnmst/md-toc + rev: '8.2.0' # or a specific git tag from md-toc + hooks: + - id: md-toc + args: [-p, 'cmark', '-l6'] # CLI options + +- repo: https://github.com/mgedmin/check-manifest + rev: '0.49' + hooks: + - id: check-manifest -- repo: https://github.com/mgedmin/check-manifest - rev: '0.49' - hooks: - - id: check-manifest + #- repo: https://github.com/rstcheck/rstcheck + # rev: 'v6.2.0' + # hooks: + # - id: rstcheck + # additional_dependencies: ["tomli"] -- repo: local - hooks: - - id: unit-tests - name: unit tests - language: system - entry: make test - verbose: true - always_run: true - pass_filenames: false - - id: build-docs - name: build docs - language: system - entry: make doc - verbose: true - always_run: true - pass_filenames: false +- repo: local + hooks: + - id: unit-tests + name: unit tests + language: system + entry: make test + verbose: true + always_run: true + pass_filenames: false + - id: build-docs + name: build docs + language: system + entry: make doc + verbose: true + always_run: true + pass_filenames: false -- repo: https://github.com/jorisroovers/gitlint - rev: 'v0.18.0' - hooks: - - id: gitlint +- repo: https://github.com/jorisroovers/gitlint + rev: 'v0.18.0' + hooks: + - id: gitlint diff --git a/MANIFEST.in b/MANIFEST.in index f3fb141..ede3bfb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ global-include LICENSE.txt global-include README.md global-include CONTRIBUTING.md +global-include SECURITY.md recursive-include md_toc/cmark *.py global-exclude *.csv *.txt prune assets diff --git a/Makefile b/Makefile index bb485c0..a0d8ab1 100644 --- a/Makefile +++ b/Makefile @@ -113,13 +113,17 @@ dist: upload: $(VENV_CMD) \ - && twine upload dist/* \ + && twine upload --repository md-toc dist/* \ && deactivate clean: rm -rf build dist *.egg-info tests/benchmark-results # Remove all markdown files except the readmes. - find -regex ".*\.[mM][dD]" ! -name 'README.md' ! -name 'CONTRIBUTING.md' -type f -exec rm -f {} + + find -regex ".*\.[mM][dD]" \ + ! -name 'README.md' \ + ! -name 'CONTRIBUTING.md' \ + | -name 'SECURITY.md' \ + -type f -exec rm -f {} + $(VENV_CMD) \ && $(MAKE) -C docs clean \ && deactivate diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..7f7dfc8 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,15 @@ +# Security Policy + +## Supported Versions + +The latest +[GIT tagged version of md-toc](https://github.com/frnmst/md-toc/tags) is the +only one supported. When a new version is released, that one will be the only +one supported. + +## Reporting a Vulnerability + +Use this +[Nextcloud form](https://cloud.franco.net.eu.org/apps/forms/s/ozgp2GqH46QMmsE9JPn5aP8B) +(preferred) or send me an +[email](https://blog.franco.net.eu.org/about/#contacts) diff --git a/docs/conf.py b/docs/conf.py index db9e49b..1ac5ca6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # md-toc documentation build configuration file, created by # sphinx-quickstart on Wed Dec 27 17:32:50 2017. diff --git a/docs/pre_commit_hook.rst b/docs/pre_commit_hook.rst index db5b186..3a917dc 100644 --- a/docs/pre_commit_hook.rst +++ b/docs/pre_commit_hook.rst @@ -1,14 +1,17 @@ Pre-commit hook --------------- -This repo provides the following :download:`plugin <../.pre-commit-hooks.yaml>` to be used with the `Pre-commit framework `_: +This repo provides the following :download:`plugin <../.pre-commit-hooks.yaml>` to be used with the `Pre-commit framework `_ .. literalinclude:: ../.pre-commit-hooks.yaml :language: yaml :caption: The .pre-commit-hooks.yaml file :name: .pre-commit-hooks.yaml -Add a ``.pre-commit-config.yaml`` file in the root of your git repo. +Add a ``.pre-commit-config.yaml`` file in the root of your GIT repo. +Have a look at the ``/.pre-commit-hooks.yaml`` file of this repository for a +full example. + These are the default plugin settings .. code-block:: yaml @@ -17,8 +20,8 @@ These are the default plugin settings repos: - repo: https://codeberg.org/frnmst/md-toc - # Remember to keep md-toc up-to-date! - rev: master # set a specific git tag + # Release updates (ATOM) https://codeberg.org/frnmst/md-toc/tags.atom + rev: master # set a GIT tag hooks: - id: md-toc @@ -30,49 +33,10 @@ You can override the defaults via the ``args`` parameter, such as repos: - repo: https://codeberg.org/frnmst/md-toc - # Remember to keep md-toc up-to-date! - rev: master # set a specific git tag + # Release updates (ATOM) https://codeberg.org/frnmst/md-toc/tags.atom + rev: master # set a GIT tag hooks: - id: md-toc args: [-p, --skip-lines, '1', redcarpet] # CLI options -This is what I use in some repositories - -.. code-block:: yaml - - # See https://pre-commit.com for more information - # See https://pre-commit.com/hooks.html for more hooks - repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.4.0' - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - - id: destroyed-symlinks - - id: detect-private-key - - id: check-ast - - id: check-case-conflict - - id: debug-statements - - id: fix-encoding-pragma - - id: forbid-submodules - - id: check-symlinks - - id: check-shebang-scripts-are-executable - - id: check-case-conflict - - id: check-added-large-files - args: ['--maxkb=16384'] - - id: destroyed-symlinks - - - repo: https://codeberg.org/frnmst/md-toc - # Remember to keep md-toc up-to-date! - rev: '8.2.0' # set a specific git tag - hooks: - - id: md-toc - args: [-p, 'cmark', '-l6'] # CLI options - - - repo: https://github.com/jorisroovers/gitlint - rev: 'v0.18.0' - hooks: - - id: gitlint - Finally, run ``pre-commit install`` to enable the hook. diff --git a/md_toc/__init__.py b/md_toc/__init__.py index e0ecc0e..1801ff5 100644 --- a/md_toc/__init__.py +++ b/md_toc/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # __init__.py # diff --git a/md_toc/__main__.py b/md_toc/__main__.py index 5d1e465..f92eff1 100755 --- a/md_toc/__main__.py +++ b/md_toc/__main__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # __main__.py # diff --git a/md_toc/api.py b/md_toc/api.py index 5c1533c..91c10e5 100644 --- a/md_toc/api.py +++ b/md_toc/api.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # api.py # @@ -249,7 +248,7 @@ def build_toc( # and these are translated into '\n' before being returned to the caller. # See # https://docs.python.org/3/library/functions.html#open-newline-parameter - f = open(filename, 'r', newline=None) + f = open(filename, newline=None) # Help the developers: override the list_marker in case # this function is called with the default unordered list marker, @@ -272,7 +271,7 @@ def build_toc( loop: bool = True line_counter = 1 while loop: - if line_counter > skip_lines or f.readline() == str(): + if line_counter > skip_lines or f.readline() == '': loop = False line_counter += 1 @@ -296,7 +295,7 @@ def build_toc( if filename != '-': # stdin is not seekable. file_pointer_pos = f.tell() - if f.readline() == str(): + if f.readline() == '': is_document_end = True f.seek(file_pointer_pos) @@ -789,7 +788,7 @@ def remove_html_tags(line: str, parser: str = 'github') -> str: ] for r in regexes: - line = re.sub(r, str(), line, flags=re.DOTALL) + line = re.sub(r, '', line, flags=re.DOTALL) return line @@ -975,7 +974,7 @@ def build_anchor_link( # This is equivalent to %x in C. In Python we don't have # the length problem so %x is equal to %lx in this case. # Apparently there is no %l in Python... - header_text_trimmed_middle_stage_str = 'part-' + '{0:x}'.format( + header_text_trimmed_middle_stage_str = 'part-' + '{:x}'.format( hash) return header_text_trimmed_middle_stage_str @@ -1198,7 +1197,7 @@ def get_atx_heading( or consecutive_escape_characters == 0): tmp = '\u005c' else: - tmp = str() + tmp = '' final_line = ''.join( [final_line[0:i], tmp, final_line[i:]]) i += 1 + len(tmp) @@ -1353,8 +1352,7 @@ def is_valid_code_fence_indent(line: str, parser: str = 'github') -> bool: return False -def is_opening_code_fence(line: str, - parser: str = 'github') -> typing.Optional[str]: +def is_opening_code_fence(line: str, parser: str = 'github') -> str | None: r"""Determine if the given line is possibly the opening of a fenced code block. :parameter line: a single markdown line to evaluate. @@ -1387,7 +1385,7 @@ def is_opening_code_fence(line: str, # The info string is the whole line except the first opening code # fence markers. if line == len(line) * line[0]: - info_string = str() + info_string = '' info_string_start = len(line) else: # Get the index where the info string starts. diff --git a/md_toc/cli.py b/md_toc/cli.py index 58f1855..3b24165 100644 --- a/md_toc/cli.py +++ b/md_toc/cli.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # cli.py # diff --git a/md_toc/cmark/__init__.py b/md_toc/cmark/__init__.py index 34186df..64433cb 100644 --- a/md_toc/cmark/__init__.py +++ b/md_toc/cmark/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # __init__.py # diff --git a/md_toc/cmark/buffer_c.py b/md_toc/cmark/buffer_c.py index f0c88e5..47c9de2 100644 --- a/md_toc/cmark/buffer_c.py +++ b/md_toc/cmark/buffer_c.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # buffer_c.py # @@ -33,7 +32,7 @@ # in that case the license header at the top of the file applies. # See docs/copyright_license.rst -cmark_strbuf__initbuf: str = str() +cmark_strbuf__initbuf: str = '' # 0.30 @@ -59,7 +58,7 @@ def _cmark_cmark_strbuf_init(mem: _cmarkCmarkMem, buf: _cmarkCmarkStrbuf, buf.mem = mem buf.asize = 0 buf.size = 0 - buf.ptr = str() + buf.ptr = '' if initial_size > 0: _cmark_cmark_strbuf_grow(buf, initial_size) @@ -114,7 +113,7 @@ def _cmark_cmark_strbuf_clear(buf: _cmarkCmarkStrbuf): if buf.asize > 0: del buf.ptr - buf.ptr = str() + buf.ptr = '' # 0.29, 0.30 @@ -195,7 +194,7 @@ def _cmark_cmark_strbuf_detach(buf: _cmarkCmarkStrbuf) -> str: if buf.asize == 0: # return an empty string # return (unsigned char *)buf->mem->calloc(1, 1); - return str() + return '' _cmark_cmark_strbuf_init(buf.mem, buf, 0) return data diff --git a/md_toc/cmark/buffer_h.py b/md_toc/cmark/buffer_h.py index b86b2bb..4d8bd42 100644 --- a/md_toc/cmark/buffer_h.py +++ b/md_toc/cmark/buffer_h.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # buffer_h.py # @@ -39,7 +38,7 @@ class _cmarkCmarkStrbuf: def __init__(self): self.mem: _cmarkCmarkMem = None - self.ptr: str = str() + self.ptr: str = '' self.asize: int = 0 self.size: int = 0 diff --git a/md_toc/cmark/chunk_h.py b/md_toc/cmark/chunk_h.py index 4c3598d..241ee43 100644 --- a/md_toc/cmark/chunk_h.py +++ b/md_toc/cmark/chunk_h.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # chunk_h.py # diff --git a/md_toc/cmark/cmark_ctype_c.py b/md_toc/cmark/cmark_ctype_c.py index 354df2f..98b83bf 100644 --- a/md_toc/cmark/cmark_ctype_c.py +++ b/md_toc/cmark/cmark_ctype_c.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # cmark_ctype_c.py # diff --git a/md_toc/cmark/cmark_h.py b/md_toc/cmark/cmark_h.py index d81c4f2..81c5930 100644 --- a/md_toc/cmark/cmark_h.py +++ b/md_toc/cmark/cmark_h.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # cmark_h.py # diff --git a/md_toc/cmark/houdini_h.py b/md_toc/cmark/houdini_h.py index ca432c6..fa3b2ab 100644 --- a/md_toc/cmark/houdini_h.py +++ b/md_toc/cmark/houdini_h.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # houdini_h.py # diff --git a/md_toc/cmark/houdini_html_u_c.py b/md_toc/cmark/houdini_html_u_c.py index 1ecae84..4bf4a69 100644 --- a/md_toc/cmark/houdini_html_u_c.py +++ b/md_toc/cmark/houdini_html_u_c.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # houdini_html_u_c.py # diff --git a/md_toc/cmark/inlines_c.py b/md_toc/cmark/inlines_c.py index 5f5d6ca..e8cff3f 100644 --- a/md_toc/cmark/inlines_c.py +++ b/md_toc/cmark/inlines_c.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # inlines_c.py # @@ -144,7 +143,7 @@ def __init__(self): self.next: _cmarkDelimiter = None self.inl_text: _cmarkCmarkNode = None self.length: int = 0 - self.delim_char = str() + self.delim_char = '' self.can_open: bool = False self.can_close: bool = False diff --git a/md_toc/cmark/node_c.py b/md_toc/cmark/node_c.py index 47b5d6c..64415cf 100644 --- a/md_toc/cmark/node_c.py +++ b/md_toc/cmark/node_c.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # node_c.py # @@ -104,8 +103,8 @@ def _cmark_S_free_nodes(e: _cmarkCmarkNode): if e.type in [_cmarkCmarkNodeType.CMARK_NODE_CODE_BLOCK.value]: del e.data del e.as_code.info - e.data = str() - e.as_code.info = str() + e.data = '' + e.as_code.info = '' elif e.type in [ _cmarkCmarkNodeType.CMARK_NODE_TEXT.value, _cmarkCmarkNodeType.CMARK_NODE_HTML_INLINE.value, @@ -113,23 +112,23 @@ def _cmark_S_free_nodes(e: _cmarkCmarkNode): _cmarkCmarkNodeType.CMARK_NODE_HTML_BLOCK.value, ]: del e.data - e.data = str() + e.data = '' elif e.type in [ _cmarkCmarkNodeType.CMARK_NODE_LINK.value, _cmarkCmarkNodeType.CMARK_NODE_IMAGE.value, ]: del e.as_link.url del e.as_link.title - e.as_link.url = str() - e.as_link.title = str() + e.as_link.url = '' + e.as_link.title = '' elif e.type in [ _cmarkCmarkNodeType.CMARK_NODE_CUSTOM_BLOCK.value, _cmarkCmarkNodeType.CMARK_NODE_CUSTOM_INLINE.value, ]: del e.as_custom.on_enter del e.as_custom.on_exit - e.as_custom.on_enter = str() - e.as_custom.on_exit = str() + e.as_custom.on_enter = '' + e.as_custom.on_exit = '' if e.last_child: # Splice children into list @@ -163,14 +162,14 @@ def _cmark_cmark_set_cstr(mem: _cmarkCmarkMem, dst: str, src: str) -> tuple: dst = copy.deepcopy(src[:length + 1]) else: length = 0 - dst = str() + dst = '' if old: # Alternative to: # mem->free(old); del old del dst - dst = str() + dst = '' return length, dst diff --git a/md_toc/cmark/node_h.py b/md_toc/cmark/node_h.py index 2a4fe9d..b05af08 100644 --- a/md_toc/cmark/node_h.py +++ b/md_toc/cmark/node_h.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # node_h.py # diff --git a/md_toc/cmark/references_c.py b/md_toc/cmark/references_c.py index 2c81ace..137af06 100644 --- a/md_toc/cmark/references_c.py +++ b/md_toc/cmark/references_c.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # reference_c.py # @@ -65,7 +64,7 @@ def _cmark_normalize_reference(mem: _cmarkCmarkMem, raise ValueError # if result[0] == '\0': - if result == str(): + if result == '': # mem.free(result) del result return None diff --git a/md_toc/cmark/references_h.py b/md_toc/cmark/references_h.py index c24b4c4..e123163 100644 --- a/md_toc/cmark/references_h.py +++ b/md_toc/cmark/references_h.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # reference_h.py # diff --git a/md_toc/cmark/scanners_c.py b/md_toc/cmark/scanners_c.py index f621642..b40d7c9 100644 --- a/md_toc/cmark/scanners_c.py +++ b/md_toc/cmark/scanners_c.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # scanners_c.py # diff --git a/md_toc/cmark/scanners_h.py b/md_toc/cmark/scanners_h.py index 218bc76..e5306fc 100644 --- a/md_toc/cmark/scanners_h.py +++ b/md_toc/cmark/scanners_h.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # scanners_h.py # diff --git a/md_toc/cmark/utf8_c.py b/md_toc/cmark/utf8_c.py index 5d75d76..e9a663f 100644 --- a/md_toc/cmark/utf8_c.py +++ b/md_toc/cmark/utf8_c.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # utf8_c.py # diff --git a/md_toc/constants.py b/md_toc/constants.py index 76ceafc..232dda9 100644 --- a/md_toc/constants.py +++ b/md_toc/constants.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # constants.py # diff --git a/md_toc/exceptions.py b/md_toc/exceptions.py index 22ee984..e646c93 100644 --- a/md_toc/exceptions.py +++ b/md_toc/exceptions.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # exceptions.py # diff --git a/md_toc/generic.py b/md_toc/generic.py index 3008518..6371456 100644 --- a/md_toc/generic.py +++ b/md_toc/generic.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # generic.py # @@ -60,7 +59,7 @@ def _extract_lines(input_file: str, start: int, end: int) -> str: lines: list[str] = list() line_counter: int = 1 - with open(input_file, 'r') as f: + with open(input_file) as f: line: str = f.readline() while line: if line_counter >= start and line_counter <= end: @@ -100,7 +99,7 @@ def _get_existing_toc(filename: str, marker: str) -> tuple: ) marker_line_positions_length: int = len(marker_line_positions) - old_toc: str = str() + old_toc: str = '' first_marker: int = 1 second_marker: int = 2 two_or_more_markers: bool = False @@ -136,7 +135,7 @@ def _get_existing_toc(filename: str, marker: str) -> tuple: old_toc = _extract_lines(filename, start_line, end_line).strip() else: - old_toc = str() + old_toc = '' lines_to_delete.append([ marker_line_positions[first_marker], diff --git a/md_toc/tests/__init__.py b/md_toc/tests/__init__.py index 0567b04..3a83b9d 100644 --- a/md_toc/tests/__init__.py +++ b/md_toc/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # __init__.py # diff --git a/md_toc/tests/benchmark.py b/md_toc/tests/benchmark.py index 94a5d24..8b2c956 100755 --- a/md_toc/tests/benchmark.py +++ b/md_toc/tests/benchmark.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- # # Copyright (C) 2022 Franco Masotti (see /README.md) # diff --git a/md_toc/tests/tests.py b/md_toc/tests/tests.py index 1cdd376..1ae16f6 100644 --- a/md_toc/tests/tests.py +++ b/md_toc/tests/tests.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # tests.py # @@ -140,8 +139,8 @@ def test__extract_lines(self): r"""Test extracting lines between line intervals.""" with open('foo.md', 'w') as f: f.write(CMARK_LINE_FOO) - self.assertEqual(generic._extract_lines('foo.md', 2, 2), str()) - self.assertEqual(generic._extract_lines('foo.md', 1024, 2048), str()) + self.assertEqual(generic._extract_lines('foo.md', 2, 2), '') + self.assertEqual(generic._extract_lines('foo.md', 1024, 2048), '') self.assertEqual(generic._extract_lines('foo.md', 1, 1), CMARK_LINE_FOO) @@ -197,7 +196,7 @@ def test__get_existing_toc(self): with open('foo.md', 'w') as f: f.write(H1 + S1 + CMARK_LINE_FOO) self.assertEqual(generic._get_existing_toc('foo.md', ''), - (str(), list(), False, 0, dict(), 0)) + ('', list(), False, 0, dict(), 0)) # 1 TOC marker: TOC == marker. with open('foo.md', 'w') as f: @@ -238,23 +237,22 @@ def test__get_existing_toc(self): MARKER + LINE_LINE_FEED + LINE_LINE_FEED + H1 + S1 + CMARK_LINE_FOO) self.assertEqual(generic._get_existing_toc('foo.md', MARKER), - (str(), list(), True, 1, { + ('', list(), True, 1, { 1: 1, 2: 5 }, 1)) def test__replace_substring(self): r"""Test that the string is replaced with another one between the two specified indices.""" - self.assertEqual(generic._replace_substring(str(), str(), 0, 0), str()) - self.assertEqual(generic._replace_substring(str(), str(), 1024, 1024), - str()) - - self.assertEqual( - generic._replace_substring(str(), CMARK_LINE_FOO, 0, 0), str()) - self.assertEqual( - generic._replace_substring(CMARK_LINE_FOO, str(), 0, 0), 'oo') - self.assertEqual( - generic._replace_substring(str(), CMARK_LINE_FOO, 0, 0), str()) + self.assertEqual(generic._replace_substring('', '', 0, 0), '') + self.assertEqual(generic._replace_substring('', '', 1024, 1024), '') + + self.assertEqual(generic._replace_substring('', CMARK_LINE_FOO, 0, 0), + '') + self.assertEqual(generic._replace_substring(CMARK_LINE_FOO, '', 0, 0), + 'oo') + self.assertEqual(generic._replace_substring('', CMARK_LINE_FOO, 0, 0), + '') # Replace first 'f' of 'foo' with 'foo' -> 'foo|oo' self.assertEqual( generic._replace_substring(CMARK_LINE_FOO, CMARK_LINE_FOO, 0, 0), @@ -313,7 +311,7 @@ def test__replace_substring(self): def test__string_empty(self): r"""A string is empty if it contains whitespace characters, excluding consecutive sequences of \n\r.""" - self.assertTrue(generic._string_empty(str())) + self.assertTrue(generic._string_empty('')) self.assertTrue(generic._string_empty('\u000a')) self.assertTrue(generic._string_empty('\u000d')) self.assertTrue(generic._string_empty('\u000b')) @@ -335,7 +333,7 @@ def test__string_empty(self): def test__detect_toc_list(self): r"""Detect a markdown list generated by md-toc.""" - self.assertFalse(generic._detect_toc_list(str())) + self.assertFalse(generic._detect_toc_list('')) # Unordered list. self.assertTrue(generic._detect_toc_list('- list')) @@ -453,14 +451,14 @@ def test__detect_toc_list(self): def test__read_line_interval(self): r"""Extract a line interval.""" - self.assertEqual(generic._read_line_interval(str(), 1, 1), str()) - self.assertEqual(generic._read_line_interval(str(), 0, 1), str()) - self.assertEqual(generic._read_line_interval(str(), 1, 0), str()) - self.assertEqual(generic._read_line_interval(str(), 0, 0), str()) + self.assertEqual(generic._read_line_interval('', 1, 1), '') + self.assertEqual(generic._read_line_interval('', 0, 1), '') + self.assertEqual(generic._read_line_interval('', 1, 0), '') + self.assertEqual(generic._read_line_interval('', 0, 0), '') self.assertEqual(generic._read_line_interval('a', 1, 1), 'a') - self.assertEqual(generic._read_line_interval('a', 0, 1), str()) - self.assertEqual(generic._read_line_interval('a', 1, 0), str()) - self.assertEqual(generic._read_line_interval('a', 0, 0), str()) + self.assertEqual(generic._read_line_interval('a', 0, 1), '') + self.assertEqual(generic._read_line_interval('a', 1, 0), '') + self.assertEqual(generic._read_line_interval('a', 0, 0), '') self.assertEqual(generic._read_line_interval('a\u000da', 1, 1), 'a') self.assertEqual(generic._read_line_interval('a\u000da', 1, 2), 'aa') self.assertEqual(generic._read_line_interval('a\u000da', 2, 2), 'a') @@ -476,7 +474,7 @@ def test__read_line_interval(self): self.assertEqual(generic._read_line_interval('ab\u000d\u000ac', 2, 2), 'c') self.assertEqual( - generic._read_line_interval('ab\u000d\u000a\u000ac', 2, 2), str()) + generic._read_line_interval('ab\u000d\u000a\u000ac', 2, 2), '') self.assertEqual( generic._read_line_interval('ab\u000d\u000a\u000ac', 2, 3), 'c') @@ -511,7 +509,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual(lines, 'hello') @@ -523,7 +521,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -537,7 +535,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual(lines, 'hello' + '\n' + MARKER + MARKER) @@ -550,7 +548,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -565,7 +563,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -580,7 +578,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -595,7 +593,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -610,7 +608,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -625,7 +623,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -640,7 +638,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -655,7 +653,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -670,7 +668,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -684,7 +682,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -698,7 +696,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -713,7 +711,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -728,7 +726,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -743,7 +741,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -758,7 +756,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -773,7 +771,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -788,7 +786,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -803,7 +801,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -818,7 +816,7 @@ def test_write_string_on_file_between_markers(self): LINE, MARKER, newline_string='\n') - with open('foo.md', 'r') as f: + with open('foo.md') as f: lines = f.readlines() lines = ''.join(lines) self.assertEqual( @@ -1317,11 +1315,10 @@ def test_build_toc_line(self): def test_filter_indices_from_line(self): r"""Test removing indices from a string.""" self.assertEqual(api.filter_indices_from_line('foo', [range(0, 3)]), - str()) - self.assertEqual(api.filter_indices_from_line(str(), [range(0, 1024)]), - str()) - self.assertEqual(api.filter_indices_from_line(str(), [range(0, 0)]), - str()) + '') + self.assertEqual(api.filter_indices_from_line('', [range(0, 1024)]), + '') + self.assertEqual(api.filter_indices_from_line('', [range(0, 0)]), '') self.assertEqual( api.filter_indices_from_line(512 * '1', [range(0, 512 - 1)]), '1') self.assertEqual(api.filter_indices_from_line(512 * '1', []), @@ -2406,11 +2403,11 @@ def test_remove_html_tags(self): # Example 632 [GFM 0.29.0.gfm.2]. self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'cmark'), - str(), + '', ) # Example 585 [Commonmark 0.28]. @@ -2419,11 +2416,11 @@ def test_remove_html_tags(self): # Example 633 [GFM 0.29.0.gfm.2]. self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'cmark'), - str(), + '', ) # Example 586 [Commonmark 0.28]. @@ -2433,41 +2430,41 @@ def test_remove_html_tags(self): # Original example with extensions. self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) # Two newlines. self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'cmark'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'cmark'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'cmark'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'cmark'), @@ -2475,7 +2472,7 @@ def test_remove_html_tags(self): ) self.assertEqual( api.remove_html_tags('', 'cmark'), - str(), + '', ) # Two newlines. self.assertEqual( @@ -2491,13 +2488,13 @@ def test_remove_html_tags(self): api.remove_html_tags( '"\'\n_boolean zoop:33=zoop:33 />', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags( '"\'\n_boolean zoop:33=zoop:33 />', 'cmark'), - str(), + '', ) # Example 588 [Commonmark 0.28]. @@ -2586,11 +2583,11 @@ def test_remove_html_tags(self): # Example 642 [GFM 0.29.0.gfm.2]. self.assertEqual( api.remove_html_tags('', 'github'), - str(), + '', ) self.assertEqual( api.remove_html_tags('', 'cmark'), - str(), + '', ) # Example 595 [Commonmark 0.28]. @@ -2830,8 +2827,7 @@ def test_replace_and_split_newlines(self): LINE_LINE_FEED + LINE_LINE_FEED + LINE_CARRIAGE_RETURN + LINE_LINE_FEED + CMARK_LINE_BAR), - [CMARK_LINE_FOO, str(), - str(), CMARK_LINE_BAR]) + [CMARK_LINE_FOO, '', '', CMARK_LINE_BAR]) def test_get_atx_heading(self): r"""Test the title gathering for edge cases and various parsers. @@ -3959,7 +3955,7 @@ def test_get_md_header(self): 'header text trimmed': None, 'visible': False }]): - with patch('md_toc.api.build_anchor_link', return_value=str()): + with patch('md_toc.api.build_anchor_link', return_value=''): self.assertEqual(api.get_md_header(CMARK_LINE_FOO, dict(), 1), [None]) @@ -3972,7 +3968,7 @@ def test_get_md_header(self): 'header text trimmed': None, 'visible': True }]): - with patch('md_toc.api.build_anchor_link', return_value=str()): + with patch('md_toc.api.build_anchor_link', return_value=''): self.assertEqual(api.get_md_header(CMARK_LINE_FOO, dict(), 1), [None]) diff --git a/md_toc/types.py b/md_toc/types.py index 4482d5a..2dd1d38 100644 --- a/md_toc/types.py +++ b/md_toc/types.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # types.py # diff --git a/setup.py b/setup.py index ee9572c..cab8e40 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # setup.py #