Mercurial > public > mercurial-scm > hg-stable
changeset 53002: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 | b624da86830e |
children | 155e1e8dc055 |
files | hg setup.py |
diffstat | 2 files changed, 0 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/hg Thu Feb 20 11:30:50 2025 +0100 +++ b/hg Thu Feb 20 11:44:44 2025 +0100 @@ -12,16 +12,6 @@ import os import sys -libdir = '@LIBDIR@' - -if libdir != '@' 'LIBDIR' '@': - if not os.path.isabs(libdir): - libdir = os.path.join( - os.path.dirname(os.path.realpath(__file__)), libdir - ) - libdir = os.path.abspath(libdir) - sys.path.insert(0, libdir) - # Make `pip install --user ...` packages available to the official Windows # build. Most py2 packaging installs directly into the system python # environment, so no changes are necessary for other platforms. The Windows
--- a/setup.py Thu Feb 20 11:30:50 2025 +0100 +++ b/setup.py Thu Feb 20 11:44:44 2025 +0100 @@ -63,7 +63,6 @@ from setuptools.command.build_py import build_py from setuptools.command.install import install from setuptools.command.install_lib import install_lib -from setuptools.command.install_scripts import install_scripts from setuptools.errors import ( CCompilerError, @@ -936,78 +935,6 @@ file_util.copy_file = realcopyfile -class hginstallscripts(install_scripts): - """ - This is a specialization of install_scripts that replaces the @LIBDIR@ with - the configured directory for modules. If possible, the path is made relative - to the directory for scripts. - """ - - def initialize_options(self): - install_scripts.initialize_options(self) - - self.install_lib = None - - def finalize_options(self): - install_scripts.finalize_options(self) - self.set_undefined_options('install', ('install_lib', 'install_lib')) - - def run(self): - install_scripts.run(self) - - # It only makes sense to replace @LIBDIR@ with the install path if - # the install path is known. For wheels, the logic below calculates - # the libdir to be "../..". This is because the internal layout of a - # wheel archive looks like: - # - # mercurial-3.6.1.data/scripts/hg - # mercurial/__init__.py - # - # When installing wheels, the subdirectories of the "<pkg>.data" - # directory are translated to system local paths and files therein - # are copied in place. The mercurial/* files are installed into the - # site-packages directory. However, the site-packages directory - # isn't known until wheel install time. This means we have no clue - # at wheel generation time what the installed site-packages directory - # will be. And, wheels don't appear to provide the ability to register - # custom code to run during wheel installation. This all means that - # we can't reliably set the libdir in wheels: the default behavior - # of looking in sys.path must do. - - if ( - os.path.splitdrive(self.install_dir)[0] - != os.path.splitdrive(self.install_lib)[0] - ): - # can't make relative paths from one drive to another, so use an - # absolute path instead - libdir = self.install_lib - else: - libdir = os.path.relpath(self.install_lib, self.install_dir) - - for outfile in self.outfiles: - with open(outfile, 'rb') as fp: - data = fp.read() - - # skip binary files - if b'\0' in data: - continue - - # During local installs, the shebang will be rewritten to the final - # install path. During wheel packaging, the shebang has a special - # value. - if data.startswith(b'#!python'): - logging.info( - 'not rewriting @LIBDIR@ in %s because install path ' - 'not known', - outfile, - ) - continue - - data = data.replace(b'@LIBDIR@', libdir.encode('unicode_escape')) - with open(outfile, 'wb') as fp: - fp.write(data) - - class hginstallcompletion(Command): description = 'Install shell completion' @@ -1132,7 +1059,6 @@ 'install': hginstall, 'install_completion': hginstallcompletion, 'install_lib': hginstalllib, - 'install_scripts': hginstallscripts, 'build_hgexe': buildhgexe, }