Skip to content

Commit 25895b9

Browse files
authored
Switch to ruff for formatting and use codespell and docformatter (#261)
1 parent bc4d114 commit 25895b9

17 files changed

+177
-165
lines changed

.pre-commit-config.yaml

+15-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@ repos:
44
hooks:
55
- id: end-of-file-fixer
66
- id: trailing-whitespace
7+
- repo: https://github.com/codespell-project/codespell
8+
rev: v2.2.6
9+
hooks:
10+
- id: codespell
11+
additional_dependencies: [ "tomli>=2.0.1" ]
12+
- repo: https://github.com/PyCQA/docformatter
13+
rev: v1.7.5
14+
hooks:
15+
- id: docformatter
16+
additional_dependencies: [ "tomli>=2.0.1" ]
17+
args: [ "--in-place", "--config", "./pyproject.toml" ]
718
- repo: https://github.com/astral-sh/ruff-pre-commit
8-
rev: "v0.1.14"
19+
rev: "v0.1.15"
920
hooks:
21+
- id: ruff-format
1022
- id: ruff
11-
args: [--fix, --exit-non-zero-on-fix]
12-
- repo: https://github.com/psf/black
13-
rev: 24.1.1
14-
hooks:
15-
- id: black
23+
args: [ "--fix", "--unsafe-fixes", "--exit-non-zero-on-fix" ]
1624
- repo: https://github.com/tox-dev/tox-ini-fmt
1725
rev: "1.3.1"
1826
hooks:
@@ -22,7 +30,7 @@ repos:
2230
rev: "1.7.0"
2331
hooks:
2432
- id: pyproject-fmt
25-
additional_dependencies: ["tox>=4.11.4"]
33+
additional_dependencies: ["tox>=4.12.1"]
2634
- repo: meta
2735
hooks:
2836
- id: check-hooks-apply

CHANGES.rst

+7-10
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ appdirs 1.4.0 (2017-08-17)
182182
- [PR #42] AppAuthor is now optional on Windows
183183
- [issue 41] Support Jython on Windows, Mac, and Unix-like platforms. Windows
184184
support requires `JNA <https://github.com/twall/jna>`_.
185-
- [PR #44] Fix incorrect behaviour of the site_config_dir method
185+
- [PR #44] Fix incorrect behavior of the site_config_dir method
186186

187187
appdirs 1.3.0 (2014-04-22)
188188
--------------------------
189189
- [Unix, issue 16] Conform to XDG standard, instead of breaking it for
190190
everybody
191191
- [Unix] Removes gratuitous case mangling of the case, since \*nix-es are
192192
usually case sensitive, so mangling is not wise
193-
- [Unix] Fixes the utterly wrong behaviour in ``site_data_dir``, return result
193+
- [Unix] Fixes the utterly wrong behavior in ``site_data_dir``, return result
194194
based on XDG_DATA_DIRS and make room for respecting the standard which
195195
specifies XDG_DATA_DIRS is a multiple-value variable
196196
- [Issue 6] Add ``*_config_dir`` which are distinct on nix-es, according to
@@ -210,7 +210,7 @@ appdirs 1.1.0 (2010-09-02)
210210
- [Unix, issue 2, issue 7] appdirs now conforms to `XDG base directory spec
211211
<https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
212212
- [Mac, issue 5] Fix ``site_data_dir()`` on Mac.
213-
- [Mac] Drop use of 'Carbon' module in favour of hardcoded paths; supports
213+
- [Mac] Drop use of 'Carbon' module in favor of hardcoded paths; supports
214214
Python3 now.
215215
- [Windows] Append "Cache" to ``user_cache_dir`` on Windows by default. Use
216216
``opinion=False`` option to disable this.
@@ -225,19 +225,16 @@ appdirs 1.1.0 (2010-09-02)
225225
- [Linux] Change default ``user_cache_dir()`` on Linux to be singular, e.g.
226226
"~/.superapp/cache".
227227
- [Windows] Add ``roaming`` option to ``user_data_dir()`` (for use on Windows only)
228-
and change the default ``user_data_dir`` behaviour to use a *non*-roaming
228+
and change the default ``user_data_dir`` behavior to use a *non*-roaming
229229
profile dir (``CSIDL_LOCAL_APPDATA`` instead of ``CSIDL_APPDATA``). Why? Because
230230
a large roaming profile can cause login speed issues. The "only syncs on
231-
logout" behaviour can cause surprises in appdata info.
231+
logout" behavior can cause surprises in appdata info.
232232

233233

234234
appdirs 1.0.1 (never released)
235235
------------------------------
236236

237237
Started this changelog 27 July 2010. Before that this module originated in the
238238
`Komodo <https://www.activestate.com/komodo-ide>`_ product as ``applib.py`` and then
239-
as `applib/location.py
240-
<https://github.com/ActiveState/applib/blob/master/applib/location.py>`_ (used by
241-
`PyPM <https://code.activestate.com/pypm/>`_ in `ActivePython
242-
<https://www.activestate.com/activepython>`_). This is basically a fork of
243-
applib.py 1.0.1 and applib/location.py 1.0.1.
239+
as ``applib/location.py`` (used by `PyPM <https://code.activestate.com/pypm/>`_ in `ActivePython
240+
<https://www.activestate.com/activepython>`_). This is basically a fork of applib.py 1.0.1 and applib/location.py 1.0.1.

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# noqa: INP001
22
"""Configuration for Sphinx."""
3+
34
from __future__ import annotations
45

56
from datetime import datetime, timezone

pyproject.toml

+31-17
Original file line numberDiff line numberDiff line change
@@ -67,33 +67,47 @@ build.hooks.vcs.version-file = "src/platformdirs/version.py"
6767
build.targets.sdist.include = ["/src", "/tests", "/tox.ini"]
6868
version.source = "vcs"
6969

70-
[tool.black]
71-
line-length = 120
72-
7370
[tool.ruff]
7471
select = ["ALL"]
7572
line-length = 120
7673
target-version = "py38"
77-
isort = {known-first-party = ["platformdirs", "tests"], required-imports = ["from __future__ import annotations"]}
74+
isort = { known-first-party = ["platformdirs", "tests"], required-imports = ["from __future__ import annotations"] }
7875
ignore = [
79-
"ANN101", # Missing type annotation for `self` in method
80-
"D301", # Use `r"""` if any backslashes in a docstring
81-
"D205", # 1 blank line required between summary line and description
82-
"D401", # First line of docstring should be in imperative mood
83-
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
84-
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
85-
"S104", # Possible binding to all interface
76+
"ANN101", # Missing type annotation for `self` in method
77+
"D301", # Use `r"""` if any backslashes in a docstring
78+
"D205", # 1 blank line required between summary line and description
79+
"D401", # The first line of docstring should be in imperative mood
80+
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
81+
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
82+
"S104", # Possible binding to all interfaces
83+
"CPY", # no copyright notices
8684
]
85+
format.preview = true
86+
lint.preview = true
8787
[tool.ruff.per-file-ignores]
8888
"tests/**/*.py" = [
89-
"S101", # asserts allowed in tests...
90-
"FBT", # don"t care about booleans as positional arguments in tests
91-
"INP001", # no implicit namespace
92-
"D", # don"t care about documentation in tests
93-
"S603", # `subprocess` call: check for execution of untrusted input
94-
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
89+
"S101", # asserts allowed in tests...
90+
"FBT", # don"t care about booleans as positional arguments in tests
91+
"INP001", # no implicit namespace
92+
"D", # don't care about documentation in tests
93+
"S603", # `subprocess` call: check for execution of untrusted input
94+
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
95+
"PLC2701", # Private name import
96+
"PLR0917", # Too many positional arguments
9597
]
9698

99+
[tool.codespell]
100+
builtin = "clear,usage,en-GB_to_en-US"
101+
count = true
102+
quiet-level = 3
103+
104+
[tool.docformatter]
105+
blank = true
106+
recursive = true
107+
pre-summary-newline = true
108+
wrap-descriptions = 120
109+
wrap-summaries = 120
110+
97111
[tool.coverage]
98112
html.show_contexts = true
99113
html.skip_covered = false

src/platformdirs/__init__.py

+39-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
2-
Utilities for determining application-specific dirs. See <https://github.com/platformdirs/platformdirs> for details and
3-
usage.
2+
Utilities for determining application-specific dirs.
3+
4+
See <https://github.com/platformdirs/platformdirs> for details and usage.
5+
46
"""
57

68
from __future__ import annotations
@@ -20,22 +22,22 @@
2022

2123
def _set_platform_dir_class() -> type[PlatformDirsABC]:
2224
if sys.platform == "win32":
23-
from platformdirs.windows import Windows as Result
25+
from platformdirs.windows import Windows as Result # noqa: PLC0415
2426
elif sys.platform == "darwin":
25-
from platformdirs.macos import MacOS as Result
27+
from platformdirs.macos import MacOS as Result # noqa: PLC0415
2628
else:
27-
from platformdirs.unix import Unix as Result
29+
from platformdirs.unix import Unix as Result # noqa: PLC0415
2830

2931
if os.getenv("ANDROID_DATA") == "/data" and os.getenv("ANDROID_ROOT") == "/system":
3032
if os.getenv("SHELL") or os.getenv("PREFIX"):
3133
return Result
3234

33-
from platformdirs.android import _android_folder
35+
from platformdirs.android import _android_folder # noqa: PLC0415
3436

3537
if _android_folder() is not None:
36-
from platformdirs.android import Android
38+
from platformdirs.android import Android # noqa: PLC0415
3739

38-
return Android # return to avoid redefinition of result
40+
return Android # return to avoid redefinition of a result
3941

4042
return Result
4143

@@ -507,7 +509,7 @@ def user_log_path(
507509

508510

509511
def user_documents_path() -> Path:
510-
""":returns: documents path tied to the user"""
512+
""":returns: documents a path tied to the user"""
511513
return PlatformDirs().user_documents_path
512514

513515

@@ -585,41 +587,41 @@ def site_runtime_path(
585587

586588

587589
__all__ = [
588-
"__version__",
589-
"__version_info__",
590-
"PlatformDirs",
591590
"AppDirs",
591+
"PlatformDirs",
592592
"PlatformDirsABC",
593-
"user_data_dir",
594-
"user_config_dir",
595-
"user_cache_dir",
596-
"user_state_dir",
597-
"user_log_dir",
598-
"user_documents_dir",
599-
"user_downloads_dir",
600-
"user_pictures_dir",
601-
"user_videos_dir",
602-
"user_music_dir",
603-
"user_desktop_dir",
604-
"user_runtime_dir",
605-
"site_data_dir",
606-
"site_config_dir",
593+
"__version__",
594+
"__version_info__",
607595
"site_cache_dir",
596+
"site_cache_path",
597+
"site_config_dir",
598+
"site_config_path",
599+
"site_data_dir",
600+
"site_data_path",
608601
"site_runtime_dir",
609-
"user_data_path",
610-
"user_config_path",
602+
"site_runtime_path",
603+
"user_cache_dir",
611604
"user_cache_path",
612-
"user_state_path",
613-
"user_log_path",
605+
"user_config_dir",
606+
"user_config_path",
607+
"user_data_dir",
608+
"user_data_path",
609+
"user_desktop_dir",
610+
"user_desktop_path",
611+
"user_documents_dir",
614612
"user_documents_path",
613+
"user_downloads_dir",
615614
"user_downloads_path",
616-
"user_pictures_path",
617-
"user_videos_path",
615+
"user_log_dir",
616+
"user_log_path",
617+
"user_music_dir",
618618
"user_music_path",
619-
"user_desktop_path",
619+
"user_pictures_dir",
620+
"user_pictures_path",
621+
"user_runtime_dir",
620622
"user_runtime_path",
621-
"site_data_path",
622-
"site_config_path",
623-
"site_cache_path",
624-
"site_runtime_path",
623+
"user_state_dir",
624+
"user_state_path",
625+
"user_videos_dir",
626+
"user_videos_path",
625627
]

src/platformdirs/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def main() -> None:
27-
"""Run main entry point."""
27+
"""Run the main entry point."""
2828
app_name = "MyApp"
2929
app_author = "MyCompany"
3030

src/platformdirs/android.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
class Android(PlatformDirsABC):
1515
"""
16-
Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_. Makes use of the
17-
`appname <platformdirs.api.PlatformDirsABC.appname>`,
18-
`version <platformdirs.api.PlatformDirsABC.version>`,
19-
`ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
16+
Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_.
17+
18+
Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`, `version
19+
<platformdirs.api.PlatformDirsABC.version>`, `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
20+
2021
"""
2122

2223
@property
@@ -44,7 +45,7 @@ def site_config_dir(self) -> str:
4445

4546
@property
4647
def user_cache_dir(self) -> str:
47-
""":return: cache directory tied to the user, e.g. e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>``"""
48+
""":return: cache directory tied to the user, e.g.,``/data/user/<userid>/<packagename>/cache/<AppName>``"""
4849
return self._append_app_name_and_version(cast(str, _android_folder()), "cache")
4950

5051
@property
@@ -119,13 +120,13 @@ def site_runtime_dir(self) -> str:
119120
def _android_folder() -> str | None:
120121
""":return: base folder for the Android OS or None if it cannot be found"""
121122
try:
122-
# First try to get path to android app via pyjnius
123-
from jnius import autoclass
123+
# First try to get a path to android app via pyjnius
124+
from jnius import autoclass # noqa: PLC0415
124125

125126
context = autoclass("android.content.Context")
126127
result: str | None = context.getFilesDir().getParentFile().getAbsolutePath()
127128
except Exception: # noqa: BLE001
128-
# if fails find an android folder looking path on the sys.path
129+
# if fails find an android folder looking a path on the sys.path
129130
pattern = re.compile(r"/data/(data|user/\d+)/(.+)/files")
130131
for path in sys.path:
131132
if pattern.match(path):
@@ -141,7 +142,7 @@ def _android_documents_folder() -> str:
141142
""":return: documents folder for the Android OS"""
142143
# Get directories with pyjnius
143144
try:
144-
from jnius import autoclass
145+
from jnius import autoclass # noqa: PLC0415
145146

146147
context = autoclass("android.content.Context")
147148
environment = autoclass("android.os.Environment")
@@ -157,7 +158,7 @@ def _android_downloads_folder() -> str:
157158
""":return: downloads folder for the Android OS"""
158159
# Get directories with pyjnius
159160
try:
160-
from jnius import autoclass
161+
from jnius import autoclass # noqa: PLC0415
161162

162163
context = autoclass("android.content.Context")
163164
environment = autoclass("android.os.Environment")
@@ -173,7 +174,7 @@ def _android_pictures_folder() -> str:
173174
""":return: pictures folder for the Android OS"""
174175
# Get directories with pyjnius
175176
try:
176-
from jnius import autoclass
177+
from jnius import autoclass # noqa: PLC0415
177178

178179
context = autoclass("android.content.Context")
179180
environment = autoclass("android.os.Environment")
@@ -189,7 +190,7 @@ def _android_videos_folder() -> str:
189190
""":return: videos folder for the Android OS"""
190191
# Get directories with pyjnius
191192
try:
192-
from jnius import autoclass
193+
from jnius import autoclass # noqa: PLC0415
193194

194195
context = autoclass("android.content.Context")
195196
environment = autoclass("android.os.Environment")
@@ -205,7 +206,7 @@ def _android_music_folder() -> str:
205206
""":return: music folder for the Android OS"""
206207
# Get directories with pyjnius
207208
try:
208-
from jnius import autoclass
209+
from jnius import autoclass # noqa: PLC0415
209210

210211
context = autoclass("android.content.Context")
211212
environment = autoclass("android.os.Environment")

0 commit comments

Comments
 (0)