muppy 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.
- muppy-1.0.0/.gitignore +164 -0
- muppy-1.0.0/CHANGELOG.md +6 -0
- muppy-1.0.0/LICENSE +9 -0
- muppy-1.0.0/PKG-INFO +129 -0
- muppy-1.0.0/README.md +108 -0
- muppy-1.0.0/logo.svg +4 -0
- muppy-1.0.0/pyproject.toml +32 -0
- muppy-1.0.0/src/muppy/__init__.py +0 -0
- muppy-1.0.0/src/muppy/main.py +139 -0
muppy-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# ---> Python
|
|
2
|
+
# Byte-compiled / optimized / DLL files
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
*$py.class
|
|
6
|
+
|
|
7
|
+
# C extensions
|
|
8
|
+
*.so
|
|
9
|
+
|
|
10
|
+
# Distribution / packaging
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
#Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# poetry
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
103
|
+
#poetry.lock
|
|
104
|
+
|
|
105
|
+
# pdm
|
|
106
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
107
|
+
#pdm.lock
|
|
108
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
109
|
+
# in version control.
|
|
110
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
111
|
+
.pdm.toml
|
|
112
|
+
.pdm-python
|
|
113
|
+
.pdm-build/
|
|
114
|
+
|
|
115
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
116
|
+
__pypackages__/
|
|
117
|
+
|
|
118
|
+
# Celery stuff
|
|
119
|
+
celerybeat-schedule
|
|
120
|
+
celerybeat.pid
|
|
121
|
+
|
|
122
|
+
# SageMath parsed files
|
|
123
|
+
*.sage.py
|
|
124
|
+
|
|
125
|
+
# Environments
|
|
126
|
+
.env
|
|
127
|
+
.venv
|
|
128
|
+
env/
|
|
129
|
+
venv/
|
|
130
|
+
ENV/
|
|
131
|
+
env.bak/
|
|
132
|
+
venv.bak/
|
|
133
|
+
|
|
134
|
+
# Spyder project settings
|
|
135
|
+
.spyderproject
|
|
136
|
+
.spyproject
|
|
137
|
+
|
|
138
|
+
# Rope project settings
|
|
139
|
+
.ropeproject
|
|
140
|
+
|
|
141
|
+
# mkdocs documentation
|
|
142
|
+
/site
|
|
143
|
+
|
|
144
|
+
# mypy
|
|
145
|
+
.mypy_cache/
|
|
146
|
+
.dmypy.json
|
|
147
|
+
dmypy.json
|
|
148
|
+
|
|
149
|
+
# Pyre type checker
|
|
150
|
+
.pyre/
|
|
151
|
+
|
|
152
|
+
# pytype static type analyzer
|
|
153
|
+
.pytype/
|
|
154
|
+
|
|
155
|
+
# Cython debug symbols
|
|
156
|
+
cython_debug/
|
|
157
|
+
|
|
158
|
+
# PyCharm
|
|
159
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
160
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
161
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
162
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
163
|
+
#.idea/
|
|
164
|
+
|
muppy-1.0.0/CHANGELOG.md
ADDED
muppy-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 desertear
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
muppy-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: muppy
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Markup Preprocessor for Python
|
|
5
|
+
Project-URL: Repository, https://codeberg.org/screwery/muppy
|
|
6
|
+
Project-URL: Issues, https://codeberg.org/screwery/muppy/issues
|
|
7
|
+
Project-URL: Changelog, https://codeberg.org/screwery/muppy/src/branch/main/CHANGELOG.md
|
|
8
|
+
Author-email: Ellie Viesná <snowboard_refinery@proton.me>
|
|
9
|
+
License: MIT License
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: c,markup,preprocessor,shell,tex,xml
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: argparse
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
## Description
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+

|
|
28
|
+

