Skip to content

Commit 9c97c94

Browse files
Community App Store (Sourcery refactored) (#162)
* 'Refactored by Sourcery' * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Sourcery AI <> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a956520 commit 9c97c94

File tree

2 files changed

+25
-49
lines changed

2 files changed

+25
-49
lines changed

conreq/_core/app_store/utils/command_line.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ def call(self, command, **kwargs):
186186

187187
if not p.commands[0].process:
188188
# the process might have been set to None in case of any exception
189-
self._logger.error(
190-
f"Error while trying to run command {joined_command}"
191-
)
189+
self._logger.error(f"Error while trying to run command {joined_command}")
192190
return None, [], []
193191

194192
all_stdout = []

conreq/_core/app_store/utils/pip.py

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,17 @@ def clean_install_command(
4646
and "--process-dependency-links" in args
4747
):
4848
logger.debug(
49-
"Found --process-dependency-links flag, version {} doesn't need that yet though, removing.".format(
50-
pip_version
51-
)
49+
f"Found --process-dependency-links flag, version {pip_version} doesn't need that yet though, removing."
5250
)
51+
5352
args.remove("--process-dependency-links")
5453

5554
# strip --no-cache-dir for versions that don't support it
5655
if pip_version not in cls.no_cache_dir and "--no-cache-dir" in args:
5756
logger.debug(
58-
"Found --no-cache-dir flag, version {} doesn't support that yet though, removing.".format(
59-
pip_version
60-
)
57+
f"Found --no-cache-dir flag, version {pip_version} doesn't support that yet though, removing."
6158
)
59+
6260
args.remove("--no-cache-dir")
6361

6462
# strip --disable-pip-version-check for versions that don't support it
@@ -67,10 +65,9 @@ def clean_install_command(
6765
and "--disable-pip-version-check" in args
6866
):
6967
logger.debug(
70-
"Found --disable-pip-version-check flag, version {} doesn't support that yet though, removing.".format(
71-
pip_version
72-
)
68+
f"Found --disable-pip-version-check flag, version {pip_version} doesn't support that yet though, removing."
7369
)
70+
7471
args.remove("--disable-pip-version-check")
7572

7673
# add --no-use-wheel for versions that otherwise break
@@ -251,11 +248,9 @@ def _setup_pip(self):
251248
if not ok:
252249
if pip_install_dir:
253250
self._logger.error(
254-
"Cannot use this pip install, can't write to the install dir and also can't use "
255-
"--user for installing. Check your setup and the permissions on {}.".format(
256-
pip_install_dir
257-
)
251+
f"Cannot use this pip install, can't write to the install dir and also can't use --user for installing. Check your setup and the permissions on {pip_install_dir}."
258252
)
253+
259254
else:
260255
self._logger.error(
261256
"Cannot use this pip install, something's wrong with the python environment. "
@@ -313,18 +308,16 @@ def autodetect_pip(cls):
313308
)
314309
if p.returncode == 0:
315310
logging.getLogger(__name__).info(
316-
'Using "{}" as command to invoke pip'.format(" ".join(command))
311+
f'Using "{" ".join(command)}" as command to invoke pip'
317312
)
313+
318314
return command
319315

320316
return None
321317

322318
@classmethod
323319
def to_sarge_command(cls, pip_command, *args):
324-
if isinstance(pip_command, list):
325-
sarge_command = pip_command
326-
else:
327-
sarge_command = [pip_command]
320+
sarge_command = pip_command if isinstance(pip_command, list) else [pip_command]
328321
return sarge_command + list(args)
329322

330323
def _get_pip_version(self, pip_command):
@@ -340,10 +333,9 @@ def _get_pip_version(self, pip_command):
340333
with _cache_mutex:
341334
if not self.ignore_cache and pip_command_str in _cache["version"]:
342335
self._logger.debug(
343-
"Using cached pip version information for {}".format(
344-
pip_command_str
345-
)
336+
f"Using cached pip version information for {pip_command_str}"
346337
)
338+
347339
return _cache["version"][pip_command_str]
348340

349341
sarge_command = self.to_sarge_command(pip_command, "--version")
@@ -369,17 +361,13 @@ def _get_pip_version(self, pip_command):
369361

370362
if not output.startswith("pip"):
371363
self._logger.warning(
372-
"pip command returned unparseable output, can't determine version: {}".format(
373-
output
374-
)
364+
f"pip command returned unparseable output, can't determine version: {output}"
375365
)
376366

377367
split_output = list(map(lambda x: x.strip(), output.split()))
378368
if len(split_output) < 2:
379369
self._logger.warning(
380-
"pip command returned unparseable output, can't determine version: {}".format(
381-
output
382-
)
370+
f"pip command returned unparseable output, can't determine version: {output}"
383371
)
384372

385373
version_segment = split_output[1]
@@ -459,9 +447,9 @@ def _check_pip_setup(self, pip_command):
459447
key, value = line.split("=", 2)
460448
data[key.strip()] = value.strip()
461449

462-
install_dir_str = data.get("PIP_INSTALL_DIR", None)
463-
virtual_env_str = data.get("PIP_VIRTUAL_ENV", None)
464-
writable_str = data.get("PIP_WRITABLE", None)
450+
install_dir_str = data.get("PIP_INSTALL_DIR")
451+
virtual_env_str = data.get("PIP_VIRTUAL_ENV")
452+
writable_str = data.get("PIP_WRITABLE")
465453

466454
if (
467455
install_dir_str is not None
@@ -478,15 +466,10 @@ def _check_pip_setup(self, pip_command):
478466
user_flag = not writable and can_use_user_flag
479467

480468
self._logger.info(
481-
"pip installs to {} (writable -> {}), --user flag needed -> {}, "
482-
"virtual env -> {}".format(
483-
install_dir,
484-
"yes" if writable else "no",
485-
"yes" if user_flag else "no",
486-
"yes" if virtual_env else "no",
487-
)
469+
f'pip installs to {install_dir} (writable -> {"yes" if writable else "no"}), --user flag needed -> {"yes" if user_flag else "no"}, virtual env -> {"yes" if virtual_env else "no"}'
488470
)
489-
self._logger.info("==> pip ok -> {}".format("yes" if ok else "NO!"))
471+
472+
self._logger.info(f'==> pip ok -> {"yes" if ok else "NO!"}')
490473

491474
# ok, enable user flag, virtual env yes/no, installation dir
492475
result = ok, user_flag, virtual_env, install_dir
@@ -545,15 +528,10 @@ def _check_pip_setup(self, pip_command):
545528
ok = writable or can_use_user_flag
546529

547530
self._logger.info(
548-
"pip installs to {} (writable -> {}), --user flag needed -> {}, "
549-
"virtual env -> {}".format(
550-
install_dir,
551-
"yes" if writable else "no",
552-
"yes" if user_flag else "no",
553-
"yes" if virtual_env else "no",
554-
)
531+
f'pip installs to {install_dir} (writable -> {"yes" if writable else "no"}), --user flag needed -> {"yes" if user_flag else "no"}, virtual env -> {"yes" if virtual_env else "no"}'
555532
)
556-
self._logger.info("==> pip ok -> {}".format("yes" if ok else "NO!"))
533+
534+
self._logger.info(f'==> pip ok -> {"yes" if ok else "NO!"}')
557535

558536
return ok, user_flag, virtual_env, install_dir
559537

0 commit comments

Comments
 (0)