Skip to main content

Group files together in a breeze with glob-like patterns

Project description

grob

Release Build status Commit activity License

Group files together in a flexible way using glob-like patterns.

pip install grob

In its simplest form, grob simply lists all files in a directory:

~ grob "*" .
[
  "examples/one_tag_same_dir/root/image_001.png",
  "examples/one_tag_same_dir/root/image_002.jpg",
  "examples/one_tag_same_dir/root/image_003.gif"
]

given the following directory content:

root
├── image_001.png
├── image_002.jpg
└── image_003.gif

However, grob is mainly useful to group different files together. Let's say you have images and corresponding JSON description for each image:

root
├── image_1.png
├── image_2.png
├── image_3.png
├── labels_1.json
├── labels_2.json
└── labels_3.json
~ grob "image=image_{id}.png,labels=labels_{id}.json" .
{
    "1": {"image": "image_1.png", "labels": "labels_1.json"},
    "2": {"image": "image_2.png", "labels": "labels_2.json"},
    "3": {"image": "image_3.png", "labels": "labels_3.json"}
}

Now imagine each group of inputs is stored in the same subdirectory:

root
├── group_a
│   ├── image.png
│   └── labels.json
├── group_b
│   ├── image.png
│   └── labels.json
├── group_c
│   ├── image.png
│   └── labels.json
└── group_d
    ├── image.png
    └── labels.json

We just need to update our pattern:

~ grob "image=group_{name}/*.png,labels=group_{name}/*.json" .
{
    "a": {"image": "group_a/image.png", "labels": "group_a/labels.json"},
    "b": {"image": "group_b/image.png", "labels": "group_b/labels.json"},
    "c": {"image": "group_c/image.png", "labels": "group_c/labels.json"},
    "d": {"image": "group_d/image.png", "labels": "group_d/labels.json"}
}

What if each type of file lives in its own directory?

root
├── images
│   ├── fifi.gif
│   ├── loulou.png
│   └── riri.jpg
└── labels
    ├── fifi.json
    ├── loulou.json
    └── riri.json
~ grob "image=images/{name}.*,labels={name}.json" .
{
    "riri": {"image": "images/riri.jpg", "labels": "labels/riri.json"},
    "fifi": {"image": "images/fifi.gif", "labels": "labels/fifi.json"},
    "loulou": {"image": "images/loulou.png", "labels": "labels/loulou.json"}
}

See more in the Examples section, or check tests/examples/.

Contribute

Install the environment and the pre-commit hooks with

make install

Run tests:

make tests
# Alternatively, you can directly run `pytest`

Run code quality tools:

make check

Repository initiated with fpgmaas/cookiecutter-poetry.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grob-0.2.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

grob-0.2.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file grob-0.2.0.tar.gz.

File metadata

  • Download URL: grob-0.2.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1016-azure

File hashes

Hashes for grob-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6332e981f9751d0f601f793cbdebd594ff7b09a6148abb1007ee65c05e39613a
MD5 1c4021343510e6bbf78a692817d1d254
BLAKE2b-256 3c5128c581bc8b2ad9b21c5007deb8a5e5fa9a5e4f2243f2e11b583183bb3dec

See more details on using hashes here.

File details

Details for the file grob-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: grob-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1016-azure

File hashes

Hashes for grob-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a42cb95e0f4703573184e9510ba5e8272feb0332adfb1a3ad9eaa6102ddbe1f6
MD5 0ced28b95f2f1208bedb818605cfc5d9
BLAKE2b-256 0c1379fec43deaa7eafa1edfb6120980a15966053ebfa988392fb66243b16197

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page