pyscaffoldext-pre-commit-ruff 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ """Extend PyScaffold with --pre-commit-ruff."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version # pragma: no cover
4
+
5
+ try:
6
+ # Change here if project is renamed and does not equal the package name
7
+ dist_name = "pyscaffoldext-pre-commit-ruff"
8
+ __version__ = version(dist_name)
9
+ except PackageNotFoundError: # pragma: no cover
10
+ __version__ = "unknown"
11
+ finally:
12
+ del version, PackageNotFoundError
@@ -0,0 +1,139 @@
1
+ """Add pre-commit-ruff extension."""
2
+
3
+ from argparse import ArgumentParser
4
+ from functools import partial, reduce
5
+ from typing import List
6
+
7
+ from pyscaffold import structure, toml
8
+ from pyscaffold.actions import Action, ActionParams, ScaffoldOpts, Structure
9
+ from pyscaffold.extensions import Extension, include
10
+ from pyscaffold.extensions.pre_commit import PreCommit
11
+ from pyscaffold.operations import FileOp, no_overwrite
12
+ from pyscaffold.structure import (
13
+ AbstractContent,
14
+ Node,
15
+ ResolvedLeaf,
16
+ reify_leaf,
17
+ )
18
+ from pyscaffold.templates import get_template
19
+ from pyscaffold.update import ConfigUpdater
20
+
21
+ from . import templates as my_templates
22
+
23
+ PYPROJ_INSERT_AFTER = 'version_scheme = "no-guess-dev"\n'
24
+
25
+
26
+ class PreCommitRuff(Extension):
27
+ """Generate pre-commit configuration file for Ruff (includes `--pre-commit`)."""
28
+
29
+ def augment_cli(self, parser: ArgumentParser):
30
+ """Augments the command-line interface parser.
31
+
32
+ See :obj:`~pyscaffold.extension.Extension.augment_cli`.
33
+ """
34
+ parser.add_argument(
35
+ self.flag,
36
+ help=self.help_text,
37
+ nargs=0,
38
+ action=include(
39
+ PreCommit(),
40
+ self,
41
+ ),
42
+ )
43
+ return self
44
+
45
+ def activate(self, actions: List[Action]) -> List[Action]:
46
+ """Activates See :obj:`pyscaffold.extension.Extension.activate`.
47
+
48
+ Args:
49
+ actions (list): list of actions to perform
50
+
51
+ Returns:
52
+ list: updated list of actions
53
+ """
54
+ return self.register(
55
+ actions,
56
+ add_files,
57
+ after="pyscaffold.extensions.pre_commit:add_files",
58
+ )
59
+
60
+
61
+ def add_files(struct: Structure, opts: ScaffoldOpts) -> ActionParams:
62
+ """Replace .pre-commit-config.yaml. Update setup.cfg and pyproject.toml.
63
+
64
+ Add mypy section to setup.cfg.
65
+ Remove flake8 section from setup.cfg. Ruff replaces flake8.
66
+
67
+ Add ruff configuration to pyproject.toml.
68
+ """
69
+ files: Structure = {
70
+ ".pre-commit-config.yaml": (
71
+ get_template(
72
+ name="pre-commit-ruff-config",
73
+ relative_to=my_templates.__name__,
74
+ ),
75
+ no_overwrite(),
76
+ ),
77
+ "setup.cfg": modify_setupcfg(struct["setup.cfg"], opts),
78
+ }
79
+
80
+ struct = structure.modify(
81
+ struct,
82
+ "pyproject.toml",
83
+ partial(modify_pyproject, opts),
84
+ )
85
+ return structure.merge(struct, files), opts
86
+
87
+
88
+ def modify_setupcfg(definition: Node, opts: ScaffoldOpts) -> ResolvedLeaf:
89
+ """Modify setup.cfg to add template settings before it is written.
90
+
91
+ See :obj:`pyscaffold.operations`.
92
+ """
93
+ content, action = reify_leaf(definition, opts) # pyright: ignore [reportArgumentType]
94
+
95
+ setupcfg = ConfigUpdater().read_string(str(content))
96
+
97
+ modifiers = (add_setupcfg,)
98
+ new_setupcfg = reduce(lambda acc, fn: fn(acc, opts), modifiers, setupcfg)
99
+
100
+ return str(new_setupcfg), action
101
+
102
+
103
+ def add_setupcfg(setupcfg: ConfigUpdater, opts) -> ConfigUpdater:
104
+ """Add section(s) to setup.cfg."""
105
+ template = ConfigUpdater().read_string(
106
+ str(
107
+ structure.reify_content(
108
+ get_template(
109
+ name="setup_cfg",
110
+ relative_to=my_templates.__name__,
111
+ ),
112
+ opts,
113
+ ),
114
+ )
115
+ )
116
+
117
+ setupcfg.remove_section("flake8")
118
+
119
+ for k in template:
120
+ setupcfg["pyscaffold"].add_before.section(k)
121
+ setupcfg[k] = template[k].detach()
122
+ setupcfg["pyscaffold"].add_before.space(newlines=1)
123
+
124
+ return setupcfg
125
+
126
+
127
+ def modify_pyproject(
128
+ opts: ScaffoldOpts, content: AbstractContent, file_op: FileOp
129
+ ) -> ResolvedLeaf:
130
+ """Add Ruff configuration to pyproject.toml."""
131
+ pyproj_new = toml.loads(
132
+ "\n".join(
133
+ (
134
+ str(structure.reify_content(content, opts)),
135
+ str(structure.reify_content(my_templates.pyproject_toml, opts)),
136
+ )
137
+ )
138
+ )
139
+ return toml.dumps(pyproj_new), file_op
@@ -0,0 +1,17 @@
1
+ """Location for pre-commit-ruff templates."""
2
+
3
+ import string
4
+
5
+ from pyscaffold import toml
6
+ from pyscaffold.actions import ScaffoldOpts
7
+ from pyscaffold.templates import get_template
8
+
9
+
10
+ def pyproject_toml(opts: ScaffoldOpts) -> str:
11
+ """Load and substitute template."""
12
+ template: string.Template = get_template(
13
+ name="pyproject_toml",
14
+ relative_to=__name__,
15
+ )
16
+ config = toml.loads(template.safe_substitute(opts))
17
+ return toml.dumps(config)
@@ -0,0 +1,37 @@
1
+ exclude: '^docs/conf.py'
2
+
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: v5.0.0
6
+ hooks:
7
+ - id: trailing-whitespace
8
+ - id: check-added-large-files
9
+ - id: check-ast
10
+ - id: check-json
11
+ - id: check-merge-conflict
12
+ - id: check-xml
13
+ - id: check-yaml
14
+ - id: debug-statements
15
+ - id: end-of-file-fixer
16
+ - id: requirements-txt-fixer
17
+ - id: mixed-line-ending
18
+ args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows
19
+
20
+ # ruff-pre-commit
21
+ - repo: https://github.com/astral-sh/ruff-pre-commit
22
+ # Ruff version.
23
+ rev: v0.6.9
24
+ hooks:
25
+ # Run the linter.
26
+ - id: ruff
27
+ types_or: [ python, pyi ]
28
+ args: [ --fix ]
29
+ # Run the formatter.
30
+ - id: ruff-format
31
+ types_or: [ python, pyi ]
32
+
33
+ ## Check for misspells in documentation files:
34
+ # - repo: https://github.com/codespell-project/codespell
35
+ # rev: v2.3.0
36
+ # hooks:
37
+ # - id: codespell
@@ -0,0 +1,30 @@
1
+ [tool.ruff]
2
+ # In addition to the standard set of exclusions, omit all tests, plus a specific file.
3
+ # ruff-format modifies dictionary wrapping and docstring indentation if not excluded.
4
+ extend-exclude = ["docs/conf.py", "setup.py", "tests/conftest.py"]
5
+
6
+ [tool.ruff.lint]
7
+ extend-select = [
8
+ # pydocstyle
9
+ # "D",
10
+ # pycodestyle
11
+ "E",
12
+ # Warning
13
+ "W",
14
+ # Pyflakes
15
+ "F",
16
+ # pyupgrade
17
+ # "UP",
18
+ # flake8-bugbear
19
+ "B",
20
+ # flake8-simplify
21
+ "SIM",
22
+ # isort
23
+ "I",
24
+ ]
25
+
26
+ [tool.ruff.lint.pydocstyle]
27
+ # convention = "google"
28
+
29
+ [tool.ruff.format]
30
+ docstring-code-format = true
@@ -0,0 +1,9 @@
1
+ [mypy]
2
+ exclude = (?x)(
3
+ \.tox/
4
+ | build/
5
+ | dist/
6
+ | docs/
7
+ )
8
+ ignore_missing_imports = True
9
+ follow_imports = silent
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 John D. Fisher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyscaffoldext-pre-commit-ruff
3
+ Version: 1.0.0
4
+ Summary: Add a short description here!
5
+ Home-page: https://github.com/pyscaffold/pyscaffold/
6
+ Author: John D. Fisher
7
+ Author-email: jdfenw@gmail.com
8
+ License: MIT
9
+ Project-URL: Documentation, https://pyscaffold.org/
10
+ Platform: any
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Programming Language :: Python
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/x-rst; charset=UTF-8
15
+ License-File: LICENSE.txt
16
+ Requires-Dist: pyscaffold<5.0a0,>=4.6
17
+ Provides-Extra: testing
18
+ Requires-Dist: tox; extra == "testing"
19
+ Requires-Dist: pre-commit; extra == "testing"
20
+ Requires-Dist: setuptools_scm; extra == "testing"
21
+ Requires-Dist: virtualenv; extra == "testing"
22
+ Requires-Dist: configupdater; extra == "testing"
23
+ Requires-Dist: pytest; extra == "testing"
24
+ Requires-Dist: pytest-cov; extra == "testing"
25
+ Requires-Dist: pytest-xdist; extra == "testing"
26
+
27
+ pyscaffoldext-pre-commit-ruff
28
+ =============================
29
+
30
+ `PyScaffold`_ extension to use the `Ruff Linter`_ and `Ruff Formatter`_
31
+ in place of the `Pre Commit Extension`_, ``putup --pre-commit`` defaults
32
+ `flake8`_ and `isort`_.
33
+
34
+ The ``ruff`` configuration is added to ``pyproject.toml`` because
35
+ ``ruff`` does not support ``setup.cfg``. Some `Ruff Linter`_ recommended
36
+ settings are commented out, for consistency with `PyScaffold`_'s
37
+ ``flake8`` settings.
38
+
39
+ `Codespell`_ is added to `pre-commit`_ configuration in
40
+ ``.pre-commit-config.yaml``; uncomment to enable.
41
+
42
+ `Mypy`_ settings are added to ``setup.cfg``.
43
+
44
+ Usage
45
+ -----
46
+
47
+ Just install this package with
48
+ ``pip install pyscaffoldext-pre-commit-ruff`` and note that ``putup -h``
49
+ shows a new option ``--pre-commit-ruff``. Use this flag to use the `Ruff
50
+ Linter`_ and `Ruff Formatter`_ in place of ``putup --pre-commit``
51
+ defaults `flake8`_ and `isort`_.
52
+
53
+ .. _pyscaffold-notes:
54
+
55
+ Making Changes & Contributing
56
+ -----------------------------
57
+
58
+ This project uses `pre-commit`_, please make sure to install it before
59
+ making any changes:
60
+
61
+ ::
62
+
63
+ uv tool install pre-commit
64
+ cd pyscaffoldext-pre-commit-ruff
65
+ pre-commit install
66
+
67
+ It is a good idea to update the hooks to the latest version:
68
+
69
+ ::
70
+
71
+ pre-commit autoupdate
72
+
73
+ Note
74
+ ----
75
+
76
+ This project has been set up using PyScaffold 4.6. For details and usage
77
+ information on PyScaffold see https://pyscaffold.org/.
78
+
79
+ .. _PyScaffold: https://pyscaffold.org/
80
+ .. _Ruff Linter: https://docs.astral.sh/ruff/linter/
81
+ .. _Ruff Formatter: https://docs.astral.sh/ruff/formatter/
82
+ .. _Pre Commit Extension: https://pyscaffold.org/en/stable/features.html#pre-commit-hooks
83
+ .. _flake8: https://flake8.pycqa.org/
84
+ .. _isort: https://pycqa.github.io/isort/
85
+ .. _Codespell: https://github.com/codespell-project/codespell
86
+ .. _pre-commit: https://pre-commit.com/
87
+ .. _Mypy: https://mypy.readthedocs.io/
@@ -0,0 +1,12 @@
1
+ pyscaffoldext/pre_commit_ruff/__init__.py,sha256=hzzhRQkDfDauc3xveaWFFwEDMen00Mn0PyhI75N86CE,421
2
+ pyscaffoldext/pre_commit_ruff/extension.py,sha256=B_HPCbsNX0FuOVNdfqFtOccyDyDkbF3fx2gZghRoZmw,4015
3
+ pyscaffoldext/pre_commit_ruff/templates/__init__.py,sha256=H76fRc_mD1QNaJcspIT3buow8GqtLoM0QvsahGX3Pro,468
4
+ pyscaffoldext/pre_commit_ruff/templates/pre-commit-ruff-config.template,sha256=mZItptCbvQ2MofJPYVnwVWhd7WtGQImPmKCi-EOjqx0,926
5
+ pyscaffoldext/pre_commit_ruff/templates/pyproject_toml.template,sha256=AeV9KS5lryU49LXe9JgURIdanG45mboHo7uKk8P2iCU,574
6
+ pyscaffoldext/pre_commit_ruff/templates/setup_cfg.template,sha256=GoQ4Dqoo3xHtzyb6cSQWru0rWB-BQort07SvEzol2K0,131
7
+ pyscaffoldext_pre_commit_ruff-1.0.0.dist-info/LICENSE.txt,sha256=acMhROUubMKbVsgxX3k_ysr2NX_FSrmTDt076TiV_3o,1081
8
+ pyscaffoldext_pre_commit_ruff-1.0.0.dist-info/METADATA,sha256=IgjsmpVsljSBV51mKzeOy4Qd4L_bMwYjKyDUnkXJNEI,2778
9
+ pyscaffoldext_pre_commit_ruff-1.0.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
10
+ pyscaffoldext_pre_commit_ruff-1.0.0.dist-info/entry_points.txt,sha256=lO0-4Df5v33SH_j9Y87UiovpARXKJoZNxAywMsIKKOQ,89
11
+ pyscaffoldext_pre_commit_ruff-1.0.0.dist-info/top_level.txt,sha256=zac9JJq83qBJe5oCWbtXhQVr8mJ5TZFW2jCFlSQ6n0Y,14
12
+ pyscaffoldext_pre_commit_ruff-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.6.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [pyscaffold.cli]
2
+ pre_commit_ruff = pyscaffoldext.pre_commit_ruff.extension:PreCommitRuff
@@ -0,0 +1 @@
1
+ pyscaffoldext