comparison setup.py @ 52664:f5091286b10c

packaging: modernize (compat PEP 517) with less distutils and setup.py calls - setup.py: less distutils imports and setuptools required distutils is deprecated and one should import commands from setuptools to support modern workflows depending on PEP 517 and 518. Moreover, for Python >=3.12, distutils comes from setuptools. It corresponds to old and unmaintain code that do not support PEP 517. The PEP 517 frontends (pip, build, pipx, PDM, UV, etc.) are responsible for creating a venv just for the build. The build dependencies (currently only setuptools) are specified in the pyproject.toml file. Therefore, there is no reason to support building without setuptools. Calling directly setup.py is deprecated and we have to use a PEP 517 frontend. For this commit we use pip with venv. - run-tests.py: install with pip instead of direct call of setup.py Mercurial is then built in an isolated environment. - Makefile: use venv+pip instead of setup.py
author paugier <pierre.augier@univ-grenoble-alpes.fr>
date Wed, 08 Jan 2025 05:07:00 +0100
parents 25bb409da058
children b7afc38468bd
comparison
equal deleted inserted replaced
52663:25bb409da058 52664:f5091286b10c
56 except ImportError: 56 except ImportError:
57 raise SystemExit( 57 raise SystemExit(
58 "Couldn't import standard bz2 (incomplete Python install)." 58 "Couldn't import standard bz2 (incomplete Python install)."
59 ) 59 )
60 60
61 ispypy = "PyPy" in sys.version 61 from setuptools import setup, Command, Extension, Distribution
62 62 from setuptools.command.build import build
63 # We have issues with setuptools on some platforms and builders. Until 63 from setuptools.command.build_ext import build_ext
64 # those are resolved, setuptools is opt-in except for platforms where 64 from setuptools.command.build_py import build_py
65 # we don't have issues. 65 from setuptools.command.install import install
66 issetuptools = os.name == 'nt' or 'FORCE_SETUPTOOLS' in os.environ 66 from setuptools.command.install_lib import install_lib
67 if issetuptools: 67 from setuptools.command.install_scripts import install_scripts
68 from setuptools import setup 68
69 else: 69 from setuptools.errors import (
70 try: 70 CCompilerError,
71 from distutils.core import setup 71 BaseError as DistutilsError,
72 except ModuleNotFoundError: 72 ExecError as DistutilsExecError,
73 from setuptools import setup 73 )
74 from distutils.ccompiler import new_compiler 74
75 from distutils.core import Command, Extension 75 # no setuptools.command.build_scripts
76 from distutils.dist import Distribution
77 from distutils.command.build import build
78 from distutils.command.build_ext import build_ext
79 from distutils.command.build_py import build_py
80 from distutils.command.build_scripts import build_scripts 76 from distutils.command.build_scripts import build_scripts
81 from distutils.command.install import install 77
82 from distutils.command.install_lib import install_lib
83 from distutils.command.install_scripts import install_scripts
84 from distutils.spawn import spawn 78 from distutils.spawn import spawn
85 from distutils import file_util 79 from distutils import file_util
86 from distutils.errors import (
87 CCompilerError,
88 DistutilsError,
89 DistutilsExecError,
90 )
91 from distutils.sysconfig import get_python_inc 80 from distutils.sysconfig import get_python_inc
81 from distutils.ccompiler import new_compiler
82
83 ispypy = "PyPy" in sys.version
92 84
93 85
94 def sysstr(s): 86 def sysstr(s):
95 return s.decode('latin-1') 87 return s.decode('latin-1')
96 88
911 objects = self.compiler.compile( 903 objects = self.compiler.compile(
912 ['mercurial/exewrapper.c'], 904 ['mercurial/exewrapper.c'],
913 output_dir=self.build_temp, 905 output_dir=self.build_temp,
914 macros=[('_UNICODE', None), ('UNICODE', None)], 906 macros=[('_UNICODE', None), ('UNICODE', None)],
915 ) 907 )
916 self.compiler.link_executable( 908 self.compiler.link_executable(objects, self.hgtarget, libraries=[])
917 objects, self.hgtarget, libraries=[], output_dir=self.build_temp
918 )
919 909
920 self.addlongpathsmanifest() 910 self.addlongpathsmanifest()
921 911
922 def addlongpathsmanifest(self): 912 def addlongpathsmanifest(self):
923 """Add manifest pieces so that hg.exe understands long paths 913 """Add manifest pieces so that hg.exe understands long paths
946 logging.info("done updating hg.exe's manifest") 936 logging.info("done updating hg.exe's manifest")
947 os.remove(manfname) 937 os.remove(manfname)
948 938
949 @property 939 @property
950 def hgexepath(self): 940 def hgexepath(self):
951 dir = os.path.dirname(self.get_ext_fullpath('dummy')) 941 return os.path.join(
952 return os.path.join(self.build_temp, dir, 'hg.exe') 942 os.path.dirname(self.get_ext_fullpath('dummy')), 'hg.exe'
943 )
953 944
954 945
955 class hgbuilddoc(Command): 946 class hgbuilddoc(Command):
956 description = 'build documentation' 947 description = 'build documentation'
957 user_options = [ 948 user_options = [