Porting Samba's CPython extensions to Python 3

Petr Viktorin pviktori at redhat.com
Mon Jul 11 14:42:42 UTC 2016

On 09/07/2015 01:43 PM, Petr Viktorin wrote:
> On 09/04/2015 05:04 AM, Andrew Bartlett wrote:
>> On Fri, 2015-08-28 at 12:57 +0200, Petr Viktorin wrote:

>>> In previous discussions, we agreed on a strategy for porting Samba to
>>> Python 3. the stand-alone libraries would get a supported Python 3
>>> port.
>>> Patches for the rest of Samba would be tolerated if they do not
>>> inconvenience other developers, and they would be unsupported (if it
>>> breaks, it's on whomever cares about Python 3 to fix it).
>>> Generally, there is opposition against a bespoke compatibility layer,
>>> which could not be tested well and would not get much use beyond
>>> Samba.
>>> As with any code written by one external developer, if I got hit by a
>>> bus, the compatibility layer could bitrot.
>>> However, *some* kind of a compatibility layer is needed.
>>> The ideal solution for Samba would be if a compatibility layer was
>>> distributed with Python itself. Unfortunately, this can't really
>>> work:
>>> no features are added to Python 2.7 any more, and even if they were,
>>> they couldn't be present in older 2.7 releases.
>>> Realistically, I see three options for Samba, if it decides to start
>>> porting:
>>> 1) Include relevant macros in the files that need them. This is used
>>> in
>>> the stand-alone libraries (which typically have one Python module
>>> each).
>>> This makes the code clear to anyone who knows C-API for Python 2 or
>>> 3;
>>> but when adding new macros it requires some care to have consistency.
>>> 2) Put all compatibility macros in a shared header. This obscures the
>>> code somewhat, with an additional header to know about, but ensures
>>> that
>>> the set of macros is the same throughout the project, and allows
>>> documenting them fairly easily.
>> I think we have to do this, or 3).  We have a strong preference against
>> duplicated functions and macros.
>>> 3) Use a third-party library for the compatibility macros. This way,
>>> the
>>> compat layer can be shared with other projects; it also makes it
>>> easier
>>> to keep it tested and documented.
>> We would prefer that, and we can import that as a third_party codebase.

Sorry for the delay – I've been working on porting FreeIPA for a few months.

I've spoken with Alexander Bokovoy earlier, and we agreed that adding a 
third_party module might be too much overhead for what is essentially a 
single header file.

So, I present two options, and I'm attaching patches that port the 
"samba.credentials" module as example usage.
- third_party/py3c, a copy of the (MIT-licensed) py3c project, with 
corresponding build system integration. (I'm not sure if I did the 
integration correctly; there's probably a better way to add a 
header-only third-party library to Waf-samba)
- lib/py3compat.h, a relatively simple header with the necessary macros. 
(I forked this from py3c when I was still the sole author, but the 
latter additions are not relevant to Samba.)

Both are available as Github branches if you prefer that:
- https://github.com/encukou/samba/commits/py3-credentials-third-party
- https://github.com/encukou/samba/commits/py3-credentials

More pros and cons:
As a developer, the single file is more straightforward (though 
third_party does have more documentation).
As a downstream redistributor (Fedora/RHEL), unbundling the third_party 
module would be easier for me.
And as someone who signed Samba Developer's Certificate of Origin, I 
feel somewhat uncomfortable bringing in a third-party project where 
contributors just send pull requests and have them merged, so if we go 
the thirt_party route, I'd like to clarify whether py3c's submission 
guidelines need to be made more strict.

Please let me know if you have any thoughts on this.

Petr Viktorin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: py3-shared-header.patch
Type: text/x-patch
Size: 13030 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160711/f2887069/py3-shared-header.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py3-third-party.patch
Type: text/x-patch
Size: 32410 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160711/f2887069/py3-third-party.bin>

More information about the samba-technical mailing list