Skip to content

Commit

Permalink
chore: some extra simplifications from Ruff (#870)
Browse files Browse the repository at this point in the history
* chore: add a few nox checks

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* chore: add a few things from preview ruff

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Apply suggestions from code review

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii authored Oct 26, 2024
1 parent 771c1c7 commit 5e02a64
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 57 deletions.
8 changes: 4 additions & 4 deletions nox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
needs_version: str | None = None

__all__ = [
"Session",
"needs_version",
"parametrize",
"param",
"session",
"options",
"Session",
"param",
"parametrize",
"project",
"session",
]
2 changes: 1 addition & 1 deletion nox/_option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OptionGroup:
kwargs: Passed through to``ArgumentParser.add_argument_group``.
"""

__slots__ = ("name", "args", "kwargs")
__slots__ = ("args", "kwargs", "name")

def __init__(self, name: str, *args: Any, **kwargs: Any) -> None:
self.name = name
Expand Down
12 changes: 5 additions & 7 deletions nox/_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,16 @@ def call_spec(self) -> dict[str, Any]:
def __str__(self) -> str:
if self.id:
return self.id
else:
call_spec = self.call_spec
args = [f"{k}={call_spec[k]!r}" for k in call_spec]
return ", ".join(args)
call_spec = self.call_spec
args = [f"{k}={call_spec[k]!r}" for k in call_spec]
return ", ".join(args)

__repr__ = __str__

def copy(self) -> Param:
new = self.__class__(
return self.__class__(
*self.args, arg_names=self.arg_names, id=self.id, tags=self.tags
)
return new

def update(self, other: Param) -> None:
self.id = ", ".join([str(self), str(other)])
Expand All @@ -87,7 +85,7 @@ def __eq__(self, other: object) -> bool:
and self.id == other.id
and self.tags == other.tags
)
elif isinstance(other, dict):
if isinstance(other, dict):
return dict(zip(self.arg_names, self.args)) == other

return NotImplemented
Expand Down
2 changes: 1 addition & 1 deletion nox/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def run(
" this."
)
raise CommandFailed("External program disallowed.")
elif external is False:
if external is False:
logger.warning(
f"Warning: {cmd} is not installed into the virtualenv, it is"
f" located at {cmd_path}. This might cause issues! Pass"
Expand Down
24 changes: 9 additions & 15 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ def _dblquote_pkg_install_arg(pkg_req_str: str) -> str:
if pkg_req_str[0] == pkg_req_str[-1] == '"':
# already double-quoted string
return pkg_req_str
else:
# need to double-quote string
if '"' in pkg_req_str:
raise ValueError(f"Cannot escape requirement string: {pkg_req_str}")
return f'"{pkg_req_str}"'
else:
# no dangerous char: no need to double-quote string
return pkg_req_str
# need to double-quote string
if '"' in pkg_req_str:
raise ValueError(f"Cannot escape requirement string: {pkg_req_str}")
return f'"{pkg_req_str}"'
# no dangerous char: no need to double-quote string
return pkg_req_str

# double-quote all args that need to be and return the result
return tuple(_dblquote_pkg_install_arg(a) for a in args)
Expand Down Expand Up @@ -917,8 +915,7 @@ def __init__(
def description(self) -> str | None:
doc = self.func.__doc__
if doc:
first_line = doc.strip().split("\n")[0]
return first_line
return doc.strip().split("\n")[0]
return None

def __str__(self) -> str:
Expand Down Expand Up @@ -1041,11 +1038,8 @@ def execute(self) -> Result:
except nox.virtualenv.InterpreterNotFound as exc:
if self.global_config.error_on_missing_interpreters:
return Result(self, Status.FAILED, reason=str(exc))
else:
logger.warning(
"Missing interpreters will error by default on CI systems."
)
return Result(self, Status.SKIPPED, reason=str(exc))
logger.warning("Missing interpreters will error by default on CI systems.")
return Result(self, Status.SKIPPED, reason=str(exc))

except _SessionQuit as exc:
return Result(self, Status.ABORTED, reason=str(exc))
Expand Down
5 changes: 2 additions & 3 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def uv_version() -> version.Version:

if ret.returncode == 0 and ret.stdout:
return version.Version(json.loads(ret.stdout).get("version"))
else:
logger.info("Failed to establish uv's version.")
return version.Version("0.0")
logger.info("Failed to establish uv's version.")
return version.Version("0.0")


def uv_install_python(python_version: str) -> bool:
Expand Down
46 changes: 22 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@ metadata.allow-ambiguous-features = true # disable normalization (tox-to-nox) fo

[tool.ruff]
lint.extend-select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"EXE", # flake8-executable
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"UP", # pyupgrade
"YTT", # flake8-2020
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"EXE", # flake8-executable
"FURB", # refurb
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"UP", # pyupgrade
"YTT", # flake8-2020
]
lint.ignore = [
"ISC001", # Conflicts with formatter
"PLR09", # Too many X
"PLR2004", # Magic value used in comparison
]

[tool.isort]
profile = "black"
lint.typing-modules = [ "nox._typing" ]

[tool.pyproject-fmt]
max_supported_python = "3.13"
Expand All @@ -99,14 +99,12 @@ filterwarnings = [ "error" ]
log_cli_level = "info"
testpaths = [ "tests" ]

[tool.coverage.run]
branch = true
omit = [ "nox/_typing.py" ]
relative_files = true
source_pkgs = [ "nox" ]

[tool.coverage.report]
exclude_also = [ "def __dir__()", "if TYPE_CHECKING:", "@overload" ]
[tool.coverage]
run.branch = true
run.omit = [ "nox/_typing.py" ]
run.relative_files = true
run.source_pkgs = [ "nox" ]
report.exclude_also = [ "def __dir__()", "if TYPE_CHECKING:", "@overload" ]

[tool.mypy]
files = [ "nox/**/*.py", "noxfile.py" ]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def make_runner(self):
func.python = None
func.venv_backend = None
func.reuse_venv = False
runner = nox.sessions.SessionRunner(
return nox.sessions.SessionRunner(
name="test",
signatures=["test(1, 2)"],
func=func,
Expand All @@ -978,7 +978,6 @@ def make_runner(self):
),
manifest=mock.create_autospec(nox.manifest.Manifest),
)
return runner

def test_properties(self):
runner = self.make_runner()
Expand Down

0 comments on commit 5e02a64

Please sign in to comment.