Skip to content

Commit c862e10

Browse files
author
Sven Siegmund
committed
create pyproject and new entrypoint
1 parent 36565fa commit c862e10

File tree

7 files changed

+266
-94
lines changed

7 files changed

+266
-94
lines changed

LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2023 Sven Siegmud
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% if sections[""] %}
2+
{% for category, val in definitions.items() if category in sections[""] %}
3+
4+
### {{ definitions[category]['name'] }}
5+
6+
{% for text, values in sections[""][category].items() %}
7+
- {{ text }} {{ values|join(', ') }}
8+
{% endfor %}
9+
10+
{% endfor %}
11+
{% else %}
12+
No significant changes.
13+
14+
15+
{% endif %}

pyproject.toml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
[build-system]
2+
requires = [
3+
"hatchling",
4+
"hatch-semver"
5+
]
6+
build-backend = "hatchling.build"
7+
8+
[project]
9+
name = "rtfparse"
10+
description = "Tool to parse Microsoft Rich Text Format (RTF)"
11+
readme = "README.md"
12+
requires-python = ">=3.10"
13+
authors = [
14+
{ name = "Sven Siegmund", email = "[email protected]" },
15+
]
16+
classifiers = [
17+
#"Development Status :: 3 - Alpha",
18+
#"Development Status :: 4 - Beta",
19+
"Development Status :: 5 - Production/Stable",
20+
"Intended Audience :: Developers",
21+
"Environment :: Console",
22+
"Topic :: Software Development :: Testing",
23+
"Topic :: Utilities",
24+
"Natural Language :: English",
25+
"Programming Language :: Python :: 3.10",
26+
"Programming Language :: Python :: 3.11",
27+
"Operating System :: OS Independent",
28+
"Operating System :: Microsoft :: Windows",
29+
"Operating System :: POSIX :: Linux",
30+
"Operating System :: MacOS :: MacOS X",
31+
]
32+
keywords = [
33+
"rtf",
34+
"parse",
35+
]
36+
dependencies = [
37+
"argcomplete",
38+
"extract-msg",
39+
"compressed_rtf",
40+
"provide_dir",
41+
]
42+
dynamic = ["version"]
43+
44+
[project.license]
45+
file = "LICENSE.txt"
46+
47+
[project.urls]
48+
Documentation = "https://github.com/fleetingbytes/rtfparse#readme"
49+
Issues = "https://github.com/fleetingbytes/rtfparse/issues"
50+
Source = "https://github.com/fleetingbytes/rtfparse"
51+
52+
[project.scripts]
53+
rtfparse = "rtfparse:main"
54+
55+
[tool.hatch.version]
56+
path = "src/rtfparse/__about__.py"
57+
validate-bump = true
58+
scheme = "semver"
59+
60+
[tool.hatch.envs.default]
61+
dependencies = [
62+
"pytest-cov",
63+
]
64+
[tool.hatch.envs.default.scripts]
65+
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/rtfparse --cov=tests {args}"
66+
no-cov = "cov --no-cov {args}"
67+
68+
[tool.hatch.envs.style]
69+
dependencies = [
70+
"black",
71+
"isort",
72+
]
73+
74+
[tool.hatch.envs.style.scripts]
75+
fmt = [
76+
"isort .",
77+
"black .",
78+
]
79+
80+
[tool.hatch.envs.tc]
81+
dependencies = [
82+
"towncrier",
83+
]
84+
85+
[tool.hatch.envs.tc.scripts]
86+
draft = "towncrier build --draft"
87+
build = "towncrier build --yes"
88+
89+
[tool.hatch.envs.docs]
90+
dependencies = [
91+
"pdoc3"
92+
]
93+
94+
[[tool.hatch.envs.test.matrix]]
95+
python = ["311"]
96+
97+
[tool.coverage.run]
98+
branch = true
99+
parallel = true
100+
omit = [
101+
#"src/rtfparse/__about__.py",
102+
]
103+
104+
[tool.coverage.report]
105+
exclude_lines = [
106+
"no cov",
107+
"if __name__ == .__main__.:",
108+
"if TYPE_CHECKING:",
109+
]
110+
111+
[tool.black]
112+
line-length = 102
113+
114+
[tool.isort]
115+
line_length = 102
116+
117+
[tool.towncrier]
118+
name = "rtfparse"
119+
package = "rtfparse"
120+
package_dir = "src"
121+
directory = "changelog.d"
122+
filename = "CHANGELOG.md"
123+
start_string = "<!-- towncrier release notes start -->\n"
124+
underlines = ["", "", ""]
125+
template = "changelog.d/changelog_template.jinja"
126+
#title_format = "## [{version}](https://github.com/fleetingbytes/rtfparse/{version}) - {project_date}"
127+
title_format = "## {version} ({project_date})"
128+
issue_format = "[#{issue}](https://github.com/fleetingbytes/rtfparse/issues/{issue})"
129+
orphan_prefix = "+"
130+
131+
[tool.towncrier.fragment.doc]
132+
name = "Documentation"
133+
134+
[tool.towncrier.fragment.feature]
135+
name = "New Features"
136+
137+
[tool.towncrier.fragment.improved]
138+
name = "Improvements"
139+
140+
[tool.towncrier.fragment.fixed]
141+
name = "Bugfixes"
142+
143+
[tool.towncrier.fragment.unimportant]
144+
name = "Development Details"

