python3, hgloader, and extensions

Ludovic Chabant ludovic at chabant.com
Fri Jun 28 21:31:04 UTC 2019


For those who missed my latest adventures on IRC, I recently discovered that the hgloader (which patches strings and other py3 things at compile time) doesn't kick in if you load an extension from a specific file-system location.

This means that:

1) If you `pip install hg-evolve` and add `[extensions] evolve=` to your config, it (mostly) works.

2) If you `hg clone evolve` and add `[extensions] evolve=/path/to/clone` to your config, mercurial complains that someone is trying to add unicode strings to the command table.

You might have noticed I just sent a patch that fixes evolve's `setup.py` file so that we can actually do option 1 until option 2 is fixed. Of course this isn't only for evolve, it's for _any_ 3rd party extension... any random single-file hg extension you might have will likely be imported via option 2, and right now, under py3, you're forced to bytify all your strings and make your code even uglier. I don't like my code being uglier than it should be.

Now, I have half of a fix for option 2, which makes sure the hgloader is applied to packages loaded by path, and not just packages loaded "normally". It looks like this: https://paste.sr.ht/%7Eludovicchabant/99176dadaddd53bf9d24ea09682b8fd403e55fdb

Of course, it doesn't totally work, otherwise I would have sent it for review:

1) evolve still crashes mercurial with some string encoding issue in the template keywords... I have no idea what's the difference between that and the code path that loads it from the PYTHONPATH. Please help :)

2) It obviously uses Python 3.5+ APIs only so it needs to be improved to work with whatever versions of Python we want to support. I don't know what the core devs want to do here.

I'd be grateful to get some help and pointers on both those issues, since I don't really know what I'm doing here (I just learned about meta_paths and loaders like a couple days ago :) ). 

Cheers!
Ludo


More information about the Mercurial-devel mailing list