ResearchObject / ro-crate-py

Python library for RO-Crate
https://pypi.org/project/rocrate/
Apache License 2.0
46 stars 23 forks source link

avoid deprecated pkg_resources #173

Closed mashehu closed 5 months ago

mashehu commented 7 months ago

I think it is unrlated: but test are not running locally due to:

ImportError while loading conftest '/Users/matho180/ro-crate-py/test/conftest.py'.
test/conftest.py:24: in <module>
    from rocrate.utils import get_norm_value
rocrate/__init__.py:54: in <module>
    import arcp  # noqa
E   ModuleNotFoundError: No module named 'arcp'

(I can import the module if I start python manually)

simleo commented 6 months ago

It is related, since without this PR tests run fine locally. I get a different error:

ImportError while loading conftest '/home/simleo/git/ro-crate-py/test/conftest.py'.
test/conftest.py:24: in <module>
    from rocrate.utils import get_norm_value
rocrate/__init__.py:57: in <module>
    from .model.metadata import Metadata  # noqa
rocrate/model/__init__.py:28: in <module>
    from .computationalworkflow import ComputationalWorkflow, WorkflowDescription, Workflow
rocrate/model/computationalworkflow.py:27: in <module>
    from .file import File
rocrate/model/file.py:28: in <module>
    from .file_or_dir import FileOrDir
rocrate/model/file_or_dir.py:24: in <module>
    from .data_entity import DataEntity
rocrate/model/data_entity.py:22: in <module>
    from .entity import Entity
rocrate/model/entity.py:25: in <module>
    from .. import vocabs
rocrate/vocabs.py:25: in <module>
    RO_CRATE = json.loads(importlib.resources.read_text(__name__, "data/ro-crate.jsonld"))
E   TypeError: 'rocrate.vocabs' is not a package

It's not just local tests that are broken, the rocrate executable is affected as well.

simleo commented 6 months ago

It turns out that automated tests also fail. However, the error is different:

ImportError while loading conftest '/home/runner/work/ro-crate-py/ro-crate-py/test/conftest.py'.
test/conftest.py:24: in <module>
    from rocrate.utils import get_norm_value
rocrate/__init__.py:57: in <module>
    from .model.metadata import Metadata  # noqa
rocrate/model/__init__.py:2[8](https://github.com/ResearchObject/ro-crate-py/actions/runs/8158453547/job/22300413292?pr=173#step:6:9): in <module>
    from .computationalworkflow import ComputationalWorkflow, WorkflowDescription, Workflow
rocrate/model/computationalworkflow.py:27: in <module>
    from .file import File
rocrate/model/file.py:28: in <module>
    from .file_or_dir import FileOrDir
rocrate/model/file_or_dir.py:24: in <module>
    from .data_entity import DataEntity
rocrate/model/data_entity.py:22: in <module>
    from .entity import Entity
rocrate/model/entity.py:25: in <module>
    from .. import vocabs
rocrate/vocabs.py:25: in <module>
    RO_CRATE = json.loads(importlib.resources.read_text(__name__, "data/ro-crate.jsonld"))
E   ValueError: 'data/ro-crate.jsonld' must be only a file name
elichad commented 6 months ago

Agh, importlib.resources.files was only introduced in Python 3.9, but the older option of importlib.resources.read_text() doesn't support the .jsonld files being inside a directory. Possible solutions: we could move those files out of data/, or split the strategy for different Python versions, or just avoid making this change until Python 3.8 goes out of support later this year...

simleo commented 6 months ago

I went for the split strategy but got unrelated errors in the CI

simleo commented 6 months ago

The errors on the Mac instances are actually unrelated to any code change, see #176

simleo commented 6 months ago

OK, it looks like this is finally working. @mashehu @elichad since you're both new contributors, before I merge I need you to update the authors section in CITATION.cff. I need also your copyright lines to update the headers -- @elichad in your case I think we already have it (University of Manchester).

elichad commented 5 months ago

@simleo I added my name, and yes my affiliation is already covered for the copyright.