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

bump ruff to 0.4.2 #13

Merged
merged 3 commits into from
May 1, 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
32 changes: 15 additions & 17 deletions mainpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import asyncio
import functools
import importlib.util
import inspect
import os
import sys
Expand All @@ -21,15 +20,13 @@
if TYPE_CHECKING:
import contextvars


if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
if sys.version_info < (3, 11):
from typing_extensions import Never, TypeAlias
else:
from typing import TypeAlias
from typing import Never, TypeAlias

__all__ = ('main',)


_R = TypeVar('_R')
_F = TypeVar('_F', bound=Callable[..., Any])

Expand Down Expand Up @@ -57,9 +54,8 @@ def _infer_debug() -> bool:
try:
env_debug = int(env_debug)
except ValueError as e:
raise OSError(
f'Invalid value for `DEBUG` env var: {env_debug!r}',
) from e
errmsg = f'Invalid value for `DEBUG` env var: {env_debug!r}'
raise OSError(errmsg) from e

return bool(env_debug)

Expand All @@ -69,10 +65,12 @@ def _infer_uvloop() -> bool:
if 'uvloop' in sys.modules:
return True

import importlib.util

return importlib.util.find_spec('uvloop') is not None


def _enable_debug():
def _enable_debug() -> None:
"""Enable debug mode."""
env = os.environ

Expand All @@ -91,7 +89,6 @@ def _enable_debug():
def main(__f: _AFunc[_R], /) -> _R | _AFunc[_R]: ...
@overload
def main(__f: _SFunc[_R], /) -> _R | _SFunc[_R]: ...

@overload
def main(
*,
Expand Down Expand Up @@ -127,19 +124,20 @@ def main(
)

if not callable(func):
raise TypeError(f'expected a callable, got {func!r}')
errmsg = f'expected a callable, got {type(func)}'
raise TypeError(errmsg)

if func.__module__ != '__main__':
frame = inspect.currentframe()
if not frame or frame.f_globals.get('__name__') != '__main__':
return func

if debug or debug is None and _infer_debug():
if debug or (debug is None and _infer_debug()):
_enable_debug()

if (
is_async is False
or is_async is None and not asyncio.iscoroutinefunction(func)
if is_async is False or (
is_async is None
and not asyncio.iscoroutinefunction(func)
):
return func()

Expand All @@ -165,6 +163,6 @@ def main(


@main
def __main():
def __main() -> Never:
# this should never run
raise AssertionError
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 19 additions & 43 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ readme = "README.md"
repository = "https://github.com/jorenham/mainpy"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Natural Language :: English",
"Topic :: Software Development",
"Topic :: Utilities",
"Operating System :: OS Independent",
"Typing :: Typed",
]

[tool.poetry.dependencies]
python = "^3.8"
typing_extensions = {version = "^4.1", python = "<3.10"}
typing_extensions = {version = "^4.1", python = "<3.11"}

[tool.poetry.dependencies.uvloop]
version = ">=0.14,<1.0"
Expand All @@ -31,7 +28,7 @@ markers = 'sys_platform != "win32"'

[tool.poetry.group.lint.dependencies]
codespell = "^2.2.6"
ruff = "^0.3.0"
ruff = "^0.4.2"

[tool.poetry.group.typecheck.dependencies]
pyright = "^1.1.351"
Expand All @@ -43,7 +40,7 @@ pytest = "^8.0"
[tool.poetry.group.test-github]
optional = true
[tool.poetry.group.test-github.dependencies]
pytest-github-actions-annotate-failures = ">=0.2,<1.0"
pytest-github-actions-annotate-failures = ">=0.2.0,<1"

[tool.poetry.extras]
uvloop = ["uvloop"]
Expand Down Expand Up @@ -98,13 +95,9 @@ src = ["mainpy", "tests"]
target-version = "py38"
line-length = 79
indent-width = 4
show-fixes = true
force-exclude = true
extend-exclude = [
".github",
".vscode",
".venv",
"py.typed",
]
extend-exclude = [".github", ".vscode"]

[tool.ruff.lint]
ignore-init-module-imports = true
Expand All @@ -119,6 +112,7 @@ select = [
"YTT", # flake8-2020
"ANN", # flake8-annotations
"ASYNC", # flake8-async
"TRIO", # flake8-trio
"S", # flake8-bandit
"BLE", # flake8-blind-except
"B", # flake8-bugbear
Expand Down Expand Up @@ -147,41 +141,30 @@ select = [
"TCH", # flake8-type-checking
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
"TD", # flake8-todos
"FIX", # flake8-fixme
"ERA", # eradicate
"PD", # pandas-vet
"PGH", # pygrep-hooks
"PL", # pylint
"TRY", # tryceratops
"FLY", # flynt
"NPY", # numpy
"AIR", # airflow
"PERF", # perflint,
"FURB", # refurb
"LOG", # flake8-logging
"RUF", # ruff
]
extend-ignore = [
# flake8-annotations
"ANN001", # missing-type-function-argument (deprecated)
"ANN002", # missing-type-args (deprecated)
"ANN401", # any-type
# flake8-bandit
"S101", # assert
# pylint
"PLC0415", # import-outside-top-level
"PLW1641", # eq-without-hash (bug: doesn't consider super)
# tryceratops
"TRY003", # raise-vanilla-args
# ruff
"RUF021", # parenthesize-chained-operators
ignore = [
"PLC0415", # pylint: import-outside-top-level
]
[tool.ruff.lint.per-file-ignores]
"**/__init__.py" = [
"F401", # pyflakes: unused-import
]
"tests/*" = [
"D", # pydocstyle
"S", # flake8-bandit
"ANN", # flake8-annotations
"ARG001", # flake8-unused-arguments: unused-function-argument
"SLF001", # flake8-self: private-member-access
"PT004", # flake8-pytest-style: pytest-missing-fixture-name-underscore
]

[tool.ruff.lint.pycodestyle]
Expand All @@ -190,28 +173,21 @@ max-line-length = 79
[tool.ruff.lint.isort]
case-sensitive = true
combine-as-imports = true
force-wrap-aliases = true
known-first-party = ["mainpy"]
lines-after-imports = 2
lines-between-types = 0
no-lines-before = ["future", "local-folder"]
split-on-trailing-comma = false

[tool.ruff.lint.pydocstyle]
convention = "google"
ignore-decorators = ["typing.overload"]

[tool.ruff.lint.flake8-annotations]
suppress-none-returning = true

[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"

[tool.ruff.lint.flake8-type-checking]
strict = true

[tool.ruff.format]
docstring-code-format = true
quote-style = "single"
indent-style = "space"
line-ending = "lf"
quote-style = "single"
skip-magic-trailing-comma = true


Expand Down
3 changes: 2 additions & 1 deletion tests/test_mainpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def no_uvloop():
mp._infer_uvloop = lambda: False

try:
yield
yield orig
finally:
mp._infer_uvloop = orig

Expand Down Expand Up @@ -96,6 +96,7 @@ def test_async_implicit_uvloop(monkeypatch: pytest.MonkeyPatch):
@mp.main
@_patch_module(monkeypatch, '__main__')
async def loop_module():
await asyncio.sleep(0)
loop = asyncio.get_running_loop()
return loop.__module__.split('.')[0]

Expand Down