clld-markdown-plugin 0.5.0__tar.gz → 1.1.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,40 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: clld-markdown-plugin
3
- Version: 0.5.0
4
- Summary: Render CLDF markdown in clld apps.
5
- Home-page: https://github.com/clld/clld-markdown-plugin
6
- Author: Robert Forkel, Florian Matter
7
- Author-email: robert_forkel@eva.mpg.de, florianmatter@gmail.com
8
- Project-URL: Bug Tracker, https://github.com/clld/clld-markdown-plugin/issues
9
- Classifier: Development Status :: 2 - Pre-Alpha
10
- Classifier: Intended Audience :: Science/Research
11
- Classifier: License :: OSI Approved :: Apache Software License
3
+ Version: 1.1.0
4
+ Summary: A clld plugin to render CLDF markdown in clld apps.
5
+ Author-email: Robert Forkel <dlce.rdm@eva.mpg.de>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/clld/clld-markdown-plugin
8
+ Keywords: web,pyramid,clld
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
12
11
  Classifier: Natural Language :: English
12
+ Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.8
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
14
  Classifier: Programming Language :: Python :: 3.11
18
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Requires-Python: >=3.11
19
20
  Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: clld>=7.0
23
+ Requires-Dist: clldutils
24
+ Requires-Dist: pycldf
25
+ Requires-Dist: markdown
20
26
  Provides-Extra: dev
27
+ Requires-Dist: ruff; extra == "dev"
28
+ Requires-Dist: wheel; extra == "dev"
29
+ Requires-Dist: build; extra == "dev"
30
+ Requires-Dist: twine; extra == "dev"
21
31
  Provides-Extra: test
22
- License-File: LICENSE
32
+ Requires-Dist: pytest>=5; extra == "test"
33
+ Requires-Dist: pytest-mock; extra == "test"
34
+ Requires-Dist: pytest-cov; extra == "test"
35
+ Requires-Dist: coverage>=4.2; extra == "test"
36
+ Requires-Dist: webtest; extra == "test"
37
+ Dynamic: license-file
23
38
 
24
39
  # clld-markdown-plugin
25
40
 
