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

Replace ruamel.yaml with PyYAML and Cleanup Imports #73

Merged
merged 5 commits into from
Jul 21, 2023
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ All notable changes to this project will be documented in this file.
- **v1.0.5** - 2023-04-01
- Add support for [custom templates](https://github.com/JakubAndrysek/MkDoxy/pull/39)
- **v1.0.6** - 2023-04-01
- Add support disable plugin [using environment variable](#disabling-the-plugin)
- Add support disable plugin [using environment variable](#disabling-the-plugin)
- **v1.1.6** - 2023-07-20
- Replace `ruamel.yaml` with `pyyaml`. [#73](https://github.com/JakubAndrysek/MkDoxy/pull/73)
- Add `isort` as dev dependency. [#73](https://github.com/JakubAndrysek/MkDoxy/pull/73)
- Sort and cleanup imports [#73](https://github.com/JakubAndrysek/MkDoxy/pull/73)
1 change: 1 addition & 0 deletions mkdoxy/DoxyTagParser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re


class DoxyTagParser:

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions mkdoxy/doxyrun.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import hashlib
import logging
import tempfile

from pathlib import Path, PurePath
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen
from typing import Optional

log: logging.Logger = logging.getLogger("mkdocs")
Expand Down
4 changes: 3 additions & 1 deletion mkdoxy/finder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Dict

from mkdoxy.constants import Kind
from mkdoxy.doxygen import Doxygen
from mkdoxy.utils import recursive_find, recursive_find_with_parent
from typing import Dict


class Finder:
def __init__(self, doxygen: Dict[str, Doxygen], debug: bool = False):
Expand Down
11 changes: 8 additions & 3 deletions mkdoxy/generatorBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import string
from typing import Dict

from jinja2 import Template, FileSystemLoader, Environment, ChoiceLoader
from jinja2 import Template
from jinja2.exceptions import TemplateError
from mkdocs import exceptions

import mkdoxy
from mkdoxy.constants import Kind
from mkdoxy.node import Node, DummyNode
from mkdoxy.utils import parseTemplateFile, merge_two_dicts, recursive_find_with_parent, recursive_find
from mkdoxy.node import DummyNode, Node
from mkdoxy.utils import (
merge_two_dicts,
parseTemplateFile,
recursive_find,
recursive_find_with_parent,
)

log: logging.Logger = logging.getLogger("mkdocs")

Expand Down
15 changes: 5 additions & 10 deletions mkdoxy/generatorSnippets.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import logging
import pathlib
import re
import string
from pprint import *

from mkdocs.config import Config
import yaml
from mkdocs.structure import pages
from mkdoxy.doxygen import Doxygen

from mkdoxy.generatorBase import GeneratorBase
from ruamel.yaml import YAML, YAMLError

from mkdoxy.doxygen import Doxygen
from mkdoxy.finder import Finder
from mkdoxy.generatorBase import GeneratorBase
from mkdoxy.node import Node

log: logging.Logger = logging.getLogger("mkdocs")
Expand Down Expand Up @@ -112,9 +108,8 @@ def generate(self):

def try_load_yaml(self, yaml_raw: str, project: str, snippet: str, config: dict) -> dict:
try:
yaml = YAML()
return yaml.load(yaml_raw)
except YAMLError as e:
return yaml.safe_load(yaml_raw)
except yaml.YAMLError as e:
log.error(f"YAML error in {project} project on page {self.page.url}")
self.doxyError(
project,
Expand Down
1 change: 1 addition & 0 deletions mkdoxy/markdown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List


def escape(s: str) -> str:
ret = s.replace('*', '\\*')
ret = ret.replace('_', '\\_')
Expand Down
2 changes: 1 addition & 1 deletion mkdoxy/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from xml.etree.ElementTree import Element as Element

from mkdoxy.cache import Cache
from mkdoxy.constants import Kind, Visibility, OVERLOAD_OPERATORS
from mkdoxy.constants import OVERLOAD_OPERATORS, Kind, Visibility
from mkdoxy.markdown import escape
from mkdoxy.property import Property
from mkdoxy.utils import split_safe
Expand Down
3 changes: 1 addition & 2 deletions mkdoxy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path, PurePath

from mkdocs import exceptions
from mkdocs.config import base, config_options, Config
from mkdocs.config import Config, base, config_options
from mkdocs.plugins import BasePlugin
from mkdocs.structure import files, pages

Expand All @@ -19,7 +19,6 @@
from mkdoxy.generatorAuto import GeneratorAuto
from mkdoxy.generatorBase import GeneratorBase
from mkdoxy.generatorSnippets import GeneratorSnippets
from mkdoxy.utils import check_enabled_markdown_extensions
from mkdoxy.xml_parser import XmlParser

log: logging.Logger = logging.getLogger("mkdocs")
Expand Down
8 changes: 3 additions & 5 deletions mkdoxy/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import re

import yaml
from mkdocs.config import Config
from ruamel.yaml import YAML

log: logging.Logger = logging.getLogger("mkdocs")

Expand Down Expand Up @@ -73,10 +73,8 @@ def parseTemplateFile(templateFile: str):
if match:
template = match["template"]
meta = match["meta"]
yaml = YAML(typ='safe')
metaData = yaml.load(meta)
# yaml.dump(metaData, sys.stdout)
return template, metaData
metadata = yaml.safe_load(meta)
return template, metadata
return templateFile, {}


Expand Down
21 changes: 19 additions & 2 deletions mkdoxy/xml_parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
from xml.etree.ElementTree import Element as Element

from mkdoxy.cache import Cache
from mkdoxy.markdown import Md, MdRenderer, MdParagraph, MdTable, Code, MdTableRow, MdCodeBlock, MdTableCell, \
MdHeader, MdImage, MdList, MdBlockQuote, MdLink, MdBold, MdItalic, Text, Br
from mkdoxy.markdown import (
Br,
Code,
Md,
MdBlockQuote,
MdBold,
MdCodeBlock,
MdHeader,
MdImage,
MdItalic,
MdLink,
MdList,
MdParagraph,
MdRenderer,
MdTable,
MdTableCell,
MdTableRow,
Text,
)
from mkdoxy.utils import lookahead

SIMPLE_SECTIONS = {
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
mkdocs
ruamel.yaml
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def requirements():
# https://pypi.org/project/mkdoxy/
setup(
name='mkdoxy',
version='1.1.5',
version='1.1.6',
description='MkDoxy → MkDocs + Doxygen = easy documentation generator with code snippets',
long_description=readme(),
long_description_content_type='text/markdown',
Expand All @@ -29,15 +29,15 @@ def requirements():
'Funding': 'https://github.com/sponsors/jakubandrysek',
},

install_requires=['mkdocs', 'ruamel.yaml'],
install_requires=['mkdocs'],
extras_require={
"dev": [
"mkdocs-material==9.1.18",
"Jinja2~=3.1.2",
"ruamel.yaml~=0.17.32",
"mkdocs-open-in-new-tab~=1.0.2",
"pathlib~=1.0.1",
"path~=16.7.1",
"isort~=5.12.0"
],
},
classifiers=[
Expand Down
10 changes: 5 additions & 5 deletions tests-old/metaDataParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from markdown.extensions import meta
import re
from pprint import *
from ruamel.yaml import YAML
import yaml


text = """\
---
Expand Down Expand Up @@ -56,7 +57,6 @@


match = re.match(regex, text2, re.MULTILINE)
meta = match.group("meta")
yaml = YAML(typ='safe')
config = yaml.load(meta)
yaml.dump(config, sys.stdout)
meta = match["meta"]
config = yaml.safe_load(meta)
yaml.safe_dump(config, sys.stdout)
7 changes: 3 additions & 4 deletions tests-old/parseMdTags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import sys
from pathlib import Path
from ruamel.yaml import YAML
import yaml


def readFile(filename: str) -> str:
Expand All @@ -28,9 +28,8 @@ def readFile(filename: str) -> str:
yamlRaw = match.group('yaml')
if yamlRaw:
try:
yaml = YAML()
config = yaml.load(yamlRaw)
yaml.dump(config, sys.stdout)
config = yaml.safe_load(yamlRaw)
yaml.safe_dump(config, sys.stdout)
except yaml.YAMLError as e:
print(e)
print()