invenio-pidbox 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. invenio_pidbox-0.1.0/.gitignore +219 -0
  2. invenio_pidbox-0.1.0/LICENSE +18 -0
  3. invenio_pidbox-0.1.0/PKG-INFO +93 -0
  4. invenio_pidbox-0.1.0/README.md +60 -0
  5. invenio_pidbox-0.1.0/invenio_pidbox/__init__.py +14 -0
  6. invenio_pidbox-0.1.0/invenio_pidbox/config.py +16 -0
  7. invenio_pidbox-0.1.0/invenio_pidbox/ext.py +143 -0
  8. invenio_pidbox-0.1.0/invenio_pidbox/models.py +5 -0
  9. invenio_pidbox-0.1.0/invenio_pidbox/profile.py +213 -0
  10. invenio_pidbox-0.1.0/invenio_pidbox/resources/__init__.py +1 -0
  11. invenio_pidbox-0.1.0/invenio_pidbox/resources/config.py +1 -0
  12. invenio_pidbox-0.1.0/invenio_pidbox/resources/resource.py +1 -0
  13. invenio_pidbox-0.1.0/invenio_pidbox/services/__init__.py +1 -0
  14. invenio_pidbox-0.1.0/invenio_pidbox/services/config.py +1 -0
  15. invenio_pidbox-0.1.0/invenio_pidbox/services/service.py +1 -0
  16. invenio_pidbox-0.1.0/invenio_pidbox/templates/semantic-ui/invenio_app_rdm/organizations/profile.html +125 -0
  17. invenio_pidbox-0.1.0/invenio_pidbox/templates/semantic-ui/invenio_app_rdm/organizations/profile_metrics.html +387 -0
  18. invenio_pidbox-0.1.0/invenio_pidbox/templates/semantic-ui/invenio_app_rdm/people/profile.html +121 -0
  19. invenio_pidbox-0.1.0/invenio_pidbox/templates/semantic-ui/invenio_app_rdm/people/profile_metrics.html +387 -0
  20. invenio_pidbox-0.1.0/pyproject.toml +66 -0
  21. invenio_pidbox-0.1.0/tests/conftest.py +33 -0
  22. invenio_pidbox-0.1.0/tests/test_models.py +17 -0
  23. invenio_pidbox-0.1.0/tests/test_profile_integration.py +126 -0
  24. invenio_pidbox-0.1.0/tests/test_profile_templates.py +37 -0
