summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Šedivý <6774676+eumiro@users.noreply.github.com>2021-04-11 23:30:45 +0200
committerGitHub <noreply@github.com>2021-04-11 22:30:45 +0100
commit963f7c548e044d48e68002bd5d99cdf495c5ac7e (patch)
treedee7893f5d7eaa0ff7cdcd2980dca01cb3c02bf0
parent931159940c55f960b68c3dc1324150c2093e84d6 (diff)
downloadtox-git-963f7c548e044d48e68002bd5d99cdf495c5ac7e.tar.gz
Minor code improvements (#2017)
* Use !r to repr strings * Simplify loops and expressions * Improve exception traceback * Add Python 3.10 to installation.rst
-rw-r--r--docs/installation.rst2
-rw-r--r--src/tox/config/cli/env_var.py3
-rw-r--r--src/tox/config/loader/convert.py2
-rw-r--r--src/tox/config/loader/ini/replace.py5
-rw-r--r--src/tox/pytest.py4
-rw-r--r--src/tox/session/cmd/run/common.py9
-rw-r--r--src/tox/tox_env/python/pip/pip_install.py4
-rw-r--r--src/tox/tox_env/python/pip/req/file.py4
-rw-r--r--src/tox/tox_env/python/runner.py2
-rw-r--r--tasks/release.py5
-rw-r--r--tests/execute/local_subprocess/test_local_subprocess.py2
11 files changed, 16 insertions, 26 deletions
diff --git a/docs/installation.rst b/docs/installation.rst
index b0bec490..1009f148 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -68,7 +68,7 @@ Python and OS Compatibility
tox works with the following Python interpreter implementations:
-- `CPython <https://www.python.org/>`_ versions 3.6, 3.7, 3.8, 3.9
+- `CPython <https://www.python.org/>`_ versions 3.6, 3.7, 3.8, 3.9, 3.10
- `PyPy <https://pypy.org/>`_ 3.6+.
This means tox works on the latest patch version of each of these minor versions. Previous patch versions are
diff --git a/src/tox/config/cli/env_var.py b/src/tox/config/cli/env_var.py
index fce62038..8f07a403 100644
--- a/src/tox/config/cli/env_var.py
+++ b/src/tox/config/cli/env_var.py
@@ -18,8 +18,7 @@ def get_env_var(key: str, of_type: Type[Any]) -> Optional[Tuple[Any, str]]:
:return:
"""
key_upper = key.upper()
- for fmt in ("TOX_{}", "TOX{}"):
- environ_key = fmt.format(key_upper)
+ for environ_key in (f"TOX_{key_upper}", f"TOX{key_upper}"):
if environ_key in os.environ:
value = os.environ[environ_key]
try:
diff --git a/src/tox/config/loader/convert.py b/src/tox/config/loader/convert.py
index 9ce2df9b..4fb4c2ed 100644
--- a/src/tox/config/loader/convert.py
+++ b/src/tox/config/loader/convert.py
@@ -72,7 +72,7 @@ class Convert(ABC, Generic[T]):
else:
new_type = next(i for i in args if i != none) # pragma: no cover # this will always find a element
result = self.to(raw, new_type, kwargs)
- elif origin == Literal or origin == type(Literal):
+ elif origin in (Literal, type(Literal)):
if sys.version_info >= (3, 7): # pragma: no cover (py37+)
choice = of_type.__args__
else: # pragma: no cover (py38+)
diff --git a/src/tox/config/loader/ini/replace.py b/src/tox/config/loader/ini/replace.py
index 898d7dbe..3585edbe 100644
--- a/src/tox/config/loader/ini/replace.py
+++ b/src/tox/config/loader/ini/replace.py
@@ -171,10 +171,7 @@ def _config_value_sources(
def replace_pos_args(args: List[str], pos_args: Optional[Sequence[str]]) -> str:
if pos_args is None:
- if args:
- replace_value = ":".join(args) # if we use the defaults join back remaining args
- else:
- replace_value = ""
+ replace_value = ":".join(args) # if we use the defaults join back remaining args
else:
replace_value = shell_cmd(pos_args)
return replace_value
diff --git a/src/tox/pytest.py b/src/tox/pytest.py
index 43fb49f0..831739c2 100644
--- a/src/tox/pytest.py
+++ b/src/tox/pytest.py
@@ -417,8 +417,8 @@ def pytest_collection_modifyitems(config: PyTestConfig, items: List[Function]) -
for item in items:
if is_integration(item):
item.add_marker(skip_int)
- # run integration tests after unit tests
- items.sort(key=lambda i: 1 if is_integration(i) else 0)
+ # run integration tests (is_integration is True) after unit tests (False)
+ items.sort(key=is_integration)
class Index:
diff --git a/src/tox/session/cmd/run/common.py b/src/tox/session/cmd/run/common.py
index 49704e4e..a65f944f 100644
--- a/src/tox/session/cmd/run/common.py
+++ b/src/tox/session/cmd/run/common.py
@@ -33,7 +33,7 @@ class SkipMissingInterpreterAction(Action):
) -> None:
value = "true" if values is None else values
if value not in ("config", "true", "false"):
- raise ArgumentError(self, f"value must be 'config', 'true', or 'false' (got {repr(value)})")
+ raise ArgumentError(self, f"value must be 'config', 'true', or 'false' (got {value!r})")
setattr(namespace, self.dest, value)
@@ -144,7 +144,7 @@ def report(start: float, runs: List[ToxEnvRunResult], is_colored: bool) -> int:
for run in runs:
all_good &= run.code == Outcome.OK or run.ignore_outcome
duration_individual = [o.elapsed for o in run.outcomes]
- extra = f"+cmd[{','.join(f'{i:.2f}' for i in duration_individual)}]" if len(duration_individual) else ""
+ extra = f"+cmd[{','.join(f'{i:.2f}' for i in duration_individual)}]" if duration_individual else ""
setup = run.duration - sum(duration_individual)
msg, color = _get_outcome_message(run)
out = f" {run.name}: {msg} ({run.duration:.2f}{f'=setup[{setup:.2f}]{extra}' if extra else ''} seconds)"
@@ -227,10 +227,7 @@ class ToxSpinner(Spinner):
def update_spinner(self, result: ToxEnvRunResult, success: bool) -> None:
if success:
- if result.skipped:
- done = self.skip
- else:
- done = self.succeed
+ done = self.skip if result.skipped else self.succeed
else:
done = self.fail
done(result.name)
diff --git a/src/tox/tox_env/python/pip/pip_install.py b/src/tox/tox_env/python/pip/pip_install.py
index 207f54f5..135b6933 100644
--- a/src/tox/tox_env/python/pip/pip_install.py
+++ b/src/tox/tox_env/python/pip/pip_install.py
@@ -168,9 +168,7 @@ class Pip(Installer[Python]):
opts_at = install_command.index("{packages}")
except ValueError:
opts_at = len(install_command)
- result = install_command[:opts_at]
- result.extend(args)
- result.extend(install_command[opts_at + 1 :])
+ result = install_command[:opts_at] + list(args) + install_command[opts_at + 1 :]
return result
diff --git a/src/tox/tox_env/python/pip/req/file.py b/src/tox/tox_env/python/pip/req/file.py
index 6c8e9c79..86cd68c3 100644
--- a/src/tox/tox_env/python/pip/req/file.py
+++ b/src/tox/tox_env/python/pip/req/file.py
@@ -213,7 +213,7 @@ class RequirementsFile:
with open(url, "rb") as file_handler:
text = self._read_decode(file_handler)
except OSError as exc:
- raise ValueError(f"Could not open requirements file: {exc}")
+ raise ValueError(f"Could not open requirements file {url}: {exc}") from exc
return text
@staticmethod
@@ -333,7 +333,7 @@ class RequirementsFile:
args = []
options = tokens[:]
for token in tokens:
- if token.startswith("-") or token.startswith("--"):
+ if token.startswith("-"): # both `-` and `--` accepted
break
else:
args.append(token)
diff --git a/src/tox/tox_env/python/runner.py b/src/tox/tox_env/python/runner.py
index 8a57467a..edb9726d 100644
--- a/src/tox/tox_env/python/runner.py
+++ b/src/tox/tox_env/python/runner.py
@@ -111,7 +111,7 @@ class PythonRun(Python, RunToxEnv, ABC):
def pkg_type(self) -> str:
pkg_type: str = self.conf["package"]
if pkg_type not in self._package_types:
- values = ", ".join(i for i in self._package_types)
+ values = ", ".join(self._package_types)
raise HandledError(f"invalid package config type {pkg_type} requested, must be one of {values}")
return pkg_type
diff --git a/tasks/release.py b/tasks/release.py
index 5e739109..b060ffcc 100644
--- a/tasks/release.py
+++ b/tasks/release.py
@@ -39,9 +39,8 @@ def create_release_branch(repo: Repo, version: Version) -> Tuple[Remote, Head]:
def get_upstream(repo: Repo) -> Remote:
for remote in repo.remotes:
- for url in remote.urls:
- if url.endswith("tox-dev/tox.git"):
- return remote
+ if any(url.endswith("tox-dev/tox.git") for url in remote.urls):
+ return remote
raise RuntimeError("could not find tox-dev/tox.git remote")
diff --git a/tests/execute/local_subprocess/test_local_subprocess.py b/tests/execute/local_subprocess/test_local_subprocess.py
index 0f58ee1b..4fb50055 100644
--- a/tests/execute/local_subprocess/test_local_subprocess.py
+++ b/tests/execute/local_subprocess/test_local_subprocess.py
@@ -44,7 +44,7 @@ def test_local_execute_basic_pass(
) -> None:
caplog.set_level(logging.NOTSET)
executor = LocalSubProcessExecutor(colored=color)
- code = f"import sys; print({repr(out)}, end=''); print({repr(err)}, end='', file=sys.stderr)"
+ code = f"import sys; print({out!r}, end=''); print({err!r}, end='', file=sys.stderr)"
request = ExecuteRequest(cmd=[sys.executable, "-c", code], cwd=Path(), env=os_env, stdin=StdinSource.OFF, run_id="")
out_err = FakeOutErr()
with executor.call(request, show=show, out_err=out_err.out_err) as status: