def PythonEgg(glob, name=None): """Refers to pre-built Python eggs in the file system. (To instead fetch eggs in a ``pip``/``easy_install`` way, use ``python_requirement``) E.g., ``egg(name='foo', glob='foo-0.1-py2.6.egg')`` would pick up the file ``foo-0.1-py2.6.egg`` from the ``BUILD`` file's directory; targets could depend on it by name ``foo``. :param string glob: File glob pattern. :param string name: Target name; by default uses the egg's project name. """ # TODO(John Sirois): Rationalize with globs handling in ParseContext eggs = fsglob(ParseContext.path(glob)) requirements = set() for egg in eggs: if os.path.isdir(egg): metadata = PathMetadata(egg, os.path.join(egg, 'EGG-INFO')) else: metadata = EggMetadata(zipimporter(egg)) dist = Distribution.from_filename(egg, metadata=metadata) requirements.add(dist.as_requirement()) if len(requirements) > 1: raise ValueError('Got multiple egg versions! => %s' % requirements) return PythonRequirement(str(requirements.pop()), name=name)
def __init__(self, base=None, mapper=None, relative_to=None): """ :param base: Base path of the "source" file paths. By default, path of the BUILD file. Useful for assets that don't live in the source code repo. :param mapper: Function that takes a path string and returns a path string. Takes a path in the source tree, returns a path to use in the resulting bundle. By default, an identity mapper. :param string relative_to: Set up a simple mapping from source path to bundle path. E.g., ``relative_to='common'`` removes that prefix from all files in the application bundle. """ if mapper and relative_to: raise ValueError("Must specify exactly one of 'mapper' or 'relative_to'") self._base = base or ParseContext.path() if relative_to: base = os.path.join(self._base, relative_to) if not os.path.isdir(base): raise ValueError('Could not find a directory to bundle relative to at %s' % base) self.mapper = RelativeToMapper(base) else: self.mapper = mapper or RelativeToMapper(self._base) self.filemap = {}