setup.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/rtfparse/__about__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
3+
4+
__version__ = "0.8.0-rc1"

src/rtfparse/__init__.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
#!/usr/bin/env python
22

33

4-
"""
5-
Parser of Microsoft RTF Format
6-
"""
7-
8-
9-
from rtfparse import version
10-
11-
12-
__author__ = "Sven Siegmund"
13-
__author_email__ = "[email protected]"
14-
__date__ = "2020-01-05"
15-
__version__ = version.version
16-
4+
from rtfparse.cli import main
175

6+
# Towncrier needs version
7+
from rtfparse.__about__ import __version__
188

9+
if __name__ == "__main__":
10+
main()

src/rtfparse/cli.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
import logging.config
5+
from pathlib import Path
6+
from provide_dir import provide_dir
7+
from rtfparse import logging_conf
8+
9+
10+
def setup_logger(directory: Path) -> logging.Logger:
11+
"""
12+
Returns a logger and a path to directory where the logs are saved
13+
"""
14+
try:
15+
provide_dir(directory)
16+
logger_config = logging_conf.create_dict_config(
17+
directory, "debug.log", "info.log", "errors.log"
18+
)
19+
except FileExistsError:
20+
logger.error(
21+
f"Failed to create the directory `{str(directory)}` because it already exists as a file."
22+
)
23+
logger.error(f"Please create the directory `{str(directory)}`")
24+
finally:
25+
logging.config.dictConfig(logger_config)
26+
logger = logging.getLogger(__name__)
27+
return logger
28+
29+
30+
logger = setup_logger(Path.home() / "rtfparse")
31+
32+
33+
def argument_parser() -> argparse.ArgumentParser:
34+
"""
35+
Creates an argument parser for command line arguments
36+
"""
37+
parser = argparse.ArgumentParser(description="RTF parser")
38+
parser.add_argument(
39+
"-v", "--version", action="store_true", help="print out rtfparse version and exit"
40+
)
41+
parser.add_argument("--autoconfig", action="store_true", help="Configure rtfparse automatically")
42+
parser.add_argument(
43+
"-f", "--file", action="store", metavar="PATH", type=Path, help="path to the rtf file"
44+
)
45+
parser.add_argument(
46+
"-m",
47+
"--msg",
48+
action="store",
49+
metavar="PATH",
50+
type=Path,
51+
help="Parse RTF from MS Outlook's .msg file",
52+
)
53+
parser.add_argument(
54+
"-d", "--de-encapsulate-html", action="store_true", help="De-encapsulate HTML from RTF"
55+
)
56+
parser.add_argument(
57+
"-i", "--embed-img", action="store_true", help="Embed images from email to HTML"
58+
)
59+
return parser
60+
61+
62+
def run(cli_args: argparse.Namespace) -> None:
63+
logger.info("Program runs")
64+
65+
66+
def main(version) -> None:
67+
"""
68+
Entry point for any component start from the commmand line
69+
"""
70+
logger.debug(f"{utils.program_name} started")
71+
parser = argument_parser()
72+
argcomplete.autocomplete(parser)
73+
cli_args = parser.parse_args()
74+
logger.debug(f"Parsed arguments: {cli_args}")
75+
try:
76+
run(cli_args)
77+
except Exception as err:
78+
logger.exception(f"Uncaught exception {repr(err)} occurred.")
79+
logger.debug(f"{utils.program_name} ended")

0 commit comments

Comments
 (0)