Skip to content

Commit

Permalink
Add build_requires option to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
drasmuss committed Aug 13, 2021
1 parent 15d3b4b commit 7976d83
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Release History
- Added support for changing the main branch name with the ``main_branch``
config option. (`#145`_)
- Added template for ``version.py``. (`#151`_)
- Added ``build_requires`` field to ``pyproject.toml`` template to specify additional
build dependencies. (`#153`_)

**Changed**

Expand Down Expand Up @@ -92,6 +94,7 @@ Release History
.. _#144: https://github.com/nengo/nengo-bones/pull/144
.. _#145: https://github.com/nengo/nengo-bones/pull/145
.. _#151: https://github.com/nengo/nengo-bones/pull/151
.. _#153: https://github.com/nengo/nengo-bones/pull/153

0.11.1 (April 13, 2020)
=======================
Expand Down
13 changes: 2 additions & 11 deletions nengo_bones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,8 @@ def validate_black_config(config):
Dictionary containing configuration values.
"""

has_precommit = "pre_commit_config_yaml" in config
has_pyproject = "pyproject_toml" in config
if not (has_precommit or has_pyproject):
return
if not (has_pyproject and has_precommit):
raise KeyError(
"Config file must define both 'pyproject_toml' "
"and 'pre_commit_config_yaml' or neither"
)
precommit = config["pre_commit_config_yaml"]
pyproject = config["pyproject_toml"]
precommit = config.get("pre_commit_config_yaml", {})
pyproject = config.get("pyproject_toml", {})
check_list(precommit, "exclude")
check_list(pyproject, "exclude")
if precommit.get("exclude", []) != pyproject.get("exclude", []):
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/pyproject.toml.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Automatically generated by nengo-bones, do not edit this file directly

[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools", "wheel",{% for pkg in build_requires %} "{{ pkg }}",{% endfor %}]

[tool.black]
target-version = ['py{{ min_python | replace(".", "") }}']
Expand Down
15 changes: 5 additions & 10 deletions nengo_bones/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,14 @@ def test_validate_config():
config.validate_config(init_cfg)
test_cfg["pre_commands"] = ["command"]

# error when only one of pre_commit_config_yaml or pyproject_toml exists
init_cfg["pyproject_toml"] = {}
with pytest.raises(KeyError, match="must define both"):
# error when Black exclude lists don't match (either because it's not defined
# in one file, or it's defined but doesn't match)
init_cfg["pre_commit_config_yaml"] = {"exclude": ["file2.py"]}
with pytest.raises(ValueError, match="must have the same 'exclude' list"):
config.validate_config(init_cfg)
init_cfg["pre_commit_config_yaml"] = {}

# error when Black exclude lists don't match
init_cfg["pre_commit_config_yaml"]["exclude"] = ["file2.py"]
init_cfg["pyproject_toml"]["exclude"] = ["file1.py"]
init_cfg["pyproject_toml"] = {"exclude": ["file1.py"]}
with pytest.raises(ValueError, match="must have the same 'exclude' list"):
config.validate_config(init_cfg)
del init_cfg["pre_commit_config_yaml"]["exclude"]
del init_cfg["pyproject_toml"]["exclude"]


def test_missing_config(tmp_path):
Expand Down
33 changes: 33 additions & 0 deletions nengo_bones/tests/test_generate_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,3 +860,36 @@ def test_version_py(version_type, release, tmp_path):
today = date.today()
version_info = (today.year - 2000, today.month)
assert version == ".".join(str(x) for x in version_info)


def test_pyproject_toml(tmp_path):
write_file(
tmp_path=tmp_path,
filename=".nengobones.yml",
contents="""
project_name: Dummy
pkg_name: dummy
repo_name: dummy_org/dummy
pyproject_toml:
build_requires:
- package0
- package1
""",
)

result = CliRunner().invoke(
generate_bones.main,
[
"--conf-file",
str(tmp_path / ".nengobones.yml"),
"--output-dir",
str(tmp_path),
],
)
assert_exit(result, 0)

with (tmp_path / "pyproject.toml").open() as f:
lines = f.readlines()

has_line = make_has_line(lines)
assert has_line('requires = ["setuptools", "wheel", "package0", "package1",]')
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Automatically generated by nengo-bones, do not edit this file directly

[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools", "wheel",]

[tool.black]
target-version = ['py36']
Expand Down

0 comments on commit 7976d83

Please sign in to comment.