📦️ use pyproject.toml to build the package
This commit is contained in:
parent
d38c9efa53
commit
3fc983f28f
|
|
@ -0,0 +1 @@
|
|||
project_civiproxy_logs2json
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/civiproxy_logs2json.iml" filepath="$PROJECT_DIR$/.idea/civiproxy_logs2json.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/../project_civiproxy_logs2json/.idea/project_civiproxy_logs2json.iml" filepath="$PROJECT_DIR$/../project_civiproxy_logs2json/.idea/project_civiproxy_logs2json.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (project_civiproxy_logs2json)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyNamespacePackagesService">
|
||||
|
|
@ -0,0 +1 @@
|
|||
include src/civiproxy_logs2json/*.toml
|
||||
|
|
@ -1 +0,0 @@
|
|||
from .__main__ import main, translate_logfile
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=61.0.0", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "civiproxy_logs2json"
|
||||
version = "1.0.4"
|
||||
description = "Translate a CiviProxy logfile into JSON format."
|
||||
readme = "README.md"
|
||||
authors = [{ name = "Marc Michalsky", email = "michalsky@forumZFD.de" }]
|
||||
license = { file = "LICENSE" }
|
||||
classifiers = [
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
]
|
||||
keywords = ["civicrm", "json", "logs"]
|
||||
dependencies = ['tomli; python_version < "3.11"',]
|
||||
requires-python = ">=3.5"
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = ["pytest", "bumpver"]
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://github.com/MarcMichalsky/civiproxy_logs2json"
|
||||
|
||||
[project.scripts]
|
||||
cpl2j = "civiproxy_logs2json.__main__:main"
|
||||
|
||||
[tool.bumpver]
|
||||
current_version = "1.0.3"
|
||||
version_pattern = "MAJOR.MINOR.PATCH"
|
||||
commit_message = "🔖 bump version {old_version} -> {new_version}"
|
||||
commit = true
|
||||
tag = true
|
||||
push = true
|
||||
|
||||
[tool.bumpver.file_patterns]
|
||||
"pyproject.toml" = [
|
||||
'current_version = "{version}"',
|
||||
]
|
||||
"src/civiproxy_logs2json/__init__.py" = [
|
||||
"{version}"
|
||||
]
|
||||
|
||||
24
setup.py
24
setup.py
|
|
@ -1,23 +1,3 @@
|
|||
from setuptools import setup, find_packages
|
||||
from setuptools import setup
|
||||
|
||||
with open("README.md", "r") as fh:
|
||||
description = fh.read()
|
||||
|
||||
setup(
|
||||
name="civiproxy_logs2json",
|
||||
version="1.0.3",
|
||||
author="Marc Michalsky",
|
||||
author_email="michalsky@forumZFD.de",
|
||||
packages=find_packages("civiproxy_logs2json", exclude=["test"]),
|
||||
description="Translate a CiviProxy logfile into JSON format.",
|
||||
long_description=description,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/MarcMichalsky/civiproxy_logs2json",
|
||||
license='MIT',
|
||||
python_requires='>=3.5',
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'cpl2j = civiproxy_logs2json.__main__:main',
|
||||
],
|
||||
},
|
||||
)
|
||||
setup()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
from importlib import resources
|
||||
from .__main__ import main, translate_logfile
|
||||
try:
|
||||
import tomllib
|
||||
except ModuleNotFoundError:
|
||||
import tomli as tomllib
|
||||
|
||||
__version__ = "1.0.3"
|
||||
|
||||
_cfg = tomllib.loads(resources.read_text("civiproxy_logs2json", "config.toml"))
|
||||
REQUEST_LINE_RE = _cfg["regex"]["request_line"]
|
||||
VALUES_LINE_RE = _cfg["regex"]["values_line"]
|
||||
CLOSING_LINE_RE = _cfg["regex"]["closing_line"]
|
||||
|
|
@ -4,21 +4,18 @@ import re
|
|||
import sys
|
||||
from typing import TextIO
|
||||
|
||||
REQUEST_LINE_RE = r"^REQUEST FROM (?P<source>(\d{1,3}\.){3}\d{1,3}) ON (?P<date>\d\d\d\d-\d\d-\d\d) (?P<time>\d\d:\d\d:\d\d) -- Array$"
|
||||
VALUES_LINE_RE = r"^\s{4}\[(?P<key>.*)] => (?P<value>.*)$"
|
||||
CLOSING_LINE_RE = r"^\)$"
|
||||
|
||||
# Setup argparse
|
||||
argparser = argparse.ArgumentParser(
|
||||
description='Translate a CiviProxy logfile into JSON format. ')
|
||||
argparser.add_argument('-f',
|
||||
'--logfile',
|
||||
help='CiviProxy logfile',
|
||||
type=argparse.FileType('r', encoding='UTF-8'),
|
||||
description="Translate a CiviProxy logfile into JSON format. ")
|
||||
argparser.add_argument("-f",
|
||||
"--logfile",
|
||||
help="CiviProxy logfile",
|
||||
type=argparse.FileType("r", encoding="UTF-8"),
|
||||
default=(None if sys.stdin.isatty() else sys.stdin))
|
||||
argparser.add_argument('-i',
|
||||
'--indent',
|
||||
help='number of spaces to indent JSON output',
|
||||
argparser.add_argument("-i",
|
||||
"--indent",
|
||||
help="number of spaces to indent JSON output",
|
||||
type=int,
|
||||
default=4)
|
||||
|
||||
|
|
@ -28,7 +25,7 @@ def main():
|
|||
|
||||
# Print info if no logfile is specified or passed via stdin
|
||||
if not args.logfile:
|
||||
print('Please specify a path to a CiviProxy logfile')
|
||||
print("Please specify a path to a CiviProxy logfile")
|
||||
sys.exit()
|
||||
|
||||
# Parse logfile and print it to console
|
||||
|
|
@ -59,5 +56,5 @@ def translate_logfile(logfile: TextIO) -> list:
|
|||
return json_
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
[regex]
|
||||
request_line = "^REQUEST FROM (?P<source>(\\d{1,3}\\.){3}\\d{1,3}) ON (?P<date>\\d\\d\\d\\d-\\d\\d-\\d\\d) (?P<time>\\d\\d:\\d\\d:\\d\\d) -- Array$"
|
||||
values_line = "^\\s{4}\\[(?P<key>.*)] => (?P<value>.*)$"
|
||||
closing_line = "^\\)$"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
import json
|
||||
from civiproxy_logs2json import translate_logfile
|
||||
from src.civiproxy_logs2json import translate_logfile
|
||||
|
||||
|
||||
def test_translate_logfile():
|
||||
|
|
|
|||
Loading…
Reference in New Issue