clld-markdown-plugin 0.5.0__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,39 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clld_markdown_plugin
3
- Version: 0.5.0
3
+ Version: 1.0.0
4
4
  Summary: Render CLDF markdown in clld apps.
5
5
  Home-page: https://github.com/clld/clld-markdown-plugin
6
6
  Author: Robert Forkel, Florian Matter
7
7
  Author-email: robert_forkel@eva.mpg.de, florianmatter@gmail.com
8
8
  Project-URL: Bug Tracker, https://github.com/clld/clld-markdown-plugin/issues
9
- Classifier: Development Status :: 2 - Pre-Alpha
9
+ Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: Intended Audience :: Science/Research
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Natural Language :: English
13
13
  Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.8
15
14
  Classifier: Programming Language :: Python :: 3.9
16
15
  Classifier: Programming Language :: Python :: 3.10
17
16
  Classifier: Programming Language :: Python :: 3.11
18
17
  Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
19
20
  Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: frontmatter<1.2; python_version < "3.10"
23
+ Requires-Dist: clldutils
24
+ Requires-Dist: pycldf
25
+ Requires-Dist: clld
26
+ Requires-Dist: markdown
20
27
  Provides-Extra: dev
28
+ Requires-Dist: flake8; extra == "dev"
29
+ Requires-Dist: twine; extra == "dev"
30
+ Requires-Dist: wheel; extra == "dev"
31
+ Requires-Dist: build; extra == "dev"
21
32
  Provides-Extra: test
22
- License-File: LICENSE
33
+ Requires-Dist: pytest; extra == "test"
34
+ Requires-Dist: pytest-mock; extra == "test"
35
+ Requires-Dist: pytest-cov; extra == "test"
36
+ Requires-Dist: tox; extra == "test"
23
37
 
24
38
  # clld-markdown-plugin
25
39
 
@@ -1,18 +1,19 @@
1
1
  [metadata]
2
- version = 0.5.0
2
+ version = 1.0.0
3
3
  author = Robert Forkel, Florian Matter
4
4
  author_email = robert_forkel@eva.mpg.de, florianmatter@gmail.com
5
5
  classifiers =
6
- Development Status :: 2 - Pre-Alpha
6
+ Development Status :: 5 - Production/Stable
7
7
  Intended Audience :: Science/Research
8
8
  License :: OSI Approved :: Apache Software License
9
9
  Natural Language :: English
10
10
  Programming Language :: Python :: 3
11
- Programming Language :: Python :: 3.8
12
11
  Programming Language :: Python :: 3.9
13
12
  Programming Language :: Python :: 3.10
14
13
  Programming Language :: Python :: 3.11
15
14
  Programming Language :: Python :: 3.12
15
+ Programming Language :: Python :: 3.13
16
+ Programming Language :: Python :: 3.14
16
17
  description = Render CLDF markdown in clld apps.
17
18
  long_description = file: README.md
18
19
  long_description_content_type = text/markdown
@@ -28,6 +29,7 @@ packages = find:
28
29
  package_dir =
29
30
  =src
30
31
  install_requires =
32
+ frontmatter<1.2;python_version<"3.10"
31
33
  clldutils
32
34
  pycldf
33
35
  clld
@@ -67,7 +69,7 @@ source =
67
69
  show_missing = true
68
70
 
69
71
  [tox:tox]
70
- envlist = py38, py39, py310, py311, py312
72
+ envlist = py39, py310, py311, py312, py313, py314
71
73
  isolated_build = true
72
74
  skip_missing_interpreter = true
73
75
 
@@ -1,10 +1,12 @@
1
1
  """Top-level package for clld-markdown-plugin."""
2
- import typing
3
2
  import logging
3
+ from collections.abc import Sequence
4
+ from typing import Optional, Callable, Any
4
5
 
5
6
  from markdown import Markdown
6
7
  from markdown import markdown as base_markdown
7
8
  from pycldf.ext.markdown import CLDFMarkdownLink
9
+ from clld.web.app import ClldRequest
8
10
  from clld.db.meta import DBSession
9
11
  from clld.db.models import common
10
12
  from clld.web.util.helpers import rendered_sentence
@@ -16,11 +18,12 @@ log = logging.getLogger(__name__)
16
18
 
17
19
  __author__ = "Robert Forkel, Florian Matter"
18
20
  __email__ = "robert_forkel@eva.mpg.de, florianmatter@gmail.com"
19
- __version__ = "0.5.0"
21
+ __version__ = "1.0.0"
20
22
  __all__ = ['markdown', 'includeme']
21
23
 
22
24
 
23
- def settings(custom: typing.Optional[dict] = None) -> dict:
25
+ def settings(custom: Optional[dict[str, Any]] = None) -> dict[str, Any]:
26
+ """Settings relevant for rendering CLDF Markdown."""
24
27
  def full_spec(spec):
