stdl 0.5.3__tar.gz → 0.5.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stdl
3
- Version: 0.5.3
3
+ Version: 0.5.4
4
4
  Summary: Extended Python Standard Library
5
5
  Author-email: Žiga Ivanšek <ziga.ivansek@gmail.com>
6
6
  Project-URL: Repository, https://github.com/zigai/stdl
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stdl"
3
- version = "0.5.3"
3
+ version = "0.5.4"
4
4
  description = "Extended Python Standard Library"
5
5
  authors = [{ name = "Žiga Ivanšek", email = "ziga.ivansek@gmail.com" }]
6
6
  license = { file = "LICENSE.txt" }
@@ -0,0 +1 @@
1
+ from stdl import decorators, dt, fs, log, lst, net, st
@@ -102,7 +102,7 @@ class File(PathLike):
102
102
  Args:
103
103
  path (os.PathLike): File path.
104
104
  encoding (str, optional): The file's encoding.
105
- abs (bool, keyword-only): Whether to use the absolute path.
105
+ abs (bool): Whether to use the absolute path.
106
106
  """
107
107
  self.encoding = encoding
108
108
  self.path: str = os.fspath(path)
@@ -698,7 +698,9 @@ def is_wsl() -> bool:
698
698
 
699
699
 
700
700
  def mkdir(path: str | Path, mode: int = 511, exist_ok: bool = True) -> None:
701
- """Creates a directory.
701
+ """
702
+ Creates a directory.
703
+
702
704
  Args:
703
705
  path (str | Path): The path of the directory to create.
704
706
  exist_ok (bool, optional): Whether to raise an exception if the directory already exists. Defaults to True.
@@ -707,7 +709,9 @@ def mkdir(path: str | Path, mode: int = 511, exist_ok: bool = True) -> None:
707
709
 
708
710
 
709
711
  def mkdirs(dest: str | Path, names: list[str]) -> None:
710
- """Creates directories inside a destination directory.
712
+ """
713
+ Creates directories inside a destination directory.
714
+
711
715
  Args:
712
716
  dest (str | Path): The destination directory.
713
717
  names (list[str]): A list of directory names to be created in the destination directory.
@@ -863,7 +867,7 @@ def ensure_paths_exist(*args: str | PathLike | Iterable[str | PathLike]) -> None
863
867
 
864
868
  def check_path(path: str | PathLike):
865
869
  if not os.path.exists(os.fspath(path)):
866
- raise FileNotFoundError(f"Path does not exist: {path}")
870
+ raise FileNotFoundError(f"Path does not exist: '{path}'")
867
871
 
868
872
  for path in args:
869
873
  if isinstance(path, (str, bytes, PathLike)):
@@ -886,7 +890,7 @@ def ensure_paths_dont_exist(*args: str | PathLike | Iterable[str | PathLike]) ->
886
890
 
887
891
  def check_path(path: str | PathLike):
888
892
  if os.path.exists(os.fspath(path)):
889
- raise FileExistsError(f"Path already exists: {path}")
893
+ raise FileExistsError(f"Path already exists: '{path}'")
890
894
 
891
895
  for path in args:
892
896
  if isinstance(path, (str, bytes, PathLike)):
@@ -1017,22 +1021,16 @@ def exec_cmd(
1017
1021
  )
1018
1022
 
1019
1023
 
1020
- def read_stdin(timeout: float = 0.0) -> list[str]:
1024
+ def read_piped() -> str:
1021
1025
  """
1022
- Reads lines from stdin.
1023
-
1024
- Args:
1025
- timeout (float, optional): The time to wait for input. Defaults to 0.
1026
-
1027
- Returns:
1028
- list[str]: The lines read from stdin.
1026
+ Reads piped input from stdin.
1029
1027
  """
1030
- if select([sys.stdin], [], [], timeout)[0]:
1031
- return sys.stdin.read().strip().splitlines()
1032
- return []
1028
+ if sys.stdin.isatty():
1029
+ return ""
1030
+ return sys.stdin.read().strip()
1033
1031
 
1034
1032
 
1035
- def startfile(path: str | PathLike) -> None:
1033
+ def start_file(path: str | PathLike) -> None:
1036
1034
  """
1037
1035
  Open the file with your OS's default application.
1038
1036
 
@@ -1086,8 +1084,8 @@ __all__ = [
1086
1084
  "dirname",
1087
1085
  "joinpath",
1088
1086
  "splitpath",
1089
- "read_stdin",
1090
- "startfile",
1087
+ "start_file",
1088
+ "read_piped",
1091
1089
  "isdir",
1092
1090
  "isfile",
1093
1091
  "islink",
@@ -92,7 +92,7 @@ def occurrences(l: list[T.Any], val: T.Any) -> int:
92
92
  Returns:
93
93
  int: Number of occurrences
94
94
  """
95
- return len([i for i in l if i == val and type(i) == type(val)])
95
+ return len([i for i in l if i == val and type(i) is type(val)])
96
96
 
97
97
 
98
98
  __all__ = [
@@ -383,6 +383,14 @@ def ansi_rjust(s: str, width: int, fillchar: str = " ") -> str:
383
383
  return s.rjust(new_width, fillchar)
384
384
 
385
385
 
386
+ def ansi_strip(r: str) -> str:
387
+ """
388
+ Remove ANSI escape codes from a string.
389
+ """
390
+ ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
391
+ return ansi_escape.sub("", r)
392
+
393
+
386
394
  if __name__ == "__main__":
387
395
  FG.print_all()
388
396
  BG.print_all()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stdl
3
- Version: 0.5.3
3
+ Version: 0.5.4
4
4
  Summary: Extended Python Standard Library
5
5
  Author-email: Žiga Ivanšek <ziga.ivansek@gmail.com>
6
6
  Project-URL: Repository, https://github.com/zigai/stdl
@@ -1 +0,0 @@
1
- from stdl import dt, fs, log, lst, net, st
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes