Skip to content

Commit

Permalink
Merge pull request #106 from jakkdl/followup_pr
Browse files Browse the repository at this point in the history
version bump, detect stdlib import
  • Loading branch information
Zac-HD committed Mar 13, 2024
2 parents b03fad6 + 8105de3 commit 5b77477
Show file tree
Hide file tree
Showing 11 changed files with 745 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
- "3.13-dev"
## LibCST fails to install under PyPy due to PyO3 compilation error?
# - "pypy-3.8"
# - "pypy-3.9"
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
*`shed` uses [calendar versioning](https://calver.org/), with a year.month.patch scheme.*

#### 2024.3.1 - 2024-03-13
- Replace usage of Autoflake, PyUpgrade and isort with ruff.

#### 2024.1.1 - 2024-01-26
- Require `black >= 24.1.0`, with their [updated code style](https://black.readthedocs.io/en/stable/change_log.html)

Expand Down
45 changes: 45 additions & 0 deletions CODEMODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,48 @@ with (
):
pass
```

## `replace_builtin_empty_collection` [removed]
A codemod that was removed in favor of ruffs C406/C409/C410/C418, but that also covered some cases that ruff currently raises no errors for.

#### input
```py
# handled by ruff
list([]) # C410
list(()) # C410

dict({}) # C418
dict([]) # C406
dict(()) # C406

tuple([]) # C409
tuple(()) # C409

# not handled by ruff, but was handled by our codemod
list({})
list("")
dict("")
tuple({})
tuple("")
```

#### output
```py
# handled by ruff
[] # C410
[] # C410

{} # C418
{} # C406
{} # C406

() # C409
() # C409

# not handled by ruff, but was handled by our codemod
[]
[]
{}
()
()
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ adding the following to your `.pre-commit-config.yaml`:
minimum_pre_commit_version: '2.9.0'
repos:
- repo: https://github.com/Zac-HD/shed
rev: 2024.1.1
rev: 2024.3.1
hooks:
- id: shed
# args: [--refactor, --py311-plus]
Expand Down
2 changes: 1 addition & 1 deletion deps/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ flake8==7.0.0
# via flake8-comprehensions
flake8-comprehensions==3.14.0
# via -r deps/test.in
hypothesis[lark]==6.99.2
hypothesis[lark]==6.99.5
# via
# -r deps/test.in
# hypothesmith
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tool.coverage.run]
# not possible to specify as a flag to pytest-cov, and while coverage seems like it
# should read from tox.ini it didn't seem to work for me.
omit = [
"*/shed/_stdlib_module_names/*",
]

# other configuration for pytest, flake8 & mypy is made in tox.ini
6 changes: 3 additions & 3 deletions src/shed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from black.mode import TargetVersion
from black.parsing import lib2to3_parse

__version__ = "2024.1.1"
__version__ = "2024.3.1"
__all__ = ["shed", "docshed"]

# Conditionally imported in refactor mode to reduce startup latency in the common case
Expand Down Expand Up @@ -75,6 +75,8 @@
# https://github.com/astral-sh/ruff/issues/10245
# ruff replaces `sorted(reversed(iterable))` with `sorted(iterable)`
# "C414", # unnecessary-double-cast # codemod: `replace_unnecessary_nested_calls`
#
#
# ** These are new fixes that Zac had enabled in his branch
# "E731", # don't assign lambdas
# "B007", # unused loop variable
Expand Down Expand Up @@ -143,8 +145,6 @@ def shed(
"""Process the source code of a single module."""
assert isinstance(source_code, str)
assert isinstance(refactor, bool)
# TODO: I guess this required frozenset because of isort compatibility
# but we can probably relax that to an iterable[str]
assert isinstance(first_party_imports, frozenset)
assert all(isinstance(name, str) for name in first_party_imports)
assert all(name.isidentifier() for name in first_party_imports)
Expand Down
9 changes: 8 additions & 1 deletion src/shed/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
from . import ShedSyntaxWarning, _version_map, docshed, shed
from ._is_python_file import is_python_file

if sys.version_info[:2] > (3, 9): # pragma: no cover
from sys import stdlib_module_names
elif sys.version_info[:2] == (3, 9): # pragma: no cover
from ._stdlib_module_names.py39 import stdlib_module_names
else: # pragma: no cover
from ._stdlib_module_names.py38 import stdlib_module_names


@functools.lru_cache
def _get_git_repo_root(cwd: Optional[str] = None) -> str:
Expand Down Expand Up @@ -48,7 +55,7 @@ def _guess_first_party_modules(cwd: Optional[str] = None) -> FrozenSet[str]:
# a fraction of the functionality. So best approach, if we still need
# the ability to exclude stdlib modules here, is probably to generate a list of
# known stdlib modules - either dynamically or store in a file.
if p.isidentifier() # and place_module(p) != "STDLIB"
if p.isidentifier() and p not in stdlib_module_names
)


Expand Down
Empty file.

0 comments on commit 5b77477

Please sign in to comment.