Skip to content

Commit b909bcb

Browse files
authored
Switch lockfiles to json (#18)
as yaml safe load is too slow
1 parent 13c424c commit b909bcb

10 files changed

+38
-31
lines changed

colcon_cache/cache/__init__.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import pathlib
66

77
from colcon_core.plugin_system import satisfies_version
8-
import yaml
98

10-
LOCKFILE_FILENAME = 'colcon_{verb_name}.yaml'
9+
LOCKFILE_FILENAME = 'colcon_{verb_name}.json'
1110
LOCKFILE_VERSION = '0.0.1'
1211

1312

@@ -78,8 +77,8 @@ def update_dependencies(self, dep_lockfiles): # noqa: D10s
7877
dep_lockfile.checksums.current
7978

8079
def load(self, path): # noqa: D102
81-
content = path.read_text()
82-
data = yaml.safe_load(content)
80+
with open(path, 'r') as f:
81+
data = json.load(f)
8382
satisfies_version(data['version'], '^0.0.1')
8483

8584
self.lock_type = data['lock_type']
@@ -90,10 +89,13 @@ def load(self, path): # noqa: D102
9089
self.metadata = data['metadata']
9190

9291
def dump(self, path): # noqa: D102
93-
data = json.loads(
94-
json.dumps(self, default=lambda o: o.__dict__))
95-
path.write_text(
96-
yaml.dump(data, sort_keys=True))
92+
with open(path, 'w') as f:
93+
json.dump(
94+
obj=self,
95+
fp=f,
96+
indent=2,
97+
default=lambda o: o.__dict__,
98+
sort_keys=True)
9799

98100

99101
def get_lockfile_path(package_build_base, verb_name):

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
dirhash
22
git+https://github.com/colcon/colcon-core
33
GitPython
4-
PyYAML

setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ install_requires =
2929
colcon-core>=0.5.2
3030
dirhash
3131
GitPython
32-
PyYAML
3332
packages = find:
3433
tests_require =
3534
flake8>=3.6.0
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"checksums": {
3+
"current": "123",
4+
"reference": "123"
5+
},
6+
"dependencies": {
7+
"bar": "456",
8+
"foo": "123"
9+
},
10+
"lock_type": "foo",
11+
"metadata": {},
12+
"version": "0.0.1"
13+
}

test/cache/colcon_cache_example_1.yaml

-9
This file was deleted.
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"checksums": {
3+
"current": "456",
4+
"reference": "123"
5+
},
6+
"dependencies": {},
7+
"lock_type": "foo",
8+
"metadata": {
9+
"baz": "spam"
10+
},
11+
"version": "0.0.1"
12+
}

test/cache/colcon_cache_example_2.yaml

-8
This file was deleted.

test/spell_check.words

-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ thomas
4343
todo
4444
unmerged
4545
wildcard
46-
yaml

test/test_cache_dirhash.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_cache_package():
106106
assert not rc
107107

108108
build_base = Path(dirhash_lock_task.context.args.build_base)
109-
assert Path(build_base, 'cache/colcon_lock.yaml').exists()
109+
assert Path(build_base, 'cache/colcon_lock.json').exists()
110110

111111
finally:
112112
event_loop.close()

test/test_cache_lockfile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_cache_lockfile():
4949
lockfile_a_path.parent.mkdir(parents=True, exist_ok=True)
5050
lockfile_c_path = pathlib.Path(
5151
pathlib.Path(__file__).parent.absolute(),
52-
'cache', 'colcon_cache_example_1.yaml')
52+
'cache', 'colcon_cache_example_1.json')
5353
lockfile_a.dump(lockfile_a_path)
5454
assert lockfile_a_path.read_text() == lockfile_c_path.read_text()
5555

@@ -61,7 +61,7 @@ def test_cache_lockfile():
6161
lockfile_b_path.parent.mkdir(parents=True, exist_ok=True)
6262
lockfile_d_path = pathlib.Path(
6363
pathlib.Path(__file__).parent.absolute(),
64-
'cache', 'colcon_cache_example_2.yaml')
64+
'cache', 'colcon_cache_example_2.json')
6565
lockfile_b.dump(lockfile_b_path)
6666
assert lockfile_b_path.read_text() == lockfile_d_path.read_text()
6767

0 commit comments

Comments
 (0)