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
setup: skip building rust extensions on Windows
Without this, the build process in the next commit would have started trying
(and failing) to copy the associated module.
Not sure why this worked before. I'd like to think there's
a better way to conditionalize this inside the extension declaration.
[snip]
done updating hg.exe's manifest
copying build\lib.win-amd64-cpython-39\mercurial\cext\base85.cp39-win_amd64.pyd -> mercurial\cext
copying build\lib.win-amd64-cpython-39\mercurial\cext\bdiff.cp39-win_amd64.pyd -> mercurial\cext
copying build\lib.win-amd64-cpython-39\mercurial\cext\mpatch.cp39-win_amd64.pyd -> mercurial\cext
copying build\lib.win-amd64-cpython-39\mercurial\cext\parsers.cp39-win_amd64.pyd -> mercurial\cext
copying build\lib.win-amd64-cpython-39\mercurial\cext\osutil.cp39-win_amd64.pyd -> mercurial\cext
copying build\lib.win-amd64-cpython-39\mercurial\thirdparty\sha1dc.cp39-win_amd64.pyd -> mercurial\thirdparty
copying build\lib.win-amd64-cpython-39\hgext\fsmonitor\pywatchman\bser.cp39-win_amd64.pyd -> hgext\fsmonitor\pywatchman
error: can't copy 'build\lib.win-amd64-cpython-39\mercurial\rustext.cp39-win_amd64.pyd': doesn't exist or not a regular file
git: skip recursing into manifest subtrees that are the same
If during manifest comparison we are presented with identical tree objects,
then we are guaranteed that:
1. the contents of these tree objects are the same
2. the contents of any of their children are the same
This speeds up 'hg diff -c <hash>' considerably since unchanged subtrees are
are skipped. For example, a commit that modified the README in the linux
kernel repo (~84k tracked files) now takes 1.1s instead of 15.7s.
tests: obfuscate Python version checks to subvert `pyupgrade`
When specifying `--py38-plus`, it reasonably deletes conditionals that check for
that version of python or earlier. But we actually want the check to remain, so
use a simple obfuscation to preserve it.
tests: drop py2 support for `fsmonitor-run-tests.py`
There's some py2 compat code still in the fsmonitor extension, but I don't care
about that and this doesn't affect that.
pyupgrade: drop redundant `''.encode("utf-8")`
Again, I'd prefer explicit. But without a way to selectively choose what fixes
are applied by `_fix_tokens()`, I'll accept this for the sake of reducing the
nuisance output when running `pyupgrade`.
pyupgrade: drop redundant `open()` modes
On one hand, this gets rid of some py2 cruft (like `U` and `t` modes). OTOH, I
like being explict. But there's no way to disable individual transformations
(and this change is part of `_fix_tokens()`, which is even harder to selectively
use locally), and I'd rather have less noise when using `pyupgrade`.
Warning: `contrib/synthrepo.py` appears not to have been updated to py3, as it's
passing str to `error.Abort`. But since it was opening the file in unicode on
py2, this change is a no-op.