Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build_requires option to pyproject.toml #153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 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 All @@ -64,6 +66,11 @@ Release History
- ``bones-format-notebook --check`` will now require that all ``codespell`` checks pass.
(`#138`_)

**Removed**

- Removed requirement that ``pre-commit-config.yaml`` be templated if ``pyproject.toml``
is templated (and vice versa). (`#153`_)

**Fixed**

- Intermittent failures installing miniconda in the remote script have been fixed by
Expand Down Expand Up @@ -92,6 +99,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