docma 2.2.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.
- docma-2.2.0/CONTRIBUTING.md +9 -0
- docma-2.2.0/LICENCE.txt +27 -0
- docma-2.2.0/MANIFEST.in +8 -0
- docma-2.2.0/PKG-INFO +118 -0
- docma-2.2.0/PYPI.md +51 -0
- docma-2.2.0/README.md +77 -0
- docma-2.2.0/docma/VERSION +1 -0
- docma-2.2.0/docma/__init__.py +45 -0
- docma-2.2.0/docma/cli/__init__.py +3 -0
- docma-2.2.0/docma/cli/docma.py +103 -0
- docma-2.2.0/docma/commands/__common__.py +189 -0
- docma-2.2.0/docma/commands/__init__.py +16 -0
- docma-2.2.0/docma/commands/compile.py +39 -0
- docma-2.2.0/docma/commands/html_batch.py +168 -0
- docma-2.2.0/docma/commands/html_render.py +61 -0
- docma-2.2.0/docma/commands/info.py +37 -0
- docma-2.2.0/docma/commands/new.py +113 -0
- docma-2.2.0/docma/commands/pdf_batch.py +218 -0
- docma-2.2.0/docma/commands/pdf_render.py +111 -0
- docma-2.2.0/docma/compilers/__common__.py +47 -0
- docma-2.2.0/docma/compilers/__init__.py +23 -0
- docma-2.2.0/docma/compilers/markdown.py +14 -0
- docma-2.2.0/docma/config.py +29 -0
- docma-2.2.0/docma/data_providers/__common__.py +157 -0
- docma-2.2.0/docma/data_providers/__init__.py +62 -0
- docma-2.2.0/docma/data_providers/db.py +318 -0
- docma-2.2.0/docma/data_providers/file.py +50 -0
- docma-2.2.0/docma/data_providers/params.py +42 -0
- docma-2.2.0/docma/docma_core.py +959 -0
- docma-2.2.0/docma/exceptions.py +51 -0
- docma-2.2.0/docma/generators/__common__.py +61 -0
- docma-2.2.0/docma/generators/__init__.py +66 -0
- docma-2.2.0/docma/generators/qrcode.py +57 -0
- docma-2.2.0/docma/generators/swatch.py +62 -0
- docma-2.2.0/docma/generators/vega.py +103 -0
- docma-2.2.0/docma/importers/__common__.py +64 -0
- docma-2.2.0/docma/importers/__init__.py +45 -0
- docma-2.2.0/docma/importers/http.py +15 -0
- docma-2.2.0/docma/importers/s3.py +29 -0
- docma-2.2.0/docma/jinja/__init__.py +25 -0
- docma-2.2.0/docma/jinja/core.py +149 -0
- docma-2.2.0/docma/jinja/extensions.py +235 -0
- docma-2.2.0/docma/jinja/resolvers.py +193 -0
- docma-2.2.0/docma/jinja/utils.py +29 -0
- docma-2.2.0/docma/lib/__init__.py +3 -0
- docma-2.2.0/docma/lib/db.py +21 -0
- docma-2.2.0/docma/lib/html.py +43 -0
- docma-2.2.0/docma/lib/http.py +43 -0
- docma-2.2.0/docma/lib/jsonschema.py +125 -0
- docma-2.2.0/docma/lib/logging.py +99 -0
- docma-2.2.0/docma/lib/metadata.py +106 -0
- docma-2.2.0/docma/lib/misc.py +313 -0
- docma-2.2.0/docma/lib/packager.py +346 -0
- docma-2.2.0/docma/lib/path.py +39 -0
- docma-2.2.0/docma/lib/plugin.py +425 -0
- docma-2.2.0/docma/lib/query.py +179 -0
- docma-2.2.0/docma/plugins/__init__.py +3 -0
- docma-2.2.0/docma/plugins/format_checkers/__init__.py +8 -0
- docma-2.2.0/docma/plugins/format_checkers/au/__init__.py +3 -0
- docma-2.2.0/docma/plugins/format_checkers/au/company_ids.py +44 -0
- docma-2.2.0/docma/plugins/format_checkers/au/industry_formats.py +36 -0
- docma-2.2.0/docma/plugins/format_checkers/deprecated.py +87 -0
- docma-2.2.0/docma/plugins/format_checkers/utility.py +53 -0
- docma-2.2.0/docma/plugins/jinja_filters/__init__.py +3 -0
- docma-2.2.0/docma/plugins/jinja_filters/au/__init__.py +3 -0
- docma-2.2.0/docma/plugins/jinja_filters/au/company_ids.py +28 -0
- docma-2.2.0/docma/plugins/jinja_filters/datetime.py +110 -0
- docma-2.2.0/docma/plugins/jinja_filters/deprecated.py +37 -0
- docma-2.2.0/docma/plugins/jinja_filters/dollars.py +26 -0
- docma-2.2.0/docma/plugins/jinja_filters/number.py +90 -0
- docma-2.2.0/docma/plugins/jinja_filters/phone.py +138 -0
- docma-2.2.0/docma/plugins/jinja_filters/utility.py +48 -0
- docma-2.2.0/docma/plugins/jinja_tests/__init__.py +8 -0
- docma-2.2.0/docma/resources/__init__.py +1 -0
- docma-2.2.0/docma/resources/config-schema.yaml +136 -0
- docma-2.2.0/docma/resources/cookiecutter/cookiecutter.json +16 -0
- docma-2.2.0/docma/resources/cookiecutter/hooks/pre_gen_project.py +38 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/charts/README +4 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/charts/woof.yaml +85 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/config.yaml +57 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/content/README +4 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/content/sample.html +269 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/css/pdf.css +4 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/data/README +4 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/data/dogs.csv +10 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/fonts/README +4 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/overlays/grid-a4-landscape.html +35 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/overlays/grid-a4-portrait.html +35 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/queries/README +4 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/resources/README +4 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/resources/img/docma-icon-light.svg +7 -0
- docma-2.2.0/docma/resources/cookiecutter/{{cookiecutter.template_src_dir}}/resources/img/docma-logo-horizontal-light.svg +11 -0
- docma-2.2.0/docma/url_fetchers/__common__.py +27 -0
- docma-2.2.0/docma/url_fetchers/__init__.py +55 -0
- docma-2.2.0/docma/url_fetchers/docma.py +52 -0
- docma-2.2.0/docma/url_fetchers/file.py +38 -0
- docma-2.2.0/docma/url_fetchers/http.py +60 -0
- docma-2.2.0/docma/url_fetchers/s3.py +55 -0
- docma-2.2.0/docma/validators.py +159 -0
- docma-2.2.0/docma/version.py +7 -0
- docma-2.2.0/docma.egg-info/PKG-INFO +118 -0
- docma-2.2.0/docma.egg-info/SOURCES.txt +111 -0
- docma-2.2.0/docma.egg-info/dependency_links.txt +1 -0
- docma-2.2.0/docma.egg-info/entry_points.txt +2 -0
- docma-2.2.0/docma.egg-info/requires.txt +34 -0
- docma-2.2.0/docma.egg-info/top_level.txt +1 -0
- docma-2.2.0/pyproject.toml +93 -0
- docma-2.2.0/requirements-build.txt +32 -0
- docma-2.2.0/requirements-duckdb.txt +1 -0
- docma-2.2.0/requirements-lava.txt +1 -0
- docma-2.2.0/requirements.txt +25 -0
- docma-2.2.0/setup.cfg +4 -0
- docma-2.2.0/setup.py +83 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Positive contributions are welcome, so let's not over-complicate this.
|
|
2
|
+
|
|
3
|
+
These are the rules, for now:
|
|
4
|
+
|
|
5
|
+
1. Be courteous and respectful, and think before you type.
|
|
6
|
+
|
|
7
|
+
2. All proposed changes should be discussed with us first by raising an issue.
|
|
8
|
+
|
|
9
|
+
3. We have the final say on everything, but we'll always try to be reasonable.
|
docma-2.2.0/LICENCE.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright 2025 Origin Energy Limited
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
4
|
+
are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
+
may be used to endorse or promote products derived from this software
|
|
15
|
+
without specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
|
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
21
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
24
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
|
docma-2.2.0/MANIFEST.in
ADDED
docma-2.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docma
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: Document manufacturer
|
|
5
|
+
Home-page: https://github.com/jin-gizmo/docma
|
|
6
|
+
Author: Murray Andrews
|
|
7
|
+
License: BSD-3-Clause
|
|
8
|
+
Platform: macOS
|
|
9
|
+
Platform: Linux
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Information Technology
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Topic :: Documentation
|
|
19
|
+
Classifier: Topic :: Text Processing
|
|
20
|
+
Requires-Python: >=3.11.0
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENCE.txt
|
|
23
|
+
Requires-Dist: altair
|
|
24
|
+
Requires-Dist: babel
|
|
25
|
+
Requires-Dist: beautifulsoup4
|
|
26
|
+
Requires-Dist: boto3
|
|
27
|
+
Requires-Dist: cachetools
|
|
28
|
+
Requires-Dist: colorama
|
|
29
|
+
Requires-Dist: cookiecutter
|
|
30
|
+
Requires-Dist: duckdb
|
|
31
|
+
Requires-Dist: jinja2
|
|
32
|
+
Requires-Dist: jsonschema[format-nongpl]
|
|
33
|
+
Requires-Dist: markdown
|
|
34
|
+
Requires-Dist: pg8000
|
|
35
|
+
Requires-Dist: phonenumbers
|
|
36
|
+
Requires-Dist: pillow
|
|
37
|
+
Requires-Dist: pydantic
|
|
38
|
+
Requires-Dist: pypdf
|
|
39
|
+
Requires-Dist: python-dotenv
|
|
40
|
+
Requires-Dist: pyyaml
|
|
41
|
+
Requires-Dist: qrcode[pil]
|
|
42
|
+
Requires-Dist: referencing
|
|
43
|
+
Requires-Dist: requests
|
|
44
|
+
Requires-Dist: tqdm
|
|
45
|
+
Requires-Dist: vl-convert-python
|
|
46
|
+
Requires-Dist: weasyprint
|
|
47
|
+
Provides-Extra: all
|
|
48
|
+
Requires-Dist: duckdb; extra == "all"
|
|
49
|
+
Requires-Dist: jinlava>=8.0.0; extra == "all"
|
|
50
|
+
Provides-Extra: duckdb
|
|
51
|
+
Requires-Dist: duckdb; extra == "duckdb"
|
|
52
|
+
Provides-Extra: lava
|
|
53
|
+
Requires-Dist: jinlava>=8.0.0; extra == "lava"
|
|
54
|
+
Dynamic: author
|
|
55
|
+
Dynamic: classifier
|
|
56
|
+
Dynamic: description
|
|
57
|
+
Dynamic: description-content-type
|
|
58
|
+
Dynamic: home-page
|
|
59
|
+
Dynamic: license
|
|
60
|
+
Dynamic: license-file
|
|
61
|
+
Dynamic: platform
|
|
62
|
+
Dynamic: provides-extra
|
|
63
|
+
Dynamic: requires-dist
|
|
64
|
+
Dynamic: requires-python
|
|
65
|
+
Dynamic: summary
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Docma -- Document Manufacturing for Fun and Profit
|
|
69
|
+
|
|
70
|
+
**Docma** is a document generator that can assemble and compose PDF and HTML
|
|
71
|
+
documents from document templates with dynamic, data driven content.
|
|
72
|
+
|
|
73
|
+
[](https://pypi.org/project/docma/)
|
|
74
|
+
[](https://pypi.org/project/docma/)
|
|
75
|
+

|
|
76
|
+
[](https://github.com/jin-gizmo/docma/blob/master/LICENCE.txt)
|
|
77
|
+
[](https://github.com/psf/black)
|
|
78
|
+
|
|
79
|
+
## Genesis
|
|
80
|
+
|
|
81
|
+
**Docma** was developed at [Origin Energy](https://www.originenergy.com.au)
|
|
82
|
+
as part of the *Jindabyne* initiative. While not part of our core IP, it proved
|
|
83
|
+
valuable internally, and we're sharing it in the hope it's useful to others.
|
|
84
|
+
|
|
85
|
+
Kudos to Origin for fostering a culture that empowers its people
|
|
86
|
+
to build complex technology solutions in-house.
|
|
87
|
+
|
|
88
|
+
[](https://jin-gizmo.github.io)
|
|
89
|
+
|
|
90
|
+
## Features
|
|
91
|
+
|
|
92
|
+
**Docma** features include:
|
|
93
|
+
|
|
94
|
+
* Document content can be defined in any combination of HTML and PDF.
|
|
95
|
+
|
|
96
|
+
* Content can also be defined in other formats that are compiled to HTML
|
|
97
|
+
(e.g. Markdown, CSV).
|
|
98
|
+
|
|
99
|
+
* Dynamic content preparation (conditionals, loops, transformation etc.) based
|
|
100
|
+
on structured data parameters fed to the rendering process at run-time.
|
|
101
|
+
|
|
102
|
+
* Composition of multiple source documents into a single output document.
|
|
103
|
+
|
|
104
|
+
* Conditional inclusion of component documents based on parameter based
|
|
105
|
+
conditions evaluated at run-time.
|
|
106
|
+
|
|
107
|
+
* Deep schema validation of structured data parameters at run-time.
|
|
108
|
+
|
|
109
|
+
* Watermarking / stamping of PDF output.
|
|
110
|
+
|
|
111
|
+
* Support for charts via the Vega-lite specification with multiple data
|
|
112
|
+
sources, including live database connections.
|
|
113
|
+
|
|
114
|
+
* Readily extensible to add new data sources and content types.
|
|
115
|
+
|
|
116
|
+
## Installation and Usage
|
|
117
|
+
|
|
118
|
+
See the [user guide](https://jin-gizmo.github.io/docma/) for details.
|
docma-2.2.0/PYPI.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Docma -- Document Manufacturing for Fun and Profit
|
|
2
|
+
|
|
3
|
+
**Docma** is a document generator that can assemble and compose PDF and HTML
|
|
4
|
+
documents from document templates with dynamic, data driven content.
|
|
5
|
+
|
|
6
|
+
[](https://pypi.org/project/docma/)
|
|
7
|
+
[](https://pypi.org/project/docma/)
|
|
8
|
+

|
|
9
|
+
[](https://github.com/jin-gizmo/docma/blob/master/LICENCE.txt)
|
|
10
|
+
[](https://github.com/psf/black)
|
|
11
|
+
|
|
12
|
+
## Genesis
|
|
13
|
+
|
|
14
|
+
**Docma** was developed at [Origin Energy](https://www.originenergy.com.au)
|
|
15
|
+
as part of the *Jindabyne* initiative. While not part of our core IP, it proved
|
|
16
|
+
valuable internally, and we're sharing it in the hope it's useful to others.
|
|
17
|
+
|
|
18
|
+
Kudos to Origin for fostering a culture that empowers its people
|
|
19
|
+
to build complex technology solutions in-house.
|
|
20
|
+
|
|
21
|
+
[](https://jin-gizmo.github.io)
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
**Docma** features include:
|
|
26
|
+
|
|
27
|
+
* Document content can be defined in any combination of HTML and PDF.
|
|
28
|
+
|
|
29
|
+
* Content can also be defined in other formats that are compiled to HTML
|
|
30
|
+
(e.g. Markdown, CSV).
|
|
31
|
+
|
|
32
|
+
* Dynamic content preparation (conditionals, loops, transformation etc.) based
|
|
33
|
+
on structured data parameters fed to the rendering process at run-time.
|
|
34
|
+
|
|
35
|
+
* Composition of multiple source documents into a single output document.
|
|
36
|
+
|
|
37
|
+
* Conditional inclusion of component documents based on parameter based
|
|
38
|
+
conditions evaluated at run-time.
|
|
39
|
+
|
|
40
|
+
* Deep schema validation of structured data parameters at run-time.
|
|
41
|
+
|
|
42
|
+
* Watermarking / stamping of PDF output.
|
|
43
|
+
|
|
44
|
+
* Support for charts via the Vega-lite specification with multiple data
|
|
45
|
+
sources, including live database connections.
|
|
46
|
+
|
|
47
|
+
* Readily extensible to add new data sources and content types.
|
|
48
|
+
|
|
49
|
+
## Installation and Usage
|
|
50
|
+
|
|
51
|
+
See the [user guide](https://jin-gizmo.github.io/docma/) for details.
|
docma-2.2.0/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Docma -- Document Manufacturing for Fun and Profit
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img src="doc/img/docma-logo/svg/docma-logo-horizontal-light.svg" alt="Docma Logo" width="300px" height="auto">
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
**Docma** is a document generator that can assemble and compose PDF and HTML
|
|
8
|
+
documents from document templates with dynamic, data driven content.
|
|
9
|
+
|
|
10
|
+
[](https://pypi.org/project/docma/)
|
|
11
|
+
[](https://pypi.org/project/docma/)
|
|
12
|
+
[](https://github.com/jin-gizmo/docma/blob/master/LICENCE.txt)
|
|
13
|
+
[](https://github.com/psf/black)
|
|
14
|
+
|
|
15
|
+
## Genesis
|
|
16
|
+
|
|
17
|
+
**Docma** was developed at [Origin Energy](https://www.originenergy.com.au)
|
|
18
|
+
as part of the *Jindabyne* initiative. While not part of our core IP, it proved
|
|
19
|
+
valuable internally, and we're sharing it in the hope it's useful to others.
|
|
20
|
+
|
|
21
|
+
Kudos to Origin for fostering a culture that empowers its people to build
|
|
22
|
+
complex technology solutions in-house.
|
|
23
|
+
|
|
24
|
+
[](https://jin-gizmo.github.io)
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
**Docma** features include:
|
|
29
|
+
|
|
30
|
+
* Document content can be defined in any combination of HTML and PDF.
|
|
31
|
+
|
|
32
|
+
* Content can also be defined in other formats that are compiled to HTML
|
|
33
|
+
(e.g. Markdown, CSV).
|
|
34
|
+
|
|
35
|
+
* Dynamic content preparation (conditionals, loops, transformation etc.) based
|
|
36
|
+
on structured data parameters fed to the rendering process at run-time.
|
|
37
|
+
|
|
38
|
+
* Composition of multiple source documents into a single output document.
|
|
39
|
+
|
|
40
|
+
* Conditional inclusion of component documents based on parameter based
|
|
41
|
+
conditions evaluated at run-time.
|
|
42
|
+
|
|
43
|
+
* Deep schema validation of structured data parameters at run-time.
|
|
44
|
+
|
|
45
|
+
* Watermarking / stamping of PDF output.
|
|
46
|
+
|
|
47
|
+
* Support for charts via the Vega-lite specification with multiple data
|
|
48
|
+
sources, including live database connections.
|
|
49
|
+
|
|
50
|
+
* Readily extensible to add new data sources and content types.
|
|
51
|
+
|
|
52
|
+
## Installation and Usage
|
|
53
|
+
|
|
54
|
+
See the [user guide](https://jin-gizmo.github.io/docma/) for details.
|
|
55
|
+
|
|
56
|
+
## Credits
|
|
57
|
+
|
|
58
|
+
Thanks to MenaG for inspiring this idea in the first place and for having faith
|
|
59
|
+
that it was worth the bother.
|
|
60
|
+
|
|
61
|
+
Thanks to Alex Boul, and Art Dorokhov for contributing to **docma**.
|
|
62
|
+
|
|
63
|
+
**Docma** is possible because of these amazing Python packages:
|
|
64
|
+
|
|
65
|
+
* [WeasyPrint](https://weasyprint.org)
|
|
66
|
+
|
|
67
|
+
* [Jinja2](https://jinja.palletsprojects.com/en/)
|
|
68
|
+
|
|
69
|
+
* [Vega-Altair](https://altair-viz.github.io/index.html)
|
|
70
|
+
|
|
71
|
+
* [PyPDF](https://pypdf.readthedocs.io/en/stable/)
|
|
72
|
+
|
|
73
|
+
Honourable mentions:
|
|
74
|
+
|
|
75
|
+
* [Babel](https://babel.pocoo.org/en/latest/)
|
|
76
|
+
|
|
77
|
+
* [Phonenumbers](https://pypi.org/project/phonenumbers/)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.2.0
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# ruff: noqa D404
|
|
2
|
+
"""
|
|
3
|
+
This is the primary docma API for compiling and rendering document templates.
|
|
4
|
+
|
|
5
|
+
Typical usage would be:
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from docma import compile_template, render_template
|
|
9
|
+
|
|
10
|
+
template_src_dir = 'a/b/c'
|
|
11
|
+
template_location = 'my-template.zip' # ... or a directory when experimenting
|
|
12
|
+
pdf_location = 'my-doc.pdf'
|
|
13
|
+
params = { ... } # A Dict of parameters.
|
|
14
|
+
|
|
15
|
+
compile_template(template_src_dir, template_location)
|
|
16
|
+
|
|
17
|
+
pdf = render_template_to_pdf(template_location, params)
|
|
18
|
+
|
|
19
|
+
# We now have a pypdf PdfWriter object. Do with it what you will. e.g.
|
|
20
|
+
pdf.write(pdf_location)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from .docma_core import (
|
|
26
|
+
compile_template as compile_template,
|
|
27
|
+
get_template_info as get_template_info,
|
|
28
|
+
read_template_version_info as read_template_version_info,
|
|
29
|
+
render_template_to_html as render_template_to_html,
|
|
30
|
+
render_template_to_pdf as render_template_to_pdf,
|
|
31
|
+
safe_render_path as safe_render_path,
|
|
32
|
+
)
|
|
33
|
+
from .version import __version__ as __version__
|
|
34
|
+
|
|
35
|
+
__author__ = 'Murray Andrews'
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
'compile_template',
|
|
39
|
+
'get_template_info',
|
|
40
|
+
'read_template_version_info',
|
|
41
|
+
'render_template_to_html',
|
|
42
|
+
'render_template_to_pdf',
|
|
43
|
+
'safe_render_path',
|
|
44
|
+
'__version__',
|
|
45
|
+
]
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Command line utility to manufacture PDF documents."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import sys
|
|
9
|
+
from logging import getLogger
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from docma.commands import CliCommand
|
|
13
|
+
from docma.config import LOGNAME
|
|
14
|
+
from docma.exceptions import DocmaInternalError
|
|
15
|
+
from docma.lib.logging import setup_logging
|
|
16
|
+
from docma.version import __version__
|
|
17
|
+
|
|
18
|
+
__author__ = 'Murray Andrews'
|
|
19
|
+
|
|
20
|
+
PROG = Path(sys.argv[0]).stem
|
|
21
|
+
LOG = getLogger(LOGNAME)
|
|
22
|
+
LOGLEVEL = 'warning'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# ------------------------------------------------------------------------------
|
|
26
|
+
def process_cli_args() -> argparse.Namespace:
|
|
27
|
+
"""
|
|
28
|
+
Process the command line arguments.
|
|
29
|
+
|
|
30
|
+
:return: The args namespace.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
argp = argparse.ArgumentParser(prog=PROG, description='Manufacture documents.')
|
|
34
|
+
|
|
35
|
+
argp.add_argument('-v', '--version', action='version', version=__version__)
|
|
36
|
+
|
|
37
|
+
# ----------------------------------------
|
|
38
|
+
# Logging args
|
|
39
|
+
|
|
40
|
+
logp = argp.add_argument_group('logging arguments')
|
|
41
|
+
logp.add_argument(
|
|
42
|
+
'--no-colour',
|
|
43
|
+
'--no-color',
|
|
44
|
+
dest='colour',
|
|
45
|
+
action='store_false',
|
|
46
|
+
default=True,
|
|
47
|
+
help='Don\'t use colour in log messages.',
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
logp.add_argument(
|
|
51
|
+
'-l',
|
|
52
|
+
'--level',
|
|
53
|
+
metavar='LEVEL',
|
|
54
|
+
default=LOGLEVEL,
|
|
55
|
+
help=(
|
|
56
|
+
'Print messages of a given severity level or above. The standard'
|
|
57
|
+
' logging level names are available but debug, info, warning and'
|
|
58
|
+
f' error are most useful. The default is {LOGLEVEL}.'
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# ----------------------------------------
|
|
63
|
+
# Add the sub-commonads
|
|
64
|
+
subp = argp.add_subparsers(title='subcommands', required=True)
|
|
65
|
+
for cmd in sorted(CliCommand.commands.values(), key=lambda c: c.name):
|
|
66
|
+
cmd(subp).add_arguments()
|
|
67
|
+
|
|
68
|
+
args = argp.parse_args()
|
|
69
|
+
|
|
70
|
+
if not hasattr(args, 'handler'):
|
|
71
|
+
raise DocmaInternalError('Args namespace missing handler entry')
|
|
72
|
+
|
|
73
|
+
try:
|
|
74
|
+
args.handler.check_arguments(args)
|
|
75
|
+
except ValueError as e:
|
|
76
|
+
argp.error(str(e))
|
|
77
|
+
|
|
78
|
+
return args
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# ------------------------------------------------------------------------------
|
|
82
|
+
def main() -> int:
|
|
83
|
+
"""Show time."""
|
|
84
|
+
|
|
85
|
+
try:
|
|
86
|
+
setup_logging(LOGLEVEL, name=LOGNAME, prefix=PROG)
|
|
87
|
+
args = process_cli_args()
|
|
88
|
+
setup_logging(args.level, name=LOGNAME, colour=args.colour)
|
|
89
|
+
args.handler.execute(args)
|
|
90
|
+
return 0
|
|
91
|
+
except Exception as e:
|
|
92
|
+
LOG.error(str(e))
|
|
93
|
+
return 1
|
|
94
|
+
except KeyboardInterrupt:
|
|
95
|
+
LOG.warning('Interrupt')
|
|
96
|
+
return 2
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# ------------------------------------------------------------------------------
|
|
100
|
+
# This only gets used during dev/test. Once deployed as a package, main() gets
|
|
101
|
+
# imported and run directly.
|
|
102
|
+
if __name__ == '__main__':
|
|
103
|
+
exit(main()) # pragma: no cover
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Common components for docma CLI commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import sys
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from argparse import ArgumentParser, Namespace
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any, Callable
|
|
11
|
+
|
|
12
|
+
import yaml
|
|
13
|
+
|
|
14
|
+
from docma.lib.misc import StoreNameValuePair, deep_update_dict
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# ------------------------------------------------------------------------------
|
|
18
|
+
class CliCommand(ABC):
|
|
19
|
+
"""
|
|
20
|
+
CLI subcommand handler.
|
|
21
|
+
|
|
22
|
+
CLI subcommands should be declared as a subclass and also registered using
|
|
23
|
+
the `register` decorator so that they are automatically discovered.
|
|
24
|
+
|
|
25
|
+
Subclasses may implement `add_arguments` and `check_arguments` methods and
|
|
26
|
+
must implement the `execute` method.
|
|
27
|
+
|
|
28
|
+
Thus:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
@CliCommand.register('command-name')
|
|
32
|
+
class Whatever(CliCommand):
|
|
33
|
+
|
|
34
|
+
def add_arguments(self) -> None:
|
|
35
|
+
self.argp.add_argument('--arg1', action='store')
|
|
36
|
+
|
|
37
|
+
def execute(self, args: Namespace) -> None:
|
|
38
|
+
print(f'The argument value for arg1 is {args.arg1}')
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
commands: dict[str, type[CliCommand]] = {}
|
|
44
|
+
name = None # Set by @register decorator for subclasses.
|
|
45
|
+
help_ = None # Set by @register from first line of docstring.
|
|
46
|
+
|
|
47
|
+
# --------------------------------------------------------------------------
|
|
48
|
+
@classmethod
|
|
49
|
+
def register(cls, name: str) -> Callable:
|
|
50
|
+
"""
|
|
51
|
+
Register a CLI command handler class.
|
|
52
|
+
|
|
53
|
+
This is a decorator. Usage is:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
@CliCommand.register('my_command')
|
|
57
|
+
class MyCommand(CliCommand):
|
|
58
|
+
...
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The help for the command is taken from the first line of the docstring.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
def decorate(cmd: type[CliCommand]):
|
|
65
|
+
"""Register the command handler class."""
|
|
66
|
+
cmd.name = name
|
|
67
|
+
try:
|
|
68
|
+
cmd.help_ = cmd.__doc__.splitlines()[0]
|
|
69
|
+
except (AttributeError, IndexError):
|
|
70
|
+
raise Exception(f'Class {cmd.__name__} must have a docstring')
|
|
71
|
+
cls.commands[name] = cmd
|
|
72
|
+
return cmd
|
|
73
|
+
|
|
74
|
+
return decorate
|
|
75
|
+
|
|
76
|
+
# --------------------------------------------------------------------------
|
|
77
|
+
def __init__(self, subparser) -> None:
|
|
78
|
+
"""Initialize the command handler."""
|
|
79
|
+
self.argp = subparser.add_parser(self.name, help=self.help_, description=self.help_)
|
|
80
|
+
self.argp.set_defaults(handler=self)
|
|
81
|
+
|
|
82
|
+
# --------------------------------------------------------------------------
|
|
83
|
+
def add_arguments(self): # noqa B027
|
|
84
|
+
"""Add arguments to the command handler."""
|
|
85
|
+
pass
|
|
86
|
+
|
|
87
|
+
# --------------------------------------------------------------------------
|
|
88
|
+
@staticmethod # noqa B027
|
|
89
|
+
def check_arguments(args: Namespace):
|
|
90
|
+
"""
|
|
91
|
+
Validate arguments.
|
|
92
|
+
|
|
93
|
+
:param args: The namespace containing the arguments.
|
|
94
|
+
:raise ValueError: If the arguments are invalid.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
pass
|
|
98
|
+
|
|
99
|
+
# --------------------------------------------------------------------------
|
|
100
|
+
@staticmethod
|
|
101
|
+
@abstractmethod
|
|
102
|
+
def execute(args: Namespace) -> None:
|
|
103
|
+
"""Execute the CLI command with the specified arguments."""
|
|
104
|
+
raise NotImplementedError('execute')
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# ------------------------------------------------------------------------------
|
|
108
|
+
def add_rendering_param_args(argp: ArgumentParser) -> None:
|
|
109
|
+
"""
|
|
110
|
+
Add the standard docma rendering CLI arguments to an argument parser.
|
|
111
|
+
|
|
112
|
+
Docma can have rendering parameters specified on the command line in a
|
|
113
|
+
number of ways:
|
|
114
|
+
* As name=value
|
|
115
|
+
* As name=file-containing-list
|
|
116
|
+
* As a JSON or YAML file containing values.
|
|
117
|
+
|
|
118
|
+
:param argp: Argument parser.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
renderp = argp.add_argument_group('rendering parameter options')
|
|
122
|
+
|
|
123
|
+
renderp.add_argument(
|
|
124
|
+
'-f',
|
|
125
|
+
'--file',
|
|
126
|
+
action='append',
|
|
127
|
+
metavar='FILE',
|
|
128
|
+
help=(
|
|
129
|
+
'Get rendering parameters from the specified file. File names with'
|
|
130
|
+
' a .json or .jsn suffix are assumed to be in JSON format, otherwise'
|
|
131
|
+
' YAML format is assumed. Any parameters specified by -p/--param'
|
|
132
|
+
' options or -l/--list options will override values in the param file.'
|
|
133
|
+
' Can be specified multiple times.'
|
|
134
|
+
),
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
renderp.add_argument(
|
|
138
|
+
'-l',
|
|
139
|
+
'--list',
|
|
140
|
+
action=StoreNameValuePair,
|
|
141
|
+
metavar='name=FILE',
|
|
142
|
+
help=(
|
|
143
|
+
'Get the values of a list rendering parameter from the specified file,'
|
|
144
|
+
' one value per line. Multiple list parameters can be specified using'
|
|
145
|
+
' multiple -l/--list arguments.'
|
|
146
|
+
),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
renderp.add_argument(
|
|
150
|
+
'-p',
|
|
151
|
+
'--param',
|
|
152
|
+
action=StoreNameValuePair,
|
|
153
|
+
metavar='name=VALUE',
|
|
154
|
+
help=(
|
|
155
|
+
'Set the value of a rendering parameter to be fed in to the document'
|
|
156
|
+
' generator. Multiple parameters can be specified using multiple'
|
|
157
|
+
' -p/--param arguments.'
|
|
158
|
+
),
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# ------------------------------------------------------------------------------
|
|
163
|
+
def marshal_rendering_params(args: Namespace) -> dict[str, Any]:
|
|
164
|
+
"""
|
|
165
|
+
Marshal rendering parameters provided on the command line.
|
|
166
|
+
|
|
167
|
+
:param args: The argparse arguments namespace from the CLI.
|
|
168
|
+
:return: Jinja rendering parameters.
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
render_params = {}
|
|
172
|
+
if args.file:
|
|
173
|
+
for paramfile in (Path(f) for f in args.file):
|
|
174
|
+
loader = json.loads if paramfile.suffix.lower() in ('.json', '.jsn') else yaml.safe_load
|
|
175
|
+
deep_update_dict(render_params, loader(paramfile.read_text()))
|
|
176
|
+
if args.param:
|
|
177
|
+
deep_update_dict(render_params, args.param)
|
|
178
|
+
if args.list:
|
|
179
|
+
for k, listfile in args.list.items():
|
|
180
|
+
if listfile == '-':
|
|
181
|
+
render_params[k] = [s.strip() for s in sys.stdin.readlines()]
|
|
182
|
+
continue
|
|
183
|
+
listpath = Path(listfile)
|
|
184
|
+
if listpath.suffix in ('.json', '.jsn', '.jsonl', '.jsnl'):
|
|
185
|
+
raise NotImplementedError('JSON List')
|
|
186
|
+
with open(listfile) as fp:
|
|
187
|
+
render_params[k] = [s.strip() for s in fp.readlines()]
|
|
188
|
+
|
|
189
|
+
return render_params
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""CLI commands."""
|
|
2
|
+
|
|
3
|
+
__author__ = 'Murray Andrews'
|
|
4
|
+
|
|
5
|
+
import pkgutil
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
|
|
8
|
+
from .__common__ import CliCommand as CliCommand
|
|
9
|
+
|
|
10
|
+
__all__ = ['CliCommand']
|
|
11
|
+
|
|
12
|
+
# Auto import our handler classes
|
|
13
|
+
for _, module_name, _ in pkgutil.iter_modules(__path__):
|
|
14
|
+
if module_name.startswith('_'):
|
|
15
|
+
continue
|
|
16
|
+
import_module(f'.{module_name}', package=__name__)
|