vocker 0.1.0__py3-none-any.whl → 0.2.0__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.
vocker/system.py CHANGED
@@ -16,8 +16,9 @@ import typing as ty
16
16
 
17
17
  import atomicwrites
18
18
  import attr
19
+ import marshmallow as ma
20
+ import marshmallow.fields as maf
19
21
  import platformdirs
20
- import strictyaml as sy
21
22
  import structlog
22
23
 
23
24
  from . import dedup as de, multihash as mh, image as im
@@ -40,10 +41,6 @@ def validate_local_repo_name(name: str) -> None:
40
41
  raise ValueError(f"invalid repo name: {name!r}")
41
42
 
42
43
 
43
- def cget(x, *args):
44
- return x.value.get(*args)
45
-
46
-
47
44
  @attr.s(eq=False, hash=False)
48
45
  class RemoteRepository:
49
46
  uri: str = attr.ib()
@@ -73,7 +70,8 @@ class _Remotes(MutableMapping[str, RemoteRepository]):
73
70
  return self.system._config["remote_repositories"]
74
71
 
75
72
  def __getitem__(self, k):
76
- d = self._data[k].data
73
+ d = self._data[k]
74
+ d.pop("comment", None)
77
75
  return RemoteRepository(**d)
78
76
 
79
77
  def __setitem__(self, k, v: RemoteRepository | None):
@@ -90,21 +88,25 @@ class _Remotes(MutableMapping[str, RemoteRepository]):
90
88
  self[k] = None
91
89
 
92
90
  def __iter__(self):
93
- return iter(x.value for x in self._data.value)
91
+ return iter(x for x in self._data)
94
92
 
95
93
  def __len__(self, k, v):
96
- return len(self._data.value)
94
+ return len(self._data)
95
+
96
+
97
+ class _SchemaWithComment(ma.Schema):
98
+ class Meta:
99
+ unknown = ma.RAISE
100
+
101
+ comment = maf.Field(allow_none=True, data_key="#", required=False)
97
102
 
98
103
 
99
- config_schema = sy.EmptyDict() | sy.MapCombined(
100
- {
101
- sy.Optional("remote_repositories"): (
102
- sy.EmptyDict() | sy.MapPattern(sy.Str(), sy.Map({"uri": sy.Str()}))
103
- ),
104
- },
105
- sy.Str(),
106
- sy.Any(),
107
- )
104
+ class SchemaRemoteRepository(_SchemaWithComment):
105
+ uri = maf.String(required=True)
106
+
107
+
108
+ class SchemaConfig(_SchemaWithComment):
109
+ remote_repositories = maf.Dict(maf.String(), maf.Nested(SchemaRemoteRepository, required=False))
108
110
 
109
111
 
110
112
  class ImageType(enum.Enum):
@@ -112,18 +114,16 @@ class ImageType(enum.Enum):
112
114
 
113
115
 
114
116
  @attr.s(eq=False, hash=False)
115
- class StrictYamlFileWithCaching:
117
+ class JSONFileWithCaching:
116
118
  path: Path = attr.ib()
117
- schema = attr.ib(default=None)
119
+ schema: ma.Schema = attr.ib(default=None)
118
120
  _mtime = None
119
121
  _document = None
120
122
 
121
123
  @property
122
124
  def document(self):
123
125
  if (mtime := (p := self.path).stat().st_mtime_ns) != self._mtime:
124
- self._document = doc = sy.load(
125
- p.read_bytes().decode("utf-8"), schema=self.schema, label=str(self.path)
126
- )
126
+ self._document = doc = self.schema.load(json.loads(p.read_bytes()))
127
127
  self._mtime = mtime
128
128
  else:
129
129
  doc = self._document
@@ -134,7 +134,7 @@ class StrictYamlFileWithCaching:
134
134
  with atomicwrites.atomic_write(
135
135
  str(self.path), mode="wt", overwrite=True, encoding="utf-8", newline="\n"
136
136
  ) as fp:
137
- fp.write(new_value.as_yaml())
137
+ json.dump(self.schema.dump(new_value), fp, indent=2)
138
138
  self._document = new_value
139
139
 
140
140
 
@@ -418,13 +418,13 @@ class System:
418
418
 
419
419
  self.path_repo_local.mkdir(exist_ok=True, parents=True)
420
420
 
