Skip to content
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
12 changes: 12 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[settings]
combine_as_imports=true
force_alphabetical_sort_within_sections=true
# Override force_grid_wrap value from profile=black, but black is still happy
force_grid_wrap=2
# Same line length as for black
line_length=120
no_lines_before=LOCALFOLDER
profile=black
reverse_relative=true
skip_gitignore=true
src_paths=src
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
graft src
include *.rst LICENSE
include *.rst LICENSE src/ephemeris/py.typed
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Default tests run with make test and make quick-tests
NOSE_TESTS?=tests ephemeris
# Default environment for make tox
ENV?=py27
ENV?=py37
# Extra arguments supplied to tox command
ARGS?=
# Location of virtualenv used for development.
Expand Down
34 changes: 20 additions & 14 deletions src/ephemeris/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@

# -*- coding: utf-8 -*-

import yaml
from bioblend import galaxy

__version__ = '0.10.7'
__version__ = "0.10.7"

PROJECT_NAME = "ephemeris"
PROJECT_OWNER = PROJECT_USERAME = "galaxyproject"
PROJECT_URL = "https://github.com/galaxyproject/ephemeris"
PROJECT_AUTHOR = 'Galaxy Project and Community'
PROJECT_EMAIL = 'jmchilton@gmail.com'
PROJECT_AUTHOR = "Galaxy Project and Community"
PROJECT_EMAIL = "jmchilton@gmail.com"
RAW_CONTENT_URL = "https://raw.github.com/%s/%s/master/" % (
PROJECT_USERAME, PROJECT_NAME
PROJECT_USERAME,
PROJECT_NAME,
)


def check_url(url, log=None):
if not url.startswith('http'):
if not url.startswith("http"):
if log:
log.warning('URL should start with http:// or https://. https:// chosen by default.')
url = 'https://' + url
log.warning(
"URL should start with http:// or https://. https:// chosen by default."
)
url = "https://" + url
return url


Expand All @@ -35,25 +37,29 @@ def get_galaxy_connection(args, file=None, log=None, login_required=True):
else:
file_content = dict()

url = args.galaxy or file_content.get('galaxy_instance')
url = args.galaxy or file_content.get("galaxy_instance")
galaxy_url = check_url(url, log)
api_key = args.api_key or file_content.get('api_key')
api_key = args.api_key or file_content.get("api_key")

if args.user and args.password:
return galaxy.GalaxyInstance(url=galaxy_url, email=args.user, password=args.password)
return galaxy.GalaxyInstance(
url=galaxy_url, email=args.user, password=args.password
)
elif api_key:
return galaxy.GalaxyInstance(url=galaxy_url, key=api_key)
elif not login_required:
return galaxy.GalaxyInstance(url=galaxy_url)
else:
raise ValueError("Missing api key or user & password combination, in order to make a galaxy connection.")
raise ValueError(
"Missing api key or user & password combination, in order to make a galaxy connection."
)


def load_yaml_file(filename):
"""
Load YAML from the `tool_list_file` and return a dict with the content.
"""
with open(filename, 'r') as f:
with open(filename, "r") as f:
dictionary = yaml.safe_load(f)
return dictionary

Expand All @@ -62,5 +68,5 @@ def dump_to_yaml_file(content, file_name):
"""
Dump YAML-compatible `content` to `file_name`.
"""
with open(file_name, 'w') as f:
with open(file_name, "w") as f:
yaml.dump(content, f, default_flow_style=False)
45 changes: 26 additions & 19 deletions src/ephemeris/common_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,36 @@


def get_common_args(login_required=True, log_file=False):

parser = argparse.ArgumentParser(add_help=False)
general_group = parser.add_argument_group('General options')
general_group.add_argument("-v", "--verbose", help="Increase output verbosity.", action="store_true")
general_group = parser.add_argument_group("General options")
general_group.add_argument(
"-v", "--verbose", help="Increase output verbosity.", action="store_true"
)
if log_file:
general_group.add_argument("--log_file",
dest="log_file",
help="Where the log file should be stored. "
"Default is a file in your system's temp folder",
default=None)
general_group.add_argument(
"--log_file",
dest="log_file",
help="Where the log file should be stored. "
"Default is a file in your system's temp folder",
default=None,
)

con_group = parser.add_argument_group('Galaxy connection')
con_group.add_argument("-g", "--galaxy",
help="Target Galaxy instance URL/IP address",
default="http://localhost:8080")
con_group = parser.add_argument_group("Galaxy connection")
con_group.add_argument(
"-g",
"--galaxy",
help="Target Galaxy instance URL/IP address",
default="http://localhost:8080",
)

if login_required:
con_group.add_argument("-u", "--user",
help="Galaxy user email address")
con_group.add_argument("-p", "--password",
help="Password for the Galaxy user")
con_group.add_argument("-a", "--api_key",
dest="api_key",
help="Galaxy admin user API key (required if not defined in the tools list file)")
con_group.add_argument("-u", "--user", help="Galaxy user email address")
con_group.add_argument("-p", "--password", help="Password for the Galaxy user")
con_group.add_argument(
"-a",
"--api_key",
dest="api_key",
help="Galaxy admin user API key (required if not defined in the tools list file)",
)

return parser
15 changes: 8 additions & 7 deletions src/ephemeris/ephemeris_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ class ProgressConsoleHandler(logging.StreamHandler):
A handler class which allows the cursor to stay on
one line for selected messages
"""

on_same_line = False

def emit(self, record):
try:
msg = self.format(record)
stream = self.stream
same_line = hasattr(record, 'same_line')
same_line = hasattr(record, "same_line")
if self.on_same_line and not same_line:
stream.write('\r\n')
stream.write("\r\n")
stream.write(msg)
if same_line:
stream.write('.')
stream.write(".")
self.on_same_line = True
else:
stream.write('\r\n')
stream.write("\r\n")
self.on_same_line = False
self.flush()
except (KeyboardInterrupt, SystemExit):
Expand All @@ -32,16 +33,16 @@ def emit(self, record):

def disable_external_library_logging():
# Omit (most of the) logging by external libraries
logging.getLogger('bioblend').setLevel(logging.ERROR)
logging.getLogger('requests').setLevel(logging.ERROR)
logging.getLogger("bioblend").setLevel(logging.ERROR)
logging.getLogger("requests").setLevel(logging.ERROR)
try:
logging.captureWarnings(True) # Capture HTTPS warngings from urllib3
except AttributeError:
pass


def setup_global_logger(name, log_file=None):
formatter = logging.Formatter('%(asctime)s %(levelname)-5s - %(message)s')
formatter = logging.Formatter("%(asctime)s %(levelname)-5s - %(message)s")
progress = ProgressConsoleHandler()
console = logging.StreamHandler()
console.setFormatter(formatter)
Expand Down
Loading