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

Unified Diff: recipe_modules/path/api.py

Issue 2909983003: [loader] Make recipe engine support examples/ module subdir (Closed)
Patch Set: Created 3 years, 7 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_modules/json/examples/full.resources/cool_script.py ('k') | recipe_modules/path/example.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_modules/path/api.py
diff --git a/recipe_modules/path/api.py b/recipe_modules/path/api.py
index ef54fd693482ce8d8452300ff10aefb44f139f3f..c62586608f0de687fe50655e2007f463eff44864 100644
--- a/recipe_modules/path/api.py
+++ b/recipe_modules/path/api.py
@@ -5,6 +5,7 @@
import functools
import itertools
import os
+import re
import tempfile
from recipe_engine import recipe_api
@@ -72,13 +73,16 @@ class fake_path(object):
self._mock_path_exists = path_set(self, _mock_path_exists)
self._pth = None
- def __getattr__(self, name):
+ def _init_pth(self):
if not self._pth:
if self._api.m.platform.is_win:
import ntpath as pth
elif self._api.m.platform.is_mac or self._api.m.platform.is_linux:
import posixpath as pth
self._pth = pth
+
+ def __getattr__(self, name):
+ self._init_pth()
return getattr(self._pth, name)
def mock_add_paths(self, path):
@@ -91,6 +95,31 @@ class fake_path(object):
"""Return True if path refers to an existing path."""
return self._mock_path_exists.contains(path)
+ # This matches:
+ # [START_DIR]
+ # RECIPE[some_pkg::some_module:recipe_name]
+ #
+ # and friends at the beginning of a string.
+ ROOT_MATCHER = re.compile('^[A-Z_]*\[[^]]*\]')
+
+ def normpath(self, path):
+ """Normalizese the path.
+
+ This splits off a recipe base (i.e. RECIPE[...]) so that normpath is
+ only called on the user-supplied portion of the path.
+ """
+ self._init_pth()
+ real_normpath = self._pth.normpath
+ m = self.ROOT_MATCHER.match(path)
+ if m:
+ prefix = m.group(0)
+ rest = path[len(prefix):]
+ if rest == '':
+ # normpath turns '' into '.'
+ return prefix
+ return prefix + real_normpath(rest)
+ return real_normpath(path)
+
def abspath(self, path):
"""Returns the absolute version of path."""
return self.normpath(path)
@@ -256,8 +285,9 @@ class PathApi(recipe_api.RecipeApi):
Raises an ValueError if the preconditions are not met, otherwise returns the
Path object.
"""
- if self.abspath(abs_string_path) != abs_string_path:
- raise ValueError("path is not absolute: %r" % abs_string_path)
+ ap = self.abspath(abs_string_path)
+ if ap != abs_string_path:
+ raise ValueError("path is not absolute: %r v %r" % (abs_string_path, ap))
# try module/recipe/package resource paths first
sPath, path = self._paths_client.find_longest_prefix(
« no previous file with comments | « recipe_modules/json/examples/full.resources/cool_script.py ('k') | recipe_modules/path/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698