Skip to content

Commit

Permalink
chore: add some preview check fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Nov 12, 2024
1 parent 6f3b191 commit 351f2a9
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 46 deletions.
2 changes: 1 addition & 1 deletion nox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

__all__ = [
"Session",
"main",
"needs_version",
"options",
"param",
"parametrize",
"project",
"session",
"main",
]
6 changes: 3 additions & 3 deletions nox/_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def copy(self) -> Param:

def update(self, other: Param) -> None:
self.id = ", ".join([str(self), str(other)])
self.args = self.args + other.args
self.arg_names = self.arg_names + other.arg_names
self.tags = self.tags + other.tags
self.args += other.args
self.arg_names += other.arg_names
self.tags += other.tags

def __eq__(self, other: object) -> bool:
if isinstance(other, self.__class__):
Expand Down
2 changes: 1 addition & 1 deletion nox/_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def lazy_stable_topo_sort(
~nox._resolver.CycleError: If a dependency cycle is encountered.
"""

visited = {node: False for node in dependencies}
visited = dict.fromkeys(dependencies, False)

def prepended_by_dependencies(
node: Node,
Expand Down
2 changes: 1 addition & 1 deletion nox/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _parse_needs_version(source: str, filename: str = "<unknown>") -> str | None

def _read_needs_version(filename: str) -> str | None:
"""Read ``nox.needs_version`` from the user's Noxfile."""
with open(filename) as io:
with open(filename, encoding="utf-8") as io:
source = io.read()

return _parse_needs_version(source, filename=filename)
Expand Down
2 changes: 1 addition & 1 deletion nox/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def make_session(
return sessions

def next(self) -> SessionRunner:
return self.__next__()
return next(self)

def notify(
self, session: str | SessionRunner, posargs: Iterable[str] | None = None
Expand Down
6 changes: 3 additions & 3 deletions nox/popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def decode_output(output: bytes) -> str:
return output.decode("utf-8")
except UnicodeDecodeError:
second_encoding = locale.getpreferredencoding()
if second_encoding.casefold() in ("utf8", "utf-8"):
if second_encoding.casefold() in {"utf8", "utf-8"}:
raise

return output.decode(second_encoding)
Expand Down Expand Up @@ -86,11 +86,11 @@ def popen(
proc = subprocess.Popen(args, env=env, stdout=stdout, stderr=stderr)

try:
out, err = proc.communicate()
out, _err = proc.communicate()
sys.stdout.flush()

except KeyboardInterrupt:
out, err = shutdown_process(proc, interrupt_timeout, terminate_timeout)
out, _err = shutdown_process(proc, interrupt_timeout, terminate_timeout)
if proc.returncode != 0:
raise

Expand Down
2 changes: 1 addition & 1 deletion nox/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import tomllib


__all__ = ["load_toml", "python_versions", "dependency_groups"]
__all__ = ["dependency_groups", "load_toml", "python_versions"]


def __dir__() -> list[str]:
Expand Down
6 changes: 4 additions & 2 deletions nox/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@


@overload
def session_decorator(__func: F) -> F: ...
def session_decorator(func: F, /) -> F: ...


@overload
def session_decorator(
__func: None = ...,
func: None = ...,
/,
python: Python | None = ...,
py: Python | None = ...,
reuse_venv: bool | None = ...,
Expand All @@ -53,6 +54,7 @@ def session_decorator(

def session_decorator(
func: F | None = None,
/,
python: Python | None = None,
py: Python | None = None,
reuse_venv: bool | None = None,
Expand Down
3 changes: 0 additions & 3 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,6 @@ def __init__(
def __bool__(self) -> bool:
return self.status.value > 0

def __nonzero__(self) -> bool:
return self.__bool__()

@property
def imperfect(self) -> str:
"""Return the English imperfect tense for the status.
Expand Down
2 changes: 1 addition & 1 deletion nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def create_report(
return results

# Write the JSON report.
with open(global_config.report, "w") as report_file:
with open(global_config.report, "w", encoding="utf-8") as report_file:
json.dump(
{
"result": int(all(results)),
Expand Down
6 changes: 3 additions & 3 deletions nox/tox_to_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def fixname(envname: str) -> str:

def write_output_to_file(output: str, filename: str) -> None:
"""Write output to a file."""
with open(filename, "w") as outfile:
with open(filename, "w", encoding="utf-8") as outfile:
outfile.write(output)


Expand All @@ -88,11 +88,11 @@ def main() -> None:
set_env = {}
for var in section.get("set_env", "").strip().splitlines():
k, v = var.split("=")
if k not in (
if k not in {
"PYTHONHASHSEED",
"PIP_DISABLE_PIP_VERSION_CHECK",
"PYTHONIOENCODING",
):
}:
set_env[k] = v

config[name]["set_env"] = set_env
Expand Down
2 changes: 1 addition & 1 deletion nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def _clean_location(self) -> bool:
def _read_pyvenv_cfg(self) -> dict[str, str] | None:
"""Read a pyvenv.cfg file into dict, returns None if missing."""
path = os.path.join(self.location, "pyvenv.cfg")
with contextlib.suppress(FileNotFoundError), open(path) as fp:
with contextlib.suppress(FileNotFoundError), open(path, encoding="utf-8") as fp:
parts = (x.partition("=") for x in fp if "=" in x)
return {k.strip(): v.strip() for k, _, v in parts}
return None
Expand Down
2 changes: 1 addition & 1 deletion tests/test__version.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_needs_version_default() -> None:
def test_get_nox_version() -> None:
"""It returns something that looks like a Nox version."""
result = get_nox_version()
year, month, day, *_ = (int(part) for part in result.split("."))
year, _month, _day, *_ = (int(part) for part in result.split("."))
assert year >= 2020


Expand Down
2 changes: 1 addition & 1 deletion tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def test_fail_with_silent(capsys):
],
silent=True,
)
out, err = capsys.readouterr()
_out, err = capsys.readouterr()
assert "out" in err
assert "err" in err

Expand Down
6 changes: 3 additions & 3 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_formatter(caplog):
logger.logger.info("bar")
logger.logger.output("foo")

logs = [rec for rec in caplog.records if rec.levelname in ("INFO", "OUTPUT")]
logs = [rec for rec in caplog.records if rec.levelname in {"INFO", "OUTPUT"}]
assert len(logs) == 1
assert not hasattr(logs[0], "asctime")

Expand All @@ -50,7 +50,7 @@ def test_formatter(caplog):
logger.logger.info("bar")
logger.logger.output("foo")

logs = [rec for rec in caplog.records if rec.levelname in ("INFO", "OUTPUT")]
logs = [rec for rec in caplog.records if rec.levelname in {"INFO", "OUTPUT"}]
assert len(logs) == 2

logs = [rec for rec in caplog.records if rec.levelname == "OUTPUT"]
Expand All @@ -75,7 +75,7 @@ def test_no_color_timestamp(caplog, color):
logger.logger.info("bar")
logger.logger.output("foo")

logs = [rec for rec in caplog.records if rec.levelname in ("INFO", "OUTPUT")]
logs = [rec for rec in caplog.records if rec.levelname in {"INFO", "OUTPUT"}]
assert len(logs) == 1
assert hasattr(logs[0], "asctime")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def test_main_requires_chain_fail(run_nox, session):
@pytest.mark.parametrize("session", ["w", "u"])
def test_main_requries_modern_param(run_nox, session):
noxfile = os.path.join(RESOURCES, "noxfile_requires.py")
returncode, _, stderr = run_nox(f"--noxfile={noxfile}", f"--session={session}")
returncode, _, _stderr = run_nox(f"--noxfile={noxfile}", f"--session={session}")
assert returncode == 0


Expand Down
2 changes: 1 addition & 1 deletion tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_iteration():

# Continuing past the end raises StopIteration.
with pytest.raises(StopIteration):
manifest.__next__()
next(manifest)


def test_len():
Expand Down
8 changes: 2 additions & 6 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_virtualenv_as_none(self):
assert session.venv_backend == "none"

def test_interactive(self):
session, runner = self.make_session_and_runner()
session, _runner = self.make_session_and_runner()

with mock.patch("nox.sessions.sys.stdin.isatty") as m_isatty:
m_isatty.return_value = True
Expand Down Expand Up @@ -426,7 +426,7 @@ def test_run_no_install_passthrough(self):
session.conda_install("numpy")

def test_run_no_conda_install(self):
session, runner = self.make_session_and_runner()
session, _runner = self.make_session_and_runner()

with pytest.raises(TypeError, match="A session without a conda"):
session.conda_install("numpy")
Expand Down Expand Up @@ -1318,15 +1318,11 @@ def test__bool_true(self):
for status in (nox.sessions.Status.SUCCESS, nox.sessions.Status.SKIPPED):
result = nox.sessions.Result(session=object(), status=status)
assert bool(result)
assert result.__bool__()
assert result.__nonzero__()

def test__bool_false(self):
for status in (nox.sessions.Status.FAILED, nox.sessions.Status.ABORTED):
result = nox.sessions.Result(session=object(), status=status)
assert not bool(result)
assert not result.__bool__()
assert not result.__nonzero__()

def test__imperfect(self):
result = nox.sessions.Result(object(), nox.sessions.Status.SUCCESS)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def test_create_report():
mock.ANY,
indent=2,
)
open_.assert_called_once_with("/path/to/report", "w")
open_.assert_called_once_with("/path/to/report", "w", encoding="utf-8")


def test_final_reduce():
Expand Down
22 changes: 11 additions & 11 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ def test_condaenv_create_interpreter(make_conda):

@has_conda
def test_conda_env_create_verbose(make_conda):
venv, dir_ = make_conda()
venv, _dir = make_conda()
with mock.patch("nox.virtualenv.nox.command.run") as mock_run:
venv.create()

args, kwargs = mock_run.call_args
_args, kwargs = mock_run.call_args
assert kwargs["log"] is False

nox.options.verbose = True
with mock.patch("nox.virtualenv.nox.command.run") as mock_run:
venv.create()

args, kwargs = mock_run.call_args
_args, kwargs = mock_run.call_args
assert kwargs["log"]


Expand All @@ -236,7 +236,7 @@ def test_condaenv_bin_windows(make_conda):

@has_conda
def test_condaenv_(make_conda):
venv, dir_ = make_conda()
venv, _dir = make_conda()
assert not venv.is_offline()


Expand Down Expand Up @@ -402,7 +402,7 @@ def test_create(monkeypatch, make_one):


def test_create_reuse_environment(make_one):
venv, location = make_one(reuse_existing=True)
venv, _location = make_one(reuse_existing=True)
venv.create()

reused = not venv.create()
Expand Down Expand Up @@ -452,21 +452,21 @@ def test_not_stale_virtualenv_environment(make_one, monkeypatch):
# Making the reuse requirement more strict
monkeypatch.setenv("NOX_ENABLE_STALENESS_CHECK", "1")

venv, location = make_one(reuse_existing=True, venv_backend="virtualenv")
venv, _location = make_one(reuse_existing=True, venv_backend="virtualenv")
venv.create()

venv, location = make_one(reuse_existing=True, venv_backend="virtualenv")
venv, _location = make_one(reuse_existing=True, venv_backend="virtualenv")
reused = not venv.create()

assert reused


@has_conda
def test_stale_virtualenv_to_conda_environment(make_one):
venv, location = make_one(reuse_existing=True, venv_backend="virtualenv")
venv, _location = make_one(reuse_existing=True, venv_backend="virtualenv")
venv.create()

venv, location = make_one(reuse_existing=True, venv_backend="conda")
venv, _location = make_one(reuse_existing=True, venv_backend="conda")
reused = not venv.create()

# The environment is not reused because it is now conda style
Expand Down Expand Up @@ -732,7 +732,7 @@ def test_inner_functions_reusing_venv(make_one, monkeypatch):
reason="Python 2.7 unsupported for virtualenv>=20.22.0",
)
def test_create_reuse_python2_environment(make_one):
venv, location = make_one(reuse_existing=True, interpreter="2.7")
venv, _location = make_one(reuse_existing=True, interpreter="2.7")

try:
venv.create()
Expand All @@ -745,7 +745,7 @@ def test_create_reuse_python2_environment(make_one):


def test_create_venv_backend(make_one):
venv, dir_ = make_one(venv_backend="venv")
venv, _dir = make_one(venv_backend="venv")
venv.create()


Expand Down

0 comments on commit 351f2a9

Please sign in to comment.