Skip to content

Commit

Permalink
Add functionality to skip files during isort
Browse files Browse the repository at this point in the history
  • Loading branch information
jchalatu committed Jan 19, 2024
1 parent b9652b1 commit ac1eb68
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .nengobones.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ docs_conf_py:
changelog.html: changes.html

pyproject_toml:
exclude:
black_exclude:
- tests/ignoreme/ignoreme.py
- tests/ignoreme/ignoreme.py

Expand Down
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Release History
license text will be added to the top of all python files, and ``bones check`` will
check for the existence of that text. (`#189`_)
- Added ``gpl-v2`` license type. (`#192`_)
- Added ``isort_exclude`` option to the ``pyproject_toml`` config, which
can be used by ``isort`` to skip files or directories via regex patterns. (`#196`)

**Changed**

Expand All @@ -38,6 +40,8 @@ Release History
- Tests now default to using the ``worksteal`` xdist option, with 3 workers. (`#186`_)
- Modified ``check-deploy`` to skip checks when no ``.pypirc`` file present. (`#187`_)
- Use micromamba to set up python environments. (`#188`_)
- Changed the ``exclude`` option to ``black_exclude`` in the ``pyproject_toml``
config. (`#196`)

**Removed**

Expand All @@ -63,6 +67,7 @@ Release History
.. _#189: https://github.com/nengo/nengo-bones/pull/189
.. _#191: https://github.com/nengo/nengo-bones/pull/191
.. _#192: https://github.com/nengo/nengo-bones/pull/192
.. _#196: https://github.com/nengo/nengo-bones/pull/196

22.11.15 (November 15, 2022)
============================
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
NengoBones license
******************

Copyright (c) 2018-2023 Applied Brain Research
Copyright (c) 2018-2024 Applied Brain Research

**ABR License**

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

project = "NengoBones"
authors = "Applied Brain Research"
copyright = "2018-2023 Applied Brain Research"
copyright = "2018-2024 Applied Brain Research"
version = ".".join(nengo_bones.__version__.split(".")[:2]) # Short X.Y version
release = nengo_bones.__version__ # Full version, with tags

Expand Down
15 changes: 10 additions & 5 deletions docs/examples/configuration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,15 @@
"source": [
"## pyproject.toml config\n",
"\n",
"The only configuration available for this file is an `exclude` option that accepts a\n",
"list of patterns to exclude from ``black``. Each entry is a regular expression.\n",
"The `pyproject.toml` template has two available configurations:\n",
"- ``black_exclude``: A list of patterns to exclude during ``black`` formatting.\n",
"- ``isort_exclude``: A list of patterns to exclude during ``isort`` formatting.\n",
"\n",
"For each configuration option, the entries must be valid regular expressions.\n",
"\n",
"When you add this file to your `.nengobones.yml` file, you should also add something\n",
"to your documentation to indicate that users should configure their editor to run Black\n",
"automatically."
"to your documentation to indicate that users should configure their editor to run ``black``\n",
"and/or ``isort`` automatically. "
]
},
{
Expand All @@ -1184,8 +1187,10 @@
"source": [
"nengobones_yml = \"\"\"\n",
"pyproject_toml:\n",
" exclude:\n",
" black_exclude:\n",
" - project/ignore_me.py\n",
" isort_exclude:\n",
" - project/ignore_me/**\n",
"\"\"\"\n",
"write_yml(nengobones_yml)\n",
"\n",
Expand Down
10 changes: 8 additions & 2 deletions nengo_bones/templates/pyproject.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ requires = ["setuptools<64", "wheel"]
{% block black %}
[tool.black]
target-version = ['py{{ min_python | replace(".", "") }}']
{% if exclude %}
{% if black_exclude %}
force_exclude = '''
(
{% for pattern in exclude %}
{% for pattern in black_exclude %}
{{ "" }}{% if not loop.first %}| {% endif %}{{ pattern }}
{% endfor %}
)
Expand All @@ -23,6 +23,12 @@ force_exclude = '''
[tool.isort]
profile = "black"
src_paths = ["{{ pkg_name }}"]
{% if isort_exclude %}
skip_glob = [
{% for pattern in isort_exclude %}
{{ "" }}{% if not loop.first %}, {% endif %}"{{ pattern }}"
{% endfor %}]
{% endif %}
{% endblock %}

{% block docformatter %}
Expand Down
40 changes: 40 additions & 0 deletions nengo_bones/tests/test_generate_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,46 @@ def test_manifest(tmp_path):
assert has_line("recursive-exclude *.bak")


def test_pyproject_toml(tmp_path):
write_nengobones(
tmp_path=tmp_path,
contents="""
pyproject_toml:
black_exclude:
- this-folder/
isort_exclude:
- that-folder/**
""",
)

result = CliRunner().invoke(
bones,
[
"generate",
"--conf-file",
str(tmp_path / ".nengobones.yml"),
"--output-dir",
str(tmp_path),
"pyproject-toml",
],
)
assert_exit(result, 0)

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

has_line = make_has_line(lines)
assert has_line("# Automatically generated by nengo-bones")
assert has_line("force_exclude = '''")
assert has_line("(")
assert has_line(" this-folder/")
assert has_line(")")
assert has_line("'''")
assert has_line("skip_glob = [")
assert has_line(' "that-folder/**"')
assert has_line("]")


def test_setup_py(tmp_path):
write_nengobones(
tmp_path=tmp_path,
Expand Down
4 changes: 2 additions & 2 deletions nengo_bones/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
tagged with the version.
"""

version_info = (23, 11, 7) # bones: ignore
version_info = (24, 1, 19) # bones: ignore

name = "nengo-bones"
dev = 0
Expand All @@ -22,4 +22,4 @@
if dev is not None:
version += ".dev%d" % dev # pragma: no cover

copyright = "Copyright (c) 2018-2023 Applied Brain Research"
copyright = "Copyright (c) 2018-2024 Applied Brain Research"

0 comments on commit ac1eb68

Please sign in to comment.