-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
Currently just creates .shed.yml files from command-line arguments. Arguably the tool author could just open this file and start editing but at least --help provides some sort guidance of what fields are available and validates categories for instance. The real reason to add this however is as a stepping stone toward #118.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import click | ||
import sys | ||
|
||
from planemo.cli import pass_context | ||
|
||
from planemo import options | ||
from planemo import shed | ||
|
||
|
||
@click.command("shed_init") | ||
@options.optional_project_arg() | ||
# TODO: | ||
# @click.option( | ||
# "--from_workflow", | ||
# type=click.Path(exists=True, file_okay=True, resolve_path=True), | ||
# help=('Attempt to generate repository dependencies from specified ' | ||
# 'workflow.') | ||
# ) | ||
@click.option( | ||
"--description", | ||
help='Specify repository description for .shed.yml.' | ||
) | ||
@click.option( | ||
"--long_description", | ||
help='Specify repository long_description for .shed.yml.' | ||
) | ||
@click.option( | ||
"--remote_repository_url", | ||
help='Specify repository remote_repository_url for .shed.yml.' | ||
) | ||
@click.option( | ||
"--homepage_url", | ||
help='Specify repository homepage_url for .shed.yml.' | ||
) | ||
@click.option( | ||
"--category", | ||
multiple=True, | ||
help='Specify repository category for .shed.yml (may specify multiple).', | ||
type=click.Choice(shed.CURRENT_CATEGORIES) | ||
) | ||
@options.shed_owner_option() | ||
@options.shed_name_option() | ||
@options.force_option() | ||
@pass_context | ||
def cli(ctx, path, **kwds): | ||
exit_code = shed.shed_init(ctx, path, **kwds) | ||
sys.exit(exit_code) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,11 @@ | |
except ImportError: | ||
toolshed = None | ||
|
||
from planemo.io import error | ||
from planemo.io import untar_to | ||
from planemo.io import ( | ||
error, | ||
untar_to, | ||
can_write_to_path, | ||
) | ||
|
||
SHED_CONFIG_NAME = '.shed.yml' | ||
NO_REPOSITORIES_MESSAGE = ("Could not find any .shed.yml files or a --name to " | ||
|
@@ -57,6 +60,54 @@ | |
REPO_TYPE_TOOL_DEP = "tool_dependency_definition" | ||
REPO_TYPE_SUITE = "repository_suite_definition" | ||
|
||
# Generate with python scripts/categories.py | ||
CURRENT_CATEGORIES = [ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jmchilton
Author
Member
|
||
"Assembly", | ||
"ChIP-seq", | ||
"Combinatorial Selections", | ||
"Computational chemistry", | ||
"Convert Formats", | ||
"Data Managers", | ||
"Data Source", | ||
"Fasta Manipulation", | ||
"Fastq Manipulation", | ||
"Genome-Wide Association Study", | ||
"Genomic Interval Operations", | ||
"Graphics", | ||
"Imaging", | ||
"Metabolomics", | ||
"Metagenomics", | ||
"Micro-array Analysis", | ||
"Next Gen Mappers", | ||
"Ontology Manipulation", | ||
"Phylogenetics", | ||
"Proteomics", | ||
"RNA", | ||
"SAM", | ||
"Sequence Analysis", | ||
"Statistics", | ||
"Systems Biology", | ||
"Text Manipulation", | ||
"Tool Dependency Packages", | ||
"Tool Generators", | ||
"Transcriptomics", | ||
"Variant Analysis", | ||
"Visualization", | ||
"Web Services", | ||
] | ||
|
||
|
||
def shed_init(ctx, path, **kwds): | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
shed_config_path = os.path.join(path, SHED_CONFIG_NAME) | ||
if not can_write_to_path(shed_config_path, **kwds): | ||
# .shed.yml exists and no --force sent. | ||
return 1 | ||
|
||
_create_shed_config(ctx, shed_config_path, **kwds) | ||
return 0 | ||
|
||
|
||
def shed_repo_config(path): | ||
shed_yaml_path = os.path.join(path, SHED_CONFIG_NAME) | ||
|
@@ -290,6 +341,34 @@ def realize_effective_repositories(path, **kwds): | |
shutil.rmtree(temp_directory) | ||
|
||
|
||
def _create_shed_config(ctx, path, **kwds): | ||
name = kwds.get("name", None) or path_to_repo_name(os.path.dirname(path)) | ||
owner = kwds.get("owner", None) | ||
if owner is None: | ||
owner = ctx.global_config.get("shed_username", None) | ||
description = kwds.get("description", None) or name | ||
long_description = kwds.get("long_description", None) | ||
remote_repository_url = kwds.get("remote_repository_url", None) | ||
homepage_url = kwds.get("homepage_url", None) | ||
categories = kwds.get("category", []) | ||
config = dict( | ||
name=name, | ||
owner=owner, | ||
description=description, | ||
long_description=long_description, | ||
remote_repository_url=remote_repository_url, | ||
homepage_url=homepage_url, | ||
categories=categories, | ||
) | ||
# Remove empty entries... | ||
for k in list(config.keys()): | ||
if config[k] is None: | ||
del config[k] | ||
|
||
with open(path, "w") as f: | ||
yaml.dump(config, f) | ||
|
||
|
||
def _find_raw_repositories(path, **kwds): | ||
name = kwds.get("name", None) | ||
recursive = kwds.get("recursive", False) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from __future__ import print_function | ||
import requests | ||
|
||
|
||
categories = requests.get("https://testtoolshed.g2.bx.psu.edu/api/categories").json() | ||
print("CURRENT_CATEGORIES = [") | ||
for c in map(lambda c: c["name"], categories): | ||
if c[" | ||
print(' "%s",' % c) | ||
print("]") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
|
||
import yaml | ||
|
||
from .test_utils import CliShedTestCase | ||
|
||
|
||
class ShedInitTestCase(CliShedTestCase): | ||
|
||
def test_minimal(self): | ||
with self._isolate() as f: | ||
name = os.path.basename(os.path.abspath(f)) | ||
self._check_exit_code(["shed_init", "--owner", "iuc"]) | ||
shed_config_path = os.path.join(f, ".shed.yml") | ||
assert os.path.exists(shed_config_path) | ||
shed_config = yaml.load(open(shed_config_path, "r")) | ||
assert shed_config["name"] == name | ||
assert shed_config["owner"] == "iuc" | ||
assert shed_config["description"] == name | ||
assert len(shed_config["categories"]) == 0 | ||
|
||
def test_more_options(self): | ||
with self._isolate() as f: | ||
repo_url = "https://github.com/galaxyproject/tools-devteam" | ||
init_command = [ | ||
"shed_init", | ||
"--owner", "devteam", | ||
"--name", "samtools-filter", | ||
"--description", "A samtools repo", | ||
"--long_description", "A longer description.", | ||
"--remote_repository_url", | ||
repo_url, | ||
"--homepage_url", "https://example.com/", | ||
"--category", "SAM", | ||
"--category", "Sequence Analysis", | ||
"--category", "Statistics", | ||
] | ||
self._check_exit_code(init_command) | ||
shed_config_path = os.path.join(f, ".shed.yml") | ||
assert os.path.exists(shed_config_path) | ||
shed_config = yaml.load(open(shed_config_path, "r")) | ||
assert shed_config["name"] == "samtools-filter" | ||
assert shed_config["owner"] == "devteam" | ||
assert shed_config["description"] == "A samtools repo" | ||
assert shed_config["long_description"] == "A longer description." | ||
assert shed_config["remote_repository_url"] == repo_url | ||
assert shed_config["homepage_url"] == "https://example.com/" | ||
|
||
categories = shed_config["categories"] | ||
assert len(categories) == 3 | ||
assert "SAM" in categories | ||
assert "Statistics" in categories |
Better option would be to ask the TS which categories are currently available. But I guess the API is not public.