Skip to content

Commit

Permalink
various: various changes
Browse files Browse the repository at this point in the history
* Bumps dependencies.
* Uses `black` tests.
* Adds 008.

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Jun 12, 2024
1 parent 0e49203 commit b873242
Show file tree
Hide file tree
Showing 60 changed files with 7,901 additions and 7,431 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/continuous-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
# with:
# access_token: ${{ github.token }}

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '14'
node-version: '16'

- name: Docker compose up
run: docker-compose up -d

- name: Set up Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ celerybeat-schedule

# VSCodium
.vscode

.DS_Store
12 changes: 5 additions & 7 deletions Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ RUN pip install --upgrade setuptools wheel pip poetry
# # uwsgi uwsgitop uwsgi-tools

# Install Node
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install --no-install-recommends -y nodejs && rm -rf /var/lib/apt/lists/*

# RUN npm update

# RUN python -m site
# RUN python -m site --user-site
RUN apt-get update && apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && apt-get install nodejs -y

# Install Invenio
ENV WORKING_DIR=/invenio
Expand Down
1,971 changes: 1,136 additions & 835 deletions poetry.lock

Large diffs are not rendered by default.

45 changes: 24 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,35 @@ invenio-oaiharvester = { git = "https://github.com/inveniosoftware/invenio-oaiha
invenio-search = {version = ">=2.1.0,<3.0.0", extras = ["elasticsearch7"]}

# Invenio core modules
invenio-app = ">=1.3.4,<1.4.0"
invenio-base = ">=1.2.16,<1.3.0"
invenio-cache = ">=1.1.1,<1.2.0"
invenio-celery = ">=1.2.5,<1.3.0"
invenio-config = ">=1.0.3,<1.1.0"
invenio-app = ">=1.4.0,<2.0.0"
invenio-base = ">=1.3.0,<2.0.0"
invenio-cache = ">=1.1.1,<2.0.0"
invenio-celery = ">=1.2.5,<2.0.0"
invenio-config = ">=1.0.3,<2.0.0"
invenio-i18n = ">=2.0.0,<3.0.0"
invenio-db = {version = ">=1.1.0,<1.2.0", extras = ["postgresql"]}
invenio-db = {version = ">=1.1.0,<2.0.0", extras = ["postgresql"]}
# Invenio base bundle
invenio-admin = ">=1.4.0,<1.5.0"
# invenio-assets = ">=3.0.0,<4.0.0" # error patch-package 6.5.1 semantic-ui-less
invenio-assets = ">=2.0.0,<3.0.0"
invenio-assets = ">=3.0.0,<4.0.0"
invenio-formatter = ">=2.0.0,<3.0.0"
invenio-logging = {version = ">=2.0.0,<3.0.0"}
invenio-logging = ">=2.0.0,<3.0.0"
invenio-mail = ">=2.0.0,<3.0.0"
invenio-rest = ">=1.3.0,<1.4.0"
invenio-theme = ">=2.5.7,<3.0.0"
invenio-rest = ">=1.3.0,<2.0.0"
invenio-theme = ">=3.0.0,<4.0.0"
# Invenio auth bundle
invenio-access = ">=2.0.0,<3.0.0"
invenio-accounts = ">=3.5.2,<4.0.0"
invenio-accounts = ">=5.0.0,<6.0.0"
invenio-oauth2server = ">=2.0.0,<3.0.0"
invenio-oauthclient = ">=3.0.0,<4.0.0"
invenio-userprofiles = ">=2.2.0,<3.0.0"
invenio-oauthclient = ">=4.0.0,<5.0.0"
invenio-userprofiles = ">=3.0.0,<4.0.0"
# Invenio metadata bundle
invenio-indexer = ">=2.2.0,<3.0.0"
invenio-jsonschemas = ">=1.1.4,<1.2.0"
invenio-oaiserver = ">=2.2.0,<2.3.0"
invenio-pidstore = ">=1.3.0,<1.4.0"
invenio-records-rest = ">=2.2.0,<2.3.0"
invenio-records-ui = ">=1.2.0,<1.3.0"
invenio-records = "2.1.0,<2.2.0"
invenio-jsonschemas = ">=1.1.4,<2.0.0"
invenio-oaiserver = ">=2.2.0,<3.0.0"
invenio-pidstore = ">=1.3.0,<2.0.0"
invenio-records-rest = ">=2.2.0,<3.0.0"
invenio-records-ui = ">=1.2.0,<2.0.0"
invenio-records = "2.1.0,<3.0.0"
#invenio-search-ui = ">=2.4.0,<3.0.0"
# Pinned due to before_first_request deprecation https://flask.palletsprojects.com/en/2.2.x/api/#flask.Flask.before_first_request
Flask = ">=2.2.0,<2.3.0"
Expand All @@ -80,7 +79,6 @@ responses = "*"

## Deployment
python-dotenv = ">=0.13.0"
pydocstyle = ">=6.1.1"

## RERO ILS specific python modules
poethepoet = "*"
Expand All @@ -92,6 +90,8 @@ poethepoet = "*"
#----------------------------------------------------------
## Default from Invenio
pytest-invenio = ">=2.1.6,<3.0.0"
pydocstyle = ">=6.1.1"
pytest-black = ">=0.3.2"
Sphinx = ">=4.5.0"
## RERO ILS specific python packages
safety = ">=1.8,<3.0.0"
Expand Down Expand Up @@ -174,6 +174,9 @@ server = {cmd = "./scripts/server", help = "Starts the server "}
setup = {cmd = "./scripts/setup", help = "Runs setup"}
update = {cmd = "./scripts/update", help = "Runs update"}

[tool.isort]
profile = "black"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
2 changes: 1 addition & 1 deletion rero_ebooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
from .ext import ReroEBooks
from .version import __version__

__all__ = ('__version__', 'ReroEBooks')
__all__ = ("__version__", "ReroEBooks")
83 changes: 36 additions & 47 deletions rero_ebooks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class EbooksSearch(RecordsSearch):
class Meta:
"""Search only on documents index."""

index = 'ebooks'
index = "ebooks"
doc_types = None
fields = ('*', )
fields = ("*",)
facets = {}

default_filter = None
Expand All @@ -63,8 +63,8 @@ class Ebook(Record):
minter = ebook_pid_minter
fetcher = ebook_pid_fetcher
provider = EbookPidProvider
object_type = 'rec'
uri_key = 'electronic_location_and_access'
object_type = "rec"
uri_key = "electronic_location_and_access"

@classmethod
def _merge_uri(cls, new_record, old_record):
Expand All @@ -83,31 +83,33 @@ def _merge_uri(cls, new_record, old_record):
# check if already exists!
if e_res not in new_e_res:
new_e_res.append(copy.deepcopy(e_res))
idx = new_record['__order__'].index(field)
new_record['__order__'].insert(idx, field)
idx = new_record["__order__"].index(field)
new_record["__order__"].insert(idx, field)
return new_record

@classmethod
def create_or_update(cls, data, id_=None, dbcommit=False, reindex=False,
vendor=None, **kwargs):
def create_or_update(
cls, data, id_=None, dbcommit=False, reindex=False, vendor=None, **kwargs
):
"""Create or update ebook record."""
pid = build_ebook_pid(data, vendor)
record = cls.get_record_by_pid(pid)
if record is not None:
merged_data = cls._merge_uri(data, record)
record.update(merged_data, dbcommit=dbcommit, reindex=reindex,
forceindex=reindex)
return record, 'UPDATE'
record.update(
merged_data, dbcommit=dbcommit, reindex=reindex, forceindex=reindex
)
return record, "UPDATE"
else:
created_record = cls.create(
data,
id_=None,
vendor=vendor,
dbcommit=dbcommit,
reindex=reindex,
forceindex=reindex
forceindex=reindex,
)
return created_record, 'CREATE'
return created_record, "CREATE"

@classmethod
def _delete_uri(cls, not_available_record, old_record, url):
Expand All @@ -125,41 +127,35 @@ def _delete_uri(cls, not_available_record, old_record, url):
epub_count = 0
for e_res in not_available_e_res:
# check if exists!
res_url = e_res.get('uniform_resource_identifier')
res_url = e_res.get("uniform_resource_identifier")
if res_url.startswith(url) and e_res in old_e_res:
epub_count += 1
old_e_res.remove(e_res)
old_record['__order__'].remove(field)
old_record["__order__"].remove(field)

return old_record, epub_count

@classmethod
def remove_uri(cls, data, vendor=None, url=None,
dbcommit=False, reindex=False):
def remove_uri(cls, data, vendor=None, url=None, dbcommit=False, reindex=False):
"""Create or update ebook record."""
pid = build_ebook_pid(data, vendor)
record = cls.get_record_by_pid(pid)
if record is not None:
merged_data, epub_count = cls._delete_uri(data, record, url)
record.replace(merged_data, dbcommit=dbcommit, reindex=reindex,
forceindex=reindex)
return record, f'REMOVE URIs: {epub_count}'
data['pid'] = pid
return data, 'REMOVE missing'
record.replace(
merged_data, dbcommit=dbcommit, reindex=reindex, forceindex=reindex
)
return record, f"REMOVE URIs: {epub_count}"
data["pid"] = pid
return data, "REMOVE missing"

@classmethod
def create(
cls,
data,
id_=None,
dbcommit=False,
reindex=False,
vendor=None,
**kwargs
cls, data, id_=None, dbcommit=False, reindex=False, vendor=None, **kwargs
):
"""Create a new ebook record."""
assert cls.minter
assert not data.get('pid')
assert not data.get("pid")
if not id_:
id_ = uuid4()
cls.minter(id_, data, vendor)
Expand Down Expand Up @@ -189,13 +185,9 @@ def get_record_by_pid(cls, pid, with_deleted=False):
"""Get ebook record by pid value."""
assert cls.provider
try:
persistent_identifier = PersistentIdentifier.get(
cls.provider.pid_type,
pid
)
persistent_identifier = PersistentIdentifier.get(cls.provider.pid_type, pid)
return super(Ebook, cls).get_record(
persistent_identifier.object_uuid,
with_deleted=with_deleted
persistent_identifier.object_uuid, with_deleted=with_deleted
)
except NoResultFound:
return None
Expand All @@ -215,12 +207,13 @@ def update(self, data, dbcommit=False, reindex=False, forceindex=False):
def replace(self, data, dbcommit=False, reindex=False, forceindex=False):
"""Replace data in record."""
new_data = copy.deepcopy(data)
pid = new_data.get('pid')
pid = new_data.get("pid")
if not pid:
raise EbookError.PidMissing(f'missing pid={self.pid}')
raise EbookError.PidMissing(f"missing pid={self.pid}")
self.clear()
self = self.update(new_data, dbcommit=dbcommit, reindex=reindex,
forceindex=forceindex)
self = self.update(
new_data, dbcommit=dbcommit, reindex=reindex, forceindex=forceindex
)
return self

def dbcommit(self, reindex=False, forceindex=False):
Expand All @@ -245,17 +238,13 @@ def delete_from_index(self):
def get_persistent_identifier(cls, pid):
"""Get Persistent Identifier."""
return PersistentIdentifier.get_by_object(
cls.provider.pid_type,
cls.object_type,
pid
cls.provider.pid_type, cls.object_type, pid
)

@classmethod
def _get_all(cls, with_deleted=False):
"""Get all persistent identifier records."""
query = PersistentIdentifier.query.filter_by(
pid_type=cls.provider.pid_type
)
query = PersistentIdentifier.query.filter_by(pid_type=cls.provider.pid_type)
if not with_deleted:
query = query.filter_by(status=PIDStatus.REGISTERED)
return query
Expand All @@ -282,4 +271,4 @@ def count(cls, with_deleted=False):
@property
def pid(self):
"""Get ebook record pid value."""
return self.get('pid')
return self.get("pid")
Loading

0 comments on commit b873242

Please sign in to comment.