def test_get_eapi(): # unknown EAPI unknown_eapi = get_eapi("unknown") assert unknown_eapi in EAPI.unknown_eapis.values() # check that unknown EAPI is now registered as an unknown assert unknown_eapi == get_eapi("unknown") # known EAPI eapi = get_eapi("6") assert eapi6 == eapi
def eapi(self, data): try: data = (x[0] for x in data) data = (x.strip() for x in data) data = [x for x in data if x] if len(data) > 1: logger.error(f'{self.name}/eapi, multiple lines detected') return get_eapi(data[0]) except IndexError: logger.error(f'{self.name}/eapi, empty file') return get_eapi('0')
def get_pkg(self, data=None, cpv="dev-util/diffball-0.1-r1", repo=None, pre_args=()): o = self.kls(*(list(pre_args) + [repo, cpv])) if data is not None: eapi_data = str(data.pop("EAPI", 0)) object.__setattr__(o, "eapi_obj", eapi.get_eapi(eapi_data, False)) object.__setattr__(o, "data", data) return o
def __init__(self, cpv, eapi="0", slot="0", subslot=None, iuse=(), use=(), repo=FakeRepo(), restrict='', keywords=None): if isinstance(repo, str): repo = FakeRepo(repo) elif isinstance(repo, (tuple, list)) and len(repo) < 3: repo = FakeRepo(*repo) FakePkgBase.__init__(self, cpv, repo=factory(repo)) if keywords is not None: object.__setattr__(self, "keywords", set(keywords)) object.__setattr__(self, "slot", str(slot)) if subslot is None: subslot = slot object.__setattr__(self, "subslot", subslot) object.__setattr__(self, "restrict", DepSet.parse(restrict, str)) object.__setattr__(self, "fetchables", []) object.__setattr__(self, "use", set(use)) object.__setattr__(self, "iuse", set(iuse)) object.__setattr__(self, 'eapi_obj', get_eapi(eapi, False))
def get_pkg(self, data=None, cpv='dev-util/diffball-0.1-r1', repo=None, pre_args=()): o = self.kls(*(list(pre_args) + [repo, cpv])) if data is not None: eapi_data = str(data.pop('EAPI', 0)) object.__setattr__(o, 'eapi_obj', eapi.get_eapi(eapi_data, False)) object.__setattr__(o, 'data', data) return o
def generate_eapi_obj(self): eapi_magic = self.data.pop("EAPI", "0") if not eapi_magic: # "" means '0' eapi eapi_magic = '0' eapi_obj = eapi.get_eapi(str(eapi_magic).strip()) # this can return None... definitely the wrong thing right now # for an unsupported eapi. Fix it later. return eapi_obj
def get_pkg(self, data=None, cpv='dev-util/diffball-0.1-r1', repo=None, pre_args=(), suppress_unsupported=True): o = self.kls(*(list(pre_args) + [repo, cpv])) if data is not None: eapi_data = str(data.pop('EAPI', 0)) object.__setattr__(o, 'eapi', get_eapi( eapi_data, suppress_unsupported=suppress_unsupported)) object.__setattr__(o, 'data', data) return o
def get_pkg(self, data=None, cpv='dev-util/diffball-0.1-r1', repo=None, pre_args=(), suppress_unsupported=True): o = self.kls(*(list(pre_args) + [repo, cpv])) if data is not None: eapi_data = data.pop('EAPI', 0) if eapi_data is not None: object.__setattr__(o, 'eapi', get_eapi( str(eapi_data), suppress_unsupported=suppress_unsupported)) object.__setattr__(o, 'data', data) return o
def test_is_supported(self, caplog): assert eapi6.is_supported with mock.patch.dict(eapi.EAPI.known_eapis): # partially supported EAPI is flagged as such test_eapi = EAPI.register("test", optionals={'is_supported': False}) assert test_eapi.is_supported assert caplog.text.endswith("EAPI 'test' isn't fully supported\n") # unsupported/unknown EAPI is flagged as such unknown_eapi = get_eapi("blah") assert not unknown_eapi.is_supported
def _update_metadata(self, pkg, ebp=None): parsed_eapi = pkg.eapi if not parsed_eapi.is_supported: return {'EAPI': str(parsed_eapi)} with processor.reuse_or_request(ebp) as my_proc: try: mydata = my_proc.get_keys(pkg, self._ecache) except processor.ProcessorError as e: raise metadata_errors.MetadataException( pkg, 'data', 'failed sourcing ebuild', e) inherited = mydata.pop("INHERITED", None) # Rewrite defined_phases as needed, since we now know the EAPI. eapi = get_eapi(mydata.get('EAPI', '0')) if parsed_eapi != eapi: raise metadata_errors.MetadataException( pkg, 'eapi', f"parsed EAPI '{parsed_eapi}' doesn't match sourced EAPI '{eapi}'" ) wipes = set(mydata) wipes.difference_update(eapi.metadata_keys) if mydata["DEFINED_PHASES"] != '-': phases = mydata["DEFINED_PHASES"].split() d = eapi.phases_rev phases = set(d.get(x) for x in phases) # Discard is required should we have gotten # a phase that isn't actually in this EAPI. phases.discard(None) mydata["DEFINED_PHASES"] = ' '.join(sorted(phases)) if inherited: mydata["_eclasses_"] = self._ecache.get_eclass_data( inherited.split()) mydata['_chf_'] = chksum.LazilyHashedPath(pkg.path) for x in wipes: del mydata[x] if self._cache is not None: for cache in self._cache: if not cache.readonly: try: cache[pkg.cpvstr] = mydata except cache_errors.CacheError as e: logger.warning("caught cache error: %s", e) del e continue break return mydata
def desc(self): # determine proper dep type from pkg EAPI eapi_obj = get_eapi(self.eapi) dep_type = 'BDEPEND' if 'BDEPEND' in eapi_obj.metadata_keys else 'DEPEND' if len(self.unpackers) == 1: dep = self.unpackers[0] else: dep = f"|| ( {' '.join(self.unpackers)} )" return ( f'missing {dep_type}="{dep}" ' f"for SRC_URI archive{_pl(self.filenames)}: " f"[ {', '.join(self.filenames)} ]" )
def get_parsed_eapi(self): ebuild = self.ebuild eapi = '0' if ebuild.path: # Use readlines directly since it does whitespace stripping # for us, far faster than native python can. i = fileutils.readlines_utf8(ebuild.path) else: i = (x.strip() for x in ebuild.text_fileobj()) for line in i: if line[0:1] in ('', '#'): continue eapi_str = _EAPI_str_regex.match(line) if eapi_str is not None: eapi_str = eapi_str.group('EAPI') if eapi_str: eapi = _EAPI_regex.match(line).group('EAPI') break try: return get_eapi(eapi) except ValueError as e: raise metadata_errors.MetadataException(self, 'eapi', f'{e}: {eapi_str!r}')
def __init__(self, *a, **kwds): super().__init__(*a, **kwds) object.__setattr__(self, "use", []) object.__setattr__(self, "data", {"SLOT": "0"}) object.__setattr__(self, "eapi", get_eapi('0'))
def eapi(self): try: return self.base_profile.eapi except profiles.NonexistentProfile: return get_eapi('0')
def test_inherits(self): for eapi_str, eapi_obj in EAPI.known_eapis.items(): objs = (get_eapi(str(x)) for x in range(int(eapi_str), -1, -1)) assert list(map(str, eapi_obj.inherits)) == list(map(str, objs))
def eapi(self): return get_eapi(self.data.get('EAPI', '0'))
def eapi_obj(self): return eapi.get_eapi(self.data.get('EAPI', '0'))
def get_atom_kls(value): eapi = get_eapi(value) if eapi is None: raise ValueError(f"EAPI {value} isn't known/supported") return eapi.atom_kls