Skip to content

Commit

Permalink
minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwlouse committed Jan 14, 2016
1 parent 5b2103d commit 27f92f2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
12 changes: 6 additions & 6 deletions sacred/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def get_py_file_if_possible(pyc_name):


def get_digest(filename):
h = hashlib.md5()
with open(filename, 'rb') as f:
h = hashlib.md5()
with open(filename, 'rb') as f:
data = f.read(1 * MB)
while data:
h.update(data)
data = f.read(1 * MB)
while data:
h.update(data)
data = f.read(1 * MB)
return h.hexdigest()


Expand Down Expand Up @@ -181,7 +181,7 @@ def get_relevant_path_parts(path):
if path_parts[-1] in ['__init__.py', '__init__.pyc']:
path_parts = path_parts[:-1]
else:
path_parts[-1], ext = os.path.splitext(path_parts[-1])
path_parts[-1], _ = os.path.splitext(path_parts[-1])
return path_parts


Expand Down
10 changes: 5 additions & 5 deletions sacred/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ def gather_commands(self):
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 All @@ -279,7 +277,7 @@ def get_experiment_info(self):
"""
dependencies = set()
sources = set()
for ing, _ in self._traverse_ingredients():
for ing, _ in self.traverse_ingredients():
dependencies |= ing.dependencies
sources |= ing.sources

Expand All @@ -292,17 +290,19 @@ def get_experiment_info(self):
dependencies=[d.to_tuple() for d in sorted(dependencies)],
doc=self.doc)

def _traverse_ingredients(self):
def traverse_ingredients(self):
if self._is_traversing:
raise CircularDependencyError()
else:
self._is_traversing = True
yield self, 0
for ingredient in self.ingredients:
for ingred, depth in ingredient._traverse_ingredients():
for ingred, depth in ingredient.traverse_ingredients():
yield ingred, depth + 1
self._is_traversing = False

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

def _create_run_for_command(self, command_name, config_updates=None,
named_configs=()):
run = create_run(self, command_name, config_updates,
Expand Down
7 changes: 3 additions & 4 deletions sacred/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ def create_scaffolding(experiment, sorted_ingredients):

def gather_ingredients_topological(ingredient):
sub_ingredients = defaultdict(int)
for sub_ing, depth in ingredient._traverse_ingredients():
for sub_ing, depth in ingredient.traverse_ingredients():
sub_ingredients[sub_ing] = max(sub_ingredients[sub_ing], depth)
return sorted(sub_ingredients, key=lambda x: -sub_ingredients[x])


def get_config_modifications(scaffolding, config_updates):
def get_config_modifications(scaffolding):
config_modifications = ConfigSummary()
for sc_path, scaffold in scaffolding.items():
config_modifications.update_add(scaffold.config_mods, path=sc_path)
Expand Down Expand Up @@ -308,8 +308,7 @@ def create_run(experiment, command_name, config_updates=None,
scaffold.set_up_seed() # partially recursive

config = get_configuration(scaffolding)
config_modifications = get_config_modifications(scaffolding,
config_updates)
config_modifications = get_config_modifications(scaffolding)

# ----------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion sacred/observers/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def resource_event(self, filename):

def artifact_event(self, filename):
with open(filename, 'rb') as f:
head, tail = os.path.split(filename)
_, tail = os.path.split(filename)
run_id = self.run_entry['_id']
db_filename = 'artifact://{}/{}/{}'.format(
self.run_entry['experiment']['name'], run_id, tail)
Expand Down

0 comments on commit 27f92f2

Please sign in to comment.