Mercurial extension - first attempt

20 views
Skip to first unread message

Marcin Kasperski

unread,
Nov 20, 2009, 5:13:02 PM11/20/09
to python-keyring
I wrote first version of keyring-backed mercurial extension:

http://bitbucket.org/Mekk/mercurial_keyring/

Not much testing yet, but it is self-feeding (I push the code to
bitbucket using keyring-saved password).

Once more thank you for the very useful library.

Tarek Ziadé

unread,
Nov 21, 2009, 4:31:51 AM11/21/09
to python-...@googlegroups.com
that's great ! I'll use it. Are you planning to release it soon ?

Tarek

--
Tarek Ziadé | http://ziade.org | オープンソースはすごい! | 开源传万世,因有你参与

Marcin Kasperski

unread,
Nov 21, 2009, 5:56:25 AM11/21/09
to python-...@googlegroups.com
> that's great ! I'll use it. Are you planning to release it soon ?

Well, I published it on bitbucket, and wrote
http://mercurial.selenic.com/wiki/KeyringExtension
Not sure what else should I do to release it

PS I considered making an egg but after reviewing a couple of other
extensions it does not seem people tend to distribute other extensions
this way - and there is a reason, easy_install won't be able to put
them into hgext/, and if it installs it normally, the path to the file
is rather ugly, so it turns out easier to just download .py and save
it in preferable place

Tarek Ziadé

unread,
Nov 21, 2009, 6:06:58 AM11/21/09
to python-...@googlegroups.com
On Sat, Nov 21, 2009 at 11:56 AM, Marcin Kasperski
<Marcin.K...@mekk.waw.pl> wrote:
>> that's great ! I'll use it. Are you planning to release it soon ?
>
> Well, I published it on bitbucket, and wrote
> http://mercurial.selenic.com/wiki/KeyringExtension
> Not sure what else should I do to release it
>

If it has a setup.py, PyPI would be a great place

> PS I considered making an egg but after reviewing a couple of other
> extensions it does not seem people tend to distribute other extensions
> this way - and there is a reason, easy_install won't be able to put
> them into hgext/, and if it installs it normally, the path to the file
> is rather ugly, so it turns out easier to just download .py and save
> it in preferable place

I saw that you have removed setup.py yes. I remembered having the same problem
with one of my extension.

There's a hack to make it work (didn't try it yet though):
define your .py file as a data file in setup.py and point the hgext
directory to install it to it.

But can't you create a package, let's say "foo", and point in .hgrc
your extensions
as "foo.keyring" ? (if "keyring.py" is the module)

or Mercurial just won't read anything else than the hgext. namespace ?

Cheers
Tarek

Marcin Kasperski

unread,
Nov 21, 2009, 7:44:22 AM11/21/09
to python-...@googlegroups.com
> But can't you create a package, let's say "foo", and point in .hgrc
> your extensions
> as "foo.keyring" ? (if "keyring.py" is the module)
>
> or Mercurial just won't read anything else than the hgext. namespace ?

I don't know at the moment, maybe will test it later. But my main
rationale is that I checked a couple of other extensions, including
those written by established mercurial community members, and none of
them had setup.py or egg. Considering this is my first attempt to
write mercurial extension, I think I will stay consistent ;-)

(at the same time, it could be a good idea to discuss the problem on
mercurial devel mailing list, I will consider it)

Tarek Ziadé

unread,
Nov 21, 2009, 7:57:38 AM11/21/09
to python-...@googlegroups.com
On Sat, Nov 21, 2009 at 1:44 PM, Marcin Kasperski
<Marcin.K...@mekk.waw.pl> wrote:
>> But can't you create a package, let's say "foo", and point in .hgrc
>> your extensions
>> as "foo.keyring" ? (if "keyring.py" is the module)
>>
>> or Mercurial just won't read anything else than the hgext. namespace ?
>
> I don't know at the moment, maybe will test it later. But my main
> rationale is that I checked a couple of other extensions, including
> those written by established mercurial community members, and none of
> them had setup.py or egg.

Ok

Notice that's not related to egg, but just to the standard way of
distributing a python
project using Distutils.

> Considering this is my first attempt to
> write mercurial extension, I think I will stay consistent ;-)

