Skip to content
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

Upgrade module #159

Merged
merged 9 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@ jobs:
matrix:
python-version: [3.9]
requirements-level: [pypi]
db-service: [postgresql12]
search-service: [elasticsearch7, opensearch1, opensearch2]
db-service: [postgresql13, postgresql14]
search-service: [elasticsearch7, opensearch2]
include:
- db-service: postgresql12
DB_EXTRAS: "postgresql"

- search-service: opensearch1
SEARCH_EXTRAS: "opensearch1"

- search-service: opensearch2
SEARCH_EXTRAS: "opensearch2"

Expand All @@ -47,7 +41,7 @@ jobs:
env:
DB: ${{ matrix.db-service }}
SEARCH: ${{ matrix.search-service }}
EXTRAS: all,${{ matrix.DB_EXTRAS }},${{ matrix.SEARCH_EXTRAS }}
EXTRAS: tests,${{ matrix.SEARCH_EXTRAS }},postgresql

steps:
- name: Checkout
Expand All @@ -60,8 +54,9 @@ jobs:

- name: Generate dependencies
run: |
python -m pip install --upgrade pip setuptools py wheel requirements-builder
pip install wheel requirements-builder
requirements-builder -e "$EXTRAS" --level=${{ matrix.requirements-level }} setup.py > .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt
cat .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt

- name: Cache pip
uses: actions/cache@v2
Expand Down
14 changes: 4 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import sphinx.environment

from invenio_circulation import __version__

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -56,23 +58,15 @@
#
# The short X.Y version.

# Get the version string. Cannot be done with import!
g = {}
with open(os.path.join(os.path.dirname(__file__), '..',
'invenio_circulation', 'version.py'),
'rt') as fp:
exec(fp.read(), g)
version = g['__version__']

