diff --git a/.nengobones.yml b/.nengobones.yml index 99f42494..6846c32d 100644 --- a/.nengobones.yml +++ b/.nengobones.yml @@ -184,7 +184,7 @@ docs_conf_py: changelog.html: changes.html pyproject_toml: - exclude: + black_exclude: - tests/ignoreme/ignoreme.py - tests/ignoreme/ignoreme.py diff --git a/CHANGES.rst b/CHANGES.rst index 0ee58d54..4556a37a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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** @@ -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** @@ -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) ============================ diff --git a/docs/examples/configuration.ipynb b/docs/examples/configuration.ipynb index f66e1165..490237a9 100644 --- a/docs/examples/configuration.ipynb +++ b/docs/examples/configuration.ipynb @@ -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." ] }, { @@ -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", diff --git a/nengo_bones/templates/pyproject.toml.template b/nengo_bones/templates/pyproject.toml.template index ac72e7c5..4a5c3673 100644 --- a/nengo_bones/templates/pyproject.toml.template +++ b/nengo_bones/templates/pyproject.toml.template @@ -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 %} ) @@ -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 %} diff --git a/nengo_bones/tests/test_generate_bones.py b/nengo_bones/tests/test_generate_bones.py index 06dea58c..9574f196 100644 --- a/nengo_bones/tests/test_generate_bones.py +++ b/nengo_bones/tests/test_generate_bones.py @@ -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, diff --git a/nengo_bones/version.py b/nengo_bones/version.py index 823d13c9..061efa50 100644 --- a/nengo_bones/version.py +++ b/nengo_bones/version.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 00e69521..6c0a8b51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ force_exclude = ''' [tool.isort] profile = "black" src_paths = ["nengo_bones"] +skip_gitignore = true [tool.docformatter] wrap-summaries = 88