Skip to content

Commit 59f82db

Browse files
author
Laurent Franceschetti
committed
Replacing local implementation of SuperDict by super-collections version
1 parent 38b9681 commit 59f82db

File tree

8 files changed

+19
-95
lines changed

8 files changed

+19
-95
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ View the [mkdocs-macro documentation](https://mkdocs-macros-plugin.readthedocs.i
3737
markdown-toc -i README.md
3838
-->
3939

40+
<!-- toc -->
41+
4042
## Overview
4143
**mkdocs-macros-plugin** is a plugin that makes it easier for contributors
4244
of an [MkDocs](https://www.mkdocs.org/) website to produce richer and more beautiful pages. It transforms the markdown pages

mkdocs_macros/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# from .plugin import MacrosPlugin
66
# for fixing URLS in macros
77
from .context import fix_url, is_relative as is_relative_url
8-
from .util import SuperDict
8+
# from .util import SuperDict, SuperList

mkdocs_macros/plugin.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# --------------------------------------------
22
# Main part of the plugin
3-
# Defines the VariablesPlugin class
3+
# Defines the MacrosPlugin class
44
#
55
# Laurent Franceschetti (c) 2018
66
# MIT License
@@ -12,11 +12,13 @@
1212
import pathspec
1313
import json
1414
from datetime import datetime
15-
1615
import yaml
16+
1717
from jinja2 import (
1818
Environment, FileSystemLoader, Undefined, DebugUndefined, StrictUndefined,
1919
)
20+
from super_collections import SuperDict
21+
2022
from mkdocs.config import config_options
2123
from mkdocs.config.config_options import Type as PluginType
2224
from mkdocs.plugins import BasePlugin
@@ -26,8 +28,9 @@
2628
from mkdocs_macros.context import define_env
2729
from mkdocs_macros.util import (
2830
install_package, parse_package, trace, debug,
29-
update, SuperDict, import_local_module, format_chatter, LOG, get_log_level,
30-
setup_directory, CustomEncoder
31+
update, import_local_module, format_chatter, LOG, get_log_level,
32+
setup_directory, CustomEncoder,
33+
# SuperDict,
3134
)
3235

3336
# ------------------------------------------

mkdocs_macros/util.py

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -236,87 +236,6 @@ def update(d1, d2):
236236
# if it is any kind of object
237237
d1 = deepcopy(d2)
238238

239-
class SuperDict(dict):
240-
"""
241-
A dictionary accessible with the dot notation
242-
243-
a['foo'] <=> a.foo
244-
245-
except for standard methods
246-
"""
247-
248-
def __init__(self, *args, **kwargs):
249-
# Call the superclass's __init__ method
250-
super().__init__(*args, **kwargs)
251-
self.__post_init__()
252-
253-
def __post_init__(self):
254-
"Recursively transform sub-dictionary"
255-
for key, value in self.items():
256-
if isinstance(value, dict):
257-
self[key] = SuperDict(value)
258-
259-
def __getattr__(self, name:str):
260-
"Allow dot notation on reading"
261-
ERR_MSG = "Cannot find attribute '%s'" % name
262-
# if name.startswith('_'):
263-
# raise AttributeError(ERR_MSG)
264-
try:
265-
return self[name]
266-
except KeyError:
267-
raise AttributeError(ERR_MSG)
268-
269-
def __setattr__(self, name, value):
270-
"Allow dot notation on writing"
271-
# ERR_MSG = "Cannot assign an attribute starting with _ ('%s')" % name
272-
# if name.startswith('_'):
273-
# raise AttributeError(ERR_MSG)
274-
self[name] = value
275-
276-
@property
277-
def _attributes(self):
278-
"Make a list of the valid attributes"
279-
return list(self.keys())
280-
281-
def _codewords(self):
282-
"Make a list of the codewords"
283-
return
284-
285-
def __dir__(self):
286-
"List all attributes (for autocompletion, etc.)"
287-
return super().__dir__() + self._attributes
288-
289-
290-
291-
# -------------------------------------
292-
# Output
293-
# -------------------------------------
294-
295-
def to_json(self):
296-
"Convert to json"
297-
return json.dumps(self, cls=CustomEncoder)
298-
299-
def to_hjson(self):
300-
"""
301-
Convert to hjson
302-
"""
303-
python_dict = json.loads(self.to_json())
304-
return hjson.dumps(python_dict)
305-
306-
307-
def __str__(self):
308-
"Print a superdict"
309-
return self.to_hjson()
310-
return self.to_yaml()
311-
# r = [f"{self.__class__.__name__}:"]
312-
# r.extend([f" - {key}: {value}" for key, value in self.items()])
313-
# return("\n".join(r))
314-
315-
def __rich__(self):
316-
"Print a superdict (for rich)"
317-
r = [f"[bold red]{self.__class__.__name__}:[/]"]
318-
r.append(self.to_hjson())
319-
return("\n".join(r))
320239

321240

322241

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Initialization
1313
# --------------------
1414

15-
VERSION_NUMBER = '1.3.2'
15+
VERSION_NUMBER = '1.3.3'
1616

1717
# required if you want to run document/test
1818
# pip install 'mkdocs-macros-plugin[test]'
@@ -49,7 +49,8 @@ def read_file(fname):
4949
'hjson',
5050
'pathspec',
5151
'python-dateutil',
52-
'packaging'
52+
'packaging',
53+
'super-collections'
5354
],
5455
extras_require={
5556
'test': TEST_REQUIRE,
@@ -67,7 +68,7 @@ def read_file(fname):
6768
packages=find_packages(exclude=['*.tests']),
6869
entry_points={
6970
'mkdocs.plugins': [
70-
'macros = mkdocs_macros.plugin:MacrosPlugin'
71+
'macros = mkdocs_macros.plugin:MacrosPlugin',
7172
]
7273
}
7374
)

test/docproject.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
from typing import Any, List
1010

1111
from bs4 import BeautifulSoup
12+
from super_collections import SuperDict
1213

13-
14-
"A dictionary where the keys are also accessible with the dot notation"
15-
from mkdocs_macros.util import SuperDict
1614
from .fixture_util import (get_frontmatter, markdown_to_html, get_first_h1,
1715
find_in_html, find_after, list_markdown_files, find_page,
1816
run_command)

test/fixture.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
This is the two classes:
66
7-
- DocProject
7+
- MacrosDocProject
88
- TestMarkdownPage
99
1010
@@ -18,7 +18,8 @@
1818
from typing import Any, List
1919

2020

21-
from mkdocs_macros.util import SuperDict
21+
from super_collections import SuperDict
22+
2223
from .fixture_util import list_markdown_files, find_after
2324
from .docproject import (MarkdownPage, DocProject, REF_DIR,
2425
DOCS_DEFAULT_DIRNAME)

test/fixture_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pandas as pd
1919
from bs4 import BeautifulSoup
2020

21-
from mkdocs_macros.util import SuperDict
21+
from super_collections import SuperDict
2222

2323
# ---------------------------
2424
# Print functions

0 commit comments

Comments
 (0)