History

scripts: sphinx-pre-install: drop support for old virtualenv

Up to Python 3.2, the virtual environment were created via virtualenv binary. As we dropped support for such old version, clean up the code.

Mauro Carvalho Chehab committed 1 year ago

Commit f25bf121 parent ea5dd671 file · +19 −52Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/sphinx-pre-install.py+19−52
@@ -80,7 +80,6 @@ class SphinxDependencyChecker: · 79 unmodified lines
80 self.need_symlink = 080 self.need_symlink = 0
81 self.need_sphinx = 081 self.need_sphinx = 0
82 self.need_pip = 082 self.need_pip = 0
83 self.need_virtualenv = 0
84 self.rec_sphinx_upgrade = 083 self.rec_sphinx_upgrade = 0
85 self.verbose_warn_install = 184 self.verbose_warn_install = 1
86 85
@@ -919,12 +918,14 @@ class SphinxDependencyChecker: · 832 unmodified lines
919 else:918 else:
920 print("\nSphinx needs to be installed either:\n1) via pip/pypi with:\n")919 print("\nSphinx needs to be installed either:\n1) via pip/pypi with:\n")
921 920
922 self.python_cmd = os.path.abspath(sys.argv[0])921 if not virtualenv_cmd:
923 922 print(" Currently not possible.\n")
924 print(f"\t{virtualenv_cmd} {self.virtenv_dir}")923 print(" Please upgrade Python to a newer version and run this script again")
925 print(f"\t. {self.virtenv_dir}/bin/activate")924 else:
926 print(f"\tpip install -r {self.requirement_file}")925 print(f"\t{virtualenv_cmd} {self.virtenv_dir}")
927 self.deactivate_help()926 print(f"\t. {self.virtenv_dir}/bin/activate")
927 print(f"\tpip install -r {self.requirement_file}")
928 self.deactivate_help()
928 929
929 print("\n2) As a package with:")930 print("\n2) As a package with:")
930 931
@@ -953,6 +954,7 @@ class SphinxDependencyChecker: · 22 unmodified lines
953 954
954 def check_needs(self):955 def check_needs(self):
955 self.get_system_release()956 self.get_system_release()
957 self.python_cmd = sys.executable
956 958
957 # Check if Sphinx is already accessible from current environment959 # Check if Sphinx is already accessible from current environment
958 self.check_sphinx()960 self.check_sphinx()
@@ -965,56 +967,21 @@ class SphinxDependencyChecker: · 6 unmodified lines
965 ver = ver_str(self.cur_version)967 ver = ver_str(self.cur_version)
966 print(f"Sphinx version: {ver}\n")968 print(f"Sphinx version: {ver}\n")
967 969
968 # FIXME: Check python command line, trying first python3
969 self.python_cmd = self.which("python3")
970 if not self.python_cmd:
971 self.python_cmd = self.check_program("python", 0)
972
973 # Check the type of virtual env, depending on Python version970 # Check the type of virtual env, depending on Python version
974 if self.python_cmd:971 virtualenv_cmd = None
975 if self.virtualenv:
976 try:
977 result = self.run(
978 [self.python_cmd, "--version"],
979 capture_output=True,
980 text=True,
981 check=True,
982 )
983
984 output = result.stdout + result.stderr
985
986 match = re.search(r"(\d+)\.(\d+)\.", output)
987 if match:
988 major = int(match.group(1))
989 minor = int(match.group(2))
990
991 if major < 3:
992 sys.exit("Python 3 is required to build the kernel docs")
993 if major == 3 and minor < 3:
994 self.need_virtualenv = True
995 else:
996 sys.exit(f"Warning: couldn't identify {self.python_cmd} version!")
997
998 except subprocess.CalledProcessError as e:
999 sys.exit(f"Error checking Python version: {e}")
1000 else:
1001 self.add_package("python-sphinx", 0)
1002 972
1003 self.venv_ver = self.recommend_sphinx_upgrade()973 if sys.version_info < MIN_PYTHON_VERSION:
974 min_ver = ver_str(MIN_PYTHON_VERSION)
975 print(f"ERROR: at least python {min_ver} is required to build the kernel docs")
976 self.need_sphinx = 1
1004 977
1005 virtualenv_cmd = ""978 self.venv_ver = self.recommend_sphinx_upgrade()
1006 979
1007 if self.need_pip:980 if self.need_pip:
1008 # Set virtualenv command line, if python < 3.3981 if sys.version_info < MIN_PYTHON_VERSION:
1009 # FIXME: can be removed as we're now with an upper min requirement982 self.need_pip = False
1010 # but then we need to check python version983 print("Warning: python version is not supported.")
1011 if self.need_virtualenv:984
1012 virtualenv_cmd = self.which("virtualenv-3")
1013 if not virtualenv_cmd:
1014 virtualenv_cmd = self.which("virtualenv-3.5")
1015 if not virtualenv_cmd:
1016 self.check_program("virtualenv", 0)
1017 virtualenv_cmd = "virtualenv"
1018 else:985 else:
1019 virtualenv_cmd = f"{self.python_cmd} -m venv"986 virtualenv_cmd = f"{self.python_cmd} -m venv"
1020 self.check_python_module("ensurepip", 0)987 self.check_python_module("ensurepip", 0)