tgedr-pycommons 0.0.2__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.
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: tgedr-pycommons
3
+ Version: 0.0.2
4
+ Summary: common python code usable across projects
5
+ Author-email: joao tiago viegas <3536754+jtviegas@users.noreply.github.com>
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: pandas>=2.3.0
9
+
10
+ # tgedr-pycommons
11
+
12
+ ![Coverage](./coverage.svg)
13
+
14
+ Common code to be used across projects
15
+
16
+
17
+ ## development
18
+ - main requirements:
19
+ - _uv_
20
+ - _bash_
21
+ - Clone the repository like this:
22
+
23
+ ``` bash
24
+ git clone git@github.com:tgedr/pycommons
25
+ ```
26
+ - cd into the folder: `cd pycommons`
27
+ - install requirements: `./helper.sh reqs`
@@ -0,0 +1,18 @@
1
+ # tgedr-pycommons
2
+
3
+ ![Coverage](./coverage.svg)
4
+
5
+ Common code to be used across projects
6
+
7
+
8
+ ## development
9
+ - main requirements:
10
+ - _uv_
11
+ - _bash_
12
+ - Clone the repository like this:
13
+
14
+ ``` bash
15
+ git clone git@github.com:tgedr/pycommons
16
+ ```
17
+ - cd into the folder: `cd pycommons`
18
+ - install requirements: `./helper.sh reqs`
@@ -0,0 +1,131 @@
1
+ [project]
2
+ name = "tgedr-pycommons"
3
+ version = "0.0.2"
4
+ description = "common python code usable across projects"
5
+ authors = [
6
+ {name = "joao tiago viegas",email = "3536754+jtviegas@users.noreply.github.com"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.11"
10
+
11
+ dependencies = [
12
+ "pandas>=2.3.0",
13
+ ]
14
+
15
+ [dependency-groups]
16
+ dev = [
17
+ "pre-commit~=4.2.0",
18
+ "pytest~=8.3.5",
19
+ "pytest-bdd~=8.1.0",
20
+ "pytest-cov~=4.1.0",
21
+ "pytest-mock~=3.15.0",
22
+ "ruff==0.9.10",
23
+ "bandit==1.8.3",
24
+ "safety==3.5.1",
25
+ "typer<0.17.0",
26
+ "genbadge[coverage]>=1.1.3",
27
+ ]
28
+
29
+
30
+ # [project.scripts]
31
+ # run = "ssds_pycommons.pip_entrypoint:entrypoint"
32
+
33
+ [build-system]
34
+ requires = ["setuptools>=78.1.0", "wheel>=0.45.1"]
35
+ build-backend = "setuptools.build_meta"
36
+
37
+ [tool.setuptools.packages.find]
38
+ where = ["src"]
39
+
40
+ [tool.setuptools]
41
+ include-package-data = true
42
+
43
+ [tool.setuptools.package-data]
44
+ "*" = ["CHANGELOG"]
45
+
46
+ [tool.coverage.paths]
47
+ source = ["src/"]
48
+
49
+ [tool.coverage.run]
50
+ source = ["src/"]
51
+ include = ["src/*"]
52
+ omit = [
53
+ "*/tests/*",
54
+ "*/test_*",
55
+ "*/__pycache__/*",
56
+ "*/migrations/*",
57
+ "*/venv/*",
58
+ "*/.venv/*"
59
+ ]
60
+
61
+ [tool.coverage.report]
62
+ exclude_lines = [
63
+ "pragma: no cover",
64
+ "def __repr__",
65
+ "raise AssertionError",
66
+ "raise NotImplementedError",
67
+ "if __name__ == .__main__.:",
68
+ "if TYPE_CHECKING:",
69
+ ]
70
+ show_missing = true
71
+ skip_covered = false
72
+ skip_empty = false
73
+
74
+ [tool.pytest.ini_options]
75
+ # bdd_features_base_dir = "documentation/features"
76
+ pythonpath = "."
77
+
78
+ [tool.ruff]
79
+ exclude = [
80
+ ".bzr",
81
+ ".direnv",
82
+ ".eggs",
83
+ ".git",
84
+ ".git-rewrite",
85
+ ".hg",
86
+ ".ipynb_checkpoints",
87
+ ".mypy_cache",
88
+ ".nox",
89
+ ".pants.d",
90
+ ".pyenv",
91
+ ".pytest_cache",
92
+ ".pytype",
93
+ ".ruff_cache",
94
+ ".svn",
95
+ ".tox",
96
+ ".venv",
97
+ ".vscode",
98
+ "__pypackages__",
99
+ "_build",
100
+ "buck-out",
101
+ "build",
102
+ "dist",
103
+ "node_modules",
104
+ "site-packages",
105
+ "venv",
106
+ "tests/",
107
+ "typings/"
108
+ ]
109
+
110
+ line-length = 120
111
+ indent-width = 4
112
+
113
+ [tool.ruff.lint]
114
+ select = ["ALL"]
115
+ ignore = ["D203", "S101", "D104", "INP001", "D213", "COM812", "I001",
116
+ "D401", "D407", "RET504", "PLR2004", "FA102", "E501", "EXE002", "PLR0913",
117
+ "PLR0912", "C901", "PLR0911", "ANN401"]
118
+ fixable = ["ALL"]
119
+ unfixable = []
120
+ # Allow unused variables when underscore-prefixed.
121
+ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
122
+
123
+ [tool.ruff.format]
124
+ # Like Black, use double quotes for strings.
125
+ quote-style = "double"
126
+ # Like Black, indent with spaces, rather than tabs.
127
+ indent-style = "space"
128
+ # Like Black, respect magic trailing commas.
129
+ skip-magic-trailing-comma = false
130
+ # Like Black, automatically detect the appropriate line ending.
131
+ line-ending = "auto"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,100 @@
1
+ """Module for executing Python callables based on command line arguments.
2
+
3
+ This module provides utilities to:
4
+ - Parse command line arguments for callable execution
5
+ - Resolve callables (functions or class methods) from module paths
6
+ - Execute the resolved callable with provided parameters
7
+ """
8
+
9
+ import argparse
10
+ from collections.abc import Sequence
11
+ from argparse import Namespace
12
+ import json
13
+ import logging
14
+ from importlib import import_module
15
+ from typing import Any
16
+
17
+
18
+ root_logger = logging.getLogger()
19
+ root_logger.setLevel(logging.INFO)
20
+ stream_handler = logging.StreamHandler()
21
+ stream_handler.setLevel(logging.INFO)
22
+ formatter = logging.Formatter("[%(asctime)s] [%(name)s] [%(levelname)s] => %(message)s")
23
+ stream_handler.setFormatter(formatter)
24
+ root_logger.addHandler(stream_handler)
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ def parse_arguments(explicit_args: Sequence[str] | None = None) -> Namespace:
30
+ """Parse command line arguments for the python callable execution.
31
+
32
+ Args:
33
+ explicit_args: A sequence of command line arguments
34
+ Returns:
35
+ Namespace: The parsed command line arguments
36
+
37
+ """
38
+ parser = argparse.ArgumentParser(description="Get the parameters for the python callable to execute.")
39
+ parser.add_argument("--module", type=str, help="The module where to find the callable")
40
+ parser.add_argument("--callable", type=str, help="The callable (function or class function)")
41
+ parser.add_argument(
42
+ "--classname", required=False, type=str, help="If the callable is a class function, specify the class name"
43
+ )
44
+ parser.add_argument(
45
+ "--classparams",
46
+ required=False,
47
+ type=str,
48
+ help="If the callable is a class function, specify the class constructor parameters (as a JSON string)",
49
+ )
50
+ parser.add_argument("--params", type=str, help="The parameters for the callable (as a JSON string)")
51
+ args = parser.parse_args(explicit_args)
52
+ return args
53
+
54
+
55
+ def resolve_callable(arguments: Namespace) -> Any:
56
+ """Resolve the callable from the parsed arguments.
57
+
58
+ Args:
59
+ arguments (Namespace): The parsed command line arguments
60
+ Returns:
61
+ Any: The resolved callable (function or class method)
62
+
63
+ """
64
+ result = None
65
+
66
+ if arguments.classname:
67
+ _class = getattr(import_module(arguments.module), arguments.classname)
68
+ class_instance = None
69
+ if arguments.classparams:
70
+ class_params: dict = json.loads(arguments.classparams)
71
+ class_instance = _class(**class_params)
72
+ else:
73
+ class_instance = _class()
74
+ result = getattr(class_instance, arguments.callable)
75
+ else:
76
+ result = getattr(import_module(arguments.module), arguments.callable)
77
+
78
+ return result
79
+
80
+
81
+ def entrypoint(explicit_args: Sequence[str] | None = None) -> Any:
82
+ """Execute a python callable based on command line arguments.
83
+
84
+ Args:
85
+ explicit_args: A sequence of command line arguments
86
+ Returns:
87
+ Any: The result of the executed callable
88
+
89
+ """
90
+ args: Namespace = parse_arguments(explicit_args)
91
+ call = resolve_callable(args)
92
+ if args.params:
93
+ params: dict = json.loads(args.params)
94
+ result: Any = call(**params)
95
+ else:
96
+ result: Any = call()
97
+ # Print result to stdout for shell capture
98
+ if result is not None:
99
+ print(result) # noqa: T201
100
+ return result
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: tgedr-pycommons
3
+ Version: 0.0.2
4
+ Summary: common python code usable across projects
5
+ Author-email: joao tiago viegas <3536754+jtviegas@users.noreply.github.com>
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: pandas>=2.3.0
9
+
10
+ # tgedr-pycommons
11
+
12
+ ![Coverage](./coverage.svg)
13
+
14
+ Common code to be used across projects
15
+
16
+
17
+ ## development
18
+ - main requirements:
19
+ - _uv_
20
+ - _bash_
21
+ - Clone the repository like this:
22
+
23
+ ``` bash
24
+ git clone git@github.com:tgedr/pycommons
25
+ ```
26
+ - cd into the folder: `cd pycommons`
27
+ - install requirements: `./helper.sh reqs`
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/tgedr/__init__.py
4
+ src/tgedr/pycommons/entrypoint.py
5
+ src/tgedr_pycommons.egg-info/PKG-INFO
6
+ src/tgedr_pycommons.egg-info/SOURCES.txt
7
+ src/tgedr_pycommons.egg-info/dependency_links.txt
8
+ src/tgedr_pycommons.egg-info/requires.txt
9
+ src/tgedr_pycommons.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ pandas>=2.3.0