25
28
  return spec if isinstance(spec, dict) else {
26
29
  'route': spec.__name__.split('.')[-1].lower() if spec else '', 'model': spec}
@@ -47,7 +50,7 @@ def settings(custom: typing.Optional[dict] = None) -> dict:
47
50
  "keep_link_labels": False,
48
51
  }
49
52
  custom = custom or {}
50
- for key in res:
53
+ for key in res: # pylint: disable=consider-using-dict-items
51
54
  if key == 'model_map':
52
55
  for k, v in custom.get(key, {}).items():
53
56
  res[key][k] = full_spec(v)
@@ -78,41 +81,48 @@ def includeme(config):
78
81
  return config
79
82
 
80
83
 
81
- def comma_and_list(entries, sep1=", ", sep2=" and "):
84
+ def _comma_and_list(entries: Sequence[str], sep1: str = ", ", sep2: str = " and ") -> str:
82
85
  output = entries[0]
83
86
  for entry in entries[1:-1]:
84
87
  output += sep1 + entry
85
88
  return output + sep2 + entries[-1]
86
89
 
87
90
 
88
- def link_entity(req, objid, route, model, session, decorate=None, ids=None, **kwargs):
91
+ def link_entity( # pylint: disable=R0913,R0917
92
+ req: ClldRequest,
93
+ objid: str,
94
+ route: str,
95
+ model: type,
96
+ session,
97
+ decorate: Optional[Callable[[str], str]] = None,
98
+ ids: Optional[Sequence[str]] = None,
99
+ **kwargs,
100
+ ) -> str:
101
+ """Render a CLDF Markdown link as HTML."""
89
102
  if objid == "__all__":
90
103
  if ids:
91
- md_strs = [
104
+ return _comma_and_list([
92
105
  link_entity(req, mid, route, model, session, decorate=decorate, **kwargs)
93
106
  for mid in ids[0].split(",")
94
- ]
95
- return comma_and_list(md_strs)
107
+ ])
96
108
  raise NotImplementedError("Table not yet implemented") # pragma: no cover
97
- else:
98
- try:
99
- entity = session.query(model).filter(model.id == objid)[0]
100
- except IndexError:
101
- raise ValueError(objid) # pragma: no cover
102
- label = kwargs.pop("label", [None])[0]
103
- anchor = kwargs.pop("_anchor", [None])[0]
104
- url = req.route_url(route, id=objid, _anchor=anchor, **kwargs)
105
- md_str = '<a class="{}" href="{}">{}</a>'.format(
106
- model.__tablename__.capitalize(), url, label or entity.name)
107
- return decorate(md_str) if decorate else md_str
108
-
109
-
110
- def render_ex(req, objid, table, session, ids=None, **kw):
109
+ try:
110
+ entity = session.query(model).filter(model.id == objid)[0]
111
+ except IndexError as e:
112
+ raise ValueError(objid) from e # pragma: no cover
113
+ label = kwargs.pop("label", [None])[0] or entity.name
114
+ anchor = kwargs.pop("_anchor", [None])[0]
115
+ url = req.route_url(route, id=objid, _anchor=anchor, **kwargs)
116
+ md_str = f'<a class="{model.__tablename__.capitalize()}" href="{url}">{label}</a>'
117
+ return decorate(md_str) if decorate else md_str
118
+
119
+
120
+ def render_ex(req: ClldRequest, objid: str, table: str, session, ids=None, **_) -> str:
121
+ """Render an IGT example."""
111
122
  if objid == "__all__":
112
123
  if ids:
113
124
  ex_strs = [
114
- render_ex(req, mid, table, session, subexample=True) for mid in ids[0].split(",")
115
- ]
125
+ render_ex(req, mid, table, session, subexample=True) for mid in ids[0].split(",")]
116
126
  return '\n\n'.join(ex_strs)
117
127
  return rendered_sentence(session.query(common.Sentence).filter(common.Sentence.id == objid)[0])
118
128
 
