jetpytools 2.2.5__tar.gz → 2.2.6__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.
Files changed (39) hide show
  1. {jetpytools-2.2.5 → jetpytools-2.2.6}/PKG-INFO +1 -1
  2. jetpytools-2.2.6/jetpytools/_version.py +2 -0
  3. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/exceptions/base.py +6 -1
  4. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/utils/file.py +39 -7
  5. {jetpytools-2.2.5 → jetpytools-2.2.6}/pyproject.toml +1 -1
  6. jetpytools-2.2.5/jetpytools/_version.py +0 -2
  7. {jetpytools-2.2.5 → jetpytools-2.2.6}/.gitignore +0 -0
  8. {jetpytools-2.2.5 → jetpytools-2.2.6}/LICENSE +0 -0
  9. {jetpytools-2.2.5 → jetpytools-2.2.6}/README.md +0 -0
  10. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/__init__.py +0 -0
  11. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/enums/__init__.py +0 -0
  12. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/enums/base.py +0 -0
  13. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/enums/other.py +0 -0
  14. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/exceptions/__init__.py +0 -0
  15. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/exceptions/enum.py +0 -0
  16. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/exceptions/file.py +0 -0
  17. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/exceptions/generic.py +0 -0
  18. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/exceptions/module.py +0 -0
  19. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/functions/__init__.py +0 -0
  20. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/functions/funcs.py +0 -0
  21. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/functions/normalize.py +0 -0
  22. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/functions/other.py +0 -0
  23. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/py.typed +0 -0
  24. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/types/__init__.py +0 -0
  25. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/types/builtins.py +0 -0
  26. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/types/check.py +0 -0
  27. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/types/file.py +0 -0
  28. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/types/funcs.py +0 -0
  29. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/types/generic.py +0 -0
  30. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/types/supports.py +0 -0
  31. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/types/utils.py +0 -0
  32. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/utils/__init__.py +0 -0
  33. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/utils/funcs.py +0 -0
  34. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/utils/math.py +0 -0
  35. {jetpytools-2.2.5 → jetpytools-2.2.6}/jetpytools/utils/ranges.py +0 -0
  36. {jetpytools-2.2.5 → jetpytools-2.2.6}/tests/test_file.py +0 -0
  37. {jetpytools-2.2.5 → jetpytools-2.2.6}/tests/test_funcs.py +0 -0
  38. {jetpytools-2.2.5 → jetpytools-2.2.6}/tests/test_normalize.py +0 -0
  39. {jetpytools-2.2.5 → jetpytools-2.2.6}/tests/test_types_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jetpytools
3
- Version: 2.2.5
3
+ Version: 2.2.6
4
4
  Summary: Collection of stuff that's useful in general python programming
5
5
  Project-URL: Source Code, https://github.com/Jaded-Encoding-Thaumaturgy/jetpytools
6
6
  Project-URL: Contact, https://discord.gg/XTpc6Fa9eB
@@ -0,0 +1,2 @@
1
+ __version__ = "2.2.6"
2
+ __version_tuple__ = (2, 2, 6)
@@ -99,8 +99,13 @@ class CustomError(Exception, metaclass=CustomErrorMeta):
99
99
  if not message:
100
100
  message = "An error occurred!"
101
101
 
102
+ truthy = ["1", "true", "yes", "on"]
103
+
102
104
  should_color = (
103
- sys.stdout and sys.stdout.isatty() and not os.getenv("NO_COLOR") and not os.getenv("JETPYTOOLS_NO_COLOR")
105
+ sys.stdout
106
+ and sys.stdout.isatty()
107
+ and os.getenv("NO_COLOR") not in truthy
108
+ and os.getenv("JETPYTOOLS_NO_COLOR") not in truthy
104
109
  )
105
110
 
106
111
  if self.func:
@@ -5,9 +5,20 @@ from os import F_OK, R_OK, W_OK, X_OK, access, getenv, path
5
5
  from pathlib import Path
