2222script to alternatives, consider maintaining a local copy as part of your infrastructure.
2323
2424For full documentation, visit https://python-poetry.org/docs/#installation.
25- """
25+ """ # noqa: E501
26+ import sys
27+
28+
29+ # Eager version check so we fail nicely before possible syntax errors
30+ if sys .version_info < (3 , 6 ): # noqa: UP036
31+ sys .stdout .write ("Poetry installer requires Python 3.6 or newer to run!\n " )
32+ sys .exit (1 )
33+
2634
2735import argparse
2836import json
2937import os
3038import re
3139import shutil
3240import subprocess
33- import sys
3441import sysconfig
3542import tempfile
3643
@@ -107,8 +114,8 @@ def is_decorated():
107114 if WINDOWS :
108115 return (
109116 os .getenv ("ANSICON" ) is not None
110- or "ON" == os .getenv ("ConEmuANSI" )
111- or "xterm" == os .getenv ("Term" )
117+ or os .getenv ("ConEmuANSI" ) == "ON" # noqa: SIM112
118+ or os .getenv ("Term" ) == "xterm" # noqa: SIM112
112119 )
113120
114121 if not hasattr (sys .stdout , "fileno" ):
@@ -278,7 +285,7 @@ def __init__(self, path: Path) -> None:
278285 self ._bin_path = self ._path .joinpath (
279286 "Scripts" if WINDOWS and not MINGW else "bin"
280287 )
281- # str is required for compatibility with subprocess run on CPython <= 3.7 on Windows
288+ # str is for compatibility with subprocess. run on CPython <= 3.7 on Windows
282289 self ._python = str (
283290 self ._path .joinpath (self ._bin_path , "python.exe" if WINDOWS else "python" )
284291 )
@@ -295,7 +302,8 @@ def bin_path(self):
295302 def make (cls , target : Path ) -> "VirtualEnvironment" :
296303 if not sys .executable :
297304 raise ValueError (
298- "Unable to determine sys.executable. Set PATH to a sane value or set it explicitly with PYTHONEXECUTABLE."
305+ "Unable to determine sys.executable. Set PATH to a sane value or set it"
306+ " explicitly with PYTHONEXECUTABLE."
299307 )
300308
301309 try :
@@ -340,7 +348,7 @@ def make(cls, target: Path) -> "VirtualEnvironment":
340348
341349 env = cls (target )
342350
343- # we do this here to ensure that outdated system default pip does not trigger older bugs
351+ # this ensures that outdated system default pip does not trigger older bugs
344352 env .pip ("install" , "--disable-pip-version-check" , "--upgrade" , "pip" )
345353
346354 return env
@@ -527,18 +535,20 @@ def _is_self_upgrade_supported(x):
527535 mx = self .VERSION_REGEX .match (x )
528536
529537 if mx is None :
530- # the version is not semver, perhaps scm or file, we assume upgrade is supported
538+ # the version is not semver, perhaps scm or file
539+ # we assume upgrade is supported
531540 return True
532541
533- vx = tuple (int (p ) for p in mx .groups ()[:3 ]) + ( mx .group (5 ), )
542+ vx = ( * tuple (int (p ) for p in mx .groups ()[:3 ]), mx .group (5 ))
534543 return vx >= (1 , 1 , 7 )
535544
536545 if version and not _is_self_upgrade_supported (version ):
537546 self ._write (
538547 colorize (
539548 "warning" ,
540- f"You are installing { version } . When using the current installer, this version does not support "
541- f"updating using the 'self update' command. Please use 1.1.7 or later." ,
549+ f"You are installing { version } . When using the current installer, "
550+ "this version does not support updating using the 'self update' "
551+ "command. Please use 1.1.7 or later." ,
542552 )
543553 )
544554 if not self ._accept_all :
@@ -551,7 +561,7 @@ def _is_self_upgrade_supported(x):
551561 except subprocess .CalledProcessError as e :
552562 raise PoetryInstallationError (
553563 return_code = e .returncode , log = e .output .decode ()
554- )
564+ ) from e
555565
556566 self ._write ("" )
557567 self .display_post_message (version )
@@ -713,11 +723,12 @@ def display_post_message_windows(self, version: str) -> None:
713723 def get_windows_path_var (self ) -> Optional [str ]:
714724 import winreg
715725
716- with winreg .ConnectRegistry (None , winreg .HKEY_CURRENT_USER ) as root :
717- with winreg .OpenKey (root , "Environment" , 0 , winreg .KEY_ALL_ACCESS ) as key :
718- path , _ = winreg .QueryValueEx (key , "PATH" )
726+ with winreg .ConnectRegistry (
727+ None , winreg .HKEY_CURRENT_USER
728+ ) as root , winreg .OpenKey (root , "Environment" , 0 , winreg .KEY_ALL_ACCESS ) as key :
729+ path , _ = winreg .QueryValueEx (key , "PATH" )
719730
720- return path
731+ return path
721732
722733 def display_post_message_fish (self , version : str ) -> None :
723734 fish_user_paths = subprocess .check_output (
@@ -778,8 +789,8 @@ def _compare_versions(x, y):
778789 mx = self .VERSION_REGEX .match (x )
779790 my = self .VERSION_REGEX .match (y )
780791
781- vx = tuple (int (p ) for p in mx .groups ()[:3 ]) + ( mx .group (5 ), )
782- vy = tuple (int (p ) for p in my .groups ()[:3 ]) + ( my .group (5 ), )
792+ vx = ( * tuple (int (p ) for p in mx .groups ()[:3 ]), mx .group (5 ))
793+ vy = ( * tuple (int (p ) for p in my .groups ()[:3 ]), my .group (5 ))
783794
784795 if vx < vy :
785796 return - 1
@@ -838,13 +849,6 @@ def _get(self, url):
838849
839850
840851def main ():
841- if sys .version_info < (3 , 6 ):
842- sys .stdout .write (
843- colorize ("error" , "Poetry installer requires Python 3.6 or newer to run!" )
844- )
845- # return error code
846- return 1
847-
848852 parser = argparse .ArgumentParser (
849853 description = "Installs the latest (or given) version of poetry"
850854 )
@@ -930,7 +934,8 @@ def main():
930934 text = True ,
931935 )
932936 installer ._write (colorize ("error" , f"See { path } for error logs." ))
933- text = f"{ e .log } \n Traceback:\n \n { '' .join (traceback .format_tb (e .__traceback__ ))} "
937+ tb = "" .join (traceback .format_tb (e .__traceback__ ))
938+ text = f"{ e .log } \n Traceback:\n \n { tb } "
934939 Path (path ).write_text (text )
935940
936941 return e .return_code
0 commit comments