421
- config_path = self.path_base / "config.yaml"
422
- cfg = StrictYamlFileWithCaching(config_path, schema=config_schema)
421
+ config_path = self.path_base / "vocker.json"
422
+ cfg = JSONFileWithCaching(config_path, schema=SchemaConfig())
423
423
  try:
424
424
  cfg.document
425
425
  except FileNotFoundError:
426
426
  config_path.parent.mkdir(exist_ok=True, parents=True)
427
- config_path.write_bytes(b"")
427
+ config_path.write_bytes(b"{}")
428
428
  cfg.document
429
429
  self._config_file = cfg
430
430
  self._init_config()
@@ -433,10 +433,17 @@ class System:
433
433
  c = self._config
434
434
  modified = False
435
435
 
436
- if cget(c, k := "remote_repositories") is None:
436
+ if c.get(k := "remote_repositories") is None:
437
437
  c[k] = {}
438
438
  modified = True
439
439
 
440
+ if c.get(k := "comment") is None:
441
+ c[k] = [
442
+ "Since JSON doesn't allow comments, you can place them inside the '#' key inside",
443
+ "most of the dictionaries.",
444
+ ]
445
+ modified = True
446
+
440
447
  if modified:
441
448
  self._config_write(c)
442
449
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vocker
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Docker-like manager for virtualenvs
5
5
  Author-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
6
6
  License: General Public License v3
@@ -18,7 +18,6 @@ Requires-Dist: platformdirs
18
18
  Requires-Dist: sansio_tools>=1.0.0
19
19
  Requires-Dist: sqlalchemy_boltons>=2.4.0
20
20
  Requires-Dist: SQLAlchemy
21
- Requires-Dist: strictyaml
22
21
  Requires-Dist: structlog
23
22
  Requires-Dist: cbor2
24
23
  Provides-Extra: zstandard
@@ -7,13 +7,13 @@ vocker/image.py,sha256=lewNLLiXnd_N1CSs4gnYFEj-d5RkIBiPQiN8hNL2fIs,28181
7
7
  vocker/integer_to_path.py,sha256=5ghlupk9VLzXLtcfwnVEVFxtBxyT8A_ooV8-2EAnoFw,1433
8
8
  vocker/multihash.py,sha256=-VhksUBam6N01fICtTg_TJrJcEIHJrYVKzkD1B_bdfI,8760
9
9
  vocker/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- vocker/system.py,sha256=kw0-0vxE5jjHjnE1kzhDZB_YdzA5kBDLeU0TdudnJgg,24416
10
+ vocker/system.py,sha256=S7ZhqaUJilPl4tiO2XHxf0tR3Uw_HJXfvvx5j-QV7Ug,24766
11
11
  vocker/util.py,sha256=bQcMzscMPaiBC4PGV9_clTOLDTJHuqa6l6o2thQJeU8,3223
12
12
  vocker/util_models.py,sha256=2bN5eousF92oH7BAv1ZFoyh6iqNAnJ_niiclp2_RaHI,395
13
13
  vocker/repo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  vocker/repo/compression.py,sha256=l2g1e6SaugpqORbg3zwRM1zwlEXedbYOihm5nDpCejU,6442
15
15
  vocker/repo/io.py,sha256=7oUDd2vag300hRJe72VcfGVAtWDIxtMd-5pY6I_z_Fs,25250
16
- vocker-0.1.0.dist-info/METADATA,sha256=P9TNrszsFyA2Q3HItjFoMeKdeCALldVmbu4VCxwv_KE,3879
17
- vocker-0.1.0.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
18
- vocker-0.1.0.dist-info/top_level.txt,sha256=5x7g7T2L44UKODxVZ4vmWjxDnnruxaZ5yloYi0wLoUg,7
19
- vocker-0.1.0.dist-info/RECORD,,
16
+ vocker-0.2.0.dist-info/METADATA,sha256=l_sFYB7OlQVrvlACM7Y3jQ95BlLtU9iTZSyj9mHYFzA,3853
17
+ vocker-0.2.0.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
18
+ vocker-0.2.0.dist-info/top_level.txt,sha256=5x7g7T2L44UKODxVZ4vmWjxDnnruxaZ5yloYi0wLoUg,7
19
+ vocker-0.2.0.dist-info/RECORD,,
File without changes