def resource(prefix: str): """Serve the a Bioregistry entry page.""" prefix = _normalize_prefix_or_404(prefix, '.' + resource.__name__) if not isinstance(prefix, str): return prefix example = bioregistry.get_example(prefix) return render_template( 'resource.html', prefix=prefix, name=bioregistry.get_name(prefix), example=example, mappings=_get_resource_mapping_rows(prefix), synonyms=bioregistry.get_synonyms(prefix), homepage=bioregistry.get_homepage(prefix), pattern=bioregistry.get_pattern(prefix), version=bioregistry.get_version(prefix), has_terms=bioregistry.has_terms(prefix), obo_download=bioregistry.get_obo_download(prefix), owl_download=bioregistry.get_owl_download(prefix), namespace_in_lui=bioregistry.namespace_in_lui(prefix), deprecated=bioregistry.is_deprecated(prefix), contact=bioregistry.get_email(prefix), banana=bioregistry.get_banana(prefix), description=bioregistry.get_description(prefix), providers=None if example is None else _get_resource_providers( prefix, example), )
def normalize_identifier(prefix: str, identifier: str) -> str: """Normalize the identifier.""" # TODO in bioregistry.resolve_identifier there is similar code. just combine with that banana = bioregistry.get_banana(prefix) if banana: if not identifier.startswith(banana): return f"{banana}:{identifier}" elif bioregistry.namespace_in_lui(prefix): banana = f"{prefix.upper()}:" if not identifier.startswith(banana): return f"{banana}{identifier}" return identifier
def resources(): """Serve the Bioregistry page.""" rows = [ dict( prefix=prefix, name=bioregistry.get_name(prefix), example=bioregistry.get_example(prefix), homepage=bioregistry.get_homepage(prefix), pattern=bioregistry.get_pattern(prefix), namespace_in_lui=bioregistry.namespace_in_lui(prefix), banana=bioregistry.get_banana(prefix), description=bioregistry.get_description(prefix), ) for prefix in bioregistry.read_registry() ] return render_template('resources.html', rows=rows)
def main(url: str, local: bool): """Test the API.""" url = url.rstrip('/') if local: url = 'http://localhost:5000' click.echo(f'Testing resolution API on {url}') failure = False prefixes = tqdm(bioregistry.read_registry()) for prefix in prefixes: identifier = bioregistry.get_example(prefix) if identifier is None: continue prefixes.set_postfix({'prefix': prefix}) req_url = f'{url}/{prefix}:{identifier}' res = requests.get(req_url, allow_redirects=False) log = partial(_log, req_url=req_url) if res.status_code == 302: # redirect continue elif res.status_code != 404: text = res.text.splitlines()[3][len('<p>'):-len('</p>')] log(f'HTTP {res.status_code}: {res.reason} {text}', fg='red') elif not bioregistry.get_providers(prefix, identifier): continue elif '/' in identifier or SLASH_URL_ENCODED in identifier: log('contains slash 🎩 🎸', fg='red') elif not bioregistry.validate(prefix, identifier): pattern = bioregistry.get_pattern(prefix) if bioregistry.get_banana(prefix): log(f'banana {pattern} 🍌', fg='red') else: log(f'invalid example does not match pattern {pattern}', fg='red') else: log('404 unknown issue', fg='red') failure = True return sys.exit(1 if failure else 0)
def test_lui(self): """Test the LUI makes sense (spoilers, they don't). Discussion is ongoing at: - https://github.com/identifiers-org/identifiers-org.github.io/issues/151 """ for prefix in bioregistry.read_registry(): if not bioregistry.namespace_in_lui(prefix): continue if bioregistry.get_banana(prefix): continue # rewrite rules are applied to prefixes with bananas if prefix in {'ark', 'obi'}: continue # these patterns on identifiers.org are garb with self.subTest(prefix=prefix): re_pattern = bioregistry.get_pattern(prefix) miriam_prefix = bioregistry.get_identifiers_org_prefix(prefix) self.assertTrue( re_pattern.startswith(f'^{miriam_prefix.upper()}') or re_pattern.startswith(miriam_prefix.upper()), msg=f'{prefix} pattern: {re_pattern}', )