@@ -0,0 +1,94 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "clld-markdown-plugin"
7
+ version = "1.1.0"
8
+ description = "A clld plugin to render CLDF markdown in clld apps."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ {name = "Robert Forkel", email = "dlce.rdm@eva.mpg.de"}
15
+ ]
16
+ keywords = ["web", "pyramid", "clld"]
17
+ classifiers = [
18
+ "Development Status :: 5 - Production/Stable",
19
+ "Intended Audience :: Developers",
20
+ "Natural Language :: English",
21
+ "Operating System :: OS Independent",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Programming Language :: Python :: 3.14",
27
+ "Programming Language :: Python :: 3.15",
28
+ ]
29
+ dependencies = [
30
+ "clld>=7.0",
31
+ "clldutils",
32
+ "pycldf",
33
+ "markdown",
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/clld/clld-markdown-plugin"
38
+
39
+ [project.optional-dependencies]
40
+ dev = [
41
+ "ruff",
42
+ "wheel",
43
+ "build",
44
+ "twine",
45
+ ]
46
+ test = [
47
+ "pytest>=5",
48
+ "pytest-mock",
49
+ "pytest-cov",
50
+ "coverage>=4.2",
51
+ "webtest",
52
+ ]
53
+
54
+ [tool.setuptools]
55
+ zip-safe = false
56
+
57
+ [tool.setuptools.packages.find]
58
+ where = ["src"]
59
+
60
+ [tool.ruff]
61
+ line-length = 100
62
+ exclude = [".tox"]
63
+
64
+ [tool.ruff.lint]
65
+ # E/F match default Flake8; D enables pydocstyle checks (since you ignored specific D rules)
66
+ select = ["UP", "N", "C90", "PL", "E", "F", "D"]
67
+ ignore = [
68
+ "D211",
69
+ "D213",
70
+ ]
71
+
72
+ [tool.pytest.ini_options]
73
+ minversion = "5.0"
74
+ testpaths = ["tests"]
75
+ addopts = ["--cov"]
76
+
77
+ [tool.coverage.run]
78
+ source = [
79
+ "clld_markdown_plugin",
80
+ "tests",
81
+ ]
82
+
83
+ [tool.coverage.report]
84
+ show_missing = true
85
+ skip_covered = true
86
+
87
+ [tool.tox]
88
+ requires = ["tox>=4.19"]
89
+ env_list = ["py311", "py312", "py313", "py314", "py315"]
90
+ skip_missing_interpreters = true
91
+
92
+ [tool.tox.env_run_base]
93
+ extras = ["test"]
94
+ commands = [["pytest", { replace = "posargs", default = [], extend = true }]]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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, Callable
4
+ from typing import 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.1.0"
20
22
  __all__ = ['markdown', 'includeme']
21
23
 
22
24
 
23
- def settings(custom: typing.Optional[dict] = None) -> dict:
25
+ def settings(custom: dict[str, Any] | None = None) -> dict[str, Any]:
26
+ """Get 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: # noqa: PLC0206
51
54
  if key == 'model_map':
52
55
  for k, v in custom.get(key, {}).items():
53
56
  res[key][k] = full_spec(v)
@@ -61,8 +64,7 @@ def settings(custom: typing.Optional[dict] = None) -> dict:
61
64
 
62
65
 
63
66
  def includeme(config):
64
- """
65
- Called when the plugin is included in a clld app via `config.include('clld_markdown_plugin')`.
67
+ """Call to include the plugin in a clld app `config.include('clld_markdown_plugin')`.
66
68
 
67
69
  Merges default and custom configuration for the plugin in the app's deployment settings under
68
70
  key 'clld_markdown_plugin'.
@@ -78,100 +80,107 @@ def includeme(config):
78
80
  return config
79
81
 
80
82
 
81
- def comma_and_list(entries, sep1=", ", sep2=" and "):
83
+ def _comma_and_list(entries: Sequence[str], sep1: str = ", ", sep2: str = " and ") -> str:
82
84
  output = entries[0]
83
85
  for entry in entries[1:-1]:
84
86
  output += sep1 + entry
85
87
  return output + sep2 + entries[-1]
86
88
 
87
89
 
88
- def link_entity(req, objid, route, model, session, decorate=None, ids=None, **kwargs):
90
+ def link_entity( # noqa: PLR0917,PLR0913
91
+ req: ClldRequest,
92
+ objid: str | None,
93
+ route: str,
94
+ model: type,
95
+ session,
96
+ decorate: Callable[[str], str] | None = None,
97
+ ids: Sequence[str] | None = None,
98
+ **kwargs,
99
+ ) -> str:
100
+ """Render a CLDF Markdown link as HTML."""
89
101
  if objid == "__all__":
90
102
  if ids:
91
- md_strs = [
103
+ return _comma_and_list([
92
104
  link_entity(req, mid, route, model, session, decorate=decorate, **kwargs)
93
105
  for mid in ids[0].split(",")
94
- ]
95
- return comma_and_list(md_strs)
106
+ ])
96
107
  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):
108
+ try:
109
+ entity = session.query(model).filter(model.id == objid)[0]
110
+ except IndexError as e:
111
+ raise ValueError(objid) from e # pragma: no cover
112
+ label = kwargs.pop("label", [None])[0] or entity.name
113
+ anchor = kwargs.pop("_anchor", [None])[0]
114
+ url = req.route_url(route, id=objid, _anchor=anchor, **kwargs)
115
+ md_str = f'<a class="{model.__tablename__.capitalize()}" href="{url}">{label}</a>'
116
+ return decorate(md_str) if decorate else md_str
117
+
118
+
119
+ def render_ex(req: ClldRequest, objid: str, table: str, session, ids=None, **_) -> str:
120
+ """Render an IGT example."""
111
121
  if objid == "__all__":
112
122
  if ids:
113
123
  ex_strs = [
114
- render_ex(req, mid, table, session, subexample=True) for mid in ids[0].split(",")
115
- ]
124
+ render_ex(req, mid, table, session, subexample=True) for mid in ids[0].split(",")]
116
125
  return '\n\n'.join(ex_strs)
117
126
  return rendered_sentence(session.query(common.Sentence).filter(common.Sentence.id == objid)[0])
118
127
 
119
128
 
129
+ def _repl(
130
+ ml: CLDFMarkdownLink,
131
+ settings_: dict,
132
+ req,
133
+ session,
134
+ source_ids):
135
+ def ref(src): # pragma: no cover
136
+ if WITH_MARKDOWN:
137
+ return base_markdown(src.bibtex().text(markdown=True))
138
+ return src.bibtex().text()
139
+
140
+ table = ml.table_or_fname
141
+ if table in settings_['renderer_map'] and "as_link" not in ml.parsed_url_query:
142
+ return settings_['renderer_map'][table](
143
+ req, ml.objid, table, session or DBSession, **ml.parsed_url_query)
144
+ if table in settings_['model_map']:
145
+ decorate = settings_['model_map'][table].get("decorate", None)
146
+ kw = dict(ml.parsed_url_query.items())
147
+ if ml.label and settings_['keep_link_labels']:
148
+ kw.setdefault('label', [ml.label])
149
+ if table == 'Source':
150
+ if ml.objid != '__all__':
151
+ source_ids.add(ml.objid)
152
+ elif 'cited_only' in ml.parsed_url.query:
153
+ model = settings_['model_map'][table]["model"]
154
+ return HTML.ul(*[
155
+ HTML.li(literal(ref(session.query(model).filter(model.id == sid)[0])))
156
+ for sid in sorted(source_ids)])
157
+ return link_entity(
158
+ req,
159
+ ml.objid,
160
+ settings_['model_map'][table]["route"],
161
+ settings_['model_map'][table]["model"],
162
+ session or DBSession,
163
+ decorate=decorate,
164
+ **kw,
165
+ )
166
+ log.error("Can't handle [%s] (%s).", ml.objid, table)
167
+ return f"{table}:{ml.objid}"
168
+
169
+
120
170
  def markdown(req, s: str, session=None) -> str:
121
- """
122
- :param req:
123
- :param s:
124
- :param permalink:
125
- :param session:
126
- :return: `str` containing HTML formatting.
127
- """
171
+ """:return: `str` containing HTML formatting."""
128
172
  if __name__ not in req.registry.settings: # pragma: no cover
129
173
  raise KeyError(
130
- '{} must be included in the app config to use the "markdown" function.'.format(
131
- __name__))
132
- settings = req.registry.settings[__name__]
174
+ f'{__name__} must be included in the app config to use the "markdown" function.')
175
+ settings_ = req.registry.settings[__name__]
133
176
  source_ids = set()
134
177
 
135
178
  def repl(ml):
136
- def ref(src): # pragma: no cover
137
- if WITH_MARKDOWN:
138
- return base_markdown(src.bibtex().text(markdown=True))
139
- return src.bibtex().text()
140
-
141
179
  if ml.is_cldf_link:
142
180
  try:
143
- 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](
146
- 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']:
151
- kw.setdefault('label', [ml.label])
152
- if table == 'Source':
153
- if ml.objid != '__all__':
154
- source_ids.add(ml.objid)
155
- elif 'cited_only' in ml.parsed_url.query:
156
- model = settings['model_map'][table]["model"]
157
- return HTML.ul(*[
158
- HTML.li(literal(ref(
159
- (session or DBSession).query(model).filter(model.id == sid)[0]
160
- )))
161
- for sid in sorted(source_ids)])
162
- return link_entity(
163
- req,
164
- ml.objid,
165
- settings['model_map'][table]["route"],
166
- settings['model_map'][table]["model"],
167
- session or DBSession,
168
- decorate=decorate,
169
- **kw,
170
- )
171
- log.error(f"Can't handle [{ml.objid}] ({table}).")
172
- return f"{table}:{ml.objid}"
173
- except: # noqa: E722
181
+ return _repl(ml, settings_, req, session or DBSession, source_ids)
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,40 @@
1
- Metadata-Version: 2.1
2
- Name: clld_markdown_plugin
3
- Version: 0.5.0
4
- Summary: Render CLDF markdown in clld apps.
5
- Home-page: https://github.com/clld/clld-markdown-plugin
6
- Author: Robert Forkel, Florian Matter
7
- Author-email: robert_forkel@eva.mpg.de, florianmatter@gmail.com
8
- Project-URL: Bug Tracker, https://github.com/clld/clld-markdown-plugin/issues
9
- Classifier: Development Status :: 2 - Pre-Alpha
10
- Classifier: Intended Audience :: Science/Research
11
- Classifier: License :: OSI Approved :: Apache Software License
1
+ Metadata-Version: 2.4
2
+ Name: clld-markdown-plugin
3
+ Version: 1.1.0
4
+ Summary: A clld plugin to render CLDF markdown in clld apps.
5
+ Author-email: Robert Forkel <dlce.rdm@eva.mpg.de>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/clld/clld-markdown-plugin
8
+ Keywords: web,pyramid,clld
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
12
11
  Classifier: Natural Language :: English
12
+ Classifier: Operating System :: OS Independent
13
13
  Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.8
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
14
  Classifier: Programming Language :: Python :: 3.11
18
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Requires-Python: >=3.11
19
20
  Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: clld>=7.0
23
+ Requires-Dist: clldutils
24
+ Requires-Dist: pycldf
25
+ Requires-Dist: markdown
20
26
  Provides-Extra: dev
27
+ Requires-Dist: ruff; extra == "dev"
28
+ Requires-Dist: wheel; extra == "dev"
29
+ Requires-Dist: build; extra == "dev"
30
+ Requires-Dist: twine; extra == "dev"
21
31
  Provides-Extra: test
22
- License-File: LICENSE
32
+ Requires-Dist: pytest>=5; extra == "test"
33
+ Requires-Dist: pytest-mock; extra == "test"
34
+ Requires-Dist: pytest-cov; extra == "test"
35
+ Requires-Dist: coverage>=4.2; extra == "test"
36
+ Requires-Dist: webtest; extra == "test"
37
+ Dynamic: license-file
23
38
 
24
39
  # clld-markdown-plugin
25
40
 
@@ -1,8 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
- setup.cfg
5
- setup.py
6
4
  src/clld_markdown_plugin/__init__.py
7
5
  src/clld_markdown_plugin.egg-info/PKG-INFO
8
6
  src/clld_markdown_plugin.egg-info/SOURCES.txt
@@ -1,16 +1,17 @@
1
+ clld>=7.0
1
2
  clldutils
2
3
  pycldf
3
- clld
4
4
  markdown
5
5
 
6
6
  [dev]
7
- flake8
8
- twine
7
+ ruff
9
8
  wheel
10
9
  build
10
+ twine
11
11
 
12
12
  [test]
13
- pytest
13
+ pytest>=5
14
14
  pytest-mock
15
15
  pytest-cov
16
- tox
16
+ coverage>=4.2
17
+ webtest
@@ -1,4 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools", "wheel"]
3
- build-backend = "setuptools.build_meta"
4
-
@@ -1,81 +0,0 @@
1
- [metadata]
2
- version = 0.5.0
3
- author = Robert Forkel, Florian Matter
4
- author_email = robert_forkel@eva.mpg.de, florianmatter@gmail.com
5
- classifiers =
6
- Development Status :: 2 - Pre-Alpha
7
- Intended Audience :: Science/Research
8
- License :: OSI Approved :: Apache Software License
9
- Natural Language :: English
10
- Programming Language :: Python :: 3
11
- Programming Language :: Python :: 3.8
12
- Programming Language :: Python :: 3.9
13
- Programming Language :: Python :: 3.10
14
- Programming Language :: Python :: 3.11
15
- Programming Language :: Python :: 3.12
16
- description = Render CLDF markdown in clld apps.
17
- long_description = file: README.md
18
- long_description_content_type = text/markdown
19
- name = clld_markdown_plugin
20
- project_urls =
21
- Bug Tracker = https://github.com/clld/clld-markdown-plugin/issues
22
- url = https://github.com/clld/clld-markdown-plugin
23
-
24
- [options]
25
- zip_safe = False
26
- include_package_data = True
27
- packages = find:
28
- package_dir =
29
- =src
30
- install_requires =
31
- clldutils
32
- pycldf
33
- clld
34
- markdown
35
-
36
- [options.extras_require]
37
- dev =
38
- flake8
39
- twine
40
- wheel
41
- build
42
- test =
43
- pytest
44
- pytest-mock
45
- pytest-cov
46
- tox
47
-
48
- [options.packages.find]
49
- include = clld_markdown_plugin, clld_markdown_plugin.*
50
- where = src
51
-
52
- [flake8]
53
- max-line-length = 100
54
- extend-ignore = E203
55
-
56
- [tool:pytest]
57
- addopts = --cov
58
- testpaths = tests
59
- filterwarnings =
60
- ignore::sqlalchemy.exc.RemovedIn20Warning
61
-
62
- [coverage:run]
63
- source =
64
- clld_markdown_plugin
65
-
66
- [coverage:report]
67
- show_missing = true
68
-
69
- [tox:tox]
70
- envlist = py38, py39, py310, py311, py312
71
- isolated_build = true
72
- skip_missing_interpreter = true
73
-
74
- [testenv]
75
- deps = .[test]
76
- commands = pytest {posargs}
77
-
78
- [egg_info]
79
- tag_build =
80
- tag_date = 0
81
-
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- import setuptools
4
-
5
- if __name__ == "__main__":
6
- setuptools.setup()