Skip to content

Commit

Permalink
Format source with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
tbekolay committed Jul 24, 2019
1 parent c656fea commit fe9d76f
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 203 deletions.
8 changes: 6 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
def pytest_addoption(parser):
parser.addoption("--test-arg", action="store_true", default=False,
help="Used to test custom pytest arguments")
parser.addoption(
"--test-arg",
action="store_true",
default=False,
help="Used to test custom pytest arguments",
)
30 changes: 19 additions & 11 deletions nengo_bones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def check_list(cfg, key):
if key in cfg and not isinstance(cfg[key], list):
raise TypeError(
"%s should be a list, found '%s'; did you forget "
"to add '-' before each entry?" % (key, cfg[key]))
"to add '-' before each entry?" % (key, cfg[key])
)


def find_config():
Expand Down Expand Up @@ -101,8 +102,8 @@ def fill_defaults(config):
cfg.setdefault("python_requires", ">=3.5")
cfg.setdefault("include_package_data", False)
cfg.setdefault(
"url",
"https://www.nengo.ai/%s" % config["pkg_name"].replace("_", "-"))
"url", "https://www.nengo.ai/%s" % config["pkg_name"].replace("_", "-")
)

if "setup_cfg" in config:
cfg = config["setup_cfg"]
Expand Down Expand Up @@ -159,15 +160,20 @@ def validate_ci_config(ci_config):
Dictionary containing ci_scripts configuration values.
"""
if "template" not in ci_config:
raise KeyError("Script config must define 'template' "
"(for entry %s)" % ci_config)
raise KeyError(
"Script config must define 'template' " "(for entry %s)" % ci_config
)

# make sure that people don't accidentally do things like
# pip_install: dependency (which gives a string), rather than
# pip_install:
# - dependency
list_opts = ("pip_install", "pre_commands", "post_commands",
"codespell_ignore_words")
list_opts = (
"pip_install",
"pre_commands",
"post_commands",
"codespell_ignore_words",
)
for opt in list_opts:
check_list(ci_config, opt)

Expand All @@ -192,8 +198,10 @@ def load_config(conf_file=None):
conf_file = find_config()

if not os.path.exists(str(conf_file)):
raise RuntimeError("Could not find conf_file: %s\n\nPerhaps you are "
"not in the project's root directory?" % conf_file)
raise RuntimeError(
"Could not find conf_file: %s\n\nPerhaps you are "
"not in the project's root directory?" % conf_file
)

def ordered_load(stream):
"""Use OrderedDict instead of dict for loading mappings."""
Expand All @@ -206,8 +214,8 @@ def construct_mapping(loader, node):
return OrderedDict(loader.construct_pairs(node))

OrderedLoader.add_constructor(
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
construct_mapping)
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, construct_mapping
)
return yaml.load(stream, OrderedLoader)

with open(str(conf_file)) as f:
Expand Down
34 changes: 18 additions & 16 deletions nengo_bones/scripts/check_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@


@click.command()
@click.option("--root-dir", default=".",
help="Directory containing files to be checked")
@click.option(
"--root-dir", default=".", help="Directory containing files to be checked"
)
@click.option("--conf-file", default=None, help="Filepath for config file")
@click.option(
"--verbose",
is_flag=True,
help="Show more information about failed checks.",
"--verbose", is_flag=True, help="Show more information about failed checks."
)
def main(root_dir, conf_file, verbose):
"""
Expand Down Expand Up @@ -57,23 +56,26 @@ def main(root_dir, conf_file, verbose):
continue

template = BonesTemplate(filename, env)
new_lines = template.render(
**template.get_render_data(config),
).splitlines(keepends=True)

diff = list(difflib.unified_diff(
current_lines,
new_lines,
fromfile="current %s" % (filename,),
tofile="new %s" % (filename,),
))
new_lines = template.render(**template.get_render_data(config)).splitlines(
keepends=True
)

diff = list(
difflib.unified_diff(
current_lines,
new_lines,
fromfile="current %s" % (filename,),
tofile="new %s" % (filename,),
)
)

if len(diff) > 0:
click.secho(
" Content does not match nengo-bones (version %s);\n"
" please update by running `bones-generate` from\n"
" the root directory." % (__version__,),
fg="red")
fg="red",
)
if verbose:
click.echo("\n Full diff")
click.echo(" =========")
Expand Down
3 changes: 1 addition & 2 deletions nengo_bones/scripts/pr_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def get_issue_count(repo):
"""Count the number of issues and PRs in a repository."""

response = requests.get(
"https://api.github.com/repos/%s/issues?state=all&sort=created"
% (repo,),
"https://api.github.com/repos/%s/issues?state=all&sort=created" % (repo,)
)
return int(response.json()[0]["number"])

Expand Down
4 changes: 1 addition & 3 deletions nengo_bones/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ def load_env():
override_dirs.append(bones_toplevel)
override_loader = jinja2.FileSystemLoader(override_dirs)
# If those fail, use the builtins
builtin_loader = jinja2.FileSystemLoader(
os.path.join(bones_toplevel, "templates")
)
builtin_loader = jinja2.FileSystemLoader(os.path.join(bones_toplevel, "templates"))

