packg 0.7.2__tar.gz → 0.9.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.
Files changed (60) hide show
  1. {packg-0.7.2 → packg-0.9.2}/LICENSE +1 -1
  2. {packg-0.7.2/src/packg.egg-info → packg-0.9.2}/PKG-INFO +8 -8
  3. {packg-0.7.2 → packg-0.9.2}/README.md +5 -5
  4. {packg-0.7.2 → packg-0.9.2}/pyproject.toml +2 -2
  5. {packg-0.7.2 → packg-0.9.2}/src/packg/__init__.py +1 -1
  6. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/__init__.py +4 -2
  7. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/file_reader.py +31 -9
  8. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/git_status_checker.py +2 -2
  9. {packg-0.7.2 → packg-0.9.2}/src/packg/log.py +25 -14
  10. {packg-0.7.2 → packg-0.9.2/src/packg.egg-info}/PKG-INFO +8 -8
  11. {packg-0.7.2 → packg-0.9.2}/requirements.txt +0 -0
  12. {packg-0.7.2 → packg-0.9.2}/setup.cfg +0 -0
  13. {packg-0.7.2 → packg-0.9.2}/src/packg/__main__.py +0 -0
  14. {packg-0.7.2 → packg-0.9.2}/src/packg/caching.py +0 -0
  15. {packg-0.7.2 → packg-0.9.2}/src/packg/constclass.py +0 -0
  16. {packg-0.7.2 → packg-0.9.2}/src/packg/debugging.py +0 -0
  17. {packg-0.7.2 → packg-0.9.2}/src/packg/dtime.py +0 -0
  18. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/compressed.py +0 -0
  19. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/file_indexer.py +0 -0
  20. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/git_root_finder.py +0 -0
  21. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/jsonext.py +0 -0
  22. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/jsonext_encoder.py +0 -0
  23. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/misc.py +0 -0
  24. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/numpyext.py +0 -0
  25. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/pathspec_matcher.py +0 -0
  26. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/tomlext.py +0 -0
  27. {packg-0.7.2 → packg-0.9.2}/src/packg/iotools/yamlext.py +0 -0
  28. {packg-0.7.2 → packg-0.9.2}/src/packg/magic.py +0 -0
  29. {packg-0.7.2 → packg-0.9.2}/src/packg/maths.py +0 -0
  30. {packg-0.7.2 → packg-0.9.2}/src/packg/misc.py +0 -0
  31. {packg-0.7.2 → packg-0.9.2}/src/packg/multiproc/__init__.py +0 -0
  32. {packg-0.7.2 → packg-0.9.2}/src/packg/multiproc/multiproc_fn.py +0 -0
  33. {packg-0.7.2 → packg-0.9.2}/src/packg/multiproc/multiproc_producer_consumer.py +0 -0
  34. {packg-0.7.2 → packg-0.9.2}/src/packg/packaging.py +0 -0
  35. {packg-0.7.2 → packg-0.9.2}/src/packg/paths.py +0 -0
  36. {packg-0.7.2 → packg-0.9.2}/src/packg/run/__init__.py +0 -0
  37. {packg-0.7.2 → packg-0.9.2}/src/packg/run/cleanup.py +0 -0
  38. {packg-0.7.2 → packg-0.9.2}/src/packg/run/create_autocomplete.py +0 -0
  39. {packg-0.7.2 → packg-0.9.2}/src/packg/run/print_paths.py +0 -0
  40. {packg-0.7.2 → packg-0.9.2}/src/packg/run/show_env.py +0 -0
  41. {packg-0.7.2 → packg-0.9.2}/src/packg/stats.py +0 -0
  42. {packg-0.7.2 → packg-0.9.2}/src/packg/strings/__init__.py +0 -0
  43. {packg-0.7.2 → packg-0.9.2}/src/packg/strings/abbreviations.py +0 -0
  44. {packg-0.7.2 → packg-0.9.2}/src/packg/strings/base64tools.py +0 -0
  45. {packg-0.7.2 → packg-0.9.2}/src/packg/strings/hasher.py +0 -0
  46. {packg-0.7.2 → packg-0.9.2}/src/packg/strings/quote_urlparse.py +0 -0
  47. {packg-0.7.2 → packg-0.9.2}/src/packg/system/__init__.py +0 -0
  48. {packg-0.7.2 → packg-0.9.2}/src/packg/system/systemcall.py +0 -0
  49. {packg-0.7.2 → packg-0.9.2}/src/packg/testing/__init__.py +0 -0
  50. {packg-0.7.2 → packg-0.9.2}/src/packg/testing/fixture_webserver.py +0 -0
  51. {packg-0.7.2 → packg-0.9.2}/src/packg/testing/import_from_source.py +0 -0
  52. {packg-0.7.2 → packg-0.9.2}/src/packg/testing/setup_tests.py +0 -0
  53. {packg-0.7.2 → packg-0.9.2}/src/packg/tqdmext.py +0 -0
  54. {packg-0.7.2 → packg-0.9.2}/src/packg/typext.py +0 -0
  55. {packg-0.7.2 → packg-0.9.2}/src/packg/web.py +0 -0
  56. {packg-0.7.2 → packg-0.9.2}/src/packg.egg-info/SOURCES.txt +0 -0
  57. {packg-0.7.2 → packg-0.9.2}/src/packg.egg-info/dependency_links.txt +0 -0
  58. {packg-0.7.2 → packg-0.9.2}/src/packg.egg-info/requires.txt +0 -0
  59. {packg-0.7.2 → packg-0.9.2}/src/packg.egg-info/top_level.txt +0 -0
  60. {packg-0.7.2 → packg-0.9.2}/src/packg.egg-info/zip-safe +0 -0
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2023 gingsi
189
+ Copyright 2023 simonging
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: packg
3
- Version: 0.7.2
3
+ Version: 0.9.2
4
4
  Summary: Collection of utilities used in other python projects.
5
- Author: gingsi
5
+ Author: simonging
6
6
  License: Apache-2.0
7
- Project-URL: Project-URL, https://github.com/gingsi/packg
7
+ Project-URL: Project-URL, https://github.com/simonging/packg
8
8
  Keywords: attrs,typing,dict,attr
9
9
  Platform: any
10
10
  Classifier: Development Status :: 3 - Alpha
@@ -36,13 +36,13 @@ Requires-Dist: requests
36
36
  # packg
37
37
 
38
38
  <p align="center">
39
- <a href="https://github.com/gingsi/packg/actions/workflows/build-py37.yml">
40
- <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/gingsi/packg/build-py37.yml?branch=main&label=build%203.7" />
39
+ <a href="https://github.com/simonging/packg/actions/workflows/build-py37.yml">
40
+ <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/simonging/packg/build-py37.yml?branch=main&label=build%203.7" />
41
41
  </a>
42
- <a href="https://github.com/gingsi/packg/actions/workflows/build-py310.yml">
43
- <img alt="build 3.10 status" title="build 3.10 status" src="https://img.shields.io/github/actions/workflow/status/gingsi/packg/build-py310.yml?branch=main&label=build%203.10" />
42
+ <a href="https://github.com/simonging/packg/actions/workflows/build-py310.yml">
43
+ <img alt="build 3.10 status" title="build 3.10 status" src="https://img.shields.io/github/actions/workflow/status/simonging/packg/build-py310.yml?branch=main&label=build%203.10" />
44
44
  </a>
45
- <img alt="coverage" title="coverage" src="https://raw.githubusercontent.com/gingsi/packg/main/docs/coverage.svg" />
45
+ <img alt="coverage" title="coverage" src="https://raw.githubusercontent.com/simonging/packg/main/docs/coverage.svg" />
46
46
  <a href="https://pypi.org/project/packg/">
47
47
  <img alt="version" title="version" src="https://img.shields.io/pypi/v/packg?color=success" />
48
48
  </a>
@@ -1,13 +1,13 @@
1
1
  # packg
2
2
 
3
3
  <p align="center">
4
- <a href="https://github.com/gingsi/packg/actions/workflows/build-py37.yml">
5
- <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/gingsi/packg/build-py37.yml?branch=main&label=build%203.7" />
4
+ <a href="https://github.com/simonging/packg/actions/workflows/build-py37.yml">
5
+ <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/simonging/packg/build-py37.yml?branch=main&label=build%203.7" />
6
6
  </a>
7
- <a href="https://github.com/gingsi/packg/actions/workflows/build-py310.yml">
8
- <img alt="build 3.10 status" title="build 3.10 status" src="https://img.shields.io/github/actions/workflow/status/gingsi/packg/build-py310.yml?branch=main&label=build%203.10" />
7
+ <a href="https://github.com/simonging/packg/actions/workflows/build-py310.yml">
8
+ <img alt="build 3.10 status" title="build 3.10 status" src="https://img.shields.io/github/actions/workflow/status/simonging/packg/build-py310.yml?branch=main&label=build%203.10" />
9
9
  </a>
10
- <img alt="coverage" title="coverage" src="https://raw.githubusercontent.com/gingsi/packg/main/docs/coverage.svg" />
10
+ <img alt="coverage" title="coverage" src="https://raw.githubusercontent.com/simonging/packg/main/docs/coverage.svg" />
11
11
  <a href="https://pypi.org/project/packg/">
12
12
  <img alt="version" title="version" src="https://img.shields.io/pypi/v/packg?color=success" />
13
13
  </a>
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
  name = "packg"
7
7
  description = "Collection of utilities used in other python projects."
8
8
  readme = "README.md"
9
- authors = [{ "name" = "gingsi" }]
9
+ authors = [{ "name" = "simonging" }]
10
10
  requires-python = ">=3.7"
11
11
  license = { text = "Apache-2.0" }
12
12
  keywords = ["attrs", "typing", "dict", "attr"]
@@ -24,7 +24,7 @@ classifiers = [
24
24
  dynamic = ["version", "dependencies"]
25
25
 
26
26
  [project.urls]
27
- Project-URL = "https://github.com/gingsi/packg"
27
+ Project-URL = "https://github.com/simonging/packg"
28
28
 
29
29
  [tool.setuptools]
30
30
  zip-safe = true
@@ -2,4 +2,4 @@ from .constclass import Const
2
2
  from .misc import format_exception
3
3
 
4
4
  __all__ = ["Const", "format_exception"]
5
- __version__ = "0.7.2"
5
+ __version__ = "0.9.2"
@@ -6,7 +6,8 @@ but from the actual source file. For everything outside, importing from this __i
6
6
  from .file_indexer import make_index, sort_file_paths_with_dirs_separated
7
7
  from .file_reader import (
8
8
  yield_chunked_bytes,
9
- yield_nonempty_stripped_lines,
9
+ yield_lines_from_file,
10
+ yield_lines_from_object,
10
11
  read_bytes_from_file_or_io,
11
12
  read_text_from_file_or_io,
12
13
  open_file_or_io,
@@ -38,7 +39,8 @@ from .yamlext import load_yaml, loads_yaml, dump_yaml, dumps_yaml
38
39
  __all__ = [
39
40
  "set_working_directory",
40
41
  "yield_chunked_bytes",
41
- "yield_nonempty_stripped_lines",
42
+ "yield_lines_from_file",
43
+ "yield_lines_from_object",
42
44
  "load_json",
43
45
  "loads_json",
44
46
  "load_jsonl",
@@ -6,7 +6,7 @@ from contextlib import contextmanager
6
6
  from pathlib import Path
7
7
  from typing import Union, Iterable
8
8
 
9
- from packg.typext import PathOrIO, PathTypeCls
9
+ from packg.typext import PathOrIO, PathTypeCls, PathType
10
10
 
11
11
 
12
12
  @contextmanager
@@ -78,27 +78,49 @@ def yield_chunked_bytes(file_or_io: PathOrIO, chunk_size=1024 * 1024) -> Iterabl
78
78
  yield data
79
79
 
80
80
 
81
- def yield_nonempty_stripped_lines(lines_obj: Union[PathOrIO, Iterable[str]]) -> Iterable[str]:
81
+ def yield_lines_from_object(
82
+ lines_obj: Union[str, Iterable[str]], strip: bool = True, skip_empty: bool = True
83
+ ) -> Iterable[str]:
82
84
  """
83
85
  Read lines from input, strip whitespaces, skip empty lines, yield lines.
84
86
 
85
87
  Args:
86
- lines_obj: Can be any of:
87
- - iterable of str (list, opened file)
88
- - filepath str or Path
88
+ lines_obj: Either str or iterable of str (list, opened file)
89
+ strip: strip whitespace from lines
90
+ skip_empty: skip empty lines
89
91
 
90
92
  Returns:
91
93
  Generator of stripped lines
92
94
 
93
95
  Examples:
94
- >>> for li in yield_nonempty_stripped_lines([" a ", " ", " b "]): print(li, end=",")
96
+ >>> for li in yield_lines_from_object([" a ", " ", " b "]): print(li, end=",")
95
97
  a,b,
96
98
  """
97
99
  if isinstance(lines_obj, str):
98
100
  lines_obj = lines_obj.splitlines()
99
- with open_file_or_io(lines_obj) as fh:
100
- for line in fh:
101
+ for line in lines_obj:
102
+ if strip:
101
103
  line = line.strip()
104
+ if skip_empty:
102
105
  if line == "":
103
106
  continue
104
- yield line
107
+ yield line
108
+
109
+
110
+ def yield_lines_from_file(
111
+ file: PathType, strip: bool = True, skip_empty: bool = True, encoding: str = "utf-8"
112
+ ) -> Iterable[str]:
113
+ """
114
+ Read lines from input, strip whitespaces, skip empty lines, yield lines.
115
+
116
+ Args:
117
+ file: Either str or iterable of str (list, opened file)
118
+ strip: strip whitespace from lines
119
+ skip_empty: skip empty lines
120
+ encoding: encoding to use for reading
121
+
122
+ Returns:
123
+ Generator of stripped lines
124
+ """
125
+ content = Path(file).read_text(encoding=encoding)
126
+ yield from yield_lines_from_object(content, strip=strip, skip_empty=skip_empty)
@@ -1,7 +1,7 @@
1
1
  from pathlib import Path
2
2
  from typing import Dict
3
3
 
4
- from packg.iotools.file_reader import yield_nonempty_stripped_lines
4
+ from packg.iotools.file_reader import yield_lines_from_object
5
5
  from packg.iotools.misc import set_working_directory
6
6
  from packg.system import systemcall_with_assert
7
7
  from packg.typext import PathType
@@ -23,7 +23,7 @@ def parse_gitadd_dryrun_output(
23
23
  Alternative way to do this would be git status: https://git-scm.com/docs/git-status#_output
24
24
  """
25
25
  files = {}
26
- for line in yield_nonempty_stripped_lines(output.splitlines()):
26
+ for line in yield_lines_from_object(output.splitlines()):
27
27
  line_split = line.split(" ")
28
28
  status = line_split[0].strip()
29
29
  file = " ".join(line_split[1:]).strip()[1:-1]
@@ -1,5 +1,4 @@
1
1
  """
2
-
3
2
  - Utils for the loguru package
4
3
  https://loguru.readthedocs.io/en/stable/overview.html
5
4
  https://loguru.readthedocs.io/en/stable/resources/recipes.html#changing-the-level-of-an-existing-handler
@@ -12,19 +11,20 @@ Usage:
12
11
  configure_logger(level=get_logger_level_from_args(args), format=SHORTEST_FORMAT)
13
12
  logger.info("Hello")
14
13
  """
14
+ from __future__ import annotations
15
+
15
16
  import logging
16
17
  import os
17
18
  import sys
18
19
  from copy import deepcopy
19
20
  from logging import getLevelName
20
- from typing import Union, Optional, List, Any, Dict
21
21
 
22
22
  from loguru import logger
23
23
  from pathspec import PathSpec
24
24
 
25
25
  from packg.iotools.pathspec_matcher import make_pathspec
26
26
 
27
- LevelType = Union[str, int] # either "DEBUG" or 10
27
+ LevelType = str | int # either "DEBUG" or 10
28
28
  DEFAULT_LOGURU_FORMAT = (
29
29
  "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | "
30
30
  "<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
@@ -55,10 +55,10 @@ def configure_logger(
55
55
  sink=sys.stderr,
56
56
  format=SHORTEST_FORMAT, # noqa # pylint: disable=redefined-builtin
57
57
  colorize=True,
58
- add_sinks: Optional[List[Any]] = None,
59
- kwargs_handler: Optional[Dict[str, Any]] = None,
60
- **kwargs: Any,
61
- ) -> Dict[str, Any]:
58
+ add_sinks: list[any] | list[dict[str, any]] | None = None,
59
+ kwargs_handler: dict[str, any] | None = None,
60
+ **kwargs: any,
61
+ ) -> dict[str, any]:
62
62
  """
63
63
  Configure the loguru logger. For more complex usages, use logger.configure() directly.
64
64
 
@@ -67,7 +67,8 @@ def configure_logger(
67
67
  sink: where to write the logs to
68
68
  format: message formatting
69
69
  colorize: add color codes to the output
70
- add_sinks: other sinks to add (str will add a file sink)
70
+ add_sinks: list of other sinks to add. str sinks will write to file.
71
+ use a dictionary to change parameters format, colorize, level separately from main sink.
71
72
  kwargs_handler: additional parameters to pass to each handler
72
73
  **kwargs: additional parameters to pass to logger.configure()
73
74
 
@@ -83,13 +84,23 @@ def configure_logger(
83
84
  kwargs_handler = kwargs_handler if kwargs_handler is not None else {}
84
85
  sinks = [sink] + add_sinks
85
86
  handlers = []
87
+ level_str = get_level_as_str(level)
86
88
  for lsink in sinks:
87
- params = {
88
- "sink": lsink,
89
- "format": format,
90
- "colorize": colorize,
91
- "level": get_level_as_str(level),
92
- }
89
+ if isinstance(lsink, dict):
90
+ params = lsink
91
+ if "format" not in params:
92
+ params["format"] = format
93
+ if "colorize" not in params:
94
+ params["colorize"] = colorize
95
+ if "level" not in params:
96
+ params["level"] = level_str
97
+ else:
98
+ params = {
99
+ "sink": lsink,
100
+ "format": format,
101
+ "colorize": colorize,
102
+ "level": level_str,
103
+ }
93
104
  assert "sink" not in kwargs_handler, f"sink is a reserved key, got {params}"
94
105
  params.update(deepcopy(kwargs_handler))
95
106
  if isinstance(lsink, str):
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: packg
3
- Version: 0.7.2
3
+ Version: 0.9.2
4
4
  Summary: Collection of utilities used in other python projects.
5
- Author: gingsi
5
+ Author: simonging
6
6
  License: Apache-2.0
7
- Project-URL: Project-URL, https://github.com/gingsi/packg
7
+ Project-URL: Project-URL, https://github.com/simonging/packg
8
8
  Keywords: attrs,typing,dict,attr
9
9
  Platform: any
10
10
  Classifier: Development Status :: 3 - Alpha
@@ -36,13 +36,13 @@ Requires-Dist: requests
36
36
  # packg
37
37
 
38
38
  <p align="center">
39
- <a href="https://github.com/gingsi/packg/actions/workflows/build-py37.yml">
40
- <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/gingsi/packg/build-py37.yml?branch=main&label=build%203.7" />
39
+ <a href="https://github.com/simonging/packg/actions/workflows/build-py37.yml">
40
+ <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/simonging/packg/build-py37.yml?branch=main&label=build%203.7" />
41
41
  </a>
42
- <a href="https://github.com/gingsi/packg/actions/workflows/build-py310.yml">
43
- <img alt="build 3.10 status" title="build 3.10 status" src="https://img.shields.io/github/actions/workflow/status/gingsi/packg/build-py310.yml?branch=main&label=build%203.10" />
42
+ <a href="https://github.com/simonging/packg/actions/workflows/build-py310.yml">
43
+ <img alt="build 3.10 status" title="build 3.10 status" src="https://img.shields.io/github/actions/workflow/status/simonging/packg/build-py310.yml?branch=main&label=build%203.10" />
44
44
  </a>
45
- <img alt="coverage" title="coverage" src="https://raw.githubusercontent.com/gingsi/packg/main/docs/coverage.svg" />
45
+ <img alt="coverage" title="coverage" src="https://raw.githubusercontent.com/simonging/packg/main/docs/coverage.svg" />
46
46
  <a href="https://pypi.org/project/packg/">
47
47
  <img alt="version" title="version" src="https://img.shields.io/pypi/v/packg?color=success" />
48
48
  </a>
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes