omdev 0.0.0.dev41__py3-none-any.whl → 0.0.0.dev42__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
@@ -35,6 +35,18 @@
35
35
  }
36
36
  }
37
37
  },
38
+ {
39
+ "module": ".cli.clicmds",
40
+ "attr": "_CLI_MODULE",
41
+ "file": "omdev/cli/clicmds.py",
42
+ "line": 55,
43
+ "value": {
44
+ "$.cli.types.CliModule": {
45
+ "cmd_name": "cli",
46
+ "mod_name": "omdev.cli.clicmds"
47
+ }
48
+ }
49
+ },
38
50
  {
39
51
  "module": ".interp.__main__",
40
52
  "attr": "_CLI_MODULE",
omdev/cache/data/cache.py CHANGED
@@ -10,11 +10,14 @@ TODO:
10
10
  - chaining? or is this compcache..
11
11
  - download resume ala hf_hub
12
12
  """
13
+ import contextlib
13
14
  import logging
14
15
  import os.path
15
16
  import shutil
16
17
  import subprocess
17
18
  import tempfile
19
+ import typing as ta
20
+ import urllib.error
18
21
  import urllib.parse
19
22
  import urllib.request
20
23
 
@@ -40,6 +43,57 @@ log = logging.getLogger(__name__)
40
43
  ##
41
44
 
42
45
 
46
+ def _url_retrieve(
47
+ req: urllib.request.Request,
48
+ out_file: str | None = None,
49
+ ) -> tuple[str, ta.Any]:
50
+ p = urllib.parse.urlparse(req.full_url)
51
+
52
+ with contextlib.ExitStack() as es:
53
+ fp = es.enter_context(contextlib.closing(urllib.request.urlopen(req))) # noqa
54
+
55
+ headers = fp.info()
56
+
57
+ # Just return the local path and the "headers" for file:// URLs. No sense in performing a copy unless requested.
58
+ if p.scheme == 'file' and not out_file:
59
+ return os.path.normpath(p.path), headers
60
+
61
+ success = False
62
+
63
+ tfp: ta.Any
64
+ if out_file:
65
+ tfp = es.enter_context(open(out_file, 'wb'))
66
+
67
+ else:
68
+ tfp = es.enter_context(tempfile.NamedTemporaryFile(delete=False))
69
+ out_file = tfp.name
70
+
71
+ def _cleanup():
72
+ if not success and out_file:
73
+ os.unlink(out_file)
74
+
75
+ es.enter_context(lang.defer(_cleanup)) # noqa
76
+
77
+ result = out_file, headers
78
+ size = -1
79
+ read = 0
80
+ if 'content-length' in headers:
81
+ size = int(headers['Content-Length'])
82
+
83
+ while block := fp.read(1024 * 8):
84
+ read += len(block)
85
+ tfp.write(block)
86
+
87
+ if size >= 0 and read < size:
88
+ raise urllib.error.ContentTooShortError(
89
+ f'retrieval incomplete: got only {read} out of {size} bytes',
90
+ result, # type: ignore
91
+ )
92
+
93
+ success = True
94
+ return result # type: ignore
95
+
96
+
43
97
  class Cache:
44
98
  def __init__(self, base_dir: str) -> None:
45
99
  super().__init__()
@@ -49,16 +103,32 @@ class Cache:
49
103
 
50
104
  #
51
105
 
52
- def _fetch_url(self, url: str, out_file: str) -> None:
106
+ def _fetch_url(
107
+ self,
108
+ url: str,
109
+ out_file: str,
110
+ *,
111
+ headers: ta.Mapping[str, str] | None = None,
112
+ ) -> None:
53
113
  log.info('Fetching url: %s -> %s', url, out_file)
54
114
 
55
- urllib.request.urlretrieve(url, out_file) # noqa
115
+ _url_retrieve(
116
+ urllib.request.Request( # noqa
117
+ url,
118
+ **(dict(headers=headers) if headers is not None else {}), # type: ignore
119
+ ),
120
+ out_file,
121
+ )
56
122
 
57
123
  def _fetch_into(self, spec: Spec, data_dir: str) -> None:
58
124
  log.info('Fetching spec: %s %r -> %s', spec.digest, spec, data_dir)
59
125
 
60
126
  if isinstance(spec, UrlSpec):
61
- self._fetch_url(spec.url, os.path.join(data_dir, spec.file_name_or_default))
127
+ self._fetch_url(
128
+ spec.url,
129
+ os.path.join(data_dir, spec.file_name_or_default),
130
+ headers=spec.headers,
131
+ )
62
132
 
63
133
  elif isinstance(spec, GithubContentSpec):
64
134
  for repo_file in spec.files:
@@ -104,7 +174,7 @@ class Cache:
104
174
 
105
175
  def _perform_action(self, action: Action, data_dir: str) -> None:
106
176
  if isinstance(action, ExtractAction):
107
- for f in action.files:
177
+ for f in [action.files] if isinstance(action.files, str) else action.files:
108
178
  file = os.path.join(data_dir, f)
109
179
  if not os.path.isfile(file):
110
180
  raise Exception(f'Not file: {file}')
omdev/cache/data/specs.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import hashlib
2
+ import operator
2
3
  import typing as ta
3
4
  import urllib.parse
4
5
  import urllib.request
@@ -59,6 +60,10 @@ class UrlSpec(Spec):
59
60
  url: str = dc.xfield(validate=lambda u: bool(urllib.parse.urlparse(u)))
60
61
  file_name: str | None = None
61
62
 
63
+ _: dc.KW_ONLY
64
+
65
+ headers: ta.Mapping[str, str] | None = dc.field(default=None) | msh.update_field_metadata(omit_if=operator.not_)
66
+
62
67
  @cached.property
63
68
  def file_name_or_default(self) -> str:
64
69
  if self.file_name is not None:
omdev/cli/clicmds.py ADDED
@@ -0,0 +1,81 @@
1
+ import argparse
2
+ import inspect
3
+ import os
4
+ import subprocess
5
+ import sys
6
+
7
+ from omlish import __about__
8
+
9
+ from . import install
10
+ from .types import CliModule
11
+
12
+
13
+ def _print_version(args) -> None:
14
+ print(__about__.__version__)
15
+
16
+
17
+ def _print_revision(args) -> None:
18
+ print(__about__.__revision__)
19
+
20
+
21
+ def _reinstall(args) -> None:
22
+ mod_name = globals()['__spec__'].name
23
+ tool_name = '.'.join([mod_name.partition('.')[0], 'tools', 'piptools'])
24
+
25
+ out = subprocess.check_output([
26
+ sys.executable,
27
+ '-m',
28
+ tool_name,
29
+ 'list-root-dists',
30
+ ]).decode()
31
+
32
+ deps = sorted(
33
+ ({s for l in out.splitlines() if (s := l.strip())} | set(args.extra_deps or []))
34
+ - {install.DEFAULT_CLI_PKG} # noqa
35
+ )
36
+
37
+ if deps:
38
+ print('Reinstalling with following additional dependencies:')
39
+ print('\n'.join(' ' + d for d in deps))
40
+ else:
41
+ print('No additional dependencies detected.')
42
+ print()
43
+ print('Continue with reinstall? (ctrl-c to cancel)')
44
+ input()
45
+
46
+ install_src = inspect.getsource(install)
47
+
48
+ os.execl(
49
+ sys.executable,
50
+ '-c',
51
+ install_src,
52
+ )
53
+
54
+
55
+ # @omlish-manifest
56
+ _CLI_MODULE = CliModule('cli', __name__)
57
+
58
+
59
+ def _main(argv=None) -> None:
60
+ parser = argparse.ArgumentParser()
61
+ subparsers = parser.add_subparsers()
62
+
63
+ parser_version = subparsers.add_parser('version')
64
+ parser_version.set_defaults(func=_print_version)
65
+
66
+ parser_revision = subparsers.add_parser('revision')
67
+ parser_revision.set_defaults(func=_print_revision)
68
+
69
+ parser_reinstall = subparsers.add_parser('reinstall')
70
+ parser_reinstall.add_argument('extra_deps', nargs='*')
71
+ parser_reinstall.set_defaults(func=_reinstall)
72
+
73
+ args = parser.parse_args(argv)
74
+ if not getattr(args, 'func', None):
75
+ parser.print_help()
76
+ else:
77
+ args.func(args)
78
+
79
+
80
+ if __name__ == '__main__':
81
+ _main()
omdev/cli/main.py CHANGED
@@ -10,8 +10,8 @@ import argparse
10
10
  import os
11
11
  import runpy
12
12
  import sys
13
+ import typing as ta
13
14
 
14
- from omlish import __about__
15
15
  from omlish import check
16
16
 
17
17
  from ..manifests.load import ManifestLoader
@@ -23,18 +23,7 @@ from .types import CliModule
23
23
  ##
24
24
 
25
25
 
26
- def _print_version() -> None:
27
- print(__about__.__version__)
28
-
29
-
30
- def _print_revision() -> None:
31
- print(__about__.__revision__)
32
-
33
-
34
- _CLI_FUNCS = [
35
- CliFunc('version', _print_version),
36
- CliFunc('revision', _print_revision),
37
- ]
26
+ _CLI_FUNCS: ta.Sequence[CliFunc] = []
38
27
 
39
28
 
40
29
  ##
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omdev
3
- Version: 0.0.0.dev41
3
+ Version: 0.0.0.dev42
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.dev41
15
+ Requires-Dist: omlish ==0.0.0.dev42
16
16
  Provides-Extra: all
17
17
  Requires-Dist: pycparser ~=2.22 ; extra == 'all'
18
18
  Requires-Dist: cffi ~=1.17 ; extra == 'all'
@@ -1,4 +1,4 @@
1
- omdev/.manifests.json,sha256=SYxLyDL2tE-9_8Zsc6xO9VeqIvgxje-MbeEOkl50GJI,3674
1
+ omdev/.manifests.json,sha256=VyNtklh8T2PrsSc2qnFCoWm4_s9MBnvgKKm5a9CGBbE,3921
2
2
  omdev/__about__.py,sha256=LqSNNFFcT84xW3W8fIOJ78kPYJKFLIXZyDX-AJREvN0,1005
3
3
  omdev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  omdev/bracepy.py,sha256=HwBK5XmlOsF_juTel25fRLJK9vHSJCWXuCc-OZlevRQ,2619
@@ -25,11 +25,11 @@ omdev/cache/compute/storage.py,sha256=woCUqHg8ZrwLEejRG3zu1L5ZXxGNNXveh3E8FnlEkj
25
25
  omdev/cache/compute/types.py,sha256=NpCTTJHDmpERjrbO6dh9TEzHuP6-vOuoX3ym9sA0ukc,2639
26
26
  omdev/cache/data/__init__.py,sha256=SQXtugLceRif463rcoklpQ33pxYLgEIm0xiI6NvOI6M,301
27
27
  omdev/cache/data/actions.py,sha256=KVYb3tBYP5c0g-wK1bXih_K7L0ER9UINKChhfc7mwKQ,1071
28
- omdev/cache/data/cache.py,sha256=WSsbFyFRT_IQFYQCrmUpaTvs9DRglLmCnhguOzdJ6p4,5753
28
+ omdev/cache/data/cache.py,sha256=NRi1WJHVixt9tL_JpOPZqOow8aIaapXCMwIkk2JlM-k,7719
29
29
  omdev/cache/data/consts.py,sha256=d6W_aeMqgah6PmPYi9RA8Be54oQ4BcNCy8kDQ7FlB_Q,26
30
30
  omdev/cache/data/defaults.py,sha256=HrapVUIf9Ozu3qSfRPyQj-vx-dz6Yyedjb-k3yV4CW8,277
31
31
  omdev/cache/data/manifests.py,sha256=CupK71fL3_PnDzUqjrWLNt64KfGKF-K4ycMkT5p0gPA,979
32
- omdev/cache/data/specs.py,sha256=h2yGkDAZ5tGpqJ280QyglFodTNf_WP1GHJo6koQ-sTk,2313
32
+ omdev/cache/data/specs.py,sha256=4eQ1o8Oxd7AWkcCGy1FgH2Sa0B9uqhp1UFO45eUAH1c,2466
33
33
  omdev/cexts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  omdev/cexts/_boilerplate.cc,sha256=sbpXEgdFrkdzZXgaNWFFNN27fL9TZu6VrwvMY4-nnFM,1726
35
35
  omdev/cexts/build.py,sha256=F3z1-CjDlEM-Gzi5IunKUBO52qdH_pMsFylobTdGJnI,2654
@@ -55,8 +55,9 @@ omdev/cexts/_distutils/compilers/options.py,sha256=H7r5IcLvga5Fs3jjXWIT-6ap3JBdu
55
55
  omdev/cexts/_distutils/compilers/unixccompiler.py,sha256=o1h8QuyupLntv4F21_XjzAZmCiwwxJuTmOirvBSL-Qw,15419
56
56
  omdev/cli/__init__.py,sha256=V_l6VP1SZMlJbO-8CJwSuO9TThOy2S_oaPepNYgIrbE,37
57
57
  omdev/cli/__main__.py,sha256=d23loR_cKfTYZwYiqpt_CmKI7dd5WcYFgIYzqMep75E,68
58
+ omdev/cli/clicmds.py,sha256=KLbd1yEnktXezKlQthPGtgSOaDJljtwBpQ0buiv7Wr4,1884
58
59
  omdev/cli/install.py,sha256=-pFczwyJn48IeqCswbJzrV15ZslQUNIcREiiOGSjDk0,3933
59
- omdev/cli/main.py,sha256=QURTY6GfDFVBztUPiUFJEPyJOSkgg3S06USrX5C60FQ,2082
60
+ omdev/cli/main.py,sha256=rGc8SIk-czOS9eILZbzu27nx3ezjc54fn880OWskpYE,1880
60
61
  omdev/cli/types.py,sha256=7_Owg0P8C8oOObSuOp6aEYSjkEukVFxTT00SRy1bLHM,250
61
62
  omdev/interp/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
62
63
  omdev/interp/__main__.py,sha256=GMCqeGYltgt5dlJzHxY9gqisa8cRkrPfmZYuZnjg4WI,162
@@ -111,9 +112,9 @@ omdev/tools/piptools.py,sha256=lhwzGXD-v0KFEQNyvzvdO2Kw1OA_2AfGPBs_rIkz8iE,2772
111
112
  omdev/tools/proftools.py,sha256=xKSm_yPoCnfsvS3iT9MblDqFMuZmGfI3_koGj8amMyU,145
112
113
  omdev/tools/rst.py,sha256=6dWk8QZHoGiLSuBw3TKsXZjjFK6wWBEtPi9krdCLKKg,977
113
114
  omdev/tools/sqlrepl.py,sha256=tmFZh80-xsGM62dyQ7_UGLebChrj7IHbIPYBWDJMgVk,5741
114
- omdev-0.0.0.dev41.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
115
- omdev-0.0.0.dev41.dist-info/METADATA,sha256=MnG0-T3ddr5dIIQCMxI0RE8fnrT6jvnkPj6eoR1zlRA,1252
116
- omdev-0.0.0.dev41.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
117
- omdev-0.0.0.dev41.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
118
- omdev-0.0.0.dev41.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
119
- omdev-0.0.0.dev41.dist-info/RECORD,,
115
+ omdev-0.0.0.dev42.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
116
+ omdev-0.0.0.dev42.dist-info/METADATA,sha256=a6sd2zo1gI_x0q3_paVbfppiUnNDT7TBrJBlTF7BPDk,1252
117
+ omdev-0.0.0.dev42.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
118
+ omdev-0.0.0.dev42.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
119
+ omdev-0.0.0.dev42.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
120
+ omdev-0.0.0.dev42.dist-info/RECORD,,