env = jinja2.Environment(
loader=jinja2.ChoiceLoader([override_loader, builtin_loader]),
Expand Down
25 changes: 18 additions & 7 deletions nengo_bones/tests/test_check_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@


def test_files(tmpdir):
write_file(tmpdir, ".nengobones.yml", """
write_file(
tmpdir,
".nengobones.yml",
"""
project_name: Dumdum
pkg_name: dummy
repo_name: dummy_org/dummy
contributors_rst: {}
""")
""",
)
check_args = [
"--root-dir", str(tmpdir),
"--conf-file", str(tmpdir.join(".nengobones.yml")),
"--root-dir",
str(tmpdir),
"--conf-file",
str(tmpdir.join(".nengobones.yml")),
"--verbose",
]

Expand All @@ -28,9 +34,14 @@ def test_files(tmpdir):
# generate a valid contributors.rst
result = CliRunner().invoke(
generate_bones.main,
["--conf-file", str(tmpdir.join(".nengobones.yml")),
"--output-dir", str(tmpdir),
"contributors-rst"])
[
"--conf-file",
str(tmpdir.join(".nengobones.yml")),
"--output-dir",
str(tmpdir),
"contributors-rst",
],
)
assert_exit(result, 0)

# successful check
Expand Down
21 changes: 9 additions & 12 deletions nengo_bones/tests/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import pytest


@pytest.mark.xfail("TRAVIS" not in os.environ,
reason="Not running on TravisCI")
@pytest.mark.xfail("TRAVIS" not in os.environ, reason="Not running on TravisCI")
def test_extra_commands():
# pre_commands will be used to set an environment variable, which
# we check for here
Expand All @@ -26,8 +25,7 @@ def test_extra_commands():
assert "TEST_POST_COMMANDS" not in os.environ


@pytest.mark.xfail("TRAVIS" not in os.environ,
reason="Not running on TravisCI")
@pytest.mark.xfail("TRAVIS" not in os.environ, reason="Not running on TravisCI")
def test_env_vars():
# global variable created in travis config
assert os.environ["TEST_GLOBAL_VAR"] == "test global var val"
Expand All @@ -36,8 +34,7 @@ def test_env_vars():
assert os.environ["TEST_LOCAL_VAR"] == "test local var val"


@pytest.mark.xfail("TRAVIS" not in os.environ,
reason="Not running on TravisCI")
@pytest.mark.xfail("TRAVIS" not in os.environ, reason="Not running on TravisCI")
def test_coverage(pytestconfig):
cov_flag = pytestconfig.getoption("--cov", None)

Expand All @@ -48,14 +45,14 @@ def test_coverage(pytestconfig):
assert cov_flag is None


@pytest.mark.xfail("TRAVIS" not in os.environ,
reason="Not running on TravisCI")
@pytest.mark.xfail("TRAVIS" not in os.environ, reason="Not running on TravisCI")
def test_custom_args(pytestconfig):
assert pytestconfig.getoption("--test-arg")


@pytest.mark.xfail("TRAVIS" not in os.environ,
reason="Not running on TravisCI")
@pytest.mark.xfail("TRAVIS" not in os.environ, reason="Not running on TravisCI")
def test_python_version():
assert ".".join(str(x) for x in sys.version_info[:2]) == os.environ[
"TRAVIS_PYTHON_VERSION"]
assert (
".".join(str(x) for x in sys.version_info[:2])
== os.environ["TRAVIS_PYTHON_VERSION"]
)
24 changes: 11 additions & 13 deletions nengo_bones/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def test_find_config():


def test_fill_defaults():
init_cfg = {"travis_yml": {"jobs": [{"script": "docs-test"}]},
"codecov_yml": {}}
init_cfg = {"travis_yml": {"jobs": [{"script": "docs-test"}]}, "codecov_yml": {}}
config.fill_defaults(init_cfg)

assert init_cfg["travis_yml"]["python"] == "3.6"
Expand Down Expand Up @@ -80,29 +79,27 @@ def test_load_config(tmpdir):
"copyright_start": 0,
"copyright_end": 1,
"ci_scripts": [
{"template": "static",
"pip_install": ["static_pip0", "static_pip1"]}
{"template": "static", "pip_install": ["static_pip0", "static_pip1"]}
],
"travis_yml": {
"python": "6.0",
"global_vars": {
"TEST_VAR": "test var val"},
"global_vars": {"TEST_VAR": "test var val"},
"pypi_user": "dummy_pypi_user",
"deploy_dists": [
"sdist",
"bdist_wheel"
],
"deploy_dists": ["sdist", "bdist_wheel"],
"jobs": [{"script": "static", "language": "generic"}],
"bones_install": "nengo-bones",
},
"codecov_yml": {
"skip_appveyor": False,
"abs_target": "test_abs",
"diff_target": "test_diff"
"diff_target": "test_diff",
},
}

utils.write_file(tmpdir, ".nengobones.yml", """
utils.write_file(
tmpdir,
".nengobones.yml",
"""
project_name: Dummy
pkg_name: dummy
repo_name: dummyorg/dummy
Expand Down Expand Up @@ -133,7 +130,8 @@ def test_load_config(tmpdir):
skip_appveyor: false
abs_target: test_abs
diff_target: test_diff
""")
""",
)

loaded = config.load_config(tmpdir.join(".nengobones.yml"))

Expand Down
Loading

0 comments on commit fe9d76f

Please sign in to comment.