Python portgroup

André Kaplan ak.ml at laposte.net
Mon Sep 19 09:09:08 PDT 2011


> Le 19 sept. 2011 à 05:46, Joshua Root a écrit :
> 
> On 2011-9-19 13:20 , Mike Savory wrote:
>> Hi All
>> 
>> I have been looking at upgrading the following ports to work under Python 2.7
>> 
>> py26-gnuplot
>> py26-scapy
>> py26-pylibpcap
>> 
>> What is a good example of the new subport python implementation that will allow all these to be merged into the new architecture? This doesn't seem to be in the guide yet.
> 
>> Any pointers appreciated
> 
> Basically it goes:
> 
> 1. Change name to something of the form py-foo.
> 2. Change PortGroup line to 'PortGroup python 1.0'.
> 3. Set the python.versions option, and if there was no previously
> existing py-foo port for python24, also set python.default_version.
> 4. Wrap anything that wouldn't work in a stub port in 'if {$subport !=
> $name} {}', because py-foo is a stub that just depends on the default
> version. This includes but is not limited to depends_*, patchfiles, and
> pre/post phase code.
> 5. Change uses of '$name' to '$subport' as appropriate (e.g. when
> creating a doc dir).
> 

Since I had the same problem as Mike I wrote a little gsed filter which automates steps 1 to 4.
But there will still be a few remaining edits. 

I'm creating ${my_n} and ${my_lname} variables for ports available on pypi.
With these, master_sites can be written http://pypi.python.org/packages/source/${my_n}/${my_name}/
Feel free to delete them if you don't need them.
I've put a long list of python.versions but usually it's 25 26 27.

Here's how you would use it:
$ port cat py26-scapy | pyunify > Portfile.new

Also you might need to merge the differences between the existing py*-scapy into the unified port.

pyunify() {
    gsed -e '
    # Do nothing if already updated
    /^PortGroup\s\+python\s\+1\.0/,$ {
        b;
    }

    # Fix PortGroup
    /^PortGroup\s\+python/ {
        s,^\(PortGroup\s\+python\)[0-9]\+\s\+\(.*\)$,\1 \2,;
    }

    # Fix name, define several useful variables for pypi master_sites
    /^name/ {
        s,^\(name\s\+py\)[0-9]\+-\(.*\)$,set my_name         \2\
set my_n            [string index ${my_name} 0]\
set my_lname        [string tolower ${my_name}]\
\1-${my_lname},;
    }

    # Append python.default_version after the checksums block
    /^checksums/,/[^\]$/ {
        /[^\]$/ {
            s,$,\
\
python.default_version  27\
python.versions         25 26 27 31 32,;
        }
    }

    # Surround each depends_ block with a $subport test
    /^depends_/,/[^\]$/ {
        /^depends_/ {
            s,^,if {$subport != $name} {\
    ,;
        }
        s,\(port:py\)[0-9]*-,port:py${python.version}-,g;
        /[^\]$/ { s,$,\
},;
        }
    }
    '
}

Have fun,
Andre






More information about the macports-dev mailing list