Tools ls for m maintai aini ning an o ng an open so n sour urce P Pyt ython p n project Ben N en Nuttall ll @b @ben en_nut nuttall ll
Be Ben N Nut uttall ll ● So Software engin e engineer er at B BBC BC N News L Labs bs ● Former erly ly a at R Rasp spbe berry Pi Pi Founda undatio ion ● Crea eator o of g gpio piozer zero, p piwh whee eels a and p nd pyjokes ● Openso pensour urce.com c corres espo ponden ent ● twit witter er.com/ben_nu ben_nuttall ● git github.com/bennut bennuttall ll @ben_nuttall
Be Ben N Nut uttall ll ● So Software engin e engineer er at B BBC BC N News L Labs bs ● Former erly ly a at R Rasp spbe berry Pi Pi Founda undatio ion ● Crea eator o of g gpio piozer zero, p piwh whee eels a and p nd pyjokes ● Openso pensour urce.com c corres espo ponden ent ● twit witter er.com/ben_nu ben_nuttall ● git github.com/bennut bennuttall ll @ben_nuttall
What this tal Wha alk co covers Organisi ising a g a Pyt ython n module ule Dist istribu ibuting s ing software Using ng gi git/GitHu Hub Virtual en l envir ironmen ents Tes esting & ng & a aut utomated ed tes estin ing Documen entatio ion Licensin ing g so software @ben_nuttall
Wha What this tal alk i is no s not ● A thorough gh follo llow-alo long ng tutorial o l on how to use ea e each o of the ~ e ~50 tools ls men entio ioned ned ● Me e tell elling ing you wh whic ich tools ls to us use ● Me e tell elling ing you that you n need ed to k know all o l of thes ese e tools ls in inside- ide-out ut in in o order der to be c be consider idered ed a a pr prope per Pyt Python programmer pr er @ben_nuttall
gp gpiozero ● Pyt ython li n library pr providing s iding sim imple ple API PI for ph physic ical c l comput utin ing wit with R Rasp spber berry P Pi ● Ea Eases es the l e learni ning c ng curve e for young ung peo people, ple, b beginn eginner ers a s and ed nd educ ucators ● Nic ice Pyt e Pythonic ic API PI wit with a advanc nced ed toolin ling for e expe xperienc ienced p ed programmer ers ● gpio gpiozer ero.r .rea eadt dthedo edocs.io .io ● git github.com/gp gpio iozer zero/gp gpio iozero @ben_nuttall
piwh wheels ● Tooling ling for a aut utomatin ing bu buil ildin ing g wheels o els of ever erythin ing on Py n PyPI PI ● piwh piwheels. els.org – g – pip- pip-compa patib ible repo eposit sitory h hosting ing Arm wh whee eels ● Natively ely c compil iled ed Arm wh wheels eels bu built ilt o on Pi 3 i 3 hardw dware ● Repo epository h hosted o d on 1 × n 1 × Pi se Pi serves es 1 1 millio llion do n downlo nloads ds per er m month ● piwh piwheels. els.org ● git github.com/piwh piwheels els/piwh piwheels eels @ben_nuttall
Dave Jone nes ● Profes essio sional p l programmer er, a amateur eur de dentis ist ● Resp esponsible ible for im implem lemen enting m ing my c crazy zy i idea eas ● I wr write e the e fjr fjrst st 9 90%, %, h he e wr writ ites es the ne e next 9 90% ● Co-author o of gpio gpiozer ero a and piwh piwheels eels (als lso aut uthor o of pic picamer era, c colo lorzer ero, pic picraft, sens sense- e- emu, em u, la lars, st structa, compoundpi, pi, pis pisen ense, e, pibo pibootctl, l, .. ...) .) ● Introdu duced ed m me e to m most st o of the e tools in in this is talk @ben_nuttall
Writing ng a Pyt Pytho hon mo n modul ule . └── project.py @ben_nuttall
GitHub ub - - p personal al @ben_nuttall
GitHub ub - - o organ ganisation @ben_nuttall
GitHub ub - - o organ ganisation @ben_nuttall
GitHub ub - - co collab laborators @ben_nuttall
GitHub ub - - b branch anches @ben_nuttall
GitHub ub - - r rele leas ases @ben_nuttall
GitHub ub - - i issue ssues @ben_nuttall
GitHub ub - - p pull ull r reque uests @ben_nuttall
GitHub ub - - p project ct b boar ards @ben_nuttall
Distribut uting so ng softwar are – h – how? w? Package ma managers: ● Linu nux – apt, rpm, m, yu yum ● Language package managers – pip, npm, gem ● Linu nux portable – sna nap, fm fmatpak, AppIma mage ● Mac – home mebrew Download from site tes: ● GitHub, GitL tLab, Sourceforge ● Personal websites ● curl @ben_nuttall
Distribut uting so ng softwar are – – wh why? ● Ea Ease o e of a access ss ● Ex Expe pectations ● Trust st a and c confjd fjdenc ence ● St Stabil ilit ity @ben_nuttall
Lice censi nsing ng ● It’s im impo portant to c choose a e a li licence e for a a projec pr ect ● Think ink a about wh what would a ld ann nnoy you ● It’s im impo portant to sp spec ecif ify whic ich lic licen ence ● It’s im impo portant to in inclu lude de the lic e licenc ence e wit with the s e source c e code a de and d nd distribu ibutio ions ● Refer er to choosea ealic licen ense. e.com @ben_nuttall
Pack ackagi aging a P ng a Pyt ython m n module ule . ├── project ├── __init__.py │ └── project.py │ ├── README.rst └── setup.py @ben_nuttall
Pack ackagi aging a P ng a Pyt ython m n module ule – se – setup up.p .py import os from setuptools import setup, find_packages def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( name="project", version="0.1.0", author="Ben Nuttall", description="Really cool project", license="MIT", keywords=["sample", "project"], url="https://github.com/bennuttall/project", packages=find_packages(), long_description=read('README.rst'), ) @ben_nuttall
Pub Publi lishing a Py a Python m n module ule o on PyP n PyPI ● Regis egister a an a n account o on p pypi. ypi.org ● Put your ur a accoun unt d det etails ils in ~ n ~/.p .pypir ypirc: ben@magicman:~ $ cat .pypirc [pypi] username: bennuttall password: correcthorsebatterystaple ● Ins nstall ll Twine: wine: ● pip install twine @ben_nuttall
Pub Publi lishing a Py a Python m n module ule o on PyP n PyPI @ben_nuttall
__ini nit__.p .py ch choice ces: s: g gpiozero User er: set setup up.py from gpiozero import LED __version__ = '1.5.1' setup( __ini _init__ __.p .py: y: version=__version__ ... from .input_devices import LED, ... ) @ben_nuttall
__ini nit__.p .py ch choice ces: s: p piwh wheels ls User er: setup set up.py from piwheels.master.pypi import import piwheels as app PiWheelsTransport setup( __ini _init__ __.p .py: y: version=app.__version__, ... __version__ = '0.17' ) @ben_nuttall
Entry p points set etup.py: entry_points = { 'console_scripts': [ 'project = project.cli:main', ], } setup( ... entry_points=entry_points, ... ) @ben_nuttall
Virtual ual e environm nments ● Vir irtual e environment for a a P Pytho hon p proje oject ● You ou c create e the e e envir iron onmen ent, pip i install in l into it it ● Is Isola olated from om you our system Python hon a and s system em p packages es ● Buil ild you our proje oject i insid ide e it it, with c h cha hange ges " "in installe lled" in in real l time mkvirtualenv -p /usr/bin/python3 project pip install -e . pip install ipython deactivate workon project @ben_nuttall
Mak akefj fjles all: @echo "make install - Install on local system" @echo "make develop - Install symlinks for development" install: pip install . develop: pip install -e . @ben_nuttall
Testing ng ● Writ ite e tes ests to valida lidate wh what your c code de is s is sup uppo posed sed to do do ● Keep eep your o old ld tes ests s to m make su e sure no e nothin ing g br brea eaks in s in fut uture ● For m maxim imum um e efg fgect, wr write e tes ests b before you u writ ite e code de! ● Tes esting c ng can be n be per performed ed qu quic ickly kly lo locall lly ● Tes esting c ng can be n be a aut utomated – ed – e. e.g. . Travis a after er pu push sh ● Be Be pr pragm gmatic ic! Test st edg edge c e cases, es, d don’t be be e exhaus ustiv ive @ben_nuttall
Testing ng - asse ssert from project import add assert add(2, 2) == 4 @ben_nuttall
Testing ng - pyt ytest from project import add def test_add(): assert add(2, 2) == 4 @ben_nuttall
Testing ng - la layout ut . ├── Makefile ├── project ├── __init__.py │ └── project.py │ ├── setup.py └── tests └── test_add.py @ben_nuttall
pyt ytest @ben_nuttall
Testing ng - pyt ytest from project import add import pytest assert add(2, 2) == 4 with pytest.raises(TypeError): add("foo", "bar") @ben_nuttall
Recommend
More recommend