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

Crate init #46

Merged
merged 6 commits into from
Feb 12, 2021
Merged

Crate init #46

merged 6 commits into from
Feb 12, 2021

Conversation

simleo
Copy link
Collaborator

@simleo simleo commented Feb 12, 2021

Adds an "init" mode that allows to initialize an RO-Crate from an existing directory tree, i.e., build an RO-Crate object that references all files and directories in the tree.

Also adds an "rocrate" command with a nested interface, with init as its first implemented subcommand. rocrate init top_dir initializes the directory tree rooted at top_dir, adding an ro-crate-metadata.json that references files and directories.

$ docker run --rm -it --name ro-crate-py ro-crate-py bash
root@ea40838f1c80:/ro-crate-py# cd /tmp/
root@ea40838f1c80:/tmp# rocrate 
Usage: rocrate [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  add
  init
root@ea40838f1c80:/tmp# rocrate init --help
Usage: rocrate init [OPTIONS] TOP_DIR

Options:
  --help  Show this message and exit.
root@ea40838f1c80:/tmp# cp -rf /ro-crate-py/test/test-data/ro-crate-galaxy-sortchangecase crate_dir
root@ea40838f1c80:/tmp# rm -fv crate_dir/ro-crate-metadata.json 
removed 'crate_dir/ro-crate-metadata.json'
root@ea40838f1c80:/tmp# cp -a crate_dir{,.bak}
root@ea40838f1c80:/tmp# rocrate init crate_dir
root@ea40838f1c80:/tmp# diff -r --brief crate_dir.bak crate_dir
Only in crate_dir: ro-crate-metadata.json
root@ea40838f1c80:/tmp# cat crate_dir/ro-crate-metadata.json 
{
    "@context": "https://w3id.org/ro/crate/1.1/context",
    "@graph": [
        {
            "@id": "./",
            "@type": "Dataset",
            "datePublished": "2021-02-12T12:11:20.426930",
            "hasPart": [
                {
                    "@id": "test/"
                },
                {
                    "@id": "LICENSE"
                },
                {
                    "@id": "sort-and-change-case.ga"
                },
                {
                    "@id": "README.md"
                },
                {
                    "@id": "test/test1/"
                },
                {
                    "@id": "test/test1/sort-and-change-case-test.yml"
                },
                {
                    "@id": "test/test1/input.bed"
                },
                {
                    "@id": "test/test1/output_exp.bed"
                }
            ]
        },
        {
            "@id": "ro-crate-metadata.json",
            "@type": "CreativeWork",
            "about": {
                "@id": "./"
            },
            "conformsTo": {
                "@id": "https://w3id.org/ro/crate/1.1"
            }
        },
        {
            "@id": "test/",
            "@type": "Dataset"
        },
        {
            "@id": "LICENSE",
            "@type": "File"
        },
        {
            "@id": "sort-and-change-case.ga",
            "@type": "File"
        },
        {
            "@id": "README.md",
            "@type": "File"
        },
        {
            "@id": "test/test1/",
            "@type": "Dataset"
        },
        {
            "@id": "test/test1/sort-and-change-case-test.yml",
            "@type": "File"
        },
        {
            "@id": "test/test1/input.bed",
            "@type": "File"
        },
        {
            "@id": "test/test1/output_exp.bed",
            "@type": "File"
        }
    ]
}

Note that the add command is not implemented yet.

Copy link
Contributor

@stain stain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very nice! Thank you!

@stain stain merged commit d7e378a into master Feb 12, 2021
@stain
Copy link
Contributor

stain commented Feb 12, 2021

I merged it, but there is a build issue on Windows:

https://github.com/ResearchObject/ro-crate-py/runs/1887751730?check_suite_focus=true

test/test_read.py::test_init[True] FAILED                                [ 38%]
...
         for p in fpaths:
>           assert isinstance(crate.dereference(p), File)
E           AssertionError: assert False
E            +  where False = isinstance(None, File)
E            +    where None = <bound method ROCrate.dereference of <rocrate.rocrate.ROCrate object at 0x00000199E82CCF08>>('test/test1/input.bed')
E            +      where <bound method ROCrate.dereference of <rocrate.rocrate.ROCrate object at 0x00000199E82CCF08>> = <rocrate.rocrate.ROCrate object at 0x00000199E82CCF08>.dereference

test\test_read.py:191: AssertionError
=========================== short test summary info ===========================
FAILED test/test_read.py::test_init[False] - AssertionError: assert False
FAILED test/test_read.py::test_init[True] - AssertionError: assert False

@stain
Copy link
Contributor

stain commented Feb 12, 2021

Perhaps breaks because

crate_dir = test_data_dir / "ro-crate-galaxy-sortchangecase"

is repeated in two tests?

@simleo
Copy link
Collaborator Author

simleo commented Feb 12, 2021

Perhaps breaks because

crate_dir = test_data_dir / "ro-crate-galaxy-sortchangecase"

is repeated in two tests?

No, every test has its own directory tree. The problems seems to be that file IDs are being added to the crate with backslashes. I'm working on a fix.

@simleo simleo deleted the crate_init branch February 12, 2021 17:13
@simleo
Copy link
Collaborator Author

simleo commented Feb 12, 2021

Windows build fixed in #47.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants