configuration de tests et de création de package
This commit is contained in:
parent
75f7a2d742
commit
d10a51757b
12 changed files with 173 additions and 19 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1 +1,7 @@
|
|||
/.idea/
|
||||
/markdown-fix-freeplane.iml
|
||||
/build/
|
||||
/dist/
|
||||
/markdown_fix_freeplane.egg-info/
|
||||
/.pytest_cache/
|
||||
/.tox/
|
||||
|
|
38
.gitlab-ci.yml
Normal file
38
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,38 @@
|
|||
# To contribute improvements to CI/CD templates, please follow the Development guide at:
|
||||
# https://docs.gitlab.com/ee/development/cicd/templates.html
|
||||
# This specific template is located at:
|
||||
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
|
||||
|
||||
# Official language image. Look for the different tagged releases at:
|
||||
# https://hub.docker.com/r/library/python/tags/
|
||||
image: python:latest
|
||||
|
||||
# Change pip's cache directory to be inside the project directory since we can
|
||||
# only cache local items.
|
||||
variables:
|
||||
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
|
||||
|
||||
# https://pip.pypa.io/en/stable/topics/caching/
|
||||
cache:
|
||||
paths:
|
||||
- .cache/pip
|
||||
|
||||
before_script:
|
||||
- python --version ; pip --version # For debugging
|
||||
- pip install virtualenv
|
||||
- virtualenv venv
|
||||
- source venv/bin/activate
|
||||
|
||||
test:
|
||||
script:
|
||||
- pip install ruff tox # you can also use tox
|
||||
- pip install --editable ".[tests]"
|
||||
- tox -e py,ruff
|
||||
|
||||
run:
|
||||
script:
|
||||
- pip install .
|
||||
- python setup.py sdist
|
||||
artifacts:
|
||||
paths:
|
||||
- dist/*
|
|
@ -1,19 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
# %%
|
||||
def replace_title_with_list(text):
|
||||
text = re.sub(r'#(#+)\s*(.*)', r'\1- \2', text)
|
||||
text = re.sub(r'#', ' ', text)
|
||||
return text
|
||||
|
||||
|
||||
def __main__():
|
||||
# read file passed as argument
|
||||
with open(sys.argv[1], 'r') as my_file:
|
||||
text = my_file.read()
|
||||
print(replace_title_with_list(text))
|
9
markdown_fix_freeplane/__init__.py
Normal file
9
markdown_fix_freeplane/__init__.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
"""Convert Freeplane generated markdown.
|
||||
|
||||
License:
|
||||
MIT License
|
||||
Copyright (c) 2024 François Pelletier
|
||||
"""
|
||||
|
||||
__version__ = '0.0.1'
|
||||
__author__ = 'François Pelletier'
|
37
markdown_fix_freeplane/markdown_fix_freeplane.py
Normal file
37
markdown_fix_freeplane/markdown_fix_freeplane.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""Include main function to convert Freeplane generated markdown.
|
||||
|
||||
License:
|
||||
MIT License
|
||||
Copyright (c) 2024 François Pelletier
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
from markdown_fix_freeplane.markdown_utils import replace_title_with_list
|
||||
|
||||
|
||||
# %% main function
|
||||
|
||||
|
||||
def __main__():
|
||||
"""Run the script.
|
||||
|
||||
Args:
|
||||
sys.argv (list): list of command line arguments passed to the script.
|
||||
|
||||
Returns:
|
||||
str: the processed Markdown text.
|
||||
---
|
||||
|
||||
Examples:
|
||||
>>> __main__()
|
||||
---
|
||||
|
||||
"""
|
||||
# read file passed as argument
|
||||
with open(sys.argv[1], 'r') as my_file:
|
||||
text = my_file.read()
|
||||
return replace_title_with_list(text)
|
41
markdown_fix_freeplane/markdown_utils.py
Normal file
41
markdown_fix_freeplane/markdown_utils.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
"""Include functions to work with markdown text.
|
||||
|
||||
License:
|
||||
MIT License
|
||||
Copyright (c) 2024 François Pelletier
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def replace_title_with_list(text: str) -> str:
|
||||
r"""Replace all titles in the text with a numbered list.
|
||||
|
||||
The titles are defined by a hashtag symbol followed by one or more
|
||||
hashtag symbols, followed by a space, and then the title text.
|
||||
The function replaces the entire hashtag symbol and space with a
|
||||
numbered list, where each item in the list is numbered with a
|
||||
hashtag symbol and a space, and the title text is listed after the
|
||||
number.
|
||||
|
||||
Args:
|
||||
text (str): The text to process.
|
||||
|
||||
Returns:
|
||||
str: The processed text.
|
||||
---
|
||||
|
||||
Examples:
|
||||
>>> replace_title_with_list("# This is a title")
|
||||
'- This is a title'
|
||||
>>> replace_title_with_list("# This is a title\n## Another title")
|
||||
'- This is a title\n - Another title'
|
||||
---
|
||||
|
||||
"""
|
||||
pattern = r'^#+'
|
||||
matches = re.findall(pattern, text, re.MULTILINE)
|
||||
for match in matches:
|
||||
nb_hashtag = len(match)-1
|
||||
text = re.sub(match, ' ' * nb_hashtag+'-', text, count=1)
|
||||
return text
|
|
@ -20,3 +20,4 @@ classifiers = [
|
|||
[project.urls]
|
||||
Homepage = "https://git.jevalide.ca/partage/markdown-fix-freeplane"
|
||||
Issues = "https://git.jevalide.ca/partage/markdown-fix-freeplane/issues"
|
||||
|
||||
|
|
18
setup.py
Normal file
18
setup.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
name="markdown_fix_freeplane",
|
||||
version="0.0.1",
|
||||
url="https://git.jevalide.ca/partage/markdown-fix-freeplane",
|
||||
author="François Pelletier",
|
||||
author_email="francois@jevalide.ca",
|
||||
description="Convert Markdown output from Freeplane to Markdown lists",
|
||||
long_description=open('README.md').read(),
|
||||
packages=setuptools.find_packages(),
|
||||
install_requires=[],
|
||||
classifiers=[
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.8',
|
||||
],
|
||||
)
|
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
|
10
tests/test_markdown_utils.py
Normal file
10
tests/test_markdown_utils.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from markdown_fix_freeplane.markdown_utils import replace_title_with_list
|
||||
|
||||
|
||||
def test_replace_title_with_list():
|
||||
assert (replace_title_with_list(
|
||||
'# This is a title\n# Another title') ==
|
||||
'- This is a title\n- Another title')
|
||||
assert (replace_title_with_list(
|
||||
'# This is a title\n## Another title') ==
|
||||
'- This is a title\n - Another title')
|
12
tox.ini
Normal file
12
tox.ini
Normal file
|
@ -0,0 +1,12 @@
|
|||
[tox]
|
||||
envlist=py311
|
||||
|
||||
[testenv]
|
||||
deps =
|
||||
pydocstyle
|
||||
pycodestyle
|
||||
pytest
|
||||
commands =
|
||||
- pydocstyle --convention=google markdown_fix_freeplane/
|
||||
- pycodestyle markdown_fix_freeplane/
|
||||
pytest
|
Loading…
Reference in a new issue