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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build a plugin starting from the template repo. #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ctb
Copy link
Owner

@ctb ctb commented Jan 5, 2023

This is an example of writing a sourmash plugin, starting from sourmash-bio/sourmash_plugin_template.

Look under "Files changed" to see the aggregate changes.

How to install and run

I install this branch with:

pip install -e .

and then:

sourmash sig cat genome.sig -o this.test1.sig

outputs

*** test1 plugin matches this.test1.sig! using!
loaded 3 signatures total, from 1 files
loaded 3 signatures total.
*** test1 plugin is writing!
output 3 signatures

and

sourmash sig describe this.test1.sig        

shows:

== This is sourmash version 4.6.1. ==
== Please cite Brown and Irber (2016), doi:10.21105/joss.00027. ==

*** test1 plugin is at work! Reading from this.test1.sig
...

demonstrating that the plugin is loading and running properly! 馃帀

@ctb ctb changed the title An example of the changes needed to build a plugin from the template. How to build a plugin starting from the template repo. Jan 5, 2023
readme = "README.md"
requires-python = ">=3.8"
version = "0.1"

dependencies = ["sourmash>=4.8.0,<5"]
dependencies = ["sourmash>=4.6.1,<5"]
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is needed because sourmash v4.8 isn't yet released.


[metadata]
license = { text = "BSD 3-Clause License" }

# CTB note: do not need both reader and writer.

[project.entry-points."sourmash.load_from"]
xyz_reader = "sourmash_plugin_xyz:load_sketches"
test1_reader = "sourmash_plugin_test1:load_sketches"
Copy link
Owner Author

Choose a reason for hiding this comment

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

the sourmash_plugin_test1 needs to match the project name, above.

@@ -15,10 +15,12 @@
#

def load_sketches(location, *args, **kwargs):
if location and location.endswith('.xyz'):
if location and location.endswith('.test1.sig'):
Copy link
Owner Author

Choose a reason for hiding this comment

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

this plugin handles loading for all files with extension .test1.sig.

@@ -37,17 +39,20 @@ def __init__(self, location):
def matches(self, location):
# match anything that is not None or ""
if location:
return location.endswith('.xyz')
notify(f"*** test1 plugin matches {location}! using!")
return location.endswith('.test1.sig')
Copy link
Owner Author

Choose a reason for hiding this comment

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

and this plugin handles saving for all files with extension .test1.sig.

class ScriptsCommand_XYZ:
command = "xyz"
description = "do something xyz"
class ScriptsCommand_Test1:
Copy link
Owner Author

Choose a reason for hiding this comment

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

This adds a command-line command sourmash scripts test1 <filename_test> -x/--xyz.

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.

None yet

1 participant