How do they distribute it to the community ?

end user have to manually copy the .py file to the hgext package ?

Cheers,
Tarek

Marcin Kasperski

unread,
Nov 21, 2009, 8:28:01 AM11/21/09
to python-...@googlegroups.com
> How do they distribute it to the community ?
>
> end user have to manually copy the .py file to the hgext package ?

No. end user is to save .py file anywhere he or she likes, then write

[extensions]
hgext.extension_name = /full/path/to/the/extension/file.py

in ~/.hgrc

Later on, if the extension turns out to be popular, it is adopted by
official distribution (here it is beneficial to have it as a single
file, easier to copy ;-))

AFAIK people tend to use dirs like ~/.hgext for extensions. And it is
easier to write
hgext.mercurial_keyring = ~/.hgext/mercurial_keyring.py
than to write
hgext.mercurial_keyring =
/usr/lib/python2.6/site-packages/mercurial_keyring-0.1-py2.6-linux-x86_64.egg/mercurial_keyring.py
or sth similar ;-)

Tarek Ziadé

unread,
Nov 21, 2009, 8:56:49 AM11/21/09
to python-...@googlegroups.com
On Sat, Nov 21, 2009 at 2:28 PM, Marcin Kasperski
<Marcin.K...@mekk.waw.pl> wrote:
[..]
>
> AFAIK people tend to use dirs like ~/.hgext for extensions. And it is
> easier to write
>   hgext.mercurial_keyring = ~/.hgext/mercurial_keyring.py
> than to write
>   hgext.mercurial_keyring =
> /usr/lib/python2.6/site-packages/mercurial_keyring-0.1-py2.6-linux-x86_64.egg/mercurial_keyring.py
> or sth similar ;-)

I wasn't thinking about that, but about a very simple way to point a
module extension:
package.module.

So in your hgrc:

[extensions]
hgext.mercurial_keyring = my_package.my_extension

Then Mercurial can import it, as easily as it would for a filename.

I'll send a proposal at mercurial-dev.

Tarek

Tarek Ziadé

unread,
Nov 22, 2009, 7:57:06 AM11/22/09
to python-...@googlegroups.com
On Sat, Nov 21, 2009 at 2:56 PM, Tarek Ziadé <ziade...@gmail.com> wrote:
> On Sat, Nov 21, 2009 at 2:28 PM, Marcin Kasperski
> <Marcin.K...@mekk.waw.pl> wrote:
> [..]
>>
>> AFAIK people tend to use dirs like ~/.hgext for extensions. And it is
>> easier to write
>>   hgext.mercurial_keyring = ~/.hgext/mercurial_keyring.py
>> than to write
>>   hgext.mercurial_keyring =
>> /usr/lib/python2.6/site-packages/mercurial_keyring-0.1-py2.6-linux-x86_64.egg/mercurial_keyring.py
>> or sth similar ;-)
>

I've looked at the mercurial code. You can definitely use a module name.

So, let's say, you install your single module called
"mercurial_keyring.py" in Python under site-packages, just write:

mercurial_keyring =

And Mercurial will try to import that module directly.

Meaning that you can safely provide your extension as a distutils package.


Cheers
Tarek

Marcin Kasperski

unread,
Dec 6, 2009, 2:09:48 PM12/6/09
to python-...@googlegroups.com
> I've looked at the mercurial code. You can definitely use a module name.
>
> So, let's say, you install your single module called
> "mercurial_keyring.py" in Python under site-packages, just write:
>
>   mercurial_keyring =
>
> And Mercurial will try to import that module directly.

OK, I did that and registered the package on pypi. You can now

easy_install mercurial_keyring

and configure it as above.

Changes pushed also to https://Me...@bitbucket.org/Mekk/mercurial_keyring/

Tarek Ziadé

unread,
Dec 15, 2009, 12:42:16 AM12/15/09
to Python Keyring Lib
Great ! Thanks,


On Dec 6, 8:09 pm, Marcin Kasperski <Marcin.Kasper...@mekk.waw.pl>
wrote:
> Changes pushed also to https://M...@bitbucket.org/Mekk/mercurial_keyring/
Reply all
Reply to author
Forward
0 new messages