winipedia-utils 0.1.62__py3-none-any.whl → 0.2.0__py3-none-any.whl
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.
Potentially problematic release.
This version of winipedia-utils might be problematic. Click here for more details.
- winipedia_utils/concurrent/concurrent.py +245 -242
- winipedia_utils/concurrent/multiprocessing.py +130 -115
- winipedia_utils/concurrent/multithreading.py +93 -93
- winipedia_utils/consts.py +23 -23
- winipedia_utils/data/__init__.py +1 -1
- winipedia_utils/data/dataframe/__init__.py +1 -0
- winipedia_utils/data/dataframe/cleaning.py +378 -0
- winipedia_utils/data/structures/__init__.py +1 -0
- winipedia_utils/data/structures/dicts.py +16 -0
- winipedia_utils/django/__init__.py +24 -24
- winipedia_utils/django/bulk.py +538 -538
- winipedia_utils/django/command.py +334 -334
- winipedia_utils/django/database.py +289 -289
- winipedia_utils/git/__init__.py +1 -1
- winipedia_utils/git/gitignore/__init__.py +1 -1
- winipedia_utils/git/gitignore/gitignore.py +136 -136
- winipedia_utils/git/pre_commit/__init__.py +1 -1
- winipedia_utils/git/pre_commit/config.py +70 -70
- winipedia_utils/git/pre_commit/hooks.py +109 -109
- winipedia_utils/git/pre_commit/run_hooks.py +49 -49
- winipedia_utils/iterating/__init__.py +1 -1
- winipedia_utils/iterating/iterate.py +29 -29
- winipedia_utils/logging/ansi.py +6 -6
- winipedia_utils/logging/config.py +64 -64
- winipedia_utils/logging/logger.py +26 -26
- winipedia_utils/modules/class_.py +119 -119
- winipedia_utils/modules/function.py +101 -103
- winipedia_utils/modules/module.py +379 -379
- winipedia_utils/modules/package.py +390 -390
- winipedia_utils/oop/mixins/meta.py +333 -331
- winipedia_utils/oop/mixins/mixin.py +37 -37
- winipedia_utils/os/__init__.py +1 -1
- winipedia_utils/os/os.py +63 -63
- winipedia_utils/projects/__init__.py +1 -1
- winipedia_utils/projects/poetry/__init__.py +1 -1
- winipedia_utils/projects/poetry/config.py +91 -91
- winipedia_utils/projects/poetry/poetry.py +31 -31
- winipedia_utils/projects/project.py +48 -48
- winipedia_utils/pyside/__init__.py +1 -1
- winipedia_utils/pyside/core/__init__.py +1 -1
- winipedia_utils/pyside/core/py_qiodevice.py +476 -476
- winipedia_utils/pyside/ui/__init__.py +1 -1
- winipedia_utils/pyside/ui/base/__init__.py +1 -1
- winipedia_utils/pyside/ui/base/base.py +180 -180
- winipedia_utils/pyside/ui/pages/__init__.py +1 -1
- winipedia_utils/pyside/ui/pages/base/__init__.py +1 -1
- winipedia_utils/pyside/ui/pages/base/base.py +92 -92
- winipedia_utils/pyside/ui/pages/browser.py +26 -26
- winipedia_utils/pyside/ui/pages/player.py +85 -85
- winipedia_utils/pyside/ui/widgets/__init__.py +1 -1
- winipedia_utils/pyside/ui/widgets/browser.py +243 -243
- winipedia_utils/pyside/ui/widgets/clickable_widget.py +57 -57
- winipedia_utils/pyside/ui/widgets/media_player.py +430 -423
- winipedia_utils/pyside/ui/widgets/notification.py +78 -78
- winipedia_utils/pyside/ui/windows/__init__.py +1 -1
- winipedia_utils/pyside/ui/windows/base/__init__.py +1 -1
- winipedia_utils/pyside/ui/windows/base/base.py +49 -49
- winipedia_utils/resources/__init__.py +1 -1
- winipedia_utils/resources/svgs/__init__.py +1 -1
- winipedia_utils/resources/svgs/download_arrow.svg +2 -2
- winipedia_utils/resources/svgs/exit_fullscreen_icon.svg +5 -5
- winipedia_utils/resources/svgs/fullscreen_icon.svg +2 -2
- winipedia_utils/resources/svgs/menu_icon.svg +3 -3
- winipedia_utils/resources/svgs/pause_icon.svg +3 -3
- winipedia_utils/resources/svgs/play_icon.svg +16 -16
- winipedia_utils/resources/svgs/plus_icon.svg +23 -23
- winipedia_utils/resources/svgs/svg.py +15 -15
- winipedia_utils/security/__init__.py +1 -1
- winipedia_utils/security/cryptography.py +29 -29
- winipedia_utils/security/keyring.py +70 -70
- winipedia_utils/setup.py +47 -47
- winipedia_utils/testing/assertions.py +23 -23
- winipedia_utils/testing/convention.py +177 -177
- winipedia_utils/testing/create_tests.py +291 -291
- winipedia_utils/testing/fixtures.py +28 -28
- winipedia_utils/testing/tests/base/fixtures/__init__.py +1 -1
- winipedia_utils/testing/tests/base/fixtures/fixture.py +6 -6
- winipedia_utils/testing/tests/base/fixtures/scopes/class_.py +33 -33
- winipedia_utils/testing/tests/base/fixtures/scopes/function.py +7 -7
- winipedia_utils/testing/tests/base/fixtures/scopes/module.py +31 -31
- winipedia_utils/testing/tests/base/fixtures/scopes/package.py +7 -7
- winipedia_utils/testing/tests/base/fixtures/scopes/session.py +312 -312
- winipedia_utils/testing/tests/base/utils/utils.py +82 -82
- winipedia_utils/testing/tests/conftest.py +32 -32
- winipedia_utils/text/string.py +126 -126
- {winipedia_utils-0.1.62.dist-info → winipedia_utils-0.2.0.dist-info}/METADATA +5 -4
- winipedia_utils-0.2.0.dist-info/RECORD +103 -0
- {winipedia_utils-0.1.62.dist-info → winipedia_utils-0.2.0.dist-info}/WHEEL +1 -1
- {winipedia_utils-0.1.62.dist-info → winipedia_utils-0.2.0.dist-info/licenses}/LICENSE +21 -21
- winipedia_utils/data/dataframe.py +0 -7
- winipedia_utils-0.1.62.dist-info/RECORD +0 -100
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
"""Mixin utilities for class composition and behavior extension.
|
|
2
|
-
|
|
3
|
-
This module provides metaclasses and mixins that facilitate class composition
|
|
4
|
-
through the mixin pattern. It includes utilities for:
|
|
5
|
-
- Automatic method logging with performance tracking
|
|
6
|
-
- Abstract class implementation enforcement with type checking
|
|
7
|
-
- Combined metaclasses that merge multiple behaviors
|
|
8
|
-
|
|
9
|
-
These utilities help create robust class hierarchies with proper implementation
|
|
10
|
-
enforcement and built-in logging capabilities.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
from winipedia_utils.logging.logger import get_logger
|
|
14
|
-
from winipedia_utils.oop.mixins.meta import ABCLoggingMeta, StrictABCLoggingMeta
|
|
15
|
-
|
|
16
|
-
logger = get_logger(__name__)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class StrictABCLoggingMixin(metaclass=StrictABCLoggingMeta):
|
|
20
|
-
"""mixin class that provides implementation, logging, and ABC functionality.
|
|
21
|
-
|
|
22
|
-
This mixin can be used as a base class for other mixins that need:
|
|
23
|
-
- Abstract method declaration (from ABC)
|
|
24
|
-
- Implementation enforcement (from ImplementationMeta)
|
|
25
|
-
- Automatic method logging (from LoggingMeta)
|
|
26
|
-
|
|
27
|
-
Subclasses must set __abstract__ = False when they provide concrete implementations.
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class ABCLoggingMixin(metaclass=ABCLoggingMeta):
|
|
32
|
-
"""Mixin class that provides automatic method logging with performance tracking.
|
|
33
|
-
|
|
34
|
-
This mixin can be used as a base class for other mixins that need:
|
|
35
|
-
- Automatic method logging (from LoggingMeta)
|
|
36
|
-
|
|
37
|
-
"""
|
|
1
|
+
"""Mixin utilities for class composition and behavior extension.
|
|
2
|
+
|
|
3
|
+
This module provides metaclasses and mixins that facilitate class composition
|
|
4
|
+
through the mixin pattern. It includes utilities for:
|
|
5
|
+
- Automatic method logging with performance tracking
|
|
6
|
+
- Abstract class implementation enforcement with type checking
|
|
7
|
+
- Combined metaclasses that merge multiple behaviors
|
|
8
|
+
|
|
9
|
+
These utilities help create robust class hierarchies with proper implementation
|
|
10
|
+
enforcement and built-in logging capabilities.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from winipedia_utils.logging.logger import get_logger
|
|
14
|
+
from winipedia_utils.oop.mixins.meta import ABCLoggingMeta, StrictABCLoggingMeta
|
|
15
|
+
|
|
16
|
+
logger = get_logger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class StrictABCLoggingMixin(metaclass=StrictABCLoggingMeta):
|
|
20
|
+
"""mixin class that provides implementation, logging, and ABC functionality.
|
|
21
|
+
|
|
22
|
+
This mixin can be used as a base class for other mixins that need:
|
|
23
|
+
- Abstract method declaration (from ABC)
|
|
24
|
+
- Implementation enforcement (from ImplementationMeta)
|
|
25
|
+
- Automatic method logging (from LoggingMeta)
|
|
26
|
+
|
|
27
|
+
Subclasses must set __abstract__ = False when they provide concrete implementations.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ABCLoggingMixin(metaclass=ABCLoggingMeta):
|
|
32
|
+
"""Mixin class that provides automatic method logging with performance tracking.
|
|
33
|
+
|
|
34
|
+
This mixin can be used as a base class for other mixins that need:
|
|
35
|
+
- Automatic method logging (from LoggingMeta)
|
|
36
|
+
|
|
37
|
+
"""
|
winipedia_utils/os/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"""__init__ module for winipedia_utils.os."""
|
|
1
|
+
"""__init__ module for winipedia_utils.os."""
|
winipedia_utils/os/os.py
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
"""OS utilities for finding commands and paths.
|
|
2
|
-
|
|
3
|
-
This module provides utility functions for working with the operating system,
|
|
4
|
-
including finding the path to commands and managing environment variables.
|
|
5
|
-
These utilities help with system-level operations and configuration.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import shutil
|
|
9
|
-
import subprocess # nosec: B404
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
from typing import Any
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def which_with_raise(cmd: str, *, raise_error: bool = True) -> str | None:
|
|
15
|
-
"""Give the path to the given command.
|
|
16
|
-
|
|
17
|
-
Args:
|
|
18
|
-
cmd: The command to find
|
|
19
|
-
raise_error: Whether to raise an error if the command is not found
|
|
20
|
-
|
|
21
|
-
Returns:
|
|
22
|
-
The path to the command
|
|
23
|
-
|
|
24
|
-
Raises:
|
|
25
|
-
FileNotFoundError: If the command is not found
|
|
26
|
-
|
|
27
|
-
"""
|
|
28
|
-
path = shutil.which(cmd)
|
|
29
|
-
if path is None:
|
|
30
|
-
msg = f"Command {cmd} not found"
|
|
31
|
-
if raise_error:
|
|
32
|
-
raise FileNotFoundError(msg)
|
|
33
|
-
return path
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def run_subprocess(
|
|
37
|
-
args: list[str | Path],
|
|
38
|
-
*,
|
|
39
|
-
input_: str | bytes | None = None,
|
|
40
|
-
capture_output: bool = True,
|
|
41
|
-
timeout: int | None = None,
|
|
42
|
-
check: bool = True,
|
|
43
|
-
**kwargs: Any,
|
|
44
|
-
) -> subprocess.CompletedProcess[Any]:
|
|
45
|
-
"""Run a subprocess.
|
|
46
|
-
|
|
47
|
-
Args:
|
|
48
|
-
args: The arguments to pass to the subprocess
|
|
49
|
-
input_: The input to pass to the subprocess
|
|
50
|
-
capture_output: Whether to capture the output of the subprocess
|
|
51
|
-
timeout: The timeout for the subprocess
|
|
52
|
-
check: to raise an exception if the subprocess returns a non-zero exit code
|
|
53
|
-
kwargs: Any other arguments to pass to subprocess.run()
|
|
54
|
-
|
|
55
|
-
"""
|
|
56
|
-
return subprocess.run( # noqa: S603 # nosec: B603
|
|
57
|
-
args,
|
|
58
|
-
check=check,
|
|
59
|
-
input=input_,
|
|
60
|
-
capture_output=capture_output,
|
|
61
|
-
timeout=timeout,
|
|
62
|
-
**kwargs,
|
|
63
|
-
)
|
|
1
|
+
"""OS utilities for finding commands and paths.
|
|
2
|
+
|
|
3
|
+
This module provides utility functions for working with the operating system,
|
|
4
|
+
including finding the path to commands and managing environment variables.
|
|
5
|
+
These utilities help with system-level operations and configuration.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess # nosec: B404
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def which_with_raise(cmd: str, *, raise_error: bool = True) -> str | None:
|
|
15
|
+
"""Give the path to the given command.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
cmd: The command to find
|
|
19
|
+
raise_error: Whether to raise an error if the command is not found
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
The path to the command
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
FileNotFoundError: If the command is not found
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
path = shutil.which(cmd)
|
|
29
|
+
if path is None:
|
|
30
|
+
msg = f"Command {cmd} not found"
|
|
31
|
+
if raise_error:
|
|
32
|
+
raise FileNotFoundError(msg)
|
|
33
|
+
return path
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def run_subprocess(
|
|
37
|
+
args: list[str | Path],
|
|
38
|
+
*,
|
|
39
|
+
input_: str | bytes | None = None,
|
|
40
|
+
capture_output: bool = True,
|
|
41
|
+
timeout: int | None = None,
|
|
42
|
+
check: bool = True,
|
|
43
|
+
**kwargs: Any,
|
|
44
|
+
) -> subprocess.CompletedProcess[Any]:
|
|
45
|
+
"""Run a subprocess.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
args: The arguments to pass to the subprocess
|
|
49
|
+
input_: The input to pass to the subprocess
|
|
50
|
+
capture_output: Whether to capture the output of the subprocess
|
|
51
|
+
timeout: The timeout for the subprocess
|
|
52
|
+
check: to raise an exception if the subprocess returns a non-zero exit code
|
|
53
|
+
kwargs: Any other arguments to pass to subprocess.run()
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
return subprocess.run( # noqa: S603 # nosec: B603
|
|
57
|
+
args,
|
|
58
|
+
check=check,
|
|
59
|
+
input=input_,
|
|
60
|
+
capture_output=capture_output,
|
|
61
|
+
timeout=timeout,
|
|
62
|
+
**kwargs,
|
|
63
|
+
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""__init__ module for winipedia_utils.projects."""
|
|
1
|
+
"""__init__ module for winipedia_utils.projects."""
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""__init__ module for winipedia_utils.projects.poetry."""
|
|
1
|
+
"""__init__ module for winipedia_utils.projects.poetry."""
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
"""Config utilities for poetry and pyproject.toml."""
|
|
2
|
-
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Any
|
|
5
|
-
|
|
6
|
-
import tomlkit
|
|
7
|
-
from tomlkit.toml_document import TOMLDocument
|
|
8
|
-
|
|
9
|
-
from winipedia_utils.projects.poetry.poetry import logger
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def laod_pyproject_toml() -> TOMLDocument:
|
|
13
|
-
"""Load the pyproject.toml file."""
|
|
14
|
-
return tomlkit.parse(Path("pyproject.toml").read_text())
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def dump_pyproject_toml(toml: TOMLDocument) -> None:
|
|
18
|
-
"""Dump the pyproject.toml file."""
|
|
19
|
-
with Path("pyproject.toml").open("w") as f:
|
|
20
|
-
tomlkit.dump(toml, f)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def get_poetry_package_name() -> str:
|
|
24
|
-
"""Get the name of the project from pyproject.toml."""
|
|
25
|
-
toml = laod_pyproject_toml()
|
|
26
|
-
project_dict = toml.get("project", {})
|
|
27
|
-
project_name = str(project_dict.get("name", ""))
|
|
28
|
-
return project_name.replace("-", "_")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def _get_pyproject_toml_tool_configs() -> dict[str, Any]:
|
|
32
|
-
"""Get the tool configurations for pyproject.toml."""
|
|
33
|
-
return {
|
|
34
|
-
"ruff": {
|
|
35
|
-
"exclude": [".*", "**/migrations/*.py"],
|
|
36
|
-
"lint": {
|
|
37
|
-
"select": ["ALL"],
|
|
38
|
-
"ignore": ["D203", "D213", "COM812", "ANN401"],
|
|
39
|
-
"fixable": ["ALL"],
|
|
40
|
-
"pydocstyle": {
|
|
41
|
-
"convention": "google",
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
"mypy": {
|
|
46
|
-
"strict": True,
|
|
47
|
-
"warn_unreachable": True,
|
|
48
|
-
"show_error_codes": True,
|
|
49
|
-
"files": ".",
|
|
50
|
-
},
|
|
51
|
-
"pytest": {
|
|
52
|
-
"ini_options": {
|
|
53
|
-
"testpaths": ["tests"],
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
"bandit": {},
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def _tool_config_is_correct(tool: str, config: dict[str, Any]) -> bool:
|
|
61
|
-
"""Check if the tool configuration in pyproject.toml is correct."""
|
|
62
|
-
toml = laod_pyproject_toml()
|
|
63
|
-
actual_tools = toml.get("tool", {})
|
|
64
|
-
|
|
65
|
-
return bool(actual_tools.get(tool) == config)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def _pyproject_tool_configs_are_correct() -> bool:
|
|
69
|
-
"""Check if the tool configurations in pyproject.toml are correct."""
|
|
70
|
-
expected_tool_dict = _get_pyproject_toml_tool_configs()
|
|
71
|
-
for tool, config in expected_tool_dict.items():
|
|
72
|
-
if not _tool_config_is_correct(tool, config):
|
|
73
|
-
return False
|
|
74
|
-
|
|
75
|
-
return True
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def _add_configurations_to_pyproject_toml() -> None:
|
|
79
|
-
"""Add tool.* configurations to pyproject.toml."""
|
|
80
|
-
expected_tool_dict = _get_pyproject_toml_tool_configs()
|
|
81
|
-
toml = laod_pyproject_toml()
|
|
82
|
-
actual_tool_dict = toml.get("tool", {})
|
|
83
|
-
# update the toml dct and dump it but only update the tools specified not all tools
|
|
84
|
-
for tool, config in expected_tool_dict.items():
|
|
85
|
-
# if tool section already exists skip it
|
|
86
|
-
if not _tool_config_is_correct(tool, config):
|
|
87
|
-
logger.info("Adding tool.%s configuration to pyproject.toml", tool)
|
|
88
|
-
# updates inplace of toml_dict["tool"][tool]
|
|
89
|
-
actual_tool_dict[tool] = config
|
|
90
|
-
|
|
91
|
-
dump_pyproject_toml(toml)
|
|
1
|
+
"""Config utilities for poetry and pyproject.toml."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import tomlkit
|
|
7
|
+
from tomlkit.toml_document import TOMLDocument
|
|
8
|
+
|
|
9
|
+
from winipedia_utils.projects.poetry.poetry import logger
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def laod_pyproject_toml() -> TOMLDocument:
|
|
13
|
+
"""Load the pyproject.toml file."""
|
|
14
|
+
return tomlkit.parse(Path("pyproject.toml").read_text())
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def dump_pyproject_toml(toml: TOMLDocument) -> None:
|
|
18
|
+
"""Dump the pyproject.toml file."""
|
|
19
|
+
with Path("pyproject.toml").open("w") as f:
|
|
20
|
+
tomlkit.dump(toml, f)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_poetry_package_name() -> str:
|
|
24
|
+
"""Get the name of the project from pyproject.toml."""
|
|
25
|
+
toml = laod_pyproject_toml()
|
|
26
|
+
project_dict = toml.get("project", {})
|
|
27
|
+
project_name = str(project_dict.get("name", ""))
|
|
28
|
+
return project_name.replace("-", "_")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _get_pyproject_toml_tool_configs() -> dict[str, Any]:
|
|
32
|
+
"""Get the tool configurations for pyproject.toml."""
|
|
33
|
+
return {
|
|
34
|
+
"ruff": {
|
|
35
|
+
"exclude": [".*", "**/migrations/*.py"],
|
|
36
|
+
"lint": {
|
|
37
|
+
"select": ["ALL"],
|
|
38
|
+
"ignore": ["D203", "D213", "COM812", "ANN401"],
|
|
39
|
+
"fixable": ["ALL"],
|
|
40
|
+
"pydocstyle": {
|
|
41
|
+
"convention": "google",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
"mypy": {
|
|
46
|
+
"strict": True,
|
|
47
|
+
"warn_unreachable": True,
|
|
48
|
+
"show_error_codes": True,
|
|
49
|
+
"files": ".",
|
|
50
|
+
},
|
|
51
|
+
"pytest": {
|
|
52
|
+
"ini_options": {
|
|
53
|
+
"testpaths": ["tests"],
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"bandit": {},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _tool_config_is_correct(tool: str, config: dict[str, Any]) -> bool:
|
|
61
|
+
"""Check if the tool configuration in pyproject.toml is correct."""
|
|
62
|
+
toml = laod_pyproject_toml()
|
|
63
|
+
actual_tools = toml.get("tool", {})
|
|
64
|
+
|
|
65
|
+
return bool(actual_tools.get(tool) == config)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _pyproject_tool_configs_are_correct() -> bool:
|
|
69
|
+
"""Check if the tool configurations in pyproject.toml are correct."""
|
|
70
|
+
expected_tool_dict = _get_pyproject_toml_tool_configs()
|
|
71
|
+
for tool, config in expected_tool_dict.items():
|
|
72
|
+
if not _tool_config_is_correct(tool, config):
|
|
73
|
+
return False
|
|
74
|
+
|
|
75
|
+
return True
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _add_configurations_to_pyproject_toml() -> None:
|
|
79
|
+
"""Add tool.* configurations to pyproject.toml."""
|
|
80
|
+
expected_tool_dict = _get_pyproject_toml_tool_configs()
|
|
81
|
+
toml = laod_pyproject_toml()
|
|
82
|
+
actual_tool_dict = toml.get("tool", {})
|
|
83
|
+
# update the toml dct and dump it but only update the tools specified not all tools
|
|
84
|
+
for tool, config in expected_tool_dict.items():
|
|
85
|
+
# if tool section already exists skip it
|
|
86
|
+
if not _tool_config_is_correct(tool, config):
|
|
87
|
+
logger.info("Adding tool.%s configuration to pyproject.toml", tool)
|
|
88
|
+
# updates inplace of toml_dict["tool"][tool]
|
|
89
|
+
actual_tool_dict[tool] = config
|
|
90
|
+
|
|
91
|
+
dump_pyproject_toml(toml)
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"""Project utilities for introspection and manipulation.
|
|
2
|
-
|
|
3
|
-
This module provides utility functions for working with Python projects
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
import sys
|
|
7
|
-
|
|
8
|
-
from winipedia_utils.consts import _DEV_DEPENDENCIES
|
|
9
|
-
from winipedia_utils.logging.logger import get_logger
|
|
10
|
-
from winipedia_utils.os.os import run_subprocess, which_with_raise
|
|
11
|
-
|
|
12
|
-
logger = get_logger(__name__)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
POETRY_PATH = which_with_raise("poetry", raise_error=False) or "poetry"
|
|
16
|
-
|
|
17
|
-
POETRY_RUN_ARGS = [POETRY_PATH, "run"]
|
|
18
|
-
|
|
19
|
-
POETRY_ADD_ARGS = [POETRY_PATH, "add"]
|
|
20
|
-
|
|
21
|
-
POETRY_ADD_DEV_ARGS = [*POETRY_ADD_ARGS, "--group", "dev"]
|
|
22
|
-
|
|
23
|
-
POETRY_RUN_PYTHON_ARGS = [*POETRY_RUN_ARGS, sys.executable]
|
|
24
|
-
|
|
25
|
-
POETRY_RUN_RUFF_ARGS = [*POETRY_RUN_ARGS, "ruff"]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def _install_dev_dependencies() -> None:
|
|
29
|
-
"""Install winipedia_utils dev dependencies as dev dependencies."""
|
|
30
|
-
logger.info("Adding dev dependencies: %s", _DEV_DEPENDENCIES)
|
|
31
|
-
run_subprocess([*POETRY_ADD_DEV_ARGS, *_DEV_DEPENDENCIES], check=True)
|
|
1
|
+
"""Project utilities for introspection and manipulation.
|
|
2
|
+
|
|
3
|
+
This module provides utility functions for working with Python projects
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from winipedia_utils.consts import _DEV_DEPENDENCIES
|
|
9
|
+
from winipedia_utils.logging.logger import get_logger
|
|
10
|
+
from winipedia_utils.os.os import run_subprocess, which_with_raise
|
|
11
|
+
|
|
12
|
+
logger = get_logger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
POETRY_PATH = which_with_raise("poetry", raise_error=False) or "poetry"
|
|
16
|
+
|
|
17
|
+
POETRY_RUN_ARGS = [POETRY_PATH, "run"]
|
|
18
|
+
|
|
19
|
+
POETRY_ADD_ARGS = [POETRY_PATH, "add"]
|
|
20
|
+
|
|
21
|
+
POETRY_ADD_DEV_ARGS = [*POETRY_ADD_ARGS, "--group", "dev"]
|
|
22
|
+
|
|
23
|
+
POETRY_RUN_PYTHON_ARGS = [*POETRY_RUN_ARGS, sys.executable]
|
|
24
|
+
|
|
25
|
+
POETRY_RUN_RUFF_ARGS = [*POETRY_RUN_ARGS, "ruff"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _install_dev_dependencies() -> None:
|
|
29
|
+
"""Install winipedia_utils dev dependencies as dev dependencies."""
|
|
30
|
+
logger.info("Adding dev dependencies: %s", _DEV_DEPENDENCIES)
|
|
31
|
+
run_subprocess([*POETRY_ADD_DEV_ARGS, *_DEV_DEPENDENCIES], check=True)
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
"""Utilities for working with Python projects."""
|
|
2
|
-
|
|
3
|
-
from types import ModuleType
|
|
4
|
-
|
|
5
|
-
from winipedia_utils.modules.module import create_module, to_path
|
|
6
|
-
from winipedia_utils.modules.package import get_src_package
|
|
7
|
-
from winipedia_utils.projects.poetry.config import get_poetry_package_name
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def _create_project_root() -> None:
|
|
11
|
-
"""Create the project root."""
|
|
12
|
-
src_package_name = get_poetry_package_name()
|
|
13
|
-
create_module(src_package_name, is_package=True)
|
|
14
|
-
_create_py_typed()
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def _create_py_typed() -> None:
|
|
18
|
-
"""Create the py.typed file."""
|
|
19
|
-
src_package_name = get_src_package().__name__
|
|
20
|
-
py_typed_path = to_path(src_package_name, is_package=True) / "py.typed"
|
|
21
|
-
py_typed_path.touch()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def make_name_from_package(
|
|
25
|
-
package: ModuleType,
|
|
26
|
-
split_on: str = "_",
|
|
27
|
-
join_on: str = "-",
|
|
28
|
-
*,
|
|
29
|
-
capitalize: bool = True,
|
|
30
|
-
) -> str:
|
|
31
|
-
"""Make a name from a package.
|
|
32
|
-
|
|
33
|
-
takes a package and makes a name from it that is readable by humans.
|
|
34
|
-
|
|
35
|
-
Args:
|
|
36
|
-
package (ModuleType): The package to make a name from
|
|
37
|
-
split_on (str, optional): what to split the package name on. Defaults to "_".
|
|
38
|
-
join_on (str, optional): what to join the package name with. Defaults to "-".
|
|
39
|
-
capitalize (bool, optional): Whether to capitalize each part. Defaults to True.
|
|
40
|
-
|
|
41
|
-
Returns:
|
|
42
|
-
str: _description_
|
|
43
|
-
"""
|
|
44
|
-
package_name = package.__name__.split(".")[-1]
|
|
45
|
-
parts = package_name.split(split_on)
|
|
46
|
-
if capitalize:
|
|
47
|
-
parts = [part.capitalize() for part in parts]
|
|
48
|
-
return join_on.join(parts)
|
|
1
|
+
"""Utilities for working with Python projects."""
|
|
2
|
+
|
|
3
|
+
from types import ModuleType
|
|
4
|
+
|
|
5
|
+
from winipedia_utils.modules.module import create_module, to_path
|
|
6
|
+
from winipedia_utils.modules.package import get_src_package
|
|
7
|
+
from winipedia_utils.projects.poetry.config import get_poetry_package_name
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _create_project_root() -> None:
|
|
11
|
+
"""Create the project root."""
|
|
12
|
+
src_package_name = get_poetry_package_name()
|
|
13
|
+
create_module(src_package_name, is_package=True)
|
|
14
|
+
_create_py_typed()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _create_py_typed() -> None:
|
|
18
|
+
"""Create the py.typed file."""
|
|
19
|
+
src_package_name = get_src_package().__name__
|
|
20
|
+
py_typed_path = to_path(src_package_name, is_package=True) / "py.typed"
|
|
21
|
+
py_typed_path.touch()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def make_name_from_package(
|
|
25
|
+
package: ModuleType,
|
|
26
|
+
split_on: str = "_",
|
|
27
|
+
join_on: str = "-",
|
|
28
|
+
*,
|
|
29
|
+
capitalize: bool = True,
|
|
30
|
+
) -> str:
|
|
31
|
+
"""Make a name from a package.
|
|
32
|
+
|
|
33
|
+
takes a package and makes a name from it that is readable by humans.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
package (ModuleType): The package to make a name from
|
|
37
|
+
split_on (str, optional): what to split the package name on. Defaults to "_".
|
|
38
|
+
join_on (str, optional): what to join the package name with. Defaults to "-".
|
|
39
|
+
capitalize (bool, optional): Whether to capitalize each part. Defaults to True.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
str: _description_
|
|
43
|
+
"""
|
|
44
|
+
package_name = package.__name__.split(".")[-1]
|
|
45
|
+
parts = package_name.split(split_on)
|
|
46
|
+
if capitalize:
|
|
47
|
+
parts = [part.capitalize() for part in parts]
|
|
48
|
+
return join_on.join(parts)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""__init__ module for winipedia_utils.pyside6."""
|
|
1
|
+
"""__init__ module for winipedia_utils.pyside6."""
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""__init__ module for winipedia_utils.pyside6.core."""
|
|
1
|
+
"""__init__ module for winipedia_utils.pyside6.core."""
|