-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global: add class based registry to extend idutils schemes #106
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cf857bd
global: add class based registry to extend idutils schemes
zzacharo 0a650d2
rename config to schemes and keep backward import compatibility
zzacharo 3c4af63
setup: remove flask extension entrypoints
zzacharo 90b42b9
docs: include setting up custom schemes
zzacharo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,70 +14,18 @@ | |
"""Functions for detecting the persistent identifier.""" | ||
|
||
from . import validators | ||
from .proxies import current_idutils | ||
from .proxies import custom_schemes_registry | ||
from .schemes import IDUTILS_PID_SCHEMES as _IDUTILS_PID_SCHEMES | ||
from .schemes import IDUTILS_SCHEME_FILTER as _IDUTILS_SCHEME_FILTER | ||
|
||
IDUTILS_PID_SCHEMES = [ | ||
("doi", validators.is_doi), | ||
("ark", validators.is_ark), | ||
("handle", validators.is_handle), | ||
("purl", validators.is_purl), | ||
("lsid", validators.is_lsid), | ||
("urn", validators.is_urn), | ||
("ads", validators.is_ads), | ||
("arxiv", validators.is_arxiv), | ||
("ascl", validators.is_ascl), | ||
("hal", validators.is_hal), | ||
("pmcid", validators.is_pmcid), | ||
("isbn", validators.is_isbn), | ||
("issn", validators.is_issn), | ||
("orcid", validators.is_orcid), | ||
("isni", validators.is_isni), | ||
("ean13", validators.is_ean13), | ||
("ean8", validators.is_ean8), | ||
("istc", validators.is_istc), | ||
("gnd", validators.is_gnd), | ||
("ror", validators.is_ror), | ||
("pmid", validators.is_pmid), | ||
("url", validators.is_url), | ||
("sra", validators.is_sra), | ||
("bioproject", validators.is_bioproject), | ||
("biosample", validators.is_biosample), | ||
("ensembl", validators.is_ensembl), | ||
("uniprot", validators.is_uniprot), | ||
("refseq", validators.is_refseq), | ||
("genome", validators.is_genome), | ||
("geo", validators.is_geo), | ||
("arrayexpress_array", validators.is_arrayexpress_array), | ||
("arrayexpress_experiment", validators.is_arrayexpress_experiment), | ||
("swh", validators.is_swh), | ||
("viaf", validators.is_viaf), | ||
] | ||
IDUTILS_PID_SCHEMES = _IDUTILS_PID_SCHEMES | ||
"""Definition of scheme name and associated test function. | ||
|
||
Order of list is important, as identifier scheme detection will test in the | ||
order given by this list.""" | ||
|
||
|
||
IDUTILS_SCHEME_FILTER = [ | ||
( | ||
"url", | ||
# None these can have URLs, in which case we exclude them | ||
["isbn", "istc", "urn", "lsid", "issn", "ean8", "viaf"], | ||
), | ||
("ean8", ["gnd", "pmid", "viaf"]), | ||
("ean13", ["gnd", "pmid"]), | ||
("isbn", ["gnd", "pmid"]), | ||
("orcid", ["gnd", "pmid"]), | ||
("isni", ["gnd", "pmid"]), | ||
( | ||
"issn", | ||
[ | ||
"gnd", | ||
"viaf", | ||
], | ||
), | ||
("pmid", ["viaf"]), | ||
] | ||
IDUTILS_SCHEME_FILTER = _IDUTILS_SCHEME_FILTER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept for backwards compatibility when importing. |
||
"""(present_scheme, [list of schemes to remove if present_scheme found]).""" | ||
|
||
|
||
|
@@ -87,7 +35,7 @@ def detect_identifier_schemes(val): | |
.. note:: Some schemes like PMID are very generic. | ||
""" | ||
schemes = [] | ||
scheme_validators = IDUTILS_PID_SCHEMES + current_idutils.pick_scheme_key( | ||
scheme_validators = IDUTILS_PID_SCHEMES + custom_schemes_registry().pick_scheme_key( | ||
"validator" | ||
) | ||
for scheme, test in scheme_validators: | ||
|
@@ -111,7 +59,9 @@ def detect_identifier_schemes(val): | |
if val.startswith(viaf_url): | ||
schemes.remove("handle") | ||
|
||
scheme_filter = IDUTILS_SCHEME_FILTER + current_idutils.pick_scheme_key("filter") | ||
scheme_filter = IDUTILS_SCHEME_FILTER + custom_schemes_registry().pick_scheme_key( | ||
"filter" | ||
) | ||
for first, remove_schemes in scheme_filter: | ||
if first in schemes: | ||
schemes = list(filter(lambda x: x not in remove_schemes, schemes)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept for backwards compatibility when importing.