@@ -0,0 +1,219 @@
1
+ # ---> Python
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[codz]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py.cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # UV
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi
127
+
128
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
129
+ __pypackages__/
130
+
131
+ # Celery stuff
132
+ celerybeat-schedule
133
+ celerybeat.pid
134
+
135
+ # Redis
136
+ *.rdb
137
+ *.aof
138
+ *.pid
139
+
140
+ # RabbitMQ
141
+ mnesia/
142
+ rabbitmq/
143
+ rabbitmq-data/
144
+
145
+ # ActiveMQ
146
+ activemq-data/
147
+
148
+ # SageMath parsed files
149
+ *.sage.py
150
+
151
+ # Environments
152
+ .env
153
+ .envrc
154
+ .venv
155
+ env/
156
+ venv/
157
+ ENV/
158
+ env.bak/
159
+ venv.bak/
160
+
161
+ # Spyder project settings
162
+ .spyderproject
163
+ .spyproject
164
+
165
+ # Rope project settings
166
+ .ropeproject
167
+
168
+ # mkdocs documentation
169
+ /site
170
+
171
+ # mypy
172
+ .mypy_cache/
173
+ .dmypy.json
174
+ dmypy.json
175
+
176
+ # Pyre type checker
177
+ .pyre/
178
+
179
+ # pytype static type analyzer
180
+ .pytype/
181
+
182
+ # Cython debug symbols
183
+ cython_debug/
184
+
185
+ # PyCharm
186
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
187
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
188
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
189
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
190
+ # .idea/
191
+
192
+ # Abstra
193
+ # Abstra is an AI-powered process automation framework.
194
+ # Ignore directories containing user credentials, local state, and settings.
195
+ # Learn more at https://abstra.io/docs
196
+ .abstra/
197
+
198
+ # Visual Studio Code
199
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
200
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
201
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
202
+ # you could uncomment the following to ignore the entire vscode folder
203
+ # .vscode/
204
+
205
+ # Ruff stuff:
206
+ .ruff_cache/
207
+
208
+ # PyPI configuration file
209
+ .pypirc
210
+
211
+ # Marimo
212
+ marimo/_static/
213
+ marimo/_lsp/
214
+ __marimo__/
215
+
216
+ # Streamlit
217
+ .streamlit/secrets.toml
218
+
219
+ notes.md
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Front Matter.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: invenio-pidbox
3
+ Version: 0.1.0
4
+ Summary: InvenioRDM PIDBox integration for people and organizations profile templates.
5
+ Project-URL: Homepage, https://codeberg.org/front-matter/invenio-pidbox
6
+ Project-URL: Repository, https://codeberg.org/front-matter/invenio-pidbox
7
+ Project-URL: Bug Tracker, https://codeberg.org/front-matter/invenio-pidbox/issues
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: author,invenio,organization,pidbox,profiles
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Web Environment
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.14
21
+ Requires-Dist: commonmeta-py[backend]>=0.269
22
+ Requires-Dist: commonmeta-rs>=0.9.72
23
+ Requires-Dist: invenio-app-rdm>=14.0.0
24
+ Provides-Extra: docs
25
+ Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == 'docs'
26
+ Requires-Dist: sphinx>=5.0.0; extra == 'docs'
27
+ Provides-Extra: tests
28
+ Requires-Dist: invenio-app>=1.4.0; extra == 'tests'
29
+ Requires-Dist: pytest-black>=0.3.0; extra == 'tests'
30
+ Requires-Dist: pytest-isort>=3.1.0; extra == 'tests'
31
+ Requires-Dist: pytest<9,>=7.4.0; extra == 'tests'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # invenio-pidbox
35
+
36
+ InvenioRDM integration for people and organization profile templates backed by the commonmeta SQLite store.
37
+
38
+ ## Features
39
+
40
+ - Ships people and organization profile templates for InvenioRDM
41
+ - Injects template context for /people/<orcid> and /organizations/<ror> routes
42
+ - Reads ORCID and ROR profiles from the commonmeta SQLite store via commonmeta-py and commonmeta-rs
43
+ - Uses the pid_annotations cache layer instead of application-specific people or organizations tables
44
+ - Mirrors the profile integration approach used in rogue-scholar
45
+
46
+ ## Requirements
47
+
48
+ - Python 3.14+
49
+ - A commonmeta SQLite database readable through commonmeta-rs
50
+
51
+ The extension resolves profile data from the path configured in PIDBOX_SQLITE_PATH.
52
+ Internally, commonmeta-rs reads pid_annotations records with source_id 4 for people
53
+ (ORCID) and source_id 3 for organizations (ROR).
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ uv add invenio-pidbox
59
+ ```
60
+
61
+ This package depends on commonmeta-py, commonmeta-rs, and invenio-app-rdm at
62
+ runtime, so installing invenio-pidbox pulls in the profile backend automatically.
63
+
64
+ If the profile store lives outside the default commonmeta location, configure
65
+ PIDBOX_SQLITE_PATH in your Invenio application.
66
+
67
+ ## How It Works
68
+
69
+ When a request path matches /people/<orcid> or /organizations/<ror>, the extension
70
+ loads the corresponding commonmeta record from SQLite and exposes template-friendly
71
+ objects such as person, organization, employment, identifiers, relations, location,
72
+ orcid, ror, and search_config.
73
+
74
+ The extension also registers default profile routes and a country_name template
75
+ filter so it can run against a standard invenio-app-rdm installation.
76
+
77
+ ## Development
78
+
79
+ ```bash
80
+ uv sync --extra tests
81
+ uv run pytest
82
+ ```
83
+
84
+ ## Entry points
85
+
86
+ | Group | Name | Value |
87
+ |---|---|---|
88
+ | `invenio_base.apps` | `invenio_pidbox` | `invenio_pidbox.ext:InvenioPidbox` |
89
+ | `invenio_base.api_apps` | `invenio_pidbox` | `invenio_pidbox.ext:InvenioPidbox` |
90
+
91
+ ## License
92
+
93
+ MIT
@@ -0,0 +1,60 @@
1
+ # invenio-pidbox
2
+
3
+ InvenioRDM integration for people and organization profile templates backed by the commonmeta SQLite store.
4
+
5
+ ## Features
6
+
7
+ - Ships people and organization profile templates for InvenioRDM
8
+ - Injects template context for /people/<orcid> and /organizations/<ror> routes
9
+ - Reads ORCID and ROR profiles from the commonmeta SQLite store via commonmeta-py and commonmeta-rs
10
+ - Uses the pid_annotations cache layer instead of application-specific people or organizations tables
11
+ - Mirrors the profile integration approach used in rogue-scholar
12
+
13
+ ## Requirements
14
+
15
+ - Python 3.14+
16
+ - A commonmeta SQLite database readable through commonmeta-rs
17
+
18
+ The extension resolves profile data from the path configured in PIDBOX_SQLITE_PATH.
19
+ Internally, commonmeta-rs reads pid_annotations records with source_id 4 for people
20
+ (ORCID) and source_id 3 for organizations (ROR).
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ uv add invenio-pidbox
26
+ ```
27
+
28
+ This package depends on commonmeta-py, commonmeta-rs, and invenio-app-rdm at
29
+ runtime, so installing invenio-pidbox pulls in the profile backend automatically.
30
+
31
+ If the profile store lives outside the default commonmeta location, configure
32
+ PIDBOX_SQLITE_PATH in your Invenio application.
33
+
34
+ ## How It Works
35
+
36
+ When a request path matches /people/<orcid> or /organizations/<ror>, the extension
37
+ loads the corresponding commonmeta record from SQLite and exposes template-friendly
38
+ objects such as person, organization, employment, identifiers, relations, location,
39
+ orcid, ror, and search_config.
40
+
41
+ The extension also registers default profile routes and a country_name template
42
+ filter so it can run against a standard invenio-app-rdm installation.
43
+
44
+ ## Development
45
+
46
+ ```bash
47
+ uv sync --extra tests
48
+ uv run pytest
49
+ ```
50
+
51
+ ## Entry points
52
+
53
+ | Group | Name | Value |
54
+ |---|---|---|
55
+ | `invenio_base.apps` | `invenio_pidbox` | `invenio_pidbox.ext:InvenioPidbox` |
56
+ | `invenio_base.api_apps` | `invenio_pidbox` | `invenio_pidbox.ext:InvenioPidbox` |
57
+
58
+ ## License
59
+
60
+ MIT
@@ -0,0 +1,14 @@
1
+ """InvenioRDM PIDBox integration for people and organizations profile templates."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ __all__ = ("__version__", "InvenioPidbox")
6
+
7
+
8
+ def __getattr__(name):
9
+ """Lazily import heavy extension dependencies on demand."""
10
+ if name == "InvenioPidbox":
11
+ from .ext import InvenioPidbox
12
+
13
+ return InvenioPidbox
14
+ raise AttributeError(name)
@@ -0,0 +1,16 @@
1
+ """Default configuration for the profile templates package."""
2
+
3
+ CROSSREF_USERNAME = None
4
+ """Crossref account username (with role) used for the cited-by service."""
5
+
6
+ CROSSREF_PASSWORD = None
7
+ """Crossref account password used for the cited-by service."""
8
+
9
+ CROSSREF_PREFIX = None
10
+ """DOI prefix whose forward links are fetched from Crossref cited-by."""
11
+
12
+ CROSSREF_ADDITIONAL_PREFIXES = []
13
+ """List of additional DOI prefixes whose forward links are fetched from Crossref cited-by."""
14
+
15
+ CROSSREF_START_DATE = "2000-01-01"
16
+ """Earliest date for Crossref cited-by forward-link queries (ISO 8601)."""
@@ -0,0 +1,143 @@
1
+ """Flask extension for invenio-pidbox."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from urllib.parse import quote
6
+
7
+ from babel import Locale
8
+ from babel.core import UnknownLocaleError
9
+ from flask import Blueprint, current_app, redirect, render_template, request
10
+ from flask_babel import get_locale
11
+ from typing import Any
12
+
13
+ from .profile import ProfileDataProvider
14
+
15
+
16
+ def _country_name(code: str | None) -> str:
17
+ """Return the localized display name for an ISO country code."""
18
+ if not code:
19
+ return ""
20
+ try:
21
+ locale = Locale.parse(str(get_locale() or "en"))
22
+ return locale.territories.get(str(code).upper()) or str(code)
23
+ except UnknownLocaleError, ValueError:
24
+ return str(code)
25
+
26
+
27
+ def _build_search_config(app, query: str, filters: list[list[str]]) -> dict[str, Any]:
28
+ """Build a search configuration for the profile page search widget."""
29
+ fallback = {
30
+ "appId": "InvenioAppRdm.Search",
31
+ "apiConfig": {
32
+ "url": "/api/records",
33
+ "headers": {"Accept": "application/vnd.inveniordm.v1+json"},
34
+ },
35
+ "initialQueryState": {
36
+ "hiddenParams": [["q", query]],
37
+ "filters": filters,
38
+ "sortBy": "newest",
39
+ },
40
+ }
41
+
42
+ try:
43
+ from invenio_search_ui.searchconfig import search_app_config
44
+ except ImportError:
45
+ return fallback
46
+
47
+ try:
48
+ search_config = search_app_config(
49
+ "RDM_SEARCH",
50
+ app.config.get("RDM_FACETS", []),
51
+ app.config.get("RDM_SORT_OPTIONS", {}),
52
+ "/api/records",
53
+ {"Accept": "application/vnd.inveniordm.v1+json"},
54
+ pagination_options=(10, 20),
55
+ hidden_params=[["q", query]],
56
+ app_id="InvenioAppRdm.Search",
57
+ )
58
+ except KeyError:
59
+ return fallback
60
+
61
+ search_config.setdefault("initialQueryState", {})["sortBy"] = "newest"
62
+ search_config["initialQueryState"]["filters"] = filters
63
+ return search_config
64
+
65
+
66
+ def _profile_context(app, profile_type: str, profile_id: str) -> dict[str, Any]:
67
+ """Build the template context for a person or organization profile."""
68
+ provider = ProfileDataProvider(app.config["PIDBOX_SQLITE_PATH"])
69
+ context = provider.get_profile_context(profile_type, profile_id)
70
+ if profile_type == "person":
71
+ context["search_config"] = _build_search_config(
72
+ app,
73
+ f"orcid:{profile_id}",
74
+ [["author_identifiers", "orcid"]],
75
+ )
76
+ else:
77
+ context["search_config"] = _build_search_config(
78
+ app,
79
+ f"ror:{profile_id}",
80
+ [["affiliations", profile_id]],
81
+ )
82
+ return context
83
+
84
+
85
+ def create_blueprint() -> Blueprint:
86
+ """Create profile routes for people and organizations."""
87
+ blueprint = Blueprint("invenio_pidbox", __name__)
88
+
89
+ @blueprint.route("/people/<path:orcid>")
90
+ def person_profile(orcid: str):
91
+ context = _profile_context(current_app, "person", orcid)
92
+ if not context.get("person"):
93
+ return redirect(f"/search?q={quote(f'orcid:{orcid}')}&l=list&sort=newest")
94
+ return render_template("invenio_app_rdm/people/profile.html", **context)
95
+
96
+ @blueprint.route("/organizations/<path:ror>")
97
+ def organization_profile(ror: str):
98
+ context = _profile_context(current_app, "organization", ror)
99
+ if not context.get("organization"):
100
+ return redirect(f"/search?q={quote(f'ror:{ror}')}&l=list&sort=newest")
101
+ return render_template("invenio_app_rdm/organizations/profile.html", **context)
102
+
103
+ return blueprint
104
+
105
+
106
+ class InvenioPidbox:
107
+ """Load profile templates and expose SQLite-backed profile context."""
108
+
109
+ def __init__(self, app=None) -> None:
110
+ """Initialize the extension."""
111
+ self.app = None
112
+ if app is not None:
113
+ self.init_app(app)
114
+
115
+ def init_app(self, app) -> None:
116
+ """Initialize the application."""
117
+ self.app = app
118
+ app.extensions["invenio-pidbox"] = self
119
+
120
+ app.config.setdefault("PIDBOX_SQLITE_PATH", "profiles.sqlite3")
121
+ app.add_template_filter(_country_name, "country_name")
122
+ app.register_blueprint(create_blueprint())
123
+
124
+ @app.context_processor
125
+ def inject_profile_context() -> dict[str, Any]:
126
+ """Expose profile data from SQLite to templates when a profile route is active."""
127
+ path = app.config.get("PIDBOX_SQLITE_PATH")
128
+ if not path or not request.path:
129
+ return {}
130
+
131
+ provider = ProfileDataProvider(path)
132
+ parts = [part for part in request.path.split("/") if part]
133
+ if len(parts) < 2:
134
+ return {}
135
+
136
+ profile_type = parts[0]
137
+ if profile_type not in {"people", "organizations"}:
138
+ return {}
139
+
140
+ profile_id = parts[1]
141
+ if profile_type == "people":
142
+ return _profile_context(app, "person", profile_id)
143
+ return _profile_context(app, "organization", profile_id)
@@ -0,0 +1,5 @@
1
+ """Models for the profile templates package."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __all__ = []