-
Notifications
You must be signed in to change notification settings - Fork 11
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
drop 3.7 support, migrate to ruff format #28
Open
davidhewitt
wants to merge
3
commits into
main
Choose a base branch
from
dh/3.12
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,12 +42,12 @@ classifiers = [ | |
'Framework :: Pytest', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
] | ||
requires-python = '>=3.7' | ||
requires-python = '>=3.8' | ||
dynamic = ['version'] | ||
dependencies = [ | ||
'pytest>=7', | ||
'black>=23', | ||
'ruff>=0.0.258', | ||
'ruff>=0.1,<0.2', | ||
] | ||
|
||
[project.entry-points.pytest11] | ||
|
@@ -68,7 +68,10 @@ extend-select = ['Q', 'RUF100', 'C90', 'UP', 'I'] | |
flake8-quotes = {inline-quotes = 'single', multiline-quotes = 'double'} | ||
mccabe = { max-complexity = 14 } | ||
isort = { known-first-party = ['pytest_examples'] } | ||
target-version = 'py37' | ||
target-version = 'py38' | ||
|
||
[tool.ruff.format] | ||
quote-style = "single" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use consistent quotes, double quotes would probably better, but we're using single quotes else where |
||
|
||
[tool.coverage.run] | ||
source = ['pytest_examples'] | ||
|
@@ -82,10 +85,3 @@ exclude_lines = [ | |
'if TYPE_CHECKING:', | ||
'@overload', | ||
] | ||
|
||
[tool.black] | ||
exclude = '.*/cases_update/.*' | ||
color = true | ||
line-length = 120 | ||
target-version = ['py310'] | ||
skip-string-normalization = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,11 @@ def __call__(self, *args: Any, sep: str = ' ', **kwargs: Any) -> None: | |
|
||
class InsertPrintStatements: | ||
def __init__( | ||
self, python_path: Path, config: ExamplesConfig, enable: bool, print_callback: Callable[[str], str] | None | ||
self, | ||
python_path: Path, | ||
config: ExamplesConfig, | ||
enable: bool, | ||
print_callback: Callable[[str], str] | None, | ||
): | ||
self.file = python_path | ||
self.config = config | ||
|
@@ -177,7 +181,12 @@ def _insert_print_statements(self, example: CodeExample) -> str: | |
return '\n'.join(lines) + '\n' | ||
|
||
def _insert_print_args( | ||
self, lines: list[str], statement: PrintStatement, in_python: bool, line_index: int, col: int | ||
self, | ||
lines: list[str], | ||
statement: PrintStatement, | ||
in_python: bool, | ||
line_index: int, | ||
col: int, | ||
) -> None: | ||
single_line = statement.sep.join(map(str, statement.args)) | ||
if self.print_callback: | ||
|
@@ -205,21 +214,6 @@ def _insert_print_args( | |
triple_quotes_prefix_re = re.compile('^ *(?:"{3}|\'{3})', re.MULTILINE) | ||
|
||
|
||
def find_print_line(lines: list[str], line_no: int) -> int: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice to remove this. |
||
""" | ||
For 3.7 we have to reverse through lines to find the print statement lint | ||
""" | ||
if sys.version_info >= (3, 8): | ||
return line_no | ||
|
||
for back in range(100): | ||
new_line_no = line_no - back | ||
m = re.search(r'^ *print\(', lines[new_line_no - 1]) | ||
if m: | ||
return new_line_no | ||
return line_no | ||
|
||
|
||
def remove_old_print(lines: list[str], line_index: int) -> None: | ||
""" | ||
Remove the old print statement. | ||
|
@@ -253,17 +247,6 @@ def find_print_location(example: CodeExample, line_no: int) -> tuple[int, int]: | |
:param line_no: The line number on which the print statement starts (or approx on 3.7) | ||
:return: tuple if `(line, column)` of the print statement | ||
""" | ||
# For 3.7 we have to reverse through lines to find the print statement lint | ||
if sys.version_info < (3, 8): | ||
# find the last print statement before the line | ||
lines = example.source.splitlines() | ||
for back in range(100): | ||
new_line_no = line_no - back | ||
m = re.match(r' *print\(', lines[new_line_no - 1]) | ||
if m: | ||
line_no = new_line_no | ||
break | ||
|
||
m = ast.parse(example.source, filename=example.path.name) | ||
return find_print(m, line_no) or (line_no, 0) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,59 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# This file is autogenerated by pip-compile with Python 3.11 | ||
# by the following command: | ||
# | ||
# pip-compile --output-file=requirements/linting.txt --resolver=backtracking requirements/linting.in | ||
# pip-compile --output-file=requirements/linting.txt requirements/linting.in | ||
# | ||
black==23.1.0 | ||
aiohttp==3.9.1 | ||
# via black | ||
aiosignal==1.3.1 | ||
# via aiohttp | ||
attrs==23.1.0 | ||
# via aiohttp | ||
black==23.12.0 | ||
# via -r requirements/linting.in | ||
cfgv==3.3.1 | ||
cfgv==3.4.0 | ||
# via pre-commit | ||
click==8.1.3 | ||
click==8.1.7 | ||
# via black | ||
distlib==0.3.6 | ||
distlib==0.3.8 | ||
# via virtualenv | ||
filelock==3.10.2 | ||
filelock==3.13.1 | ||
# via virtualenv | ||
identify==2.5.21 | ||
frozenlist==1.4.1 | ||
# via | ||
# aiohttp | ||
# aiosignal | ||
identify==2.5.33 | ||
# via pre-commit | ||
idna==3.6 | ||
# via yarl | ||
multidict==6.0.4 | ||
# via | ||
# aiohttp | ||
# yarl | ||
mypy-extensions==1.0.0 | ||
# via black | ||
nodeenv==1.7.0 | ||
nodeenv==1.8.0 | ||
# via pre-commit | ||
packaging==23.0 | ||
packaging==23.2 | ||
# via black | ||
pathspec==0.11.1 | ||
pathspec==0.12.1 | ||
# via black | ||
platformdirs==3.1.1 | ||
platformdirs==4.1.0 | ||
# via | ||
# black | ||
# virtualenv | ||
pre-commit==2.21.0 | ||
# via -r requirements/linting.in | ||
pyyaml==6.0 | ||
pyyaml==6.0.1 | ||
# via pre-commit | ||
ruff==0.0.258 | ||
ruff==0.1.8 | ||
# via -r requirements/linting.in | ||
tomli==2.0.1 | ||
# via black | ||
virtualenv==20.21.0 | ||
virtualenv==20.25.0 | ||
# via pre-commit | ||
yarl==1.9.4 | ||
# via aiohttp | ||
|
||
# The following packages are considered to be unsafe in a requirements file: | ||
# setuptools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,46 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# This file is autogenerated by pip-compile with Python 3.11 | ||
# by the following command: | ||
# | ||
# pip-compile --output-file=requirements/pyproject.txt --resolver=backtracking pyproject.toml | ||
# pip-compile --output-file=requirements/pyproject.txt pyproject.toml | ||
# | ||
attrs==22.2.0 | ||
# via pytest | ||
black==23.1.0 | ||
aiohttp==3.9.1 | ||
# via black | ||
aiosignal==1.3.1 | ||
# via aiohttp | ||
attrs==23.1.0 | ||
# via aiohttp | ||
black==23.12.0 | ||
# via pytest-examples (pyproject.toml) | ||
click==8.1.3 | ||
click==8.1.7 | ||
# via black | ||
exceptiongroup==1.1.1 | ||
# via pytest | ||
frozenlist==1.4.1 | ||
# via | ||
# aiohttp | ||
# aiosignal | ||
idna==3.6 | ||
# via yarl | ||
iniconfig==2.0.0 | ||
# via pytest | ||
multidict==6.0.4 | ||
# via | ||
# aiohttp | ||
# yarl | ||
mypy-extensions==1.0.0 | ||
# via black | ||
packaging==23.0 | ||
packaging==23.2 | ||
# via | ||
# black | ||
# pytest | ||
pathspec==0.11.1 | ||
pathspec==0.12.1 | ||
# via black | ||
platformdirs==3.1.1 | ||
platformdirs==4.1.0 | ||
# via black | ||
pluggy==1.0.0 | ||
pluggy==1.3.0 | ||
# via pytest | ||
pytest==7.2.2 | ||
pytest==7.4.3 | ||
# via pytest-examples (pyproject.toml) | ||
tomli==2.0.1 | ||
# via | ||
# black | ||
# pytest | ||
ruff==0.1.8 | ||
# via pytest-examples (pyproject.toml) | ||
yarl==1.9.4 | ||
# via aiohttp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
# | ||
# This file is autogenerated by pip-compile with Python 3.10 | ||
# This file is autogenerated by pip-compile with Python 3.11 | ||
# by the following command: | ||
# | ||
# pip-compile --output-file=requirements/testing.txt requirements/testing.in | ||
# | ||
coverage==7.2.2 | ||
coverage==7.3.4 | ||
# via -r requirements/testing.in | ||
exceptiongroup==1.1.1 | ||
# via pytest | ||
iniconfig==2.0.0 | ||
# via pytest | ||
markdown-it-py==2.2.0 | ||
markdown-it-py==3.0.0 | ||
# via rich | ||
mdurl==0.1.2 | ||
# via markdown-it-py | ||
packaging==23.0 | ||
packaging==23.2 | ||
# via pytest | ||
pluggy==1.0.0 | ||
pluggy==1.3.0 | ||
# via pytest | ||
pygments==2.14.0 | ||
pygments==2.17.2 | ||
# via rich | ||
pytest==7.4.2 | ||
pytest==7.4.3 | ||
# via pytest-pretty | ||
pytest-pretty==1.1.1 | ||
pytest-pretty==1.2.0 | ||
# via -r requirements/testing.in | ||
rich==13.3.2 | ||
rich==13.7.0 | ||
# via pytest-pretty | ||
ruff==0.0.258 | ||
ruff==0.1.8 | ||
# via -r requirements/testing.in | ||
tomli==2.0.1 | ||
# via pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess you can remove black as a dependency now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
black_format
still exists as a function for now, I want to push that as a follow up PR to keep a smaller diff. "ruff format" in this context is for our CI, not for the functionality 😂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'll just add here as a follow-up commit.