omdev 0.0.0.dev107__py3-none-any.whl → 0.0.0.dev109__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 omdev might be problematic. Click here for more details.

omdev/.manifests.json CHANGED
@@ -282,7 +282,7 @@
282
282
  "module": ".tools.pip",
283
283
  "attr": "_CLI_MODULE",
284
284
  "file": "omdev/tools/pip.py",
285
- "line": 88,
285
+ "line": 164,
286
286
  "value": {
287
287
  "$.cli.types.CliModule": {
288
288
  "cmd_name": "pip",
@@ -302,6 +302,18 @@
302
302
  }
303
303
  }
304
304
  },
305
+ {
306
+ "module": ".tools.qr",
307
+ "attr": "_CLI_MODULE",
308
+ "file": "omdev/tools/qr.py",
309
+ "line": 74,
310
+ "value": {
311
+ "$.cli.types.CliModule": {
312
+ "cmd_name": "qr",
313
+ "mod_name": "omdev.tools.qr"
314
+ }
315
+ }
316
+ },
305
317
  {
306
318
  "module": ".tools.sqlrepl",
307
319
  "attr": "_CLI_MODULE",
omdev/__about__.py CHANGED
@@ -41,6 +41,10 @@ class Project(ProjectBase):
41
41
  'prompt-toolkit ~= 3.0',
42
42
  ],
43
43
 
44
+ 'qr': [
45
+ 'segno ~= 1.6',
46
+ ],
47
+
44
48
  'tokens': [
45
49
  'tokenize-rt ~= 6.1',
46
50
  ],
@@ -1 +0,0 @@
1
- # @omlish-lite
@@ -0,0 +1,82 @@
1
+ """
2
+ NOTE: This cannot be auto-imported as @omlish-lite usage of other modules in this package requires it be importable on
3
+ 8.
4
+ """
5
+ import dataclasses as dc
6
+ import typing as ta
7
+
8
+ from omlish import lang
9
+ from omlish import marshal as msh
10
+ from omlish import matchfns as mfs
11
+ from omlish import reflect as rfl
12
+
13
+ from .requires import RequiresMarkerItem
14
+ from .requires import RequiresMarkerList
15
+ from .requires import RequiresNode
16
+ from .requires import RequiresOp
17
+ from .requires import RequiresValue
18
+ from .requires import RequiresVariable
19
+
20
+
21
+ ##
22
+
23
+
24
+ class MarshalRequiresMarkerList(lang.NotInstantiable, lang.Final):
25
+ pass
26
+
27
+
28
+ @dc.dataclass(frozen=True)
29
+ class RequiresMarkerListMarshaler(msh.Marshaler):
30
+ item_m: msh.Marshaler
31
+ node_m: msh.Marshaler
32
+
33
+ def marshal(self, ctx: msh.MarshalContext, o: ta.Any) -> msh.Value:
34
+ def inner(c: ta.Any) -> ta.Any:
35
+ if isinstance(c, str):
36
+ return c
37
+ elif isinstance(c, RequiresMarkerItem):
38
+ return self.item_m.marshal(ctx, c)
39
+ elif isinstance(c, ta.Iterable):
40
+ return [inner(e) for e in c]
41
+ else:
42
+ raise TypeError(c)
43
+ return [inner(e) for e in o]
44
+
45
+
46
+ class RequiresMarkerListMarshalerFactory(msh.MarshalerFactoryMatchClass):
47
+ @mfs.simple(lambda _, ctx, rty: rty is MarshalRequiresMarkerList)
48
+ def _build(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
49
+ return RequiresMarkerListMarshaler(
50
+ ctx.make(RequiresMarkerItem),
51
+ ctx.make(RequiresNode),
52
+ )
53
+
54
+
55
+ ##
56
+
57
+
58
+ @lang.static_init
59
+ def _install_standard_marshalling() -> None:
60
+ requires_node_poly = msh.Polymorphism(
61
+ RequiresNode,
62
+ [
63
+ msh.Impl(RequiresVariable, 'variable'),
64
+ msh.Impl(RequiresValue, 'value'),
65
+ msh.Impl(RequiresOp, 'op'),
66
+ ],
67
+ )
68
+ msh.STANDARD_MARSHALER_FACTORIES[0:0] = [
69
+ msh.PolymorphismMarshalerFactory(requires_node_poly),
70
+ msh.PolymorphismUnionMarshalerFactory(requires_node_poly.impls, allow_partial=True),
71
+ RequiresMarkerListMarshalerFactory(),
72
+
73
+ ]
74
+ msh.STANDARD_UNMARSHALER_FACTORIES[0:0] = [
75
+ msh.PolymorphismUnmarshalerFactory(requires_node_poly),
76
+ ]
77
+
78
+ msh.GLOBAL_REGISTRY.register(
79
+ RequiresMarkerList,
80
+ msh.ReflectOverride(MarshalRequiresMarkerList),
81
+ identity=True,
82
+ )
omdev/packaging/names.py CHANGED
@@ -1,3 +1,4 @@
1
+ # @omlish-lite
1
2
  # Copyright (c) Donald Stufft and individual contributors.
2
3
  # All rights reserved.
3
4
  #
@@ -1,3 +1,4 @@
1
+ # @omlish-lite
1
2
  # Copyright (c) Donald Stufft and individual contributors.
2
3
  # All rights reserved.
3
4
  #
@@ -194,10 +195,9 @@ class RequiresTokenizer:
194
195
  self.read()
195
196
 
196
197
 
198
+ @dc.dataclass(frozen=True)
197
199
  class RequiresNode:
198
- def __init__(self, value: str) -> None:
199
- super().__init__()
200
- self.value = value
200
+ value: str
201
201
 
202
202
  def __str__(self) -> str:
203
203
  return self.value
@@ -209,27 +209,36 @@ class RequiresNode:
209
209
  raise NotImplementedError
210
210
 
211
211
 
212
+ @dc.dataclass(frozen=True)
212
213
  class RequiresVariable(RequiresNode):
213
214
  def serialize(self) -> str:
214
215
  return str(self)
215
216
 
216
217
 
218
+ @dc.dataclass(frozen=True)
217
219
  class RequiresValue(RequiresNode):
218
220
  def serialize(self) -> str:
219
221
  return f'"{self}"'
220
222
 
221
223
 
224
+ @dc.dataclass(frozen=True)
222
225
  class RequiresOp(RequiresNode):
223
226
  def serialize(self) -> str:
224
227
  return str(self)
225
228
 
226
229
 
227
230
  RequiresMarkerVar = ta.Union['RequiresVariable', 'RequiresValue']
228
- RequiresMarkerItem = ta.Tuple['RequiresMarkerVar', 'RequiresOp', 'RequiresMarkerVar']
231
+
229
232
  RequiresMarkerAtom = ta.Union['RequiresMarkerItem', ta.Sequence['RequiresMarkerAtom']]
230
233
  RequiresMarkerList = ta.Sequence[ta.Union['RequiresMarkerList', 'RequiresMarkerAtom', str]]
231
234
 
232
235
 
236
+ class RequiresMarkerItem(ta.NamedTuple):
237
+ l: ta.Union[RequiresVariable, RequiresValue]
238
+ op: RequiresOp
239
+ r: ta.Union[RequiresVariable, RequiresValue]
240
+
241
+
233
242
  class ParsedRequirement(ta.NamedTuple):
234
243
  name: str
235
244
  url: str
@@ -441,7 +450,7 @@ def _parse_requires_marker_item(tokenizer: RequiresTokenizer) -> RequiresMarkerI
441
450
  tokenizer.consume('WS')
442
451
  marker_var_right = _parse_requires_marker_var(tokenizer)
443
452
  tokenizer.consume('WS')
444
- return (marker_var_left, marker_op, marker_var_right)
453
+ return RequiresMarkerItem(marker_var_left, marker_op, marker_var_right)
445
454
 
446
455
 
447
456
  def _parse_requires_marker_var(tokenizer: RequiresTokenizer) -> RequiresMarkerVar:
@@ -1,3 +1,4 @@
1
+ # @omlish-lite
1
2
  # Copyright (c) Donald Stufft and individual contributors.
2
3
  # All rights reserved.
3
4
  #
@@ -1,3 +1,4 @@
1
+ # @omlish-lite
1
2
  # Copyright (c) Donald Stufft and individual contributors.
2
3
  # All rights reserved.
3
4
  #
omdev/tools/pip.py CHANGED
@@ -1,18 +1,35 @@
1
+ """
2
+ TODO:
3
+ - https://github.com/pypa/pip/blob/420435903ff2fc694d6950a47b896427ecaed78f/src/pip/_internal/req/req_file.py ?
4
+ """
5
+ import contextlib
1
6
  import importlib.metadata
2
7
  import io
8
+ import os.path
3
9
  import sys
10
+ import typing as ta
4
11
  import urllib.request
5
- import xml.etree.ElementTree as ET # noqa
6
12
 
7
13
  from omlish import argparse as ap
8
14
  from omlish import check
15
+ from omlish import lang
16
+ from omlish import marshal as msh
17
+ from omlish.formats import json
9
18
 
10
19
  from ..cli import CliModule
20
+ from ..packaging import marshal as _ # noqa
11
21
  from ..packaging.names import canonicalize_name
22
+ from ..packaging.requires import ParsedRequirement
12
23
  from ..packaging.requires import RequiresVariable
13
24
  from ..packaging.requires import parse_requirement
14
25
 
15
26
 
27
+ if ta.TYPE_CHECKING:
28
+ import xml.etree.ElementTree as ET # noqa
29
+ else:
30
+ ET = lang.proxy_import('xml.etree.ElementTree')
31
+
32
+
16
33
  PYPI_URL = 'https://pypi.org/'
17
34
 
18
35
 
@@ -84,6 +101,65 @@ class Cli(ap.Cli):
84
101
  if not uses_by_req.get(d):
85
102
  print(d)
86
103
 
104
+ @ap.command(
105
+ ap.arg('files', nargs='*'),
106
+ ap.arg('-r', '--follow-requirements', action='store_true'),
107
+ ap.arg('-j', '--json', action='store_true'),
108
+ ap.arg('-b', '--bare', action='store_true'),
109
+ )
110
+ def parse(self) -> None:
111
+ def print_req(req: ParsedRequirement) -> None:
112
+ if self.args.json:
113
+ req_m = msh.marshal(req)
114
+ print(json.dumps(req_m))
115
+
116
+ elif self.args.bare:
117
+ print(req.name)
118
+
119
+ else:
120
+ print(f'{req.name}{req.specifier or ""}')
121
+
122
+ #
123
+
124
+ seen_files: set[str] = set()
125
+
126
+ def do_file(file: ta.TextIO | str) -> None:
127
+ if isinstance(file, str) and file in seen_files:
128
+ return
129
+
130
+ with contextlib.ExitStack() as es:
131
+ f: ta.TextIO
132
+ if isinstance(file, str):
133
+ f = es.enter_context(open(file))
134
+ else:
135
+ f = file
136
+
137
+ for l in f:
138
+ if '#' in l:
139
+ l = l.partition('#')[0]
140
+
141
+ if not (l := l.strip()):
142
+ continue
143
+
144
+ if l.startswith('git+'):
145
+ continue # FIXME
146
+
147
+ elif l.startswith('-r'): # noqa
148
+ if self.args.follow_requirements:
149
+ base_dir = os.path.dirname(file) if isinstance(file, str) else '.'
150
+ r_file = os.path.join(base_dir, l[2:].strip())
151
+ do_file(r_file)
152
+
153
+ else:
154
+ req = parse_requirement(l)
155
+ print_req(req)
156
+
157
+ if self.args.files:
158
+ for file in self.args.files:
159
+ do_file(file)
160
+ else:
161
+ do_file(sys.stdin)
162
+
87
163
 
88
164
  # @omlish-manifest
89
165
  _CLI_MODULE = CliModule('pip', __name__)
omdev/tools/qr.py ADDED
@@ -0,0 +1,79 @@
1
+ """
2
+ https://segno.readthedocs.io/en/stable/comparison-qrcode-libs.html
3
+ - https://github.com/nayuki/QR-Code-generator
4
+ - https://github.com/heuer/segno/
5
+ - https://github.com/lincolnloop/python-qrcode
6
+ """
7
+ import argparse
8
+ import os
9
+ import subprocess
10
+ import sys
11
+ import tempfile
12
+ import typing as ta
13
+
14
+ from omlish import lang
15
+
16
+ from ..cli import CliModule
17
+
18
+
19
+ if ta.TYPE_CHECKING:
20
+ import segno
21
+ else:
22
+ segno = lang.proxy_import('segno')
23
+
24
+
25
+ def _main() -> None:
26
+ parser = argparse.ArgumentParser()
27
+ parser.add_argument('content', nargs='?')
28
+
29
+ parser.add_argument('-x', '--target-size', type=int)
30
+
31
+ parser.add_argument('-o', '--output')
32
+ parser.add_argument('-O', '--open', action='store_true')
33
+
34
+ parser.add_argument(
35
+ '--error', '-e',
36
+ help=(
37
+ 'Error correction level: '
38
+ '"L": 7%% (default), '
39
+ '"M": 15%%, '
40
+ '"Q": 25%%, '
41
+ '"H": 30%%, '
42
+ '"-": no error correction (used for M1 symbols)'
43
+ ),
44
+ choices=('L', 'M', 'Q', 'H', '-'),
45
+ )
46
+ args = parser.parse_args()
47
+
48
+ if (content := args.content) is None:
49
+ content = sys.stdin.read()
50
+
51
+ qr = segno.make(content)
52
+
53
+ if (tx := args.target_size) is not None:
54
+ sz = max(*qr.symbol_size())
55
+ sc = max(float(tx) / sz, 1)
56
+ else:
57
+ sc = 1
58
+
59
+ if args.output is not None:
60
+ out_file = args.output
61
+ else:
62
+ fd, out_file = tempfile.mkstemp(suffix='-qrcode.png')
63
+ os.close(fd)
64
+
65
+ qr.save(out_file, scale=sc)
66
+
67
+ if args.output is None:
68
+ print(out_file)
69
+
70
+ if args.open:
71
+ subprocess.check_call(['open', out_file])
72
+
73
+
74
+ # @omlish-manifest
75
+ _CLI_MODULE = CliModule('qr', __name__)
76
+
77
+
78
+ if __name__ == '__main__':
79
+ _main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omdev
3
- Version: 0.0.0.dev107
3
+ Version: 0.0.0.dev109
4
4
  Summary: omdev
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -12,7 +12,7 @@ Classifier: Operating System :: OS Independent
12
12
  Classifier: Operating System :: POSIX
13
13
  Requires-Python: >=3.12
14
14
  License-File: LICENSE
15
- Requires-Dist: omlish ==0.0.0.dev107
15
+ Requires-Dist: omlish ==0.0.0.dev109
16
16
  Provides-Extra: all
17
17
  Requires-Dist: black ~=24.10 ; extra == 'all'
18
18
  Requires-Dist: pycparser ~=2.22 ; extra == 'all'
@@ -23,6 +23,7 @@ Requires-Dist: markdown ~=3.7 ; extra == 'all'
23
23
  Requires-Dist: mypy ~=1.11 ; extra == 'all'
24
24
  Requires-Dist: gprof2dot ~=2024.6 ; extra == 'all'
25
25
  Requires-Dist: prompt-toolkit ~=3.0 ; extra == 'all'
26
+ Requires-Dist: segno ~=1.6 ; extra == 'all'
26
27
  Requires-Dist: tokenize-rt ~=6.1 ; extra == 'all'
27
28
  Requires-Dist: wheel ~=0.44 ; extra == 'all'
28
29
  Provides-Extra: black
@@ -40,6 +41,8 @@ Provides-Extra: prof
40
41
  Requires-Dist: gprof2dot ~=2024.6 ; extra == 'prof'
41
42
  Provides-Extra: ptk
42
43
  Requires-Dist: prompt-toolkit ~=3.0 ; extra == 'ptk'
44
+ Provides-Extra: qr
45
+ Requires-Dist: segno ~=1.6 ; extra == 'qr'
43
46
  Provides-Extra: tokens
44
47
  Requires-Dist: tokenize-rt ~=6.1 ; extra == 'tokens'
45
48
  Provides-Extra: wheel
@@ -1,5 +1,5 @@
1
- omdev/.manifests.json,sha256=V5q8HDU47d2-GTm_W_-iEVx0R8weTrzg_3PcmNCZXxA,6713
2
- omdev/__about__.py,sha256=ON7EnhbxbwLsMj60wkd9OEYPloXZ7jmnMMzeLg44LXY,1225
1
+ omdev/.manifests.json,sha256=7k8X6dwsYix3aVgNr4us8gpWAOW47Kr6PvOwgERlXyA,6951
2
+ omdev/__about__.py,sha256=n5x-SO70OgbDQFzQ1d7sZDVMsnkQc4PxQZPFaIQFa0E,1281
3
3
  omdev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  omdev/bracepy.py,sha256=I8EdqtDvxzAi3I8TuMEW-RBfwXfqKbwp06CfOdj3L1o,2743
5
5
  omdev/classdot.py,sha256=YOvgy6x295I_8NKBbBlRVd3AN7Osirm_Lqt4Wj0j9rY,1631
@@ -89,11 +89,12 @@ omdev/manifests/load.py,sha256=LtEsluDdd8CkNGj0QGBxee3twBn095Fru0xz2mtr7uk,4788
89
89
  omdev/manifests/types.py,sha256=Jv6PAdVLPb9Hh4y6vDhPlWuMNBBViin1bC_u83jfsH4,234
90
90
  omdev/mypy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
91
91
  omdev/mypy/debug.py,sha256=WcZw-3Z1njg_KFGqi3DB6RuqbBa3dLArJnjVCuY1Mn0,3003
92
- omdev/packaging/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
93
- omdev/packaging/names.py,sha256=lwws9dgClio0_-w6fZcihOKxx4FPkrHUxum918KjZO8,2513
94
- omdev/packaging/requires.py,sha256=VQ-rRDK4_w2R-0xMTbLCwhvZwkO-qgS8uEMbRhNmfOw,15598
95
- omdev/packaging/specifiers.py,sha256=6Odf9e6farwlPRsD_YqwTfYKG-BXn_dIcKtqfkhfodI,17432
96
- omdev/packaging/versions.py,sha256=ei2eopEsJq3zSMJmezK1nzZgikgCdxFtnF3f69nCRZQ,12246
92
+ omdev/packaging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
93
+ omdev/packaging/marshal.py,sha256=mWRuZ_okYxRJXylKFQLQpC8Pp7xjkUEfWYNzQIS5A2c,2376
94
+ omdev/packaging/names.py,sha256=-a7AykFPVR1i6EYJepbe3ABRrZQ_tPPmK5olzbn9HLI,2528
95
+ omdev/packaging/requires.py,sha256=kyyVCM0RyaKqmXd6tU5zf0QjWvCLQMNV_ev5hvOee_o,15731
96
+ omdev/packaging/specifiers.py,sha256=X8xOcwRLXTQYx5mYAS3ijqoTLlCtYESyUu4fX9bvblY,17447
97
+ omdev/packaging/versions.py,sha256=K4eUOUvLmYcR4aeUywekeWTBqAvZchrIxLf7dl07MS4,12261
97
98
  omdev/precheck/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
98
99
  omdev/precheck/__main__.py,sha256=UEuS4z5-heIrwTtB-ONe1KeXJdqj8tYXMqWMpuO10so,165
99
100
  omdev/precheck/base.py,sha256=a_lGoFM-QhL8u8XDUYFhb-feEyfPbP4j8lcmNO51sHY,732
@@ -130,15 +131,16 @@ omdev/tools/git.py,sha256=87DrMPtMLVPJ0R6yazX8JkKe8KIQyfEAcI0tYIQgKjU,4188
130
131
  omdev/tools/importscan.py,sha256=QeGjR3UGcuuuDUiisFuAXWHlcKJScGxGEcU6tfOh2CM,4069
131
132
  omdev/tools/mkrelimp.py,sha256=wsJAjTIf3nqcSfnT9TkDpS1VUOoM9W2Az5tZdWuzyLM,4054
132
133
  omdev/tools/notebook.py,sha256=M8Xi_gfZdlahnyFLtp0RBgYZPSHWQStMMDYZc71Zync,3494
133
- omdev/tools/pip.py,sha256=-jR5q3w4sHqntxCLExFCBNIARB788FUsAbJ62PK2sBU,2774
134
+ omdev/tools/pip.py,sha256=_O7WAACQ1F1ffH4ogZHcppT4P8VQxWQchJMLn9FvsJc,5073
134
135
  omdev/tools/prof.py,sha256=8ZU9x_Dq8eT2ZFwU9sJpDIvxcIn9qBc8y2ELKPb5e5M,1382
136
+ omdev/tools/qr.py,sha256=tm68lPwEAkEwIL2sUKPKBYfwwPtjVWG1DBZwur8_jY8,1737
135
137
  omdev/tools/sqlrepl.py,sha256=tmFZh80-xsGM62dyQ7_UGLebChrj7IHbIPYBWDJMgVk,5741
136
138
  omdev/tools/pawk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
137
139
  omdev/tools/pawk/__main__.py,sha256=VCqeRVnqT1RPEoIrqHFSu4PXVMg4YEgF4qCQm90-eRI,66
138
140
  omdev/tools/pawk/pawk.py,sha256=Eckymn22GfychCQcQi96BFqRo_LmiJ-EPhC8TTUJdB4,11446
139
- omdev-0.0.0.dev107.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
140
- omdev-0.0.0.dev107.dist-info/METADATA,sha256=YvVixJXzhPOArqpAuSbxYpi67N4-8pmSm4kcBZjTm8E,1704
141
- omdev-0.0.0.dev107.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
142
- omdev-0.0.0.dev107.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
143
- omdev-0.0.0.dev107.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
144
- omdev-0.0.0.dev107.dist-info/RECORD,,
141
+ omdev-0.0.0.dev109.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
142
+ omdev-0.0.0.dev109.dist-info/METADATA,sha256=7MFiPl54Th78lW2YIYpz80vxX6hgmmMSkQbZTruU3YA,1810
143
+ omdev-0.0.0.dev109.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
144
+ omdev-0.0.0.dev109.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
145
+ omdev-0.0.0.dev109.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
146
+ omdev-0.0.0.dev109.dist-info/RECORD,,