holger krekel: re-inventing packaging and testing with python

41
Re-inventing Python Packaging & Testing (0.9) Holger Krekel, http://twitter.com/hpk42 ( http://twitter.com/hpk42 ) Pycon Russia, Ekaterinburg, 25th Feb 2013 (XKCD of course) file:///home/hpk/p/pycon-russia-keynote/html/index.html#... 1 of 41 03/01/2013 12:04 PM

Upload: it-people

Post on 08-May-2015

531 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Holger Krekel: Re-inventing packaging and testing with python

Re-inventing Python Packaging &Testing (0.9)Holger Krekel, http://twitter.com/hpk42 (http://twitter.com/hpk42)

Pycon Russia, Ekaterinburg, 25th Feb 2013

(XKCD of course)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

1 of 41 03/01/2013 12:04 PM

Page 2: Holger Krekel: Re-inventing packaging and testing with python

Very happy to be here!file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

2 of 41 03/01/2013 12:04 PM

Page 3: Holger Krekel: Re-inventing packaging and testing with python

My backgroundstarted games programming 1986studied computer science in the 1990tieslots of Assembler, C, C++, distributed programmingcame to Python around 2001co-founded PyPy project in 2003, core dev for many yearsauthor of pytest, tox, execnet libraries

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

3 of 41 03/01/2013 12:04 PM

Page 4: Holger Krekel: Re-inventing packaging and testing with python

And now for something completelydifferent

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

4 of 41 03/01/2013 12:04 PM

Page 5: Holger Krekel: Re-inventing packaging and testing with python

RememberPerl:

There is more than one way to do it.

Python:

There should be one -- and preferably only one -- obvious way to do it.

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

5 of 41 03/01/2013 12:04 PM

Page 6: Holger Krekel: Re-inventing packaging and testing with python

Second version syndrome

Python3 may have beaten Perl6