# The full version, including alpha/beta/rc tags.
release = version
release = __version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down
3 changes: 2 additions & 1 deletion invenio_circulation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""Invenio module for the circulation of bibliographic items."""

from .ext import InvenioCirculation
from .version import __version__

__version__ = "2.0.0a1"

__all__ = ('__version__', 'InvenioCirculation')
52 changes: 37 additions & 15 deletions invenio_circulation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,44 @@
from .api import Loan
from .links import loan_links_factory
from .permissions import views_permissions_factory
from .pidstore.pids import _LOANID_CONVERTER, CIRCULATION_LOAN_FETCHER, \
CIRCULATION_LOAN_MINTER, CIRCULATION_LOAN_PID_TYPE
from .pidstore.pids import (
_LOANID_CONVERTER,
CIRCULATION_LOAN_FETCHER,
CIRCULATION_LOAN_MINTER,
CIRCULATION_LOAN_PID_TYPE,
)
from .search.api import LoansSearch
from .transitions.transitions import CreatedToPending, \
ItemAtDeskToItemOnLoan, ItemInTransitHouseToItemReturned, \
ItemOnLoanToItemInTransitHouse, ItemOnLoanToItemOnLoan, \
ItemOnLoanToItemReturned, PendingToItemAtDesk, \
PendingToItemInTransitPickup, ToCancelled, ToItemOnLoan
from .utils import can_be_requested, document_exists, document_ref_builder, \
get_default_extension_duration, get_default_extension_max_count, \
get_default_loan_duration, is_loan_duration_valid, item_can_circulate, \
item_exists, item_location_retriever, item_ref_builder, patron_exists, \
patron_ref_builder, same_location_validator, \
transaction_location_validator, transaction_user_validator, \
validate_item_pickup_transaction_locations
from .transitions.transitions import (
CreatedToPending,
ItemAtDeskToItemOnLoan,
ItemInTransitHouseToItemReturned,
ItemOnLoanToItemInTransitHouse,
ItemOnLoanToItemOnLoan,
ItemOnLoanToItemReturned,
PendingToItemAtDesk,
PendingToItemInTransitPickup,
ToCancelled,
ToItemOnLoan,
)
from .utils import (
can_be_requested,
document_exists,
document_ref_builder,
get_default_extension_duration,
get_default_extension_max_count,
get_default_loan_duration,
is_loan_duration_valid,
item_can_circulate,
item_exists,
item_location_retriever,
item_ref_builder,
patron_exists,
patron_ref_builder,
same_location_validator,
transaction_location_validator,
transaction_user_validator,
validate_item_pickup_transaction_locations,
)

CIRCULATION_ITEMS_RETRIEVER_FROM_DOCUMENT = None
"""Function that returns a list of item PIDs given a Document PID."""
Expand Down Expand Up @@ -183,7 +206,6 @@
pid_minter=CIRCULATION_LOAN_MINTER,
pid_fetcher=CIRCULATION_LOAN_FETCHER,
search_class=LoansSearch,
search_type=None,
record_class=Loan,
record_loaders={
"application/json": (
Expand Down
7 changes: 5 additions & 2 deletions invenio_circulation/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

from . import config
from .api import Loan
from .errors import InvalidLoanStateError, NoValidTransitionAvailableError, \
TransitionConditionsFailedError
from .errors import (
InvalidLoanStateError,
NoValidTransitionAvailableError,
TransitionConditionsFailedError,
)
from .pidstore.pids import CIRCULATION_LOAN_PID_TYPE
from .search.api import LoansSearch
from .transitions.base import Transition
Expand Down
6 changes: 3 additions & 3 deletions invenio_circulation/records/loaders/schemas/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import arrow
from flask import current_app
from flask_babelex import lazy_gettext as _
from invenio_i18n import lazy_gettext as _
from invenio_records_rest.schemas import RecordMetadataSchemaJSONV1
from invenio_records_rest.schemas.fields import PersistentIdentifier
from marshmallow import Schema, ValidationError, fields, post_load, validates
Expand Down Expand Up @@ -46,7 +46,7 @@ def deserialize(self, value, attr=None, data=None, **kwargs):
_value = super().deserialize(value, attr, data, **kwargs)
# return the value as string after marshmallow validation
# because Invenio does not support Python datetime JSON serializer yet
if _value and type(_value) == datetime:
if _value and isinstance(_value, datetime):
return _value.isoformat()
return _value

Expand All @@ -60,7 +60,7 @@ def deserialize(self, value, attr=None, data=None, **kwargs):
_value = super().deserialize(value, attr, data, **kwargs)
# return the value as string after marshmallow validation
# because Invenio does not support Python datetime JSON serializer yet
if _value and type(_value) == date:
if _value and isinstance(_value, date):
return _value.isoformat()
return _value

Expand Down
14 changes: 10 additions & 4 deletions invenio_circulation/transitions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
from invenio_db import db

from ..api import Loan, is_item_available_for_checkout
from ..errors import DocumentDoNotMatchError, DocumentNotAvailableError, \
InvalidLoanStateError, InvalidPermissionError, ItemNotAvailableError, \
MissingRequiredParameterError, TransitionConditionsFailedError, \
TransitionConstraintsViolationError
from ..errors import (
DocumentDoNotMatchError,
DocumentNotAvailableError,
InvalidLoanStateError,
InvalidPermissionError,
ItemNotAvailableError,
MissingRequiredParameterError,
TransitionConditionsFailedError,
TransitionConstraintsViolationError,
)
from ..proxies import current_circulation
from ..signals import loan_state_changed
from ..utils import str2datetime
Expand Down
21 changes: 15 additions & 6 deletions invenio_circulation/transitions/transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@

from invenio_circulation.proxies import current_circulation

from ..api import can_be_requested, get_available_item_by_doc_pid, \
get_document_pid_by_item_pid, get_pending_loans_by_doc_pid, \
is_item_at_desk_available_for_checkout
from ..errors import ItemDoNotMatchError, ItemNotAvailableError, \
LoanMaxExtensionError, RecordCannotBeRequestedError, \
TransitionConditionsFailedError, TransitionConstraintsViolationError
from ..api import (
can_be_requested,
get_available_item_by_doc_pid,
get_document_pid_by_item_pid,
get_pending_loans_by_doc_pid,
is_item_at_desk_available_for_checkout,
)
from ..errors import (
ItemDoNotMatchError,
ItemNotAvailableError,
LoanMaxExtensionError,
RecordCannotBeRequestedError,
TransitionConditionsFailedError,
TransitionConstraintsViolationError,
)
from ..transitions.base import Transition


Expand Down
15 changes: 0 additions & 15 deletions invenio_circulation/version.py

This file was deleted.

7 changes: 5 additions & 2 deletions invenio_circulation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
from invenio_records_rest.views import pass_record
from invenio_rest import ContentNegotiatedMethodView

from .errors import InvalidLoanStateError, ItemNotAvailableError, \
MissingRequiredParameterError
from .errors import (
InvalidLoanStateError,
ItemNotAvailableError,
MissingRequiredParameterError,
)
from .permissions import need_permissions
from .pidstore.pids import _LOANID_CONVERTER, CIRCULATION_LOAN_PID_TYPE
from .proxies import current_circulation
Expand Down
30 changes: 26 additions & 4 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,37 @@ set -o errexit
# Quit on unbound symbols
set -o nounset

# Always bring down docker services
function cleanup() {
# Define function for bringing down services
function cleanup {
eval "$(docker-services-cli down --env)"
}
trap cleanup EXIT

# Check for arguments
# Note: "-k" would clash with "pytest"
keep_services=0
pytest_args=()
for arg in $@; do
# from the CLI args, filter out some known values and forward the rest to "pytest"
# note: we don't use "getopts" here b/c of some limitations (e.g. long options),
# which means that we can't combine short options (e.g. "./run-tests -Kk pattern")
case ${arg} in
-K|--keep-services)
keep_services=1
;;
*)
pytest_args+=( ${arg} )
;;
esac
done

if [[ ${keep_services} -eq 0 ]]; then
trap cleanup EXIT
fi


python -m check_manifest --ignore ".*-requirements.txt"
python -m sphinx.cmd.build -qnNW docs docs/_build/html
eval "$(docker-services-cli up --db ${DB:-postgresql} --search ${SEARCH:-elasticsearch} --cache ${CACHE:-redis} --env)"
eval "$(docker-services-cli up --db ${DB:-postgresql} --search ${SEARCH:-opensearch} --cache ${CACHE:-redis} --env)"
python -m pytest
tests_exit_code=$?
python -m sphinx.cmd.build -qnNW -b doctest docs docs/_build/doctest
Expand Down
Loading
Loading