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

version bump, detect stdlib import #106

Merged
merged 5 commits into from
Mar 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially only enabled checks that had a direct analog in autoflake/pyupgrade/isort/codemods, but that left a bunch that you had enabled in your branch. Presumably you added them because you thought they were useful to have enabled by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zac-HD ... soooo should I do a separate PR where I do enable them?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open an issue and I'll get to in eventually?

The more important one to me personally is that our just-released shed no longer detects hypothesis' own test suite as first-party, and so all the imports get moved.

None of this is work-related though!

# "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.
Loading
Loading