comparison setup.py @ 53000:33e06272ff1a

cleanup: drop the LIBDIR related code This code is no longer used as the python packaging echo system evolved. This code was introduced in 10da5a1f25dd, with two feature in mind: - Mercurial may be installed into a non-standard location without having to set PYTHONPATH. - Multiple installations can use Mercurial from different locations. As a side effect it also provided performance improvement at a time where the `sys.path` could be greatly inflated from setuptools `.pth` files. And it also protected from incompatible directory within the `$PTYHONPATH` variable. Both of these benefit has faded overtime as `.pth` are less common and `$PYTHONPATH` is less used (as both where creating issue to more than just Mercurial). The initial motivation (easily install Mercurial anywhere), can now be handled by a new generation of tool like pipx or uv, so it is less of a concern. Regardless of all the above, the current code is no longer used. The evolution of python packaging means that installation always go through first building a location agnostic "wheel" that cannot update LIBDIR to a proper location. Upstream packaging (debian, redhat, etc?) does not seems to adjust this variable themself. So it is safer to drop this dead code that pretend we could be doing something with it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 20 Feb 2025 11:44:44 +0100
parents 53ae4495e5f0
children e2c239dae5a2
comparison
equal deleted inserted replaced
52999:b624da86830e 53000:33e06272ff1a
61 from setuptools.command.build import build 61 from setuptools.command.build import build
62 from setuptools.command.build_ext import build_ext 62 from setuptools.command.build_ext import build_ext
63 from setuptools.command.build_py import build_py 63 from setuptools.command.build_py import build_py
64 from setuptools.command.install import install 64 from setuptools.command.install import install
65 from setuptools.command.install_lib import install_lib 65 from setuptools.command.install_lib import install_lib
66 from setuptools.command.install_scripts import install_scripts
67 66
68 from setuptools.errors import ( 67 from setuptools.errors import (
69 CCompilerError, 68 CCompilerError,
70 BaseError as DistutilsError, 69 BaseError as DistutilsError,
71 ExecError as DistutilsExecError, 70 ExecError as DistutilsExecError,
934 install_lib.run(self) 933 install_lib.run(self)
935 finally: 934 finally:
936 file_util.copy_file = realcopyfile 935 file_util.copy_file = realcopyfile
937 936
938 937
939 class hginstallscripts(install_scripts):
940 """
941 This is a specialization of install_scripts that replaces the @LIBDIR@ with
942 the configured directory for modules. If possible, the path is made relative
943 to the directory for scripts.
944 """
945
946 def initialize_options(self):
947 install_scripts.initialize_options(self)
948
949 self.install_lib = None
950
951 def finalize_options(self):
952 install_scripts.finalize_options(self)
953 self.set_undefined_options('install', ('install_lib', 'install_lib'))
954
955 def run(self):
956 install_scripts.run(self)
957
958 # It only makes sense to replace @LIBDIR@ with the install path if
959 # the install path is known. For wheels, the logic below calculates
960 # the libdir to be "../..". This is because the internal layout of a
961 # wheel archive looks like:
962 #
963 # mercurial-3.6.1.data/scripts/hg
964 # mercurial/__init__.py
965 #
966 # When installing wheels, the subdirectories of the "<pkg>.data"
967 # directory are translated to system local paths and files therein
968 # are copied in place. The mercurial/* files are installed into the
969 # site-packages directory. However, the site-packages directory
970 # isn't known until wheel install time. This means we have no clue
971 # at wheel generation time what the installed site-packages directory
972 # will be. And, wheels don't appear to provide the ability to register
973 # custom code to run during wheel installation. This all means that
974 # we can't reliably set the libdir in wheels: the default behavior
975 # of looking in sys.path must do.
976
977 if (
978 os.path.splitdrive(self.install_dir)[0]
979 != os.path.splitdrive(self.install_lib)[0]
980 ):
981 # can't make relative paths from one drive to another, so use an
982 # absolute path instead
983 libdir = self.install_lib
984 else:
985 libdir = os.path.relpath(self.install_lib, self.install_dir)
986
987 for outfile in self.outfiles:
988 with open(outfile, 'rb') as fp:
989 data = fp.read()
990
991 # skip binary files
992 if b'\0' in data:
993 continue
994
995 # During local installs, the shebang will be rewritten to the final
996 # install path. During wheel packaging, the shebang has a special
997 # value.
998 if data.startswith(b'#!python'):
999 logging.info(
1000 'not rewriting @LIBDIR@ in %s because install path '
1001 'not known',
1002 outfile,
1003 )
1004 continue
1005
1006 data = data.replace(b'@LIBDIR@', libdir.encode('unicode_escape'))
1007 with open(outfile, 'wb') as fp:
1008 fp.write(data)
1009
1010
1011 class hginstallcompletion(Command): 938 class hginstallcompletion(Command):
1012 description = 'Install shell completion' 939 description = 'Install shell completion'
1013 940
1014 def initialize_options(self): 941 def initialize_options(self):
1015 self.install_dir = None 942 self.install_dir = None
1130 'build_scripts': hgbuildscripts, 1057 'build_scripts': hgbuildscripts,
1131 'build_hgextindex': buildhgextindex, 1058 'build_hgextindex': buildhgextindex,
1132 'install': hginstall, 1059 'install': hginstall,
1133 'install_completion': hginstallcompletion, 1060 'install_completion': hginstallcompletion,
1134 'install_lib': hginstalllib, 1061 'install_lib': hginstalllib,
1135 'install_scripts': hginstallscripts,
1136 'build_hgexe': buildhgexe, 1062 'build_hgexe': buildhgexe,
1137 } 1063 }
1138 1064
1139 if py2exehacked: 1065 if py2exehacked:
1140 cmdclass['py2exe'] = hgbuildpy2exe 1066 cmdclass['py2exe'] = hgbuildpy2exe