comparison piecrust/processing/less.py @ 119:0811f92cbdc7

Slightly more robust dependency handling for the LESS processor.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 29 Oct 2014 08:19:58 -0700
parents 1c13f3389fcb
children b4724e577a8c
comparison
equal deleted inserted replaced
118:e5f048799d61 119:0811f92cbdc7
28 def getDependencies(self, path): 28 def getDependencies(self, path):
29 map_path = self._getMapPath(path) 29 map_path = self._getMapPath(path)
30 try: 30 try:
31 with open(map_path, 'r') as f: 31 with open(map_path, 'r') as f:
32 dep_map = json.load(f) 32 dep_map = json.load(f)
33 source = dep_map.get('sources') 33
34 # The last one is always the file itself, so skip that. Also, 34 # Check the version, since the `sources` list has changed
35 # make all paths absolute. 35 # meanings over time.
36 if dep_map.get('version') != 3:
37 logger.warning("Unknown LESS map version. Force rebuilding.")
38 return FORCE_BUILD
39
40 # Get the sources, but make all paths absolute.
41 sources = dep_map.get('sources')
36 path_dir = os.path.dirname(path) 42 path_dir = os.path.dirname(path)
37 def _makeAbs(p): 43 def _makeAbs(p):
38 return os.path.join(path_dir, p) 44 return os.path.join(path_dir, p)
39 return list(map(_makeAbs, source[:-1])) 45 deps = list(map(_makeAbs, sources))
46 return [map_path] + deps
40 except IOError: 47 except IOError:
41 # Map file not found... rebuild. 48 # Map file not found... rebuild.
42 logger.debug("No map file found for LESS file '%s' at '%s'. " 49 logger.debug("No map file found for LESS file '%s' at '%s'. "
43 "Rebuilding" % (path, map_path)) 50 "Rebuilding" % (path, map_path))
44 return FORCE_BUILD 51 return FORCE_BUILD
80 if not isinstance(self._conf['options'], list): 87 if not isinstance(self._conf['options'], list):
81 raise Exception("The `less/options` configuration setting " 88 raise Exception("The `less/options` configuration setting "
82 "must be an array of arguments.") 89 "must be an array of arguments.")
83 90
84 def _getMapPath(self, path): 91 def _getMapPath(self, path):
85 map_name = "%s.map" % hashlib.md5(path.encode('utf8')).hexdigest() 92 map_name = "%s_%s.map" % (
93 os.path.basename(path),
94 hashlib.md5(path.encode('utf8')).hexdigest())
86 map_path = os.path.join(self._map_dir, map_name) 95 map_path = os.path.join(self._map_dir, map_name)
87 return map_path 96 return map_path
88 97