diff --git a/loanpy/pyproject.toml b/loanpy/pyproject.toml index 0e4f0696632bcc6f833eeeec8b05cf4db47c09c2..9534aed6027d3e70922a1f8c5c3773e4dd1164a4 100644 --- a/loanpy/pyproject.toml +++ b/loanpy/pyproject.toml @@ -24,10 +24,26 @@ classifiers = [ requires-python = ">= 3.8" dependencies = [ "caosadvancedtools", + "importlib_resources", "py3-validate-email", "linkahead@git+https://gitlab.indiscale.com/caosdb/src/caosdb-pylib.git@dev" ] + +[project.optional-dependencies] +test = [ + "pytest", + "pytest-env", + "pytest-cov", + "coverage>=4.4.2", +] + +[tool.setuptools.packages.find] +where = ["src"] + +[tool.setuptools.package-data] +"loan" = ["*.ini"] + [project.urls] Homepage = "https://getlinkahead.com" Documentation = "https://docs.indiscale.com" diff --git a/loanpy/src/loan/conf.py b/loanpy/src/loan/conf.py index 68c36d8d5ace019ef8d8ef4ff47a7b4187b75f18..390830bdf9a6120222bc446562cd42862fc4c945 100644 --- a/loanpy/src/loan/conf.py +++ b/loanpy/src/loan/conf.py @@ -1,25 +1,27 @@ import linkahead as db import os import configparser -import importlib.resources as pkg_resources +from importlib_resources import files, as_file -default_config_path = pkg_resources.path(__package__, 'default_config.ini') -user_config_path = os.path.expanduser('~/.linkahead_loan') -config = configparser.ConfigParser() -config.read([default_config_path, user_config_path]) -rts = config['RecordTypes'] -ps = config['Properties'] -# RecordTypes +with as_file(files('loan').joinpath('default_config.ini')) as default_config_path: + user_config_path = os.path.expanduser('~/.linkahead_loan') + config = configparser.ConfigParser() + config.read([default_config_path, user_config_path]) + global rts, ps + rts = config['RecordTypes'] + ps = config['Properties'] +# RecordTypes BOX = db.RecordType(name=rts['BOX']) PERSON = db.RecordType(name=rts['PERSON']) LOAN = db.RecordType(name=rts['LOAN']) +LOCATION = db.RecordType(name=rts['LOCATION']) # Properties FIRST_NAME = db.Property(name=ps['FIRST_NAME'], datatype=db.TEXT) LAST_NAME = db.Property(name=ps['LAST_NAME'], datatype=db.TEXT) EMAIL = db.Property(name=ps['EMAIL'], datatype=db.TEXT) -LOCATION = db.RecordType(name=rts['LOCATION']) + DESTINATION = db.Property(name=ps['DESTINATION'], datatype=rts['LOCATION']) RETURNLOCATION = db.Property(name=ps['RETURNLOCATION'], datatype=rts['LOCATION']) COMMENT = db.Property(name=ps['COMMENT'], datatype=db.TEXT) diff --git a/loanpy/src/loan/default_config.ini b/loanpy/src/loan/default_config.ini new file mode 100644 index 0000000000000000000000000000000000000000..7b49b0fa1978a4a801689b4c2eb242b3513586cd --- /dev/null +++ b/loanpy/src/loan/default_config.ini @@ -0,0 +1,25 @@ +[RecordTypes] +BOX = Box +PERSON = Person +LOAN = Loan +LOCATION = Location + + +[Properties] +FIRST_NAME = firstName +LAST_NAME = lastName +EMAIL = email +DESTINATION = LoanLocation +RETURNLOCATION = ReturnLocation +COMMENT = comment +EXHAUST_CONTENTS = exhaustContents +BORROWER = Borrower +CONTENT = Content +LOAN_REQUESTED = loanRequested +EXPECTED_RETURN = expectedReturn +LOAN_ACCEPTED = loanAccepted +LENT = lent +RETURN_REQUESTED = returnRequested +RETURN_ACCEPTED = returnAccepted +RETURNED = returned +BOX_NUMBER = Number diff --git a/loanpy/src/loan/request_loan.py b/loanpy/src/loan/request_loan.py index 16eb783153a1cf292d81262d5c221a37efe27790..e582089bec41c772e5d564b59e032108c87cb5bf 100755 --- a/loanpy/src/loan/request_loan.py +++ b/loanpy/src/loan/request_loan.py @@ -83,8 +83,8 @@ def _check_data(data): bad_references.append(item) if bad_references: raise ValueError( - f"The following value(s) of {F_BOX} has/have the wrong type. It should be " - f"integers or string representations thereof.\n{bad_references}") + f"The following value(s) of {F_BOX} has/have the wrong type. It should be " + f"integers or string representations thereof.\n{bad_references}") assert_date_in_future( data[F_EXPECTED_RETURN_DATE], ("The expected return date needs to be in the future."