Browse Source

Added comments. Fixed function so it conforms to PEP. Changed from requirements.txt to pipenv.

master
Franco Masotti 2 years ago
parent
commit
51fa0190a8
  1. 1
      .gitignore
  2. 14
      Makefile
  3. 20
      Pipfile
  4. 25
      md_toc/api.py
  5. 10
      requirements.txt

1
.gitignore vendored

@ -1,3 +1,4 @@
Pipfile.lock
*.md
*.MD
tests/benchmark-results

14
Makefile

@ -28,17 +28,17 @@ githook:
git config core.hooksPath .githooks
pep:
yapf --style '{based_on_style: pep8; indent_width: 4}' -i md_toc/*.py tests/*.py
flake8 --ignore=F401,E501,W503,W504,W605,E125 md_toc/*.py tests/*.py
pipenv run yapf --style '{based_on_style: pep8; indent_width: 4}' -i md_toc/*.py tests/*.py
pipenv run flake8 --ignore=F401,E501,W503,W504,W605,E125 md_toc/*.py tests/*.py
doc:
$(MAKE) -C docs html
pipenv run $(MAKE) -C docs html
install:
pip install .
test:
python setup.py test
pipenv run python setup.py test
benchmark:
pushd tests && ./benchmark.sh 10 && popd
@ -47,11 +47,11 @@ uninstall:
pip uninstall md_toc
dist:
python setup.py sdist
python setup.py bdist_wheel
pipenv run python setup.py sdist
pipenv run python setup.py bdist_wheel
upload:
twine upload dist/*
pipenv run twine upload dist/*
clean:
rm -rf build dist *.egg-info tests/benchmark-results

20
Pipfile

@ -0,0 +1,20 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
flake8 = "==3.7.7"
flake8-docstrings = "==1.5.0"
yapf = "==0.26.0"
alabaster = "==0.7.12"
twine = "==1.13"
fpyutils = "==1.1.0"
nose = "==1.3"
nose-timer = "==0.7"
Sphinx = "==1.8"
[requires]
python_version = "3.8"

25
md_toc/api.py

@ -30,14 +30,25 @@ from .exceptions import (GithubOverflowCharsLinkLabel, GithubEmptyLinkLabel,
from .constants import common_defaults
from .constants import parser as md_parser
# _ctoi and _isascii taken from cpython source Lib/curses/ascii.py
# See:
# https://github.com/python/cpython/blob/283de2b9c18e38c9a573526d6c398ade7dd6f8e9/Lib/curses/ascii.py#L48
# https://github.com/python/cpython/blob/283de2b9c18e38c9a573526d6c398ade7dd6f8e9/Lib/curses/ascii.py#L56
#
# These 2 functions are released under the
# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
# See https://directory.fsf.org/wiki/License:Python-2.0.1
def _ctoi(c: str):
assert len(c) == 1
retval = c
if isinstance(c, str):
retval = ord(c)
return retval
def _ctoi(c):
if type(c) == type(""):
return ord(c)
else:
return c
def _isascii(c):
return 0 <= _ctoi(c) <= 127
@ -640,7 +651,7 @@ def build_anchor_link(header_text_trimmed: str,
# str.find() == -1 if character is not found in str.
# https://docs.python.org/3.6/library/stdtypes.html?highlight=find#str.find
elif not _isascii(header_text_trimmed[i]) or STRIPPED.find(
header_text_trimmed[i]) != -1:
header_text_trimmed[i]) != -1:
if inserted and not stripped:
header_text_trimmed_middle_stage += '-'
stripped = 1

10
requirements.txt

@ -1,10 +0,0 @@
flake8==3.7.7
flake8-docstrings==1.3.0
yapf==0.26.0
alabaster==0.7.12
Sphinx==1.8
twine==1.13
fpyutils==1.1.0
setuptools==41.0
nose==1.3
nose-timer==0.7
Loading…
Cancel
Save