Skip to content

Commit

Permalink
Merge 3c6cbb4 into c8e570f
Browse files Browse the repository at this point in the history
  • Loading branch information
bosr committed Nov 2, 2018
2 parents c8e570f + 3c6cbb4 commit 08fabd0
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 60 deletions.
2 changes: 1 addition & 1 deletion docs/collected_information.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ also collected. The default host info includes:
ENV captured ENVIRONMENT variables (if set)
=============== ==========================================

Host information is available from the :ref:api_run through ``run.host_info``.
Host information is available from the :ref:`api_run` through ``run.host_info``.
It is sent to the observers by the :ref:`started_event <event_started>`.

The list of captured ENVIRONMENT variables (empty by default) can be extended
Expand Down
20 changes: 10 additions & 10 deletions docs/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,11 @@ some distributed workers fetch and start the queued up runs.
Priority
--------

+---------------+-----------------------------------------+
| ``-p`` | Only queue this run, do not start it. |
+---------------+ |
| ``--queue`` | |
+---------------+-----------------------------------------+
+--------------------------+----------------------------------------+
| ``-P PRIORITY`` | The (numeric) priority for this run. |
+--------------------------+ |
| ``--priority=PRIORITY`` | |
+--------------------------+----------------------------------------+



Expand All @@ -605,11 +605,11 @@ repository, i.e. with no uncommitted changes.

Print Config
------------
+-------------------------+---------------------------------------------------+
| ``-P PRIORITY`` | Always print the config first. |
+-------------------------+ |
| ``--priority=PRIORITY`` | |
+-------------------------+---------------------------------------------------+
+------------------------+------------------------------------------+
| ``-p`` | Always print the config first. |
+------------------------+ |
| ``--print_config`` | |
+------------------------+------------------------------------------+

If this flag is set, sacred will always print the current configuration
including modifications (like the :ref:`print_config` command) before running
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
colorama>=0.4.0
docopt>=0.6.2
jsonpickle>=0.9.3
mock>=2.0.0
Expand All @@ -7,4 +8,4 @@ py>=1.4.32
py-cpuinfo>=4.0
pytest>=3.0.5
six>=1.10.0
wrapt>=1.10.8
wrapt>=1.10.8
44 changes: 25 additions & 19 deletions sacred/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import pprint
import pydoc
import re
import os
from collections import namedtuple, OrderedDict
from pkg_resources import parse_version

from colorama import Fore, Style

from sacred.config import save_config_file
from sacred.serializer import flatten
Expand All @@ -15,16 +19,18 @@
__all__ = ('print_config', 'print_dependencies', 'save_config',
'help_for_command', 'print_named_configs')

BLUE = '\033[94m'
GREEN = '\033[92m'
RED = '\033[91m'
GREY = '\033[90m'
ENDC = '\033[0m'
COLOR_DIRTY = Fore.RED
COLOR_TYPECHANGED = Fore.RED # prepend Style.BRIGHT for bold
COLOR_ADDED = Fore.GREEN
COLOR_MODIFIED = Fore.BLUE
COLOR_DOC = Style.DIM
ENDC = Style.RESET_ALL # '\033[0m'

LEGEND = '(' + BLUE + 'modified' + ENDC +\
', ' + GREEN + 'added' + ENDC +\
', ' + RED + 'typechanged' + ENDC +\
', ' + GREY + 'doc' + ENDC + ')'
LEGEND = \
'(' + COLOR_MODIFIED + 'modified' + ENDC +\
', ' + COLOR_ADDED + 'added' + ENDC +\
', ' + COLOR_TYPECHANGED + 'typechanged' + ENDC +\
', ' + COLOR_DOC + 'doc' + ENDC + ')'

ConfigEntry = namedtuple('ConfigEntry',
'key value added modified typechanged doc')
Expand Down Expand Up @@ -68,16 +74,16 @@ def _format_named_config(indent, path, named_config):
if hasattr(named_config, '__doc__') and named_config.__doc__ is not None:
doc_string = named_config.__doc__
if doc_string.strip().count('\n') == 0:
assign += GREY + ' # {}'.format(doc_string.strip()) + ENDC
assign += COLOR_DOC + ' # {}'.format(doc_string.strip()) + ENDC
else:
doc_string = doc_string.replace('\n', '\n' + indent)
assign += GREY + '\n{}"""{}"""'.format(indent + ' ',
doc_string) + ENDC
assign += COLOR_DOC + '\n{}"""{}"""'.format(indent + ' ',
doc_string) + ENDC
return indent + assign


def _format_named_configs(named_configs, indent=2):
lines = ['Named Configurations (' + GREY + 'doc' + ENDC + '):']
lines = ['Named Configurations (' + COLOR_DOC + 'doc' + ENDC + '):']
for path, named_config in named_configs.items():
lines.append(_format_named_config(indent, path, named_config))
if len(lines) < 2:
Expand Down Expand Up @@ -125,7 +131,7 @@ def print_dependencies(_run):
repos = _run.experiment_info['repositories']
print('\nVersion Control:')
for repo in repos:
mod = RED + 'M' if repo['dirty'] else ' '
mod = COLOR_DIRTY + 'M' if repo['dirty'] else ' '
print('{} {:<43} {}'.format(mod, repo['url'], repo['commit']) +
ENDC)
print('')
Expand Down Expand Up @@ -167,21 +173,21 @@ def _format_entry(indent, entry):
color = ""
indent = ' ' * indent
if entry.typechanged:
color = RED
color = COLOR_TYPECHANGED # red
elif entry.added:
color = GREEN
color = COLOR_ADDED # green
elif entry.modified:
color = BLUE
color = COLOR_MODIFIED # blue
if entry.key == '__doc__':
color = GREY
color = COLOR_DOC # grey
doc_string = entry.value.replace('\n', '\n' + indent)
assign = '{}"""{}"""'.format(indent, doc_string)
elif isinstance(entry, ConfigEntry):
assign = indent + entry.key + " = " + PRINTER.pformat(entry.value)
else: # isinstance(entry, PathEntry):
assign = indent + entry.key + ":"
if entry.doc:
doc_string = GREY + '# ' + entry.doc + ENDC
doc_string = COLOR_DOC + '# ' + entry.doc + ENDC
if len(assign) <= 35:
assign = "{:<35} {}".format(assign, doc_string)
else:
Expand Down
2 changes: 1 addition & 1 deletion sacred/config/config_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def dedent_function_body(body):
if is_empty_or_comment(line):
continue
else:
indent = re.match('^\s*', line).group()
indent = re.match(r'^\s*', line).group()
break

out_lines = [dedent_line(line, indent) for line in lines]
Expand Down
2 changes: 1 addition & 1 deletion sacred/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def create(cls, mod):
for tln in toplevel_names:
cls.modname_to_dist[
tln] = dist.project_name, dist.version
except:
except Exception:
pass

# version = PackageDependency.get_version_heuristic(mod)
Expand Down
2 changes: 1 addition & 1 deletion sacred/host_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _get_cpu_by_sysctl():
def _get_cpu_by_proc_cpuinfo():
command = ["cat", "/proc/cpuinfo"]
all_info = subprocess.check_output(command).decode()
model_pattern = re.compile("^\s*model name\s*:")
model_pattern = re.compile(r"^\s*model name\s*:")
for line in all_info.split("\n"):
if model_pattern.match(line):
return model_pattern.sub("", line, 1).strip()
Expand Down
2 changes: 1 addition & 1 deletion sacred/observers/file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sacred.commandline_options import CommandLineOption
from sacred.dependencies import get_digest
from sacred.observers.base import RunObserver
from sacred.utils import FileNotFoundError, FileExistsError # For compatibility with py2
from sacred.utils import FileNotFoundError, FileExistsError # py2 compat.
from sacred import optional as opt
from sacred.serializer import flatten

Expand Down
2 changes: 1 addition & 1 deletion sacred/observers/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class MongoDbOption(CommandLineOption):
RUN_ID_PATTERN = r"(?P<overwrite>\d{1,12})"
PORT1_PATTERN = r"(?P<port1>\d{1,5})"
PORT2_PATTERN = r"(?P<port2>\d{1,5})"
PRIORITY_PATTERN = "(?P<priority>-?\d+)?"
PRIORITY_PATTERN = r"(?P<priority>-?\d+)?"
DB_NAME_PATTERN = r"(?P<db_name>[_A-Za-z]" \
r"[0-9A-Za-z#%&'()+\-;=@\[\]^_{}]{0,63})"
COLL_NAME_PATTERN = r"(?P<collection>[_A-Za-z]" \
Expand Down
4 changes: 2 additions & 2 deletions sacred/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"convert_to_nested_dict", "convert_camel_case_to_snake_case",
"print_filtered_stacktrace", "is_subdir",
"optional_kwargs_decorator", "get_inheritors",
"apply_backspaces_and_linefeeds", "StringIO", "FileNotFoundError", "FileExistsError",
"rel_path", "IntervalTimer"]
"apply_backspaces_and_linefeeds", "StringIO", "FileNotFoundError",
"FileExistsError", "rel_path", "IntervalTimer"]

