-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9caad08
Showing
25 changed files
with
728 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Build and test | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
oarepo: | ||
description: OARepo version (11, 12, ...) | ||
required: true | ||
default: 11 | ||
type: string | ||
|
||
env: | ||
OAREPO_VERSION: ${{ inputs.oarepo }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Cache pip | ||
uses: actions/cache@v3 | ||
with: | ||
# This path is specific to Ubuntu | ||
path: ~/.cache/pip | ||
# Look to see if there is a cache hit for the corresponding requirements file | ||
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
${{ runner.os }}- | ||
- name: Configure sysctl limits | ||
run: | | ||
sudo swapoff -a | ||
sudo sysctl -w vm.swappiness=1 | ||
sudo sysctl -w fs.file-max=262144 | ||
sudo sysctl -w vm.max_map_count=262144 | ||
- name: Runs Opensearch | ||
uses: ankane/setup-opensearch@v1 | ||
with: | ||
plugins: analysis-icu | ||
|
||
- name: Start Redis | ||
uses: supercharge/[email protected] | ||
with: | ||
redis-version: ${{ matrix.redis-version }} | ||
|
||
- name: Run tests | ||
run: | | ||
./run-tests.sh | ||
- name: Build package to publish | ||
run: | | ||
.venv-builder/bin/python setup.py sdist bdist_wheel | ||
- name: Freeze packages | ||
run: | | ||
.venv-builder/bin/pip freeze > requirements.txt | ||
.venv-tests/bin/pip freeze >>requirements.txt | ||
- name: Archive production artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist | ||
|
||
- name: Archive production artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: requirements.txt | ||
path: requirements.txt |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Dispatch | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
oarepo: | ||
description: OARepo version (11, 12, ...) | ||
required: true | ||
default: 11 | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/build.yaml | ||
with: | ||
oarepo: ${{ github.event.inputs.oarepo }} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Build, test and publish | ||
|
||
on: push | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
build11: | ||
uses: ./.github/workflows/build.yaml | ||
with: | ||
oarepo: 11 | ||
|
||
build12: | ||
uses: ./.github/workflows/build.yaml | ||
with: | ||
oarepo: 12 | ||
|
||
publish: | ||
runs-on: ubuntu-latest | ||
needs: build11 | ||
steps: | ||
- name: Use built artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist | ||
|
||
- name: List files | ||
run: | | ||
ls -la | ||
ls -la dist | ||
- name: Publish package | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
skip_existing: true | ||
user: __token__ | ||
password: ${{ secrets.PYPI_PASSWORD }} |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# Idea software family | ||
.idea/ | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
venv/ | ||
.venv/ | ||
build/ | ||
develop-eggs/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Vim swapfiles | ||
.*.sw? | ||
|
||
tests/test.db | ||
|
||
.venv* | ||
.direnv | ||
|
||
docs/migration/data | ||
|
||
.env | ||
.envrc | ||
/.python-version | ||
/poetry.lock | ||
example/data | ||
.DS_Store | ||
|
||
test-model | ||
|
||
# Testing | ||
sample/ | ||
|
||
tests/test-sample-app | ||
tests/test-sample-site | ||
|
||
example_document/ | ||
dist/ | ||
|
||
.model_venv/ | ||
.vscode | ||
|
||
thesis |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (C) 2021 CESNET. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
recursive-include oarepo_doi * | ||
prune tests | ||
prune thesis |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# OARepo DOI |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
black oarepo_requests tests --target-version py310 | ||
autoflake --in-place --remove-all-unused-imports --recursive oarepo_requests tests | ||
isort oarepo_requests tests --profile black |
Empty file.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from invenio_requests.customizations import SubmitAction | ||
from invenio_requests.resolvers.registry import ResolverRegistry | ||
from invenio_records_resources.proxies import current_service_registry | ||
|
||
from oarepo_doi.api import create_doi | ||
|
||
|
||
class DoiDraftAction(SubmitAction): | ||
def execute(self, identity, uow): | ||
topic = self.request.topic.resolve() | ||
# create_doi(topic, event=None) | ||
super().execute(identity, uow) |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import requests | ||
import json | ||
from invenio_base.utils import obj_or_import_string | ||
from flask import current_app | ||
|
||
|
||
def create_doi(service, record, data, event = None ): | ||
""" if event = None, doi will be created as a draft.""" | ||
|
||
mapping = obj_or_import_string(service.mapping[record.schema])() | ||
errors = mapping.metadata_check(data) | ||
if len(errors) > 0 and event: | ||
return #todo: dois can not be published with missing mandatory values | ||
|
||
request_metadata = mapping.create_datacite_payload(data) | ||
|
||
if event: | ||
request_metadata["data"]["attributes"]["event"] = event | ||
|
||
request_metadata["data"]["attributes"]["prefix"] = service.prefix | ||
|
||
request = requests.post(url=service.url, json=request_metadata, headers={'Content-type': 'application/vnd.api+json'}, | ||
auth=(service.username, service.password) | ||
) | ||
|
||
if request.status_code != 201: | ||
raise requests.ConnectionError("Expected status code 201, but got {}".format(request.status_code)) | ||
|
||
content = request.content.decode('utf-8') | ||
json_content = json.loads(content) | ||
doi_value = json_content['data']['id'] | ||
mapping.add_doi(record, data, doi_value) | ||
|
||
|
||
def edit_doi(service, record, event = None): | ||
""" edit existing draft """ | ||
|
||
mapping = obj_or_import_string(service.mapping[record.schema])() | ||
errors = mapping.metadata_check(record) | ||
if len(errors) > 0 and event: | ||
return #todo: dois can not be published with missing mandatory values | ||
doi_value = mapping.get_doi(record) | ||
if doi_value: | ||
if not service.url.endswith('/'): | ||
url = service.url + '/' | ||
else: | ||
url = service.url | ||
url = url + doi_value.replace("/", "%2F") | ||
|
||
request_metadata = mapping.create_datacite_payload(record) | ||
if event: | ||
request_metadata["data"]["attributes"]["event"] = event | ||
|
||
request = requests.put(url=url, json=request_metadata, headers={'Content-type': 'application/vnd.api+json'}, | ||
auth=(service.username, service.password)) | ||
|
||
if request.status_code != 200: | ||
raise requests.ConnectionError("Expected status code 200, but got {}".format(request.status_code)) | ||
|
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
class OARepoDOI(object): | ||
"""OARepo DOI extension.""" | ||
|
||
def __init__(self, app=None): | ||
"""Extension initialization.""" | ||
if app: | ||
self.init_app(app) | ||
|
||
def init_app(self, app): | ||
"""Flask application initialization.""" | ||
self.init_config(app) | ||
app.extensions["oarepo-doi"] = self | ||
|
||
def init_config(self, app): | ||
"""Initialize configuration.""" | ||
if "DATACITE_URL" not in app.config: | ||
app.config["DATACITE_URL"] = 'https://api.datacite.org/dois' | ||
if "DATACITE_MODE" not in app.config: | ||
app.config["DATACITE_MODE"] = "ON_EVENT" |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import json | ||
import requests | ||
from invenio_records_resources.services.records.components import ServiceComponent | ||
from flask import current_app | ||
from invenio_base.utils import obj_or_import_string | ||
|
||
from oarepo_doi.api import create_doi, edit_doi | ||
|
||
|
||
class DoiComponent(ServiceComponent): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.mode = current_app.config.get("DATACITE_MODE") | ||
self.username = current_app.config.get("DATACITE_USERNAME") | ||
self.password = current_app.config.get("DATACITE_PASSWORD") | ||
self.url = current_app.config.get("DATACITE_URL") | ||
self.prefix = current_app.config.get("DATACITE_PREFIX") | ||
self.mapping = current_app.config.get("DATACITE_MAPPING") | ||
|
||
def create(self, identity, data=None, record=None, **kwargs): | ||
if self.mode == "AUTOMATIC_DRAFT": | ||
create_doi(self, record,data, None) | ||
|
||
def update_draft(self, identity, data=None, record=None, **kwargs): | ||
if self.mode == "AUTOMATIC_DRAFT": | ||
edit_doi(self, record) | ||
|
||
def update(self, identity, data=None, record=None, **kwargs): | ||
if self.mode == "AUTOMATIC_DRAFT" or self.mode == "AUTOMATIC": | ||
edit_doi(self, record) | ||
|
||
def publish(self, identity, data=None, record=None, **kwargs): | ||
if self.mode == "AUTOMATIC": | ||
create_doi(self, record, data, "publish") | ||
if self.mode == "AUTOMATIC_DRAFT": | ||
edit_doi(self, record, "publish") |
Empty file.
Oops, something went wrong.