Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix 2 typos #62

Merged
merged 5 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publishdocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Publish gxformat2 Docs
on:
push:
branches:
push:
branches:
- master
jobs:
deploy:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Python CI
on: [push, pull_request]
concurrency:
group: tox-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
Expand Down
17 changes: 8 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# complexity documentation build configuration file, created by
# sphinx-quickstart on Tue Jul 9 22:26:36 2013.
Expand Down Expand Up @@ -62,8 +61,8 @@
master_doc = 'index'

# General information about the project.
project = u'gxformat2'
copyright = u'2015'
project = 'gxformat2'
copyright = '2015'

# The version info for the project you're documenting, acts as replacement
# for |version| and |release|, also used in various other places throughout
Expand Down Expand Up @@ -217,8 +216,8 @@
# [howto/manual]).
latex_documents = [
('index', 'gxformat2.tex',
u'gxformat2 Documentation',
u'Galaxy Project and Community', 'manual'),
'gxformat2 Documentation',
'Galaxy Project and Community', 'manual'),
]

# The name of an image file (relative to this directory) to place at
Expand Down Expand Up @@ -248,8 +247,8 @@
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'galaxy-lib',
u'Galaxy-lib Documentation',
[u'Galaxy Project and Community'], 1)
'Galaxy-lib Documentation',
['Galaxy Project and Community'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -263,8 +262,8 @@
# dir menu entry, description, category)
texinfo_documents = [
('index', 'galaxy-lib',
u'Galaxy-Lib Documentation',
u'Galaxy Project and Community',
'Galaxy-Lib Documentation',
'Galaxy Project and Community',
'galaxy-lib',
'One line description of project.',
'Miscellaneous'),
Expand Down
4 changes: 2 additions & 2 deletions gxformat2/_labels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Utilities for handling unlabelled objects when translating workflow formats."""


class Labels(object):
class Labels:
"""Track labels assigned and generate anonymous ones."""

def __init__(self):
Expand All @@ -13,7 +13,7 @@ def ensure_new_output_label(self, label: str):
"""Ensure supplied label has value or generate an anonymous one."""
if label is None:
self.anonymous_labels += 1
label = "_anonymous_output_%d" % self.anonymous_labels
label = f"_anonymous_output_{self.anonymous_labels}"
assert label not in self.seen_labels
self.seen_labels.add(label)
return label
Expand Down
8 changes: 4 additions & 4 deletions gxformat2/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
CWL_VERSION = "v1.2"

SCRIPT_DESCRIPTION = """
This script converts the an executable Galaxy workflow (in either format -
Format 2 or native .ga) into an abstract CWL representation.
This script converts an executable Galaxy workflow (in either format - Format 2
or native .ga) into an abstract CWL representation.

In order to represent Galaxy tool executions in the Common Workflow Language
workflow language, they are serialized as v1.2+ abstract 'Operation' classes.
Expand Down Expand Up @@ -73,7 +73,7 @@ def _format2_step_to_abstract(format2_step, requirements):
step_run = from_dict(format2_run, subworkflow=True)
abstract_step["run"] = step_run
else:
raise NotImplementedError("Unknown runnabled type encountered [%s]" % format2_run_class)
raise NotImplementedError(f"Unknown runnabled type encountered [{format2_run_class}]")
else:
step_run = {
"class": "Operation",
Expand Down Expand Up @@ -166,7 +166,7 @@ def main(argv=None):
if workflow_path == "-":
workflow_dict = ordered_load(sys.stdin)
else:
with open(workflow_path, "r") as f:
with open(workflow_path) as f:
workflow_dict = ordered_load(f)

abstract_dict = from_dict(workflow_dict)
Expand Down
25 changes: 12 additions & 13 deletions gxformat2/converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Functionality for converting a Format 2 workflow into a standard Galaxy workflow."""
from __future__ import print_function

import argparse
import copy
Expand Down Expand Up @@ -94,13 +93,13 @@ def rename_arg(argument):
def clean_connection(value):
if value and "#" in value and SUPPORT_LEGACY_CONNECTIONS:
# Hope these are just used by Galaxy testing workflows and such, and not in production workflows.
log.warn("Legacy workflow syntax for connections [%s] will not be supported in the future" % value)
log.warn(f"Legacy workflow syntax for connections [{value}] will not be supported in the future")
value = value.replace("#", "/", 1)
else:
return value


class ImportOptions(object):
class ImportOptions:

def __init__(self):
self.deduplicate_subworkflows = False
Expand Down Expand Up @@ -151,7 +150,7 @@ def steps_as_list(format2_workflow: dict, add_ids: bool = False, inputs_offset:
Add keys as labels instead of IDs. Why am I doing this?
"""
if "steps" not in format2_workflow:
raise Exception("No 'steps' key in dict, keys are %s" % format2_workflow.keys())
raise Exception(f"No 'steps' key in dict, keys are {format2_workflow.keys()}")
steps = format2_workflow["steps"]
steps = convert_dict_to_id_list_if_needed(steps, add_label=True, mutate=mutate)
if add_ids:
Expand Down Expand Up @@ -229,9 +228,9 @@ def _python_to_workflow(as_python, conversion_context):
step_type = step.get("type", "tool")
step_type = STEP_TYPE_ALIASES.get(step_type, step_type)
if step_type not in STEP_TYPES:
raise Exception("Unknown step type encountered %s" % step_type)
raise Exception(f"Unknown step type encountered {step_type}")
step["type"] = step_type
eval("transform_%s" % step_type)(conversion_context, step)
eval(f"transform_{step_type}")(conversion_context, step)

outputs = as_python.pop("outputs", [])
outputs = convert_dict_to_id_list_if_needed(outputs)
Expand Down Expand Up @@ -512,7 +511,7 @@ def run_tool_to_step(conversion_context, step, run_action):
step["tool_uuid"] = tool_description.get("uuid")


class BaseConversionContext(object):
class BaseConversionContext:

def __init__(self):
self.labels = {}
Expand Down Expand Up @@ -559,7 +558,7 @@ def get_runnable_description(self, run_action):

run_action_path = run_action["@import"]
runnable_path = os.path.join(self.workflow_directory, run_action_path)
with open(runnable_path, "r") as f:
with open(runnable_path) as f:
runnable_description = ordered_load(f)
run_action = runnable_description

Expand All @@ -572,7 +571,7 @@ def get_runnable_description(self, run_action):
class ConversionContext(BaseConversionContext):

def __init__(self, galaxy_interface, workflow_directory, import_options: Optional[ImportOptions] = None):
super(ConversionContext, self).__init__()
super().__init__()
self.import_options = import_options or ImportOptions()
self.graph_ids = OrderedDict() # type: Dict
self.graph_id_subworkflow_conversion_contexts = {} # type: Dict
Expand All @@ -595,7 +594,7 @@ def get_subworkflow_conversion_context_graph(self, graph_id):
class SubworkflowConversionContext(BaseConversionContext):

def __init__(self, parent_context):
super(SubworkflowConversionContext, self).__init__()
super().__init__()
self.parent_context = parent_context

@property
Expand Down Expand Up @@ -632,7 +631,7 @@ def _is_link(value):

def _join_prefix(prefix, key):
if prefix:
new_key = "%s|%s" % (prefix, key)
new_key = f"{prefix}|{key}"
else:
new_key = key
return new_key
Expand All @@ -657,7 +656,7 @@ def _init_connect_dict(step):
elif isinstance(value, dict) and 'default' in value:
continue
elif isinstance(value, dict):
raise KeyError('step input must define either source or default %s' % value)
raise KeyError(f'step input must define either source or default {value}')
connect[key] = [value]
connection_keys.add(key)

Expand Down Expand Up @@ -731,7 +730,7 @@ def main(argv=None):
workflow_directory = os.path.abspath(format2_path)
galaxy_interface = None

with open(format2_path, "r") as f:
with open(format2_path) as f:
has_workflow = ordered_load(f)

output = python_to_workflow(has_workflow, galaxy_interface=galaxy_interface, workflow_directory=workflow_directory)
Expand Down
16 changes: 7 additions & 9 deletions gxformat2/cytoscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
import string
import sys

import pkg_resources

from gxformat2.model import ensure_step_position
from gxformat2.normalize import steps_normalized

CYTOSCAPE_JS_TEMPLATE = pkg_resources.resource_filename(__name__, 'cytoscape.html')
CYTOSCAPE_JS_TEMPLATE = os.path.join(os.path.dirname(__file__), 'cytoscape.html')
MAIN_TS_PREFIX = "toolshed.g2.bx.psu.edu/repos/"
SCRIPT_DESCRIPTION = """
This script converts the an executable Galaxy workflow (in either format -
Format 2 or native .ga) into a format for visualization with Cytoscape
This script converts an executable Galaxy workflow (in either format - Format 2
or native .ga) into a format for visualization with Cytoscape
(https://cytoscape.org/).

If the target output path ends with .html this script will output a HTML
Expand All @@ -35,7 +33,7 @@ def to_cytoscape(workflow_path: str, output_path=None):
for i, step in enumerate(steps):
step_id = step.get("id") or step.get("label") or str(i)
step_type = step.get("type") or 'tool'
classes = ["type_%s" % step_type]
classes = [f"type_{step_type}"]
if step_type in ['tool', 'subworkflow']:
classes.append("runnable")
else:
Expand All @@ -44,7 +42,7 @@ def to_cytoscape(workflow_path: str, output_path=None):
tool_id = step.get("tool_id")
if tool_id and tool_id.startswith(MAIN_TS_PREFIX):
tool_id = tool_id[len(MAIN_TS_PREFIX):]
label = step.get("id") or step.get("label") or ("tool:%s" % tool_id) or str(i)
label = step.get("id") or step.get("label") or (f"tool:{tool_id}" if tool_id else str(i))
ensure_step_position(step, i)
node_position = dict(x=int(step["position"]["left"]), y=int(step["position"]["top"]))
repo_link = None
Expand All @@ -70,12 +68,12 @@ def to_cytoscape(workflow_path: str, output_path=None):
from_step, output = value.split("/", 1)
else:
from_step, output = value, None
edge_id = "%s__to__%s" % (step_id, from_step)
edge_id = f"{step_id}__to__{from_step}"
edge_data = {"id": edge_id, "source": from_step, "target": step_id, "input": key, "output": output}
elements.append({"group": "edges", "data": edge_data})

if output_path.endswith(".html"):
with open(CYTOSCAPE_JS_TEMPLATE, "r") as f:
with open(CYTOSCAPE_JS_TEMPLATE) as f:
template = f.read()
viz = string.Template(template).safe_substitute(elements=json.dumps(elements))
with open(output_path, "w") as f:
Expand Down
4 changes: 2 additions & 2 deletions gxformat2/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _to_source(has_output_name, label_map, output_id=None):
if output_name == "output":
source = output_label
else:
source = "%s/%s" % (output_label, output_name)
source = f"{output_label}/{output_name}"
return source


Expand All @@ -252,7 +252,7 @@ def main(argv=None):

format2_path = args.input_path
output_path = args.output_path or (format2_path + ".gxwf.yml")
with open(format2_path, "r") as f:
with open(format2_path) as f:
native_workflow_dict = json.load(f)

as_dict = from_galaxy_native(native_workflow_dict)
Expand Down
6 changes: 2 additions & 4 deletions gxformat2/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import abc

import bioblend # type: ignore
import six


@six.add_metaclass(abc.ABCMeta)
class ImporterGalaxyInterface(object):
class ImporterGalaxyInterface(metaclass=abc.ABCMeta):
"""An abstract interface describing Galaxy operations used by gxformat2.

Specifically containing definitions of operations required to load
Expand All @@ -30,7 +28,7 @@ def import_tool(self, tool):
raise NotImplementedError()


class BioBlendImporterGalaxyInterface(object):
class BioBlendImporterGalaxyInterface:
"""Implementation of :class:`ImporterGalaxyInterface` using bioblend."""

def __init__(self, **kwds):
Expand Down
8 changes: 4 additions & 4 deletions gxformat2/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def ensure_key_has_value(lint_context, has_keys, key, value, has_class=None, has
def _lint_step_errors(lint_context, step):
step_errors = step.get("errors")
if step_errors is not None:
lint_context.warn("tool step contains error indicated during Galaxy export - %s" % step_errors)
lint_context.warn(f"tool step contains error indicated during Galaxy export - {step_errors}")


def lint_ga_path(lint_context, path):
Expand Down Expand Up @@ -147,7 +147,7 @@ def _validate_report(lint_context, workflow_dict):
try:
validate_galaxy_markdown(markdown)
except ValueError as e:
lint_context.error("Report markdown validation failed [%s]" % e)
lint_context.error(f"Report markdown validation failed [{e}]")


def _lint_training(lint_context, workflow_dict):
Expand All @@ -159,7 +159,7 @@ def _lint_training(lint_context, workflow_dict):
else:
tags = workflow_dict["tags"]
if lint_context.training_topic not in tags:
lint_context.warn("Missing expected training topic (%s) as workflow tag." % lint_context.training_topic)
lint_context.warn(f"Missing expected training topic ({lint_context.training_topic}) as workflow tag.")
# Move up into individual lints - all workflows should have docs.
format2_dict = ensure_format2(workflow_dict)
if "doc" not in format2_dict:
Expand All @@ -174,7 +174,7 @@ def main(argv=None):
argv = sys.argv
args = _parser().parse_args(argv[1:])
path = args.path
with open(path, "r") as f:
with open(path) as f:
try:
workflow_dict = ordered_load(f)
except Exception:
Expand Down
10 changes: 5 additions & 5 deletions gxformat2/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
DEFAULT_TRAINING_LINT = None


class LintContext(object):
class LintContext:
"""Track running status (state) of linting."""

def __init__(self, level=LEVEL_WARN, training_topic=DEFAULT_TRAINING_LINT):
Expand Down Expand Up @@ -46,15 +46,15 @@ def print_messages(self):
"""Print error messages and update state at the end of linting."""
for message in self.error_messages:
self.found_errors = True
print(".. ERROR: %s" % message)
print(f".. ERROR: {message}")

if self.level != LEVEL_ERROR:
for message in self.warn_messages:
self.found_warns = True
print(".. WARNING: %s" % message)
print(f".. WARNING: {message}")

if self.level == LEVEL_ALL:
for message in self.info_messages:
print(".. INFO: %s" % message)
print(f".. INFO: {message}")
for message in self.valid_messages:
print(".. CHECK: %s" % message)
print(f".. CHECK: {message}")
2 changes: 1 addition & 1 deletion gxformat2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def convert_and_import_workflow(has_workflow, **kwds):
workflow_path = has_workflow
if workflow_directory is None:
workflow_directory = os.path.dirname(has_workflow)
with open(workflow_path, "r") as f:
with open(workflow_path) as f:
has_workflow = ordered_load(f)

if workflow_directory is not None:
Expand Down
Loading