Skip to content

Commit

Permalink
some style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwlouse committed Sep 24, 2015
1 parent c4a1df0 commit f0b41b2
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
# -- Options for HTML output ----------------------------------------------

# on_rtd is whether we are on readthedocs.org
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get('READTHEDOCS') == 'True'

if not on_rtd: # only import and set the theme if we're building docs locally
try:
Expand Down
2 changes: 1 addition & 1 deletion examples/03_hello_config_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
@ex.config
def cfg():
recipient = "world"
message = "Hello %s!" % recipient
message = "Hello {}!".format(recipient)


# again we can access the message here by taking it as an argument
Expand Down
4 changes: 2 additions & 2 deletions examples/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def cfg1():

@data_ingredient.capture
def load_data(filename, normalize):
print("loading dataset from '%s'" % filename)
print("loading dataset from '{}'".format(filename))
if normalize:
print("normalizing dataset")
return 1
Expand All @@ -27,7 +27,7 @@ def load_data(filename, normalize):

@data_ingredient.command
def stats(filename):
print('Statistics for dataset "%s":' % filename)
print('Statistics for dataset "{}":'.format(filename))
print('mean = 42.23')


Expand Down
4 changes: 2 additions & 2 deletions examples/named_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
@ex.named_config
def rude():
recipient = "bastard"
message = "Fuck off you %s!" % recipient
message = "Fuck off you {}!".format(recipient)


@ex.config
def cfg():
recipient = "world"
message = "Hello %s!" % recipient
message = "Hello {}!".format(recipient)


@ex.automain
Expand Down
1 change: 0 additions & 1 deletion sacred/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def parse_args(argv, description="", commands=None, print_help=True):
"""
Parse the given commandline-arguments.
:param argv: list of command-line arguments as in ``sys.argv``
:type argv: list[str]
:param description: description of the experiment (docstring) to be used
Expand Down
6 changes: 3 additions & 3 deletions sacred/config/config_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def __call__(self, fixed=None, preset=None, fallback=None):

for arg in self.arg_spec.args:
if arg not in available_entries:
raise KeyError("'%s' not in preset for ConfigScope. "
"Available options are: %s" %
(arg, available_entries))
raise KeyError("'{}' not in preset for ConfigScope. "
"Available options are: {}"
.format(arg, available_entries))
if arg in preset:
cfg_locals[arg] = preset[arg]
else: # arg in fallback
Expand Down
3 changes: 2 additions & 1 deletion sacred/config/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def construct_arguments(self, args, kwargs, options, bound=False):
def __unicode__(self):
pos_args = self.positional_args
varg = ["*" + self.vararg_name] if self.vararg_name else []
kwargs = ["%s=%s" % (n, v.__repr__()) for n, v in self.kwargs.items()]
kwargs = ["{}={}".format(n, v.__repr__())
for n, v in self.kwargs.items()]
kw_wc = ["**" + self.kw_wildcard_name] if self.kw_wildcard_name else []
arglist = pos_args + varg + kwargs + kw_wc
return "{}({})".format(self.name, ", ".join(arglist))
Expand Down
10 changes: 4 additions & 6 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def run_command(self, command_name, config_updates=None,
op_name = '--' + option.get_flag()[1]
if op_name in args and args[op_name]:
option.apply(args[op_name], run)
self.current_run.run_logger.info("Running command '%s'" % command_name)
self.current_run.run_logger.info("Running command '%s'", command_name)
run()
self.current_run = None
return run
Expand All @@ -151,7 +151,7 @@ def run_commandline(self, argv=None):
"""
if argv is None:
argv = sys.argv
all_commands = self._gather_commands()
all_commands = self.gather_commands()

args = parse_args(argv,
description=self.doc,
Expand Down Expand Up @@ -224,12 +224,10 @@ def my_captured_function(_run):
"""
return self.current_run.info

# =========================== Private Helpers =============================

def _gather_commands(self):
def gather_commands(self):
for cmd_name, cmd in self.commands.items():
yield cmd_name, cmd

for ingred in self.ingredients:
for cmd_name, cmd in ingred._gather_commands():
for cmd_name, cmd in ingred.gather_commands():
yield cmd_name, cmd
20 changes: 10 additions & 10 deletions sacred/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ def add_package_dependency(self, package_name, version):
raise ValueError('Invalid Version: "{}"'.format(version))
self.dependencies.add(PackageDependency(package_name, version))

def gather_commands(self):
for cmd_name, cmd in self.commands.items():
yield self.path + '.' + cmd_name, cmd

for ingred in self.ingredients:
for cmd_name, cmd in ingred.gather_commands():
yield cmd_name, cmd

# ======================== Private Helpers ================================

def get_experiment_info(self):
"""Get a dictionary with information about this experiment.
Expand Down Expand Up @@ -256,8 +266,6 @@ def get_experiment_info(self):
dependencies=[d.to_tuple() for d in sorted(dependencies)],
doc=self.doc)

# ======================== Private Helpers ================================

def _traverse_ingredients(self):
if self._is_traversing:
raise CircularDependencyError()
Expand All @@ -274,11 +282,3 @@ def _create_run_for_command(self, command_name, config_updates=None,
run = create_run(self, command_name, config_updates,
named_configs=named_configs_to_use)
return run

def _gather_commands(self):
for cmd_name, cmd in self.commands.items():
yield self.path + '.' + cmd_name, cmd

for ingred in self.ingredients:
for cmd_name, cmd in ingred._gather_commands():
yield cmd_name, cmd
2 changes: 1 addition & 1 deletion sacred/observers/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def final_save(self, attempts=10):
prefix='sacred_mongo_fail_') as f:
pickle.dump(self.run_entry, f)
print("Warning: saving to MongoDB failed! "
"Stored experiment entry in '%s'" % f.name,
"Stored experiment entry in '{}'".format(f.name),
file=sys.stderr)

def started_event(self, ex_info, host_info, start_time, config, comment):
Expand Down
2 changes: 1 addition & 1 deletion sacred/randomness.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_seed(rnd=None):

def create_rnd(seed):
assert isinstance(seed, integer_types), \
"Seed has to be integer but was %s %s" % (repr(seed), type(seed))
"Seed has to be integer but was {} {}".format(repr(seed), type(seed))
if opt.has_numpy:
return opt.np.random.RandomState(seed)
else:
Expand Down
6 changes: 3 additions & 3 deletions sacred/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,22 @@ def _emit_completed(self, result):
if result is not None:
self.run_logger.info('Result: {}'.format(result))
elapsed_time = self._stop_time()
self.run_logger.info('Completed after %s' % elapsed_time)
self.run_logger.info('Completed after %s', elapsed_time)
for observer in self.observers:
self._final_call(observer, 'completed_event',
stop_time=self.stop_time,
result=result)

def _emit_interrupted(self):
elapsed_time = self._stop_time()
self.run_logger.warning("Aborted after %s!" % elapsed_time)
self.run_logger.warning("Aborted after %s!", elapsed_time)
for observer in self.observers:
self._final_call(observer, 'interrupted_event',
interrupt_time=self.stop_time)

def _emit_failed(self, exc_type, exc_value, trace):
elapsed_time = self._stop_time()
self.run_logger.error("Failed after %s!" % elapsed_time)
self.run_logger.error("Failed after %s!", elapsed_time)
fail_trace = traceback.format_exception(exc_type, exc_value, trace)
for observer in self.observers:
self._final_call(observer, 'failed_event',
Expand Down
10 changes: 2 additions & 8 deletions sacred/utils.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
#!/usr/bin/env python
# coding=utf-8
from __future__ import division, print_function, unicode_literals

import collections
import logging
import os.path
import re
import sys
import traceback as tb
from contextlib import contextmanager

from six import StringIO
import wrapt

__sacred__ = True # marks files that should be filtered from stack traces


if sys.version_info[0] == 3:
import io
StringIO = io.StringIO
else:
from StringIO import StringIO

NO_LOGGER = logging.getLogger('ignore')
NO_LOGGER.disabled = 1

Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_example(capsys, example_test):
captured_out = captured_out.split('\n')
captured_err = captured_err.split('\n')
for out_line in out:
assert out_line == captured_out[0] or out_line == captured_err[0]
assert out_line in [captured_out[0], captured_err[0]]
if out_line == captured_out[0]:
captured_out.pop(0)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ingredients.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,6 @@ def foo():
def bar():
pass

commands = list(ing2._gather_commands())
commands = list(ing2.gather_commands())
assert ('other.bar', bar) in commands
assert ('tickle.foo', foo) in commands

0 comments on commit f0b41b2

Please sign in to comment.