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 functionality to skip files during isort #196

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
7 changes: 7 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,10 @@ 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`_)
- ``pyproject_toml`` config now sets ``skip_gitignore`` flag to true by default.
(`#196`_)

**Removed**

Expand All @@ -63,6 +69,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
16 changes: 11 additions & 5 deletions docs/examples/configuration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,16 @@
"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\n",
"``black``\n",
"and/or ``isort`` automatically."
]
},
{
Expand All @@ -1184,8 +1188,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
11 changes: 9 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,13 @@ force_exclude = '''
[tool.isort]
profile = "black"
src_paths = ["{{ pkg_name }}"]
skip_gitignore = true
{% if isort_exclude %}
extend_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("extend_skip_glob = [")
assert has_line(' "that-folder/**"')
assert has_line("]")


def test_setup_py(tmp_path):
write_nengobones(
tmp_path=tmp_path,
Expand Down
2 changes: 1 addition & 1 deletion 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 = (24, 1, 15) # bones: ignore
version_info = (24, 1, 22) # bones: ignore

name = "nengo-bones"
dev = 0
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ force_exclude = '''
[tool.isort]
profile = "black"
src_paths = ["nengo_bones"]
skip_gitignore = true

[tool.docformatter]
wrap-summaries = 88
Expand Down