6
6
  from typing import Callable
7
7
 
8
- from ..exceptions import FileIsADirectoryError, FileNotExistsError, FilePermissionError, FileWasNotFoundError
8
+ from ..exceptions import (
9
+ CustomRuntimeError,
10
+ FileIsADirectoryError,
11
+ FileNotExistsError,
12
+ FilePermissionError,
13
+ FileWasNotFoundError,
14
+ )
9
15
  from ..types import FilePathType, FuncExcept, OpenBinaryMode, OpenTextMode, SPath
10
16
 
17
+ if sys.version_info < (3, 13):
18
+ from typing_extensions import deprecated
19
+ else:
20
+ from warnings import deprecated
21
+
11
22
  __all__ = [
12
23
  "add_script_path_hook",
13
24
  "check_perms",
@@ -19,10 +30,12 @@ __all__ = [
19
30
  _script_path_hooks = list[Callable[[], SPath | None]]()
20
31
 
21
32
 
33
+ @deprecated("", category=PendingDeprecationWarning)
22
34
  def add_script_path_hook(hook: Callable[[], SPath | None]) -> None:
23
35
  _script_path_hooks.append(hook)
24
36
 
25
37
 
38
+ @deprecated("", category=PendingDeprecationWarning)
26
39
  def remove_script_path_hook(hook: Callable[[], SPath | None]) -> None:
27
40
  _script_path_hooks.remove(hook)
28
41
 
@@ -30,15 +43,34 @@ def remove_script_path_hook(hook: Callable[[], SPath | None]) -> None:
30
43
  def get_script_path() -> SPath:
31
44
  for hook in reversed(_script_path_hooks):
32
45
  if (script_path := hook()) is not None:
33
- return script_path
46
+ return SPath(script_path)
34
47
 
35
- import __main__
48
+ lib_root = __name__.split(".", 1)[0] if "." in __name__ else __name__
36
49
 
50
+ frame = sys._getframe(1)
37
51
  try:
38
- path = SPath(__main__.__file__)
39
- return path if path.exists() else SPath.cwd()
40
- except AttributeError:
41
- return SPath.cwd()
52
+ while frame:
53
+ f_globals = frame.f_globals
54
+ module_name: str = f_globals.get("__name__", "")
55
+
56
+ # Skip if the frame belongs to the current library family
57
+ if module_name.startswith(lib_root):
58
+ frame = frame.f_back
59
+ continue
60
+
61
+ filename = frame.f_code.co_filename
62
+
63
+ # - No __package__ (execution entry point)
64
+ # - Is a file on disk
65
+ # - Not in site-packages
66
+ if not f_globals.get("__package__") and path.isfile(filename) and "site-packages" not in filename:
67
+ return SPath(filename)
68
+
69
+ frame = frame.f_back
70
+
71
+ raise CustomRuntimeError("Couldn't find the script path")
72
+ finally:
73
+ del frame
42
74
 
43
75
 
44
76
  def get_user_data_dir() -> Path:
@@ -25,7 +25,7 @@ dependencies = ["typing_extensions>=4.15.0; python_version<'3.13'"]
25
25
  "Contact" = "https://discord.gg/XTpc6Fa9eB"
26
26
 
27
27
  [dependency-groups]
28
- dev = ["mypy~=1.19.0", "ruff~=0.14.0", "pytest>=9.0.0, <10.0.0", "twine>=6.2.0"]
28
+ dev = ["mypy~=1.19.0", "ruff~=0.15.0", "pytest>=9.0.0, <10.0.0", "twine>=6.2.0"]
29
29
 
30
30
  [build-system]
31
31
  requires = ["hatchling>=1.27.0", "versioningit"]
@@ -1,2 +0,0 @@
1
- __version__ = "2.2.5"
2
- __version_tuple__ = (2, 2, 5)
File without changes
File without changes
File without changes