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

add ga4gh refget digest functionality #58

Merged
merged 5 commits into from
Dec 20, 2024
Merged

add ga4gh refget digest functionality #58

merged 5 commits into from
Dec 20, 2024

Conversation

nsheff
Copy link
Member

@nsheff nsheff commented Dec 17, 2024

Adds a new digests module that provides md5 and ga4gh digest computation for strings and fasta files.

I did not implement a CLI for it, just rust library functions and python bindings.

I confirmed the python bindings work for me locally.

@nsheff
Copy link
Member Author

nsheff commented Dec 17, 2024

Do you know why I can't do this?

from gtars.digests import digest_fasta
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gtars.digests'

When I can do this?

from gtars import digests
>>> digests
<module 'digests'>
>>> digests.digest_fasta()

@nleroy917
Copy link
Member

Two things:

  1. When I test, I make sure that I am in a different directory, otherwise python can be weird about imports (because there is a gtars folder already there so it tries that first...)
  2. You might need to create a bindings/python/gtars/digests/__init__.py file with this inside:
from .gtars.digests import *

You can place a __init__.pyi file next to it to add type-annotations/docs for intellisense inside IDE's too. Check out the other folders for examples. Tokenizers is probably a good example.

The reason this __init__.py file is needed is not totally clear to me... but its what I got to work after looking at other examples of Rust + Python bindings for pyo3 with a module system and then also looking at the pyo3 discussion forum

@nsheff
Copy link
Member Author

nsheff commented Dec 17, 2024

yeah I had figured that out, but even after adding that I still get the same issue...

@nsheff
Copy link
Member Author

nsheff commented Dec 17, 2024

But now the error is different:

from gtars.digests import md5_digest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nsheff/.local/lib/python3.12/site-packages/gtars/digests/__init__.py", line 1, in <module>
    from .gtars.digests import *  # noqa: F403
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'gtars.digests.gtars'

@nleroy917
Copy link
Member

I think we are missing sys_modules.set_item("")... line 35 in bindings/python/src/lib.rs

    // set names of submodules
    sys_modules.set_item("gtars.tokenizers", m.getattr("tokenizers")?)?;
    sys_modules.set_item("gtars.ailist", m.getattr("ailist")?)?;
    sys_modules.set_item("gtars.utils", m.getattr("utils")?)?;
    sys_modules.set_item("gtars.models", m.getattr("models")?)?;
    // <--------    add your module here? 

@nsheff
Copy link
Member Author

nsheff commented Dec 17, 2024

Yep that was what I was missing. it works now! thanks.

@nleroy917
Copy link
Member

Do we want to merge this soon?

Copy link
Member

@donaldcampbelljr donaldcampbelljr left a comment

Choose a reason for hiding this comment

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

Great. Thanks for adding tests and docs, too.

gtars/src/digests/mod.rs Outdated Show resolved Hide resolved
@nsheff nsheff merged commit 47b6316 into dev Dec 20, 2024
@nsheff nsheff deleted the digests branch December 20, 2024 18:31
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.

3 participants