# A PY2 compatible basestring, int_types and FileNotFoundError
if sys.version_info[0] == 2:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pep8ignore =
dist/* ALL
sacred.egg-info/* ALL
[flake8]
ignore = D100,D101,D102,D103,D104,D105,D203,D401,F821,E722
ignore = D100,D101,D102,D103,D104,D105,D203,D401,F821,W504,E722
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
'jsonpickle>=0.7.2, <1.0',
'munch>=2.0.2, <3.0',
'wrapt>=1.0, <2.0',
'py-cpuinfo>=4.0'
'py-cpuinfo>=4.0',
'colorama>=0.4',
],
tests_require=[
'mock>=0.8, <3.0',
Expand Down
39 changes: 20 additions & 19 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import pytest
from sacred import Ingredient, Experiment
from sacred.commands import (BLUE, ENDC, GREY, GREEN, RED, ConfigEntry,
from sacred.commands import (COLOR_MODIFIED, ENDC, COLOR_DOC, COLOR_ADDED,
COLOR_TYPECHANGED, ConfigEntry,
PathEntry, _format_config, _format_entry,
help_for_command, _iterate_marked, _non_unicode_repr,
_format_named_configs, _format_named_config)
Expand Down Expand Up @@ -113,28 +114,28 @@ def test_iterate_marked_typechanged(cfg):
(PathEntry('f', False, False, None, None), "f:"),
# Docstring entry
(ConfigEntry('__doc__', 'multiline\ndocstring', False, False, None, None),
GREY + '"""multiline\ndocstring"""' + ENDC),
COLOR_DOC + '"""multiline\ndocstring"""' + ENDC),
])
def test_format_entry(entry, expected):
assert _format_entry(0, entry) == expected


@pytest.mark.parametrize("entry,color", [
(ConfigEntry('a', 1, True, False, None, None), GREEN),
(ConfigEntry('b', 2, False, True, None, None), BLUE),
(ConfigEntry('c', 3, False, False, (bool, int), None), RED),
(ConfigEntry('d', 4, True, True, None, None), GREEN),
(ConfigEntry('e', 5, True, False, (bool, int), None), RED),
(ConfigEntry('f', 6, False, True, (bool, int), None), RED),
(ConfigEntry('g', 7, True, True, (bool, int), None), RED),
(ConfigEntry('a', 1, True, False, None, None), COLOR_ADDED),
(ConfigEntry('b', 2, False, True, None, None), COLOR_MODIFIED),
(ConfigEntry('c', 3, False, False, (bool, int), None), COLOR_TYPECHANGED),
(ConfigEntry('d', 4, True, True, None, None), COLOR_ADDED),
(ConfigEntry('e', 5, True, False, (bool, int), None), COLOR_TYPECHANGED),
(ConfigEntry('f', 6, False, True, (bool, int), None), COLOR_TYPECHANGED),
(ConfigEntry('g', 7, True, True, (bool, int), None), COLOR_TYPECHANGED),
# Path entries
(PathEntry('a', True, False, None, None), GREEN),
(PathEntry('b', False, True, None, None), BLUE),
(PathEntry('c', False, False, (bool, int), None), RED),
(PathEntry('d', True, True, None, None), GREEN),
(PathEntry('e', True, False, (bool, int), None), RED),
(PathEntry('f', False, True, (bool, int), None), RED),
(PathEntry('g', True, True, (bool, int), None), RED),
(PathEntry('a', True, False, None, None), COLOR_ADDED),
(PathEntry('b', False, True, None, None), COLOR_MODIFIED),
(PathEntry('c', False, False, (bool, int), None), COLOR_TYPECHANGED),
(PathEntry('d', True, True, None, None), COLOR_ADDED),
(PathEntry('e', True, False, (bool, int), None), COLOR_TYPECHANGED),
(PathEntry('f', False, True, (bool, int), None), COLOR_TYPECHANGED),
(PathEntry('g', True, True, (bool, int), None), COLOR_TYPECHANGED),
])
def test_format_entry_colors(entry, color):
s = _format_entry(0, entry)
Expand Down Expand Up @@ -183,10 +184,10 @@ def _config_scope_with_multiline_doc():
(0, 'a', None, 'a'),
(1, 'b', None, ' b'),
(4, 'a.b.c', None, ' a.b.c'),
(0, 'c', ConfigScope(_config_scope_with_single_line_doc), 'c' + GREY
(0, 'c', ConfigScope(_config_scope_with_single_line_doc), 'c' + COLOR_DOC
+ ' # doc' + ENDC),
(0, 'd', ConfigScope(_config_scope_with_multiline_doc),
'd' + GREY + '\n """Multiline\n docstring!\n """' + ENDC)
'd' + COLOR_DOC + '\n """Multiline\n docstring!\n """' + ENDC)
])
def test_format_named_config(indent, path, named_config, expected):
assert _format_named_config(indent, path, named_config) == expected
Expand All @@ -211,7 +212,7 @@ def named_config2():
named_configs_text = _format_named_configs(OrderedDict(
ex.gather_named_configs()))
assert named_configs_text.startswith('Named Configurations (' +
GREY + 'doc' + ENDC + '):')
COLOR_DOC + 'doc' + ENDC + '):')
assert 'named_config2' in named_configs_text
assert '# named config with doc' in named_configs_text
assert 'ingred.named_config1' in named_configs_text
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ commands =
py.test \
--cov sacred \
{posargs}
coveralls
coveralls

0 comments on commit 08fabd0

Please sign in to comment.