(http://www.theregister.co.uk/2008/12/04/python_3point0_release/)

(from theregister.co.uk)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

6 of 41 03/01/2013 12:04 PM

Page 7: Holger Krekel: Re-inventing packaging and testing with python

but Perl is coming back to haunt us ...file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

7 of 41 03/01/2013 12:04 PM

Page 8: Holger Krekel: Re-inventing packaging and testing with python

Comprehensive Perl Archive network(CPAN)cpan.pm comes with base Perl installs:

downloads/builds/installs and tests packages and depscpan index has hundreds of public mirrorsuses declarative metadata since 2003can verify cryptographic signing of packages

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

8 of 41 03/01/2013 12:04 PM

Page 9: Holger Krekel: Re-inventing packaging and testing with python

CPAN server / uploadingPAUSE is the upload server for perl packages:

supports/can enforce versioning semanticsdevelopment releases are mirrored but not indexedpolicy for taking over maintenance of abandoned packagesprovides a mirrored un-indexed "home" area for authors/uploaders for patches, littledocs

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

9 of 41 03/01/2013 12:04 PM

Page 10: Holger Krekel: Re-inventing packaging and testing with python

Python Installer situation Feb 2013no download+install tool coming with core Pythontwo ways to download/install packages (pip, easy_install):

pip installs only source distributionseasy_install also binary distributions

slow: dependency discovery requires client-side crawling for packages in alldownload and homepage sitesno reliable way to test before installno cryptographic signature verification

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

10 of 41 03/01/2013 12:04 PM

Page 11: Holger Krekel: Re-inventing packaging and testing with python

upload/PYPI server interaction todaypypi.python.org server code not easily deployable on your laptopno enforced versioning semanticsno policy for taking over maintenance of abandoned packagesbrittle protocol: network and server failures of any download/homepage serverlead to aborted installs or installation of wrong versionsmetadata through code (setup.py) has tons of problems, has been hard so farto move away from.

and as to mirrors ...

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

11 of 41 03/01/2013 12:04 PM

Page 12: Holger Krekel: Re-inventing packaging and testing with python

CPAN Mirror status

(http://mirrors.cpan.org/)

(http://mirrors.cpan.org/ (http://mirrors.cpan.org/) )

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

12 of 41 03/01/2013 12:04 PM

Page 13: Holger Krekel: Re-inventing packaging and testing with python

PyPI Mirror status

(http://www.pypi-mirrors.org)

(http://www.pypi-mirrors.org (http://www.pypi-mirrors.org) )

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

13 of 41 03/01/2013 12:04 PM

Page 14: Holger Krekel: Re-inventing packaging and testing with python

We can stop the comparison already ...

(from www.cavstheblog.com)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

14 of 41 03/01/2013 12:04 PM

Page 15: Holger Krekel: Re-inventing packaging and testing with python

Three Lessons learnedfile:///home/hpk/p/pycon-russia-keynote/html/index.html#...

15 of 41 03/01/2013 12:04 PM

Page 16: Holger Krekel: Re-inventing packaging and testing with python

Comparing with others can quicklymake you unhappy

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

16 of 41 03/01/2013 12:04 PM

Page 17: Holger Krekel: Re-inventing packaging and testing with python

Perl and Python both not living up totheir mantras

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

17 of 41 03/01/2013 12:04 PM

Page 18: Holger Krekel: Re-inventing packaging and testing with python

There is a lot to improve onfile:///home/hpk/p/pycon-russia-keynote/html/index.html#...

18 of 41 03/01/2013 12:04 PM

Page 19: Holger Krekel: Re-inventing packaging and testing with python

Python Tools and PEPs to improvesetuptools/distribute projectspip/distlib/pkglib/... projectsPEP386 new version comparison for distutilsPEP345 Packaging Metadata 1.2PEP376 infrastructure for managing distributions locallyPEP405 virtual environmentsPEP426 Packaging Metadata Version 1.3 (finishing)PEP427 Wheel binary package format (APPROVED)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

19 of 41 03/01/2013 12:04 PM

Page 20: Holger Krekel: Re-inventing packaging and testing with python

beware: the standardization trap

(one of the many great XKCD comics)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

20 of 41 03/01/2013 12:04 PM

Page 21: Holger Krekel: Re-inventing packaging and testing with python

To avoid the standardization trap:

Don't demand that the world changes first

before your tool/idea can be used

(was also my motto when starting PyPy)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

21 of 41 03/01/2013 12:04 PM

Page 22: Holger Krekel: Re-inventing packaging and testing with python

Rather: write meta toolsconfigure and invoke existing toolsmake it work for most use casesenable new facilities/standards from there

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

22 of 41 03/01/2013 12:04 PM

Page 23: Holger Krekel: Re-inventing packaging and testing with python

example from the testing arena

(you do know the goat is Python's testing mascott, right?)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

23 of 41 03/01/2013 12:04 PM

Page 24: Holger Krekel: Re-inventing packaging and testing with python

Python Testing toolsnose: popular unittest-runnerpy.test: popular generic test runnerunittest/2: standard library TestCaseszope.testing: layered-setup unittest-runnertwisted.trial: running twisted/async test casesmany other methods, including "make test"setuptools has "setup.py test"

Would inventing a new test runner help to standardize testing?

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

24 of 41 03/01/2013 12:04 PM

Page 25: Holger Krekel: Re-inventing packaging and testing with python

tox: a "meta" test running toolmission: standardize testing in Python

configure multiple dependency configsinstall packages in virtualenv environmentsrun tests with your tools of choiceact as a frontend to CI servers

See http://tox.testrun.org (http://tox.testrun.org) for details.

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

25 of 41 03/01/2013 12:04 PM

Page 26: Holger Krekel: Re-inventing packaging and testing with python

But that's about testing ...

what about packaging/pypi?

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

26 of 41 03/01/2013 12:04 PM

Page 27: Holger Krekel: Re-inventing packaging and testing with python

I did a little prototyping ...file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

27 of 41 03/01/2013 12:04 PM

Page 28: Holger Krekel: Re-inventing packaging and testing with python

shown first here at Pycon Russia :)file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

28 of 41 03/01/2013 12:04 PM

Page 29: Holger Krekel: Re-inventing packaging and testing with python

devpi: a meta tool for packagingactivitiesdevpi serves two purposes:

it's a new compatible index and upload serversubcommands for managing release and QA workflows

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

29 of 41 03/01/2013 12:04 PM

Page 30: Holger Krekel: Re-inventing packaging and testing with python

why a new approach to index serving?there is no good existing pypi server to build these features:

multiple indexes and staging (dev->QA->PROD)merging of upstream (pypi.python.org) indexesserver-side crawling of download/homepagesrecording of automated test results with each packageseemlessly allow offline usage (e. g. on a laptop)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

30 of 41 03/01/2013 12:04 PM

Page 31: Holger Krekel: Re-inventing packaging and testing with python

Open Source principle:

talk is cheap, show working code!

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

31 of 41 03/01/2013 12:04 PM

Page 32: Holger Krekel: Re-inventing packaging and testing with python

$ devpi servermultiple indexes, organized as ~USERNAME/INDEXNAMEeach index has an upstream index whose packages are seemlessly mergedeach index is "crawl-clean" for clientsuploading a package to an index will not push it to upstreamcompatible for pip, easy_install and setup.py upload

enough theory - on to a a little demo :)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

32 of 41 03/01/2013 12:04 PM

Page 33: Holger Krekel: Re-inventing packaging and testing with python

summary of devpi server demo insightsupstream merging makes a private overlay index simplecrawling at server-side makes it easy and fast for installersdevpi maintains a nginx-servable static view

but:

typing in index server urls, maintaining .pypirc config is burdensome withmultiple indexes ... therefore ...

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

33 of 41 03/01/2013 12:04 PM

Page 34: Holger Krekel: Re-inventing packaging and testing with python

devpi also provides "workflow"subcommandsuse set current pypi index

install download and install one or more packages

upload build and upload packages from a checkout

test download and test a package

push push a package to another index

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

34 of 41 03/01/2013 12:04 PM

Page 35: Holger Krekel: Re-inventing packaging and testing with python

$ devpi testexample:

$ devpi test -e py25,py33 mypkg

download and unpack a package from current indexcall tox for provisioning and performing testsstream test results from a test run (currently pytest only, nose/unittest to follow)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

35 of 41 03/01/2013 12:04 PM

Page 36: Holger Krekel: Re-inventing packaging and testing with python

$ devpi pushexample:

$ devpi push mypkg https://pypi.python.org

pushes uploaded packages to another indexcurrently specified by "PKGNAME-VER"in the future this could be done to constraints like "all tests on windows need topass"

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

36 of 41 03/01/2013 12:04 PM

Page 37: Holger Krekel: Re-inventing packaging and testing with python

devpi: typical Open Source work flowstart a localhost index server:

$ devpi server

1.

use a user-specific index:

$ devpi use http://localhost:3141/~hpk42/dev/ (http://localhost:3141/~hpk42/dev/)

2.

upload a package from a checkout:

$ devpi upload

3.

perform tests on multiple machines from multiple users:

$ devpi test PKGNAME

4.

test results at http://localhost:3141/~hpk42/dev/tests (http://localhost:3141/~hpk42/dev/tests)

5.

when release is ready:

$ devpi push PKG https://pypi.python.org

6.

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

37 of 41 03/01/2013 12:04 PM

Page 38: Holger Krekel: Re-inventing packaging and testing with python

devpi implementation planto be MIT licensedtest-driven developmentget early adopters and streamline processes according to real-life usagedon't aim for standard lib or PEPs (for now)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

38 of 41 03/01/2013 12:04 PM

Page 39: Holger Krekel: Re-inventing packaging and testing with python

my priorities

use cases from contracting companies

use cases from my and others open source work

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

39 of 41 03/01/2013 12:04 PM

Page 40: Holger Krekel: Re-inventing packaging and testing with python

Open areas / future workuse VCS for index persistence?plugin system for upload/serve/test/installimplement mirroring of index as static filessupport declarative metadata / Wheel format /...support server-side PGP signing and verificationa public, redundant,global web serviceCI: per-commit automatic integration, testing and packaging

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

40 of 41 03/01/2013 12:04 PM

Page 41: Holger Krekel: Re-inventing packaging and testing with python

devpi going public mid 2013 ...aiming for a <1.0 public release, to involve early adopters and contributors for finalizingprocesses and good defaults.

Approach me here at Pycon Russia 2013

and thanks for listening!

No public channels yet, but am going to announce them via:

http://twitter.com/hpk42 (http://twitter.com/hpk42)http://holgerkrekel.net (http://holgerkrekel.net)

file:///home/hpk/p/pycon-russia-keynote/html/index.html#...

41 of 41 03/01/2013 12:04 PM