Mercurial > public > mercurial-scm > hg-stable
view tests/test-status-inprocess.py @ 52742:f8f14e6d032b
py3: update the remaining shebang lines (mostly tests) to `python3`
I noticed this when running `py hghave` on a system that still has Python2- the
Windows launcher attempts to honor the version of python in the shebang, but
`hghave` recently gained py3 type annotations, so that resulted in a
SyntaxError. I guess CI has the compat shim installed to redirect `python` to
`python3`, and maybe that's why nobody noticed.
These were located by grepping for `#!.+python\b`. The remaining handful of
cases are tests trying to find python files, which is fine as-is.
The one thing to call out here is that apparently the RPM building hasn't worked
with Python3 (or we've been getting lucky). `contrib/hg-ssh` has had a python3
shebang line since late 2020, which means the EOL anchor would have caused it to
not match and not be replaced with `%{pythonexe}`. OTOH, it looks like that
variable was used prior to the `hg-ssh` update in order to default to python3
(as opposed to using a specific /path/to/pythonX), and maybe the update to
`hg-ssh` simply broke python2 builds. I'm not going to worry about this for
now, since there are also direct calls to `setup.py`, which no longer work as of
this release cycle. Somebody interested in RPMs can figure out all of the
issues at once.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 30 Jan 2025 13:51:02 -0500 |
parents | 6000f5b25c9b |
children |
line wrap: on
line source
#!/usr/bin/env python3 import sys from mercurial import ( commands, localrepo, ui as uimod, ) print_ = print def print(*args, **kwargs): """print() wrapper that flushes stdout buffers to avoid py3 buffer issues We could also just write directly to sys.stdout.buffer the way the ui object will, but this was easier for porting the test. """ print_(*args, **kwargs) sys.stdout.flush() u = uimod.ui.load() print('% creating repo') repo = localrepo.instance(u, b'.', create=True) f = open('test.py', 'w') try: f.write('foo\n') finally: f.close print('% add and commit') commands.add(u, repo, b'test.py') commands.commit(u, repo, message=b'*') commands.status(u, repo, clean=True) print('% change') f = open('test.py', 'w') try: f.write('bar\n') finally: f.close() # this would return clean instead of changed before the fix commands.status(u, repo, clean=True, modified=True)