Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Unified Diff: recipe_engine/package.py

Issue 2785503002: Revert of [package.proto] convert deps from list to map. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « recipe_engine/package.proto ('k') | recipe_engine/package_pb2.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_engine/package.py
diff --git a/recipe_engine/package.py b/recipe_engine/package.py
index 52a3b6eab66704fc4afc73490e9f6fd8cf75221c..bd0ebf1ea48842beaa5bc6257c35721ac116ab03 100644
--- a/recipe_engine/package.py
+++ b/recipe_engine/package.py
@@ -60,12 +60,7 @@
"""A collection of functions operating on a proto path.
This is an object so that it can be mocked in the tests.
-
- Proto files read will always be upconverted to the current proto in
- package.proto, and will be written back in their original format.
"""
- API_VERSIONS = (1, 2)
-
def __init__(self, path):
self._path = path
@@ -78,32 +73,13 @@
return fh.read()
def read(self):
- obj = json.loads(self.read_raw())
-
- vers = obj.get('api_version')
- assert vers in self.API_VERSIONS, (
- 'expected %r to be one of %r' % (vers, self.API_VERSIONS)
- )
-
- # upconvert old deps-as-a-list to deps-as-a-dict
- if 'deps' in obj and vers == 1:
- obj['deps'] = {d.pop('project_id'): d for d in obj['deps']}
-
+ text = self.read_raw()
buf = package_pb2.Package()
- json_format.ParseDict(obj, buf, ignore_unknown_fields=True)
+ json_format.Parse(text, buf, ignore_unknown_fields=True)
return buf
def to_raw(self, buf):
obj = json_format.MessageToDict(buf, preserving_proto_field_name=True)
-
- # downconvert if api_version is 1
- if buf.deps and buf.api_version < 2:
- deps = []
- for pid, d in sorted(obj['deps'].iteritems()):
- d['project_id'] = pid
- deps.append(d)
- obj['deps'] = deps
-
return json.dumps(obj, indent=2, sort_keys=True).replace(' \n', '\n')
def write(self, buf):
@@ -229,6 +205,7 @@
def dump(self):
buf = package_pb2.DepSpec(
+ project_id=self.project_id,
url=self.repo,
branch=self.branch,
revision=self.revision)
@@ -353,6 +330,7 @@
def dump(self):
"""Returns the package.proto DepSpec form of this RepoSpec."""
return package_pb2.DepSpec(
+ project_id=self.project_id,
url="file://"+self.path)
def __eq__(self, other):
@@ -484,12 +462,12 @@
def get_rolled_spec(self):
"""Returns a PackageSpec with all the deps updates from this roll."""
+ # TODO(phajdan.jr): does this preserve comments? should it?
new_deps = _updated(
self._package_spec.deps,
{ project_id: spec for project_id, spec in
self._updates.iteritems() })
return PackageSpec(
- self._package_spec.api_version,
self._package_spec.project_id,
self._package_spec.recipes_path,
new_deps)
@@ -521,8 +499,9 @@
class PackageSpec(object):
- def __init__(self, api_version, project_id, recipes_path, deps):
- self._api_version = api_version
+ API_VERSION = 1
+
+ def __init__(self, project_id, recipes_path, deps):
self._project_id = project_id
self._recipes_path = recipes_path
self._deps = deps
@@ -534,25 +513,25 @@
@classmethod
def load_proto(cls, proto_file):
buf = proto_file.read()
-
- deps = { pid: cls.spec_for_dep(pid, dep)
- for pid, dep in buf.deps.iteritems() }
- return cls(buf.api_version, str(buf.project_id), str(buf.recipes_path),
- deps)
+ assert buf.api_version == cls.API_VERSION
+
+ deps = { str(dep.project_id): cls.spec_for_dep(dep)
+ for dep in buf.deps }
+ return cls(str(buf.project_id), str(buf.recipes_path), deps)
@classmethod
- def spec_for_dep(cls, project_id, dep):
+ def spec_for_dep(cls, dep):
"""Returns a RepoSpec for the given dependency protobuf."""
url = str(dep.url)
if url.startswith("file://"):
- return PathRepoSpec(str(project_id), url[len("file://"):])
+ return PathRepoSpec(str(dep.project_id), url[len("file://"):])
if dep.repo_type in (package_pb2.DepSpec.GIT, package_pb2.DepSpec.GITILES):
if dep.repo_type == package_pb2.DepSpec.GIT:
backend = fetch.GitBackend()
elif dep.repo_type == package_pb2.DepSpec.GITILES:
backend = fetch.GitilesBackend()
- return GitRepoSpec(str(project_id),
+ return GitRepoSpec(str(dep.project_id),
url,
str(dep.branch),
str(dep.revision),
@@ -573,16 +552,12 @@
def deps(self):
return self._deps
- @property
- def api_version(self):
- return self._api_version
-
def dump(self):
return package_pb2.Package(
- api_version=self._api_version,
+ api_version=self.API_VERSION,
project_id=self._project_id,
recipes_path=self._recipes_path,
- deps={k: v.dump() for k, v in self._deps.iteritems()})
+ deps=[ self._deps[dep].dump() for dep in sorted(self._deps.keys()) ])
def roll_candidates(self, root_spec, context):
"""Returns list of consistent roll candidates, and rejected roll candidates.
« no previous file with comments | « recipe_engine/package.proto ('k') | recipe_engine/package_pb2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698