jetpytools 2.2.5__tar.gz → 2.2.7__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.7}/PKG-INFO +1 -1
  2. jetpytools-2.2.7/jetpytools/_version.py +2 -0
  3. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/exceptions/base.py +6 -1
  4. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/utils/file.py +45 -7
  5. {jetpytools-2.2.5 → jetpytools-2.2.7}/pyproject.toml +1 -1
  6. jetpytools-2.2.5/jetpytools/_version.py +0 -2
  7. {jetpytools-2.2.5 → jetpytools-2.2.7}/.gitignore +0 -0
  8. {jetpytools-2.2.5 → jetpytools-2.2.7}/LICENSE +0 -0
  9. {jetpytools-2.2.5 → jetpytools-2.2.7}/README.md +0 -0
  10. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/__init__.py +0 -0
  11. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/enums/__init__.py +0 -0
  12. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/enums/base.py +0 -0
  13. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/enums/other.py +0 -0
  14. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/exceptions/__init__.py +0 -0
  15. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/exceptions/enum.py +0 -0
  16. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/exceptions/file.py +0 -0
  17. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/exceptions/generic.py +0 -0
  18. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/exceptions/module.py +0 -0
  19. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/functions/__init__.py +0 -0
  20. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/functions/funcs.py +0 -0
  21. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/functions/normalize.py +0 -0
  22. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/functions/other.py +0 -0
  23. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/py.typed +0 -0
  24. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/types/__init__.py +0 -0
  25. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/types/builtins.py +0 -0
  26. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/types/check.py +0 -0
  27. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/types/file.py +0 -0
  28. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/types/funcs.py +0 -0
  29. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/types/generic.py +0 -0
  30. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/types/supports.py +0 -0
  31. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/types/utils.py +0 -0
  32. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/utils/__init__.py +0 -0
  33. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/utils/funcs.py +0 -0
  34. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/utils/math.py +0 -0
  35. {jetpytools-2.2.5 → jetpytools-2.2.7}/jetpytools/utils/ranges.py +0 -0
  36. {jetpytools-2.2.5 → jetpytools-2.2.7}/tests/test_file.py +0 -0
  37. {jetpytools-2.2.5 → jetpytools-2.2.7}/tests/test_funcs.py +0 -0
  38. {jetpytools-2.2.5 → jetpytools-2.2.7}/tests/test_normalize.py +0 -0
  39. {jetpytools-2.2.5 → jetpytools-2.2.7}/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.7
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.7"
2
+ __version_tuple__ = (2, 2, 7)
@@ -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:
@@ -1,13 +1,25 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import linecache
3
4
  import sys
4
5
  from os import F_OK, R_OK, W_OK, X_OK, access, getenv, path
5
6
  from pathlib import Path
6
7
  from typing import Callable
7
8
 
8
- from ..exceptions import FileIsADirectoryError, FileNotExistsError, FilePermissionError, FileWasNotFoundError
9
+ from ..exceptions import (
10
+ CustomRuntimeError,
11
+ FileIsADirectoryError,
12
+ FileNotExistsError,
13
+ FilePermissionError,
14
+ FileWasNotFoundError,
15
+ )
9
16
  from ..types import FilePathType, FuncExcept, OpenBinaryMode, OpenTextMode, SPath
10
17
 
18
+ if sys.version_info < (3, 13):
19
+ from typing_extensions import deprecated
20
+ else:
21
+ from warnings import deprecated
22
+
11
23
  __all__ = [
12
24
  "add_script_path_hook",
13
25
  "check_perms",
@@ -19,10 +31,12 @@ __all__ = [
19
31
  _script_path_hooks = list[Callable[[], SPath | None]]()
20
32
 
21
33
 
34
+ @deprecated("", category=PendingDeprecationWarning)
22
35
  def add_script_path_hook(hook: Callable[[], SPath | None]) -> None:
23
36
  _script_path_hooks.append(hook)
24
37
 
25
38
 
39
+ @deprecated("", category=PendingDeprecationWarning)
26
40
  def remove_script_path_hook(hook: Callable[[], SPath | None]) -> None:
27
41
  _script_path_hooks.remove(hook)
28
42
 
@@ -30,15 +44,39 @@ def remove_script_path_hook(hook: Callable[[], SPath | None]) -> None:
30
44
  def get_script_path() -> SPath:
31
45
  for hook in reversed(_script_path_hooks):
32
46
  if (script_path := hook()) is not None:
33
- return script_path
47
+ return SPath(script_path)
34
48
 
35
- import __main__
49
+ lib_root = __name__.split(".", 1)[0] if "." in __name__ else __name__
36
50
 
51
+ frame = sys._getframe(1)
37
52
  try:
38
- path = SPath(__main__.__file__)
39
- return path if path.exists() else SPath.cwd()
40
- except AttributeError:
41
- return SPath.cwd()
53
+ while frame:
54
+ f_globals = frame.f_globals
55
+ module_name: str = f_globals.get("__name__", "")
56
+
57
+ # Skip if the frame belongs to the current library family
58
+ if module_name.startswith(lib_root):
59
+ frame = frame.f_back
60
+ continue
61
+
62
+ filename = frame.f_code.co_filename
63
+
64
+ # - No __package__ (execution entry point)
65
+ # - Not in site-packages
66
+ # - Is a file on disk
67
+ # - Is a virtual file
68
+ if (
69
+ not f_globals.get("__package__")
70
+ and "site-packages" not in filename
71
+ and (path.isfile(filename) or filename in linecache.cache)
72
+ ):
73
+ return SPath(filename)
74
+
75
+ frame = frame.f_back
76
+
77
+ raise CustomRuntimeError("Couldn't find the script path")
78
+ finally:
79
+ del frame
42
80
 
43
81
 
44
82
  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