|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
**Muppy** means MarkUp Preprocessor for Python.
|
|
35
|
+
If you want some Python in markup, not some markup in Python—Muppy is probably the thing you need.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
**WARNING:** This script is using `exec()`. Be careful when you execute Muppy with a file you get from strangers, and keep in mind that it can be harmful as any other Python script.
|
|
40
|
+
Use Muppy script standalone from the git repo if you have reasons not to trust the wheel.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
The script is pure Python and a part of [PyPI](https://pypi.org/project/muppy), so can be installed via *pip*:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
python3 -m pip install muppy
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## So, what does it do, exactly?
|
|
51
|
+
|
|
52
|
+
Technically, Muppy gets comments in various formats and executes them as Python code.
|
|
53
|
+
Any text between comment blocks is treated as string literals.
|
|
54
|
+
|
|
55
|
+
### Basic HTML example
|
|
56
|
+
|
|
57
|
+
Contents of `test.html`. Mind Python indentation after `<!-- (py):`, placeholders `?????`, and empty lines `<!-- (py):-->`:
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<!-- (py):print(?????)-->
|
|
61
|
+
<html>
|
|
62
|
+
<head>
|
|
63
|
+
<title>
|
|
64
|
+
<!-- (py):if lang=="en":--><!-- (py): print(?????)-->Hello world!<!-- (py):-->
|
|
65
|
+
<!-- (py):if lang=="ru":--><!-- (py): print(?????)-->Привет, мир!<!-- (py):-->
|
|
66
|
+
<!-- (py):print(?????)-->
|
|
67
|
+
</title>
|
|
68
|
+
</head>
|
|
69
|
+
<body>
|
|
70
|
+
</body>
|
|
71
|
+
</html>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Shell command:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
muppy compile -s xml -i test.html -d 'lang="en"'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The preprocessor code to be executed:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
# string literals
|
|
84
|
+
MUPPY_657acc3e8ec943f4b25df555b97f6157 = ''
|
|
85
|
+
MUPPY_9dd9938c266b4cfb86ce9bccbfe33377 = '\n<html>\n\t<head>\n\t\t<title>\n\t\t\t'
|
|
86
|
+
MUPPY_b9df68b0daa54bbdb969b045b8996f14 = ''
|
|
87
|
+
MUPPY_8d278dc0965849c3a163a5427675b84a = 'Hello world!'
|
|
88
|
+
MUPPY_39639e4d3a5c4109a760b57bc8f1388e = '\n\t\t\t'
|
|
89
|
+
MUPPY_105fec3e43fa40c89d2cb39c6e5ee4cc = ''
|
|
90
|
+
MUPPY_e35ecf5319b8466f8c30ed50f48e96eb = 'Привет, мир!'
|
|
91
|
+
MUPPY_69b0bda88bba4562a765a73a6ba8caab = '\n'
|
|
92
|
+
MUPPY_918e6a4eb97149ff87eabad02d26c771 = '\n\t\t</title>\n\t</head>\n\t<body>\n\t</body>\n</html>\n'
|
|
93
|
+
|
|
94
|
+
# definitions
|
|
95
|
+
lang="en"
|
|
96
|
+
|
|
97
|
+
# your code
|
|
98
|
+
print(MUPPY_9dd9938c266b4cfb86ce9bccbfe33377)
|
|
99
|
+
if lang=="en":
|
|
100
|
+
print(MUPPY_8d278dc0965849c3a163a5427675b84a)
|
|
101
|
+
|
|
102
|
+
if lang=="ru":
|
|
103
|
+
print(MUPPY_e35ecf5319b8466f8c30ed50f48e96eb)
|
|
104
|
+
|
|
105
|
+
print(MUPPY_918e6a4eb97149ff87eabad02d26c771)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Comment styles
|
|
109
|
+
|
|
110
|
+
For now, Muppy supports the following comment styles (`-s`):
|
|
111
|
+
|
|
112
|
+
| Style | Start tag | End tag | Description |
|
|
113
|
+
|---------|--------------|---------|--------------------------------------|
|
|
114
|
+
| `xml` | `<!-- (py):` | `-->` | Any XML format: HTML, SVG, FB2, etc. |
|
|
115
|
+
| `c` | `/* (py):` | `*/` | C, C++, CSS, PHP, etc. |
|
|
116
|
+
| `tex` | `% (py):` | Newline | TeX-compatible markup |
|
|
117
|
+
| `shell` | `# (py):` | Newline | Bash, Python, etc. |
|
|
118
|
+
|
|
119
|
+
### Definitions
|
|
120
|
+
|
|
121
|
+
You can define (`-d`) any variables as you do in common Python code:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
muppy compile -s tex -i test.html -d 'var1 = 10' 'some_list = ["a", "b", "c"]'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Bugs
|
|
128
|
+
|
|
129
|
+
Feel free to report bugs and request features [here](https://codeberg.org/screwery/muppy/issues).
|
muppy-1.0.0/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
**Muppy** means MarkUp Preprocessor for Python.
|
|
14
|
+
If you want some Python in markup, not some markup in Python—Muppy is probably the thing you need.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
**WARNING:** This script is using `exec()`. Be careful when you execute Muppy with a file you get from strangers, and keep in mind that it can be harmful as any other Python script.
|
|
19
|
+
Use Muppy script standalone from the git repo if you have reasons not to trust the wheel.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
The script is pure Python and a part of [PyPI](https://pypi.org/project/muppy), so can be installed via *pip*:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python3 -m pip install muppy
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## So, what does it do, exactly?
|
|
30
|
+
|
|
31
|
+
Technically, Muppy gets comments in various formats and executes them as Python code.
|
|
32
|
+
Any text between comment blocks is treated as string literals.
|
|
33
|
+
|
|
34
|
+
### Basic HTML example
|
|
35
|
+
|
|
36
|
+
Contents of `test.html`. Mind Python indentation after `<!-- (py):`, placeholders `?????`, and empty lines `<!-- (py):-->`:
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<!-- (py):print(?????)-->
|
|
40
|
+
<html>
|
|
41
|
+
<head>
|
|
42
|
+
<title>
|
|
43
|
+
<!-- (py):if lang=="en":--><!-- (py): print(?????)-->Hello world!<!-- (py):-->
|
|
44
|
+
<!-- (py):if lang=="ru":--><!-- (py): print(?????)-->Привет, мир!<!-- (py):-->
|
|
45
|
+
<!-- (py):print(?????)-->
|
|
46
|
+
</title>
|
|
47
|
+
</head>
|
|
48
|
+
<body>
|
|
49
|
+
</body>
|
|
50
|
+
</html>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Shell command:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
muppy compile -s xml -i test.html -d 'lang="en"'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The preprocessor code to be executed:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
# string literals
|
|
63
|
+
MUPPY_657acc3e8ec943f4b25df555b97f6157 = ''
|
|
64
|
+
MUPPY_9dd9938c266b4cfb86ce9bccbfe33377 = '\n<html>\n\t<head>\n\t\t<title>\n\t\t\t'
|
|
65
|
+
MUPPY_b9df68b0daa54bbdb969b045b8996f14 = ''
|
|
66
|
+
MUPPY_8d278dc0965849c3a163a5427675b84a = 'Hello world!'
|
|
67
|
+
MUPPY_39639e4d3a5c4109a760b57bc8f1388e = '\n\t\t\t'
|
|
68
|
+
MUPPY_105fec3e43fa40c89d2cb39c6e5ee4cc = ''
|
|
69
|
+
MUPPY_e35ecf5319b8466f8c30ed50f48e96eb = 'Привет, мир!'
|
|
70
|
+
MUPPY_69b0bda88bba4562a765a73a6ba8caab = '\n'
|
|
71
|
+
MUPPY_918e6a4eb97149ff87eabad02d26c771 = '\n\t\t</title>\n\t</head>\n\t<body>\n\t</body>\n</html>\n'
|
|
72
|
+
|
|
73
|
+
# definitions
|
|
74
|
+
lang="en"
|
|
75
|
+
|
|
76
|
+
# your code
|
|
77
|
+
print(MUPPY_9dd9938c266b4cfb86ce9bccbfe33377)
|
|
78
|
+
if lang=="en":
|
|
79
|
+
print(MUPPY_8d278dc0965849c3a163a5427675b84a)
|
|
80
|
+
|
|
81
|
+
if lang=="ru":
|
|
82
|
+
print(MUPPY_e35ecf5319b8466f8c30ed50f48e96eb)
|
|
83
|
+
|
|
84
|
+
print(MUPPY_918e6a4eb97149ff87eabad02d26c771)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Comment styles
|
|
88
|
+
|
|
89
|
+
For now, Muppy supports the following comment styles (`-s`):
|
|
90
|
+
|
|
91
|
+
| Style | Start tag | End tag | Description |
|
|
92
|
+
|---------|--------------|---------|--------------------------------------|
|
|
93
|
+
| `xml` | `<!-- (py):` | `-->` | Any XML format: HTML, SVG, FB2, etc. |
|
|
94
|
+
| `c` | `/* (py):` | `*/` | C, C++, CSS, PHP, etc. |
|
|
95
|
+
| `tex` | `% (py):` | Newline | TeX-compatible markup |
|
|
96
|
+
| `shell` | `# (py):` | Newline | Bash, Python, etc. |
|
|
97
|
+
|
|
98
|
+
### Definitions
|
|
99
|
+
|
|
100
|
+
You can define (`-d`) any variables as you do in common Python code:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
muppy compile -s tex -i test.html -d 'var1 = 10' 'some_list = ["a", "b", "c"]'
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Bugs
|
|
107
|
+
|
|
108
|
+
Feel free to report bugs and request features [here](https://codeberg.org/screwery/muppy/issues).
|
muppy-1.0.0/logo.svg
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg width="111.16" height="112.38" viewBox="0 0 111.16 112.38" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path style="fill:#939dac;" d="m 85.63,28.65 v 11.90 c 0,9.23 -7.82,16.99 -16.75,17 h -26.78 c -7.33,0 -13.40,6.27 -13.40,13.62 v 25.53 c 0,7.26 6.31,11.54 13.40,13.62 8.48,2.49 16.62,2.94 26.78,0 6.75,-1.95 13.40,-5.88 13.40,-13.62 v -10.21 h -26.78 v -3.40 h 26.78 13.40 c 7.79,0 10.69,-5.43 13.40,-13.59 2.79,-8.39 2.68,-16.47 0,-27.25 -1.92,-7.75 -5.60,-13.59 -13.40,-13.59 z M 72.83,63.12 86.59,68.53 v 3.07 L 72.83,77.01 V 73.77 L 83.18,70.08 72.83,66.37 Z m -30.37,5.59 h 10.29 v 3.78 H 42.45 Z m 16.05,0 h 10.29 v 3.78 H 58.51 Z m 12.06,24.59 c 2.77,3e-6 5.03,2.27 5.03,5.09 -2e-6,2.82 -2.25,5.12 -5.03,5.12 -2.76,0 -5.03,-2.29 -5.03,-5.12 2e-6,-2.81 2.26,-5.09 5.03,-5.09 z" />
|
|
3
|
+
<path style="fill:#535d6c;" d="M 54.91,9.19e-4 C 50.33,0.02 45.95,0.41 42.10,1.09 30.76,3.09 28.70,7.29 28.70,15.03 v 10.21 h 26.81 v 3.40 h -23.03 v 6.10 l -0.88,7.5 h -1.80 l -1.01,-7.5 v -6.10 h -0.07 -10.06 c -7.79,0 -14.61,4.68 -16.75,13.59 -2.46,10.21 -2.57,16.58 0,27.25 1.90,7.93 6.45,13.59 14.25,13.59 h 9.21 v -12.25 c 0,-8.84 7.65,-16.65 16.75,-16.65 h 26.78 c 7.45,0 13.40,-6.13 13.40,-13.62 v -25.53 c 0,-7.26 -6.12,-12.72 -13.40,-13.93 C 64.28,0.32 59.50,-0.02 54.91,9.19e-4 Z m -14.5,8.21 c 2.76,0 5.03,2.29 5.03,5.12 -2e-6,2.81 -2.26,5.09 -5.03,5.09 -2.77,-1e-6 -5.03,-2.27 -5.03,-5.09 -10e-7,-2.82 2.25,-5.12 5.03,-5.12 z M 21.50,33.14 v 3.25 l -10.35,3.71 10.35,3.68 v 3.24 L 7.74,41.63 v -3.07 z m 20.95,5.59 h 10.29 v 3.78 H 42.45 Z m 16.05,0 h 10.29 v 3.78 H 58.51 Z m -27.82,5.85 c 0.64,0 1.17,0.22 1.60,0.66 0.42,0.42 0.63,1.00 0.63,1.73 0,0.18 -0.02,0.39 -0.06,0.63 -0.03,0.19 -0.10,0.38 -0.22,0.58 -0.05,0.09 -0.10,0.17 -0.14,0.23 -0.04,0.06 -0.11,0.14 -0.22,0.25 -0.22,0.23 -0.46,0.40 -0.72,0.50 -0.14,0.06 -0.29,0.11 -0.44,0.13 -0.14,0.02 -0.29,0.03 -0.44,0.03 -0.32,0 -0.63,-0.06 -0.91,-0.18 -0.26,-0.12 -0.50,-0.28 -0.70,-0.48 -0.43,-0.43 -0.65,-1.01 -0.65,-1.74 0,-0.70 0.21,-1.27 0.65,-1.70 0.09,-0.09 0.15,-0.15 0.18,-0.16 l 0.09,-0.09 c 0.09,-0.06 0.19,-0.12 0.29,-0.18 0.01,-0.00 0.06,-0.02 0.13,-0.05 0.07,-0.03 0.14,-0.06 0.19,-0.07 l 0.33,-0.07 c 0.13,-0.01 0.27,-0.02 0.40,-0.02 z" />
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [ "hatchling" ]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "muppy"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
authors = [ { name = "Ellie Viesná", email="snowboard_refinery@proton.me" } ]
|
|
9
|
+
description = "Markup Preprocessor for Python"
|
|
10
|
+
keywords = [ "markup", "preprocessor", "xml", "tex", "c", "shell" ]
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
license = { text = "MIT License" }
|
|
13
|
+
requires-python = ">= 3.11"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"argparse"
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Natural Language :: English",
|
|
22
|
+
"Development Status :: 4 - Beta",
|
|
23
|
+
"Environment :: Console"
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
muppy = "muppy.main:main"
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
"Repository" = "https://codeberg.org/screwery/muppy"
|
|
31
|
+
"Issues" = "https://codeberg.org/screwery/muppy/issues"
|
|
32
|
+
"Changelog" = "https://codeberg.org/screwery/muppy/src/branch/main/CHANGELOG.md"
|
|
File without changes
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Muppy means MarkUp Preprocessor for Python. If you want some Python in markup, not
|
|
3
|
+
some markup in Python---Muppy is probably the thing you need.
|
|
4
|
+
|
|
5
|
+
Details: https://pypi.org/project/muppy
|
|
6
|
+
Git repo: https://codeberg.org/screwery/muppy
|
|
7
|
+
'''
|
|
8
|
+
|
|
9
|
+
__version__ = '1.0.0'
|
|
10
|
+
__repository__ = 'https://codeberg.org/screwery/muppy'
|
|
11
|
+
__bugtracker__ = 'https://codeberg.org/screwery/muppy/issues'
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
import uuid
|
|
15
|
+
from argparse import ArgumentParser, RawDescriptionHelpFormatter #
|
|
16
|
+
|
|
17
|
+
def find_comment(code, index, style, position):
|
|
18
|
+
'''
|
|
19
|
+
Find a comment block in markup/code.
|
|
20
|
+
'''
|
|
21
|
+
result = None
|
|
22
|
+
if style == 'xml':
|
|
23
|
+
if position == 'start':
|
|
24
|
+
result = code.find('<!-- (py):', index), 10
|
|
25
|
+
if position == 'end':
|
|
26
|
+
result = code.find('-->', index), 3
|
|
27
|
+
if style == 'c':
|
|
28
|
+
if position == 'start':
|
|
29
|
+
result = code.find('/* (py):', index), 8
|
|
30
|
+
if position == 'end':
|
|
31
|
+
result = code.find('*/', index), 2
|
|
32
|
+
if style == 'shell':
|
|
33
|
+
if position == 'start':
|
|
34
|
+
result = code.find('# (py):', index), 7
|
|
35
|
+
if position == 'end':
|
|
36
|
+
result = code.find('\n', index), 1
|
|
37
|
+
if style == 'tex':
|
|
38
|
+
if position == 'start':
|
|
39
|
+
result = code.find('% (py):', index), 7
|
|
40
|
+
if position == 'end':
|
|
41
|
+
result = code.find('\n', index), 1
|
|
42
|
+
return result
|
|
43
|
+
|
|
44
|
+
def preprocessor_compile(code, style, placeholder, definitions):
|
|
45
|
+
'''
|
|
46
|
+
Compile preprocessor Python code.
|
|
47
|
+
'''
|
|
48
|
+
intervals = []
|
|
49
|
+
index = 0
|
|
50
|
+
current_uuid = uuid.uuid4().hex
|
|
51
|
+
while True:
|
|
52
|
+
new_start, tag_len = find_comment(code, index, style, 'start')
|
|
53
|
+
if new_start != -1:
|
|
54
|
+
intervals.append({
|
|
55
|
+
'type': 'literal',
|
|
56
|
+
'content': code[index:new_start],
|
|
57
|
+
'tag': current_uuid
|
|
58
|
+
})
|
|
59
|
+
index = new_start + tag_len
|
|
60
|
+
else:
|
|
61
|
+
intervals.append({
|
|
62
|
+
'type': 'literal',
|
|
63
|
+
'content': code[index:len(code)],
|
|
64
|
+
'tag': current_uuid
|
|
65
|
+
})
|
|
66
|
+
break
|
|
67
|
+
new_end, tag_len = find_comment(code, index, style, 'end')
|
|
68
|
+
if new_end != -1:
|
|
69
|
+
current_uuid = uuid.uuid4().hex
|
|
70
|
+
intervals.append({
|
|
71
|
+
'type': 'instruction',
|
|
72
|
+
'content': code[index:new_end],
|
|
73
|
+
'tag': current_uuid
|
|
74
|
+
})
|
|
75
|
+
index = new_end + tag_len
|
|
76
|
+
else:
|
|
77
|
+
raise RuntimeError(f'Endless comment at position {index}')
|
|
78
|
+
literals, instructions = '', ''
|
|
79
|
+
for item in definitions:
|
|
80
|
+
instructions += f'{item}\n'
|
|
81
|
+
for item in intervals:
|
|
82
|
+
if item['type'] == 'instruction':
|
|
83
|
+
instructions += item['content'].replace(
|
|
84
|
+
placeholder, f'MUPPY_{item["tag"]}'
|
|
85
|
+
) + '\n'
|
|
86
|
+
else:
|
|
87
|
+
literals += f'MUPPY_{item["tag"]} = {repr(item["content"])}\n'
|
|
88
|
+
return literals + instructions
|
|
89
|
+
|
|
90
|
+
def create_parser():
|
|
91
|
+
'''
|
|
92
|
+
Create CLI arguments parser
|
|
93
|
+
'''
|
|
94
|
+
default_parser = ArgumentParser(
|
|
95
|
+
formatter_class=RawDescriptionHelpFormatter,
|
|
96
|
+
description=f'muppy {__version__}: Markup Preprocessor for Python',
|
|
97
|
+
epilog=f'Bug tracker: {__bugtracker__}'
|
|
98
|
+
)
|
|
99
|
+
default_parser.add_argument('-v', '--version', action='version',
|
|
100
|
+
version=__version__)
|
|
101
|
+
subparsers = default_parser.add_subparsers(title='Commands', dest='command')
|
|
102
|
+
# Compile parser
|
|
103
|
+
compile_p = subparsers.add_parser('compile', help='compile and execute muppy file')
|
|
104
|
+
compile_p.add_argument('-d', '--def', type=str, nargs='*', dest='definitions',
|
|
105
|
+
help='Definitions (formatted as Python instructions)')
|
|
106
|
+
compile_p.add_argument('-i', '--input', required=True, type=str,
|
|
107
|
+
dest='input_file', help='Input file path (REQUIRED)')
|
|
108
|
+
compile_p.add_argument('-s', '--style', required=True, choices=['xml', 'c', 'shell', 'tex'],
|
|
109
|
+
dest='style', help='Comment style (REQUIRED)')
|
|
110
|
+
compile_p.add_argument('-p', '--placeholder', type=str, default='?????',
|
|
111
|
+
dest='placeholder', help='Literal placeholder (default: "?????")')
|
|
112
|
+
compile_p.add_argument('-c', '--code', type=str, default='',
|
|
113
|
+
dest='code_file',
|
|
114
|
+
help='Save preprocessor Python code in specified file (DEFAULT: none)')
|
|
115
|
+
compile_p.add_argument('-n', '--noexec', action='store_true',
|
|
116
|
+
dest='no_exec', help='Do not execute preprocessor (DEFAULT: false)')
|
|
117
|
+
return default_parser
|
|
118
|
+
|
|
119
|
+
def main():
|
|
120
|
+
'''
|
|
121
|
+
Main function (entrypoint)
|
|
122
|
+
'''
|
|
123
|
+
parser = create_parser()
|
|
124
|
+
nmsp = parser.parse_args(sys.argv[1:])
|
|
125
|
+
if nmsp.command == 'compile':
|
|
126
|
+
with open(nmsp.input_file, 'rt', encoding='utf-8') as stream:
|
|
127
|
+
code = stream.read()
|
|
128
|
+
ppcode = preprocessor_compile(code, nmsp.style, nmsp.placeholder,
|
|
129
|
+
nmsp.definitions)
|
|
130
|
+
if nmsp.code_file:
|
|
131
|
+
with open(nmsp.code_file, 'wt', encoding='utf-8') as stream:
|
|
132
|
+
stream.write(ppcode)
|
|
133
|
+
if not nmsp.no_exec:
|
|
134
|
+
exec(ppcode)
|
|
135
|
+
else:
|
|
136
|
+
parser.print_help()
|
|
137
|
+
|
|
138
|
+
if __name__ == '__main__':
|
|
139
|
+
main()
|