@@ -127,9 +137,8 @@ def markdown(req, s: str, session=None) -> str:
127
137
  """
128
138
  if __name__ not in req.registry.settings: # pragma: no cover
129
139
  raise KeyError(
130
- '{} must be included in the app config to use the "markdown" function.'.format(
131
- __name__))
132
- settings = req.registry.settings[__name__]
140
+ f'{__name__} must be included in the app config to use the "markdown" function.')
141
+ settings_ = req.registry.settings[__name__]
133
142
  source_ids = set()
134
143
 
135
144
  def repl(ml):
@@ -141,19 +150,19 @@ def markdown(req, s: str, session=None) -> str:
141
150
  if ml.is_cldf_link:
142
151
  try:
143
152
  table = ml.table_or_fname
144
- if table in settings['renderer_map'] and "as_link" not in ml.parsed_url_query:
145
- return settings['renderer_map'][table](
153
+ if table in settings_['renderer_map'] and "as_link" not in ml.parsed_url_query:
154
+ return settings_['renderer_map'][table](
146
155
  req, ml.objid, table, session or DBSession, **ml.parsed_url_query)
147
- elif table in settings['model_map']:
148
- decorate = settings['model_map'][table].get("decorate", None)
149
- kw = {k: v for k, v in ml.parsed_url_query.items()}
150
- if ml.label and settings['keep_link_labels']:
156
+ if table in settings_['model_map']:
157
+ decorate = settings_['model_map'][table].get("decorate", None)
158
+ kw = dict(ml.parsed_url_query.items())
159
+ if ml.label and settings_['keep_link_labels']:
151
160
  kw.setdefault('label', [ml.label])
152
161
  if table == 'Source':
153
162
  if ml.objid != '__all__':
154
163
  source_ids.add(ml.objid)
155
164
  elif 'cited_only' in ml.parsed_url.query:
156
- model = settings['model_map'][table]["model"]
165
+ model = settings_['model_map'][table]["model"]
157
166
  return HTML.ul(*[
158
167
  HTML.li(literal(ref(
159
168
  (session or DBSession).query(model).filter(model.id == sid)[0]
@@ -162,16 +171,16 @@ def markdown(req, s: str, session=None) -> str:
162
171
  return link_entity(
163
172
  req,
164
173
  ml.objid,
165
- settings['model_map'][table]["route"],
166
- settings['model_map'][table]["model"],
174
+ settings_['model_map'][table]["route"],
175
+ settings_['model_map'][table]["model"],
167
176
  session or DBSession,
168
177
  decorate=decorate,
169
178
  **kw,
170
179
  )
171
- log.error(f"Can't handle [{ml.objid}] ({table}).")
180
+ log.error("Can't handle [%s] (%s).", ml.objid, table)
172
181
  return f"{table}:{ml.objid}"
173
- except: # noqa: E722
182
+ except: # noqa: E722 # pylint: disable=W0702
174
183
  return ml.label
175
184
  return ml
176
185
 
177
- return Markdown(extensions=settings["extensions"]).convert(CLDFMarkdownLink.replace(s, repl))
186
+ return Markdown(extensions=settings_["extensions"]).convert(CLDFMarkdownLink.replace(s, repl))
@@ -1,25 +1,39 @@
1
1
  Metadata-Version: 2.1
2
- Name: clld-markdown-plugin
3
- Version: 0.5.0
2
+ Name: clld_markdown_plugin
3
+ Version: 1.0.0
4
4
  Summary: Render CLDF markdown in clld apps.
5
5
  Home-page: https://github.com/clld/clld-markdown-plugin
6
6
  Author: Robert Forkel, Florian Matter
7
7
  Author-email: robert_forkel@eva.mpg.de, florianmatter@gmail.com
8
8
  Project-URL: Bug Tracker, https://github.com/clld/clld-markdown-plugin/issues
9
- Classifier: Development Status :: 2 - Pre-Alpha
9
+ Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: Intended Audience :: Science/Research
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Natural Language :: English
13
13
  Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.8
15
14
  Classifier: Programming Language :: Python :: 3.9
16
15
  Classifier: Programming Language :: Python :: 3.10
17
16
  Classifier: Programming Language :: Python :: 3.11
18
17
  Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
19
20
  Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: frontmatter<1.2; python_version < "3.10"
23
+ Requires-Dist: clldutils
24
+ Requires-Dist: pycldf
25
+ Requires-Dist: clld
26
+ Requires-Dist: markdown
20
27
  Provides-Extra: dev
28
+ Requires-Dist: flake8; extra == "dev"
29
+ Requires-Dist: twine; extra == "dev"
30
+ Requires-Dist: wheel; extra == "dev"
31
+ Requires-Dist: build; extra == "dev"
21
32
  Provides-Extra: test
22
- License-File: LICENSE
33
+ Requires-Dist: pytest; extra == "test"
34
+ Requires-Dist: pytest-mock; extra == "test"
35
+ Requires-Dist: pytest-cov; extra == "test"
36
+ Requires-Dist: tox; extra == "test"
23
37
 
24
38
  # clld-markdown-plugin
25
39
 
@@ -3,6 +3,9 @@ pycldf
3
3
  clld
4
4
  markdown
5
5
 
6
+ [:python_version < "3.10"]
7
+ frontmatter<1.2
8
+
6
9
  [dev]
7
10
  flake8
8
11
  twine