SlideShare une entreprise Scribd logo
1  sur  57
Télécharger pour lire hors ligne
Python+Gradle
Stephen	
  Holsapple	
  
Python	
  
What	
  is	
  setuptools?	
  
#!/usr/bin/env python
from setuptools import setup
setup(
description=README,
author='Stephen Holsapple',
author_email='sholsapp@linkedin.com',
packages=['foo'],
install_requires=[],
)
What	
  is	
  setuptools?	
  Everything.	
  
•  To	
  Python,	
  setuptools	
  is	
  everything.	
  
– Is	
  the	
  core	
  API	
  that	
  most	
  tools	
  nowadays	
  use.	
  
– Is	
  the	
  brains	
  behind:	
  
•  Build	
  
•  Packaging	
  
•  Metadata	
  discovery	
  
•  Dependency	
  management	
  
Building	
  w/	
  setuptools
•  Tools	
  like	
  virtualenv	
  and	
  pip	
  make	
  life	
  
preHy	
  good.	
  
More	
  about	
  virtualenv	
  
$ virtualenv my-env
$ source my-env/bin/activate
(my-env)$ python
Python 2.7.5
>>> import sys
>>> sys.path
['./my-env/lib/python2.7/site-
packages']
(my-env) $ deactivate
$
More	
  about	
  virtualenv
•  A	
  command	
  line	
  tool	
  useful	
  for:	
  
– CreaJng	
  isolated	
  Python	
  environments.	
  
•  Really,	
  a	
  plaLorm	
  to	
  solve	
  dependency	
  and	
  
version	
  problems.	
  
More	
  about	
  pip
•  A	
  command	
  line	
  tool	
  useful	
  for:	
  
– Finding	
  dependencies	
  
– Installing	
  dependencies	
  
– ArJfact	
  management	
  
– Caching	
  
•  Really,	
  an	
  implementaJon	
  of	
  the	
  
setuptools	
  programming	
  interface.	
  
More	
  about	
  pip
(my-env)$ pip install requests
Downloading/unpacking requests
Downloading requests-2.7.0-py2.py3-none-
any.whl (470kB): 470kB downloaded
Installing collected packages: requests
Successfully installed requests
Cleaning up...
Building	
  w/	
  setuptools	
  
(my-env)$ pip install requests
(my-env)$ python
>>> import requests
>>> ...
Packaging	
  w/	
  setuptools
•  Tools	
  like	
  setuptools,	
  pip, pex	
  make	
  life	
  
preHy	
  good.	
  
– Source	
  distribuJons	
  
– Binary	
  distribuJons	
  
– Deployable	
  distribuJon	
  
Metadata	
  w/	
  setuptools
•  Doesn't	
  provide	
  great	
  ways	
  to:	
  
– Reason	
  about	
  builds	
  before/aOer	
  
– Reason	
  about	
  arJfacts	
  programaJcally	
  
•  Does	
  expose	
  programming	
  interfaces	
  to	
  
integrate	
  with	
  exisJng	
  metadata	
  systems.	
  
•  Requires	
  us	
  to	
  evaluate	
  Python	
  to	
  query	
  about	
  
metadata.	
  
Metadata	
  w/	
  setuptools
(my-env)$ pip show requests
---
Name: requests
Version: 2.7.0
Location: my-env/lib/python2.7/site-packages
Requires:
(my-env)$ pip freeze
requests==2.7.0
wsgiref==0.1.2
Dependencies	
  w/	
  setuptools
#!/usr/bin/env python
import setuptools
setuptools.setup(,
# ...
install_requires=[
"requests>=2.6",
"pyOpenSSL==0.15",
"urllib3",
],
# ...
)
Dependencies	
  w/	
  pip
$ cat requirements.txt
requests>=2.6
pyOpenSSL==0.15
urllib3
[pip/issues/988]
“Requirements	
  files	
  are	
  
used	
  to	
  force	
  pip	
  to	
  
properly	
  resolve	
  
dependencies.	
  As	
  it	
  is	
  now,	
  
pip	
  doesn't	
  have	
  true	
  
dependency	
  resolu=on,	
  
but	
  instead	
  simply	
  uses	
  
the	
  first	
  specifica=on	
  it	
  
finds	
  for	
  a	
  project.”	
  
pkg_resources	
  is	
  greedy	
  
•  Simply	
  use	
  the	
  first	
  specificaJon	
  found	
  for	
  a	
  
dependency.	
  
•  Ask	
  developers	
  to	
  pin	
  all	
  of	
  their	
  
dependencies.	
  
– pip freeze > requirements.txt
[VersionConflict]
pkg_resources.VersionConflict:
(requests 2.6.2,
Requirement.parse('requests<=2.6.0')
[DistributionNotFound]
pip.exceptions.DistributionNotFound:
No distributions at all found for
requests
Future	
  Work	
  
•  Sincere	
  thanks	
  to	
  
Donald	
  StuS	
  et	
  al.	
  on	
  
PyPA	
  working	
  to	
  
improve	
  state	
  of	
  
Python	
  packaging.	
  
•  Python	
  is	
  rapidly	
  
changing	
  for	
  the	
  
beHer.	
  
Python	
  
•  Report	
  card	
  
– Ecosystem	
  (great)	
  
– Build	
  System	
  (good)	
  
– Packaging	
  (good)	
  
– Metadata	
  (okay)	
  
– Dependency	
  Management	
  (bad)	
  
Scaling	
  Products	
  
•  Builds	
  
•  ArJfacts	
  
– Downloading	
  
– Caching	
  
– Metadata	
  
•  Dependencies	
  
– Dependency	
  ResoluJon	
  
– Conflict	
  ResoluJon	
  
•  TesJng	
  
Building	
  BeHer	
  Building	
  Systems	
  
•  We	
  have	
  a	
  core	
  set	
  of	
  great	
  tools	
  to	
  work	
  
with:	
  
– virtualenv
– setuptools
– pip
– pex
A	
  polite	
  tool	
  
•  The	
  pip	
  tool	
  is	
  polite	
  because:	
  
– Allows	
  for	
  customizaJon	
  or	
  disabling	
  of	
  
setuptools	
  and	
  pip	
  features:	
  
•  --index-url
•  --extra-index-url
•  --no-deps
– Allows	
  us	
  to	
  use	
  local	
  repositories.	
  
– Allows	
  us	
  to	
  solve	
  our	
  problems	
  our	
  way.	
  
#!/bin/build.sh	
  
vinit && source activate
python setup.py install
py.test
python setup.py sdist
#!/bin/build.sh	
  
vinit && source activate
python setup.py install
py.test
python setup.py sdist
pip wheel .
#!/bin/build.sh
vinit && source activate
for dep in $( cache/ ); do
pip install --no-deps dep
done
python setup.py install
py.test
python setup.py sdist
#!/bin/build.sh
vinit && source activate
for dep in $( ???/ ); do
pip install --no-deps dep
done
python setup.py install
py.test
python setup.py sdist
Gradle	
  
#!/bin/build.sh
vinit && source activate
for dep in $( gradle/ ); do
pip install --no-deps dep
done
python setup.py install
py.test
python setup.py sdist
Philosophy	
  
Let’s	
  let	
  Python	
  do	
  what	
  Python	
  is	
  
good	
  at	
  and	
  let	
  Gradle	
  do	
  what	
  Gradle	
  
is	
  good	
  at.	
  
Gradle	
  as	
  a	
  Build	
  Orchestrator	
  
•  First,	
  resolve	
  my	
  dependencies
•  Second,	
  run	
  my	
  build
– pip install --no-deps dep
•  Third,	
  run	
  my	
  package
– python setup.py sdist
•  Last,	
  run	
  my	
  publish
build.gradle
apply plugin: 'python-venv'
apply plugin: 'python-sdist'
sdist {
sourceDirectory 'src'
}
build.gradle
apply plugin: 'python-venv'
apply plugin: 'python-pex'
sdist {
sourceDirectory 'src'
}
Enhancing	
  Python	
  
•  Represent	
  arJfacts	
  and	
  dependencies	
  in	
  a	
  way	
  
Gradle	
  can	
  understand.	
  
•  Integrate	
  exisJng	
  metadata	
  with	
  setuptools	
  
using	
  custom	
  distribuJon	
  class.	
  
RepresenJng	
  Dependencies	
  
<ivy-module version="1.0">
<info module="cryptography" revision="0.8.2" />
<publications>
<artifact name="cryptography" conf="default"/>
</publications>
<dependencies>
<dependency name="pyasn1" rev="0.1.7" />
<dependency name="six" rev="1.9.0" />
<dependency name="setuptools" rev="3.4.4" />
<dependency name="enum34" rev="1.0.4" />
<dependency name="cffi" rev="0.9.2" />
</dependencies>
</ivy-module>
The	
  Cheese	
  Shop	
  
•  Python	
  Package	
  Index	
  (PyPI)	
  
– Community	
  hosts	
  packages	
  here	
  
– Cannot	
  modify	
  packages	
  here	
  
•  Internal	
  Python	
  Package	
  Index	
  
– ArJfactory	
  
– Add	
  Ivy	
  metadata	
  for	
  packages	
  
IntegraJng	
  Metadata	
  
•  How	
  to	
  marry	
  setuptools	
  with	
  custom	
  
metadata	
  systems.	
  
– Product	
  names	
  
– Product	
  versions	
  
– SpecificaJon	
  files	
  
– Dependencies	
  
IntegraJng	
  Metadata	
  
#!/usr/bin/env python2.6
import setuptools
from distgradle import GradleDistribution
setuptools.setup(
distclass=GradleDistribution,
package_dir={'': 'src'},
packages=setuptools.find_packages('src'),
include_package_data=True,
namespace_packages=['linkedin'],
)
Gradle	
  Infrastructure	
  
•  python-product
– Your	
  enterprise	
  build	
  logic,	
  covering	
  everything	
  
from	
  your	
  resoluJon	
  strategies,	
  your	
  repositories,	
  
your	
  metadata,	
  and	
  more.	
  
– You	
  could	
  write	
  a	
  simple	
  plugin	
  that	
  simply	
  defers	
  
to	
  setuptools,	
  if	
  you	
  want.	
  
Gradle	
  Plugins	
  
•  python-venv
– Builds	
  a	
  local	
  environment	
  
•  python-sdist
– Build	
  a	
  source	
  distribuJon	
  using	
  setuptools.	
  
•  python-wheel	
  
– Build	
  a	
  wheel	
  distribuJon	
  using	
  setuptools.	
  
•  python-pex
– Build	
  a	
  pex	
  distribuJon	
  using	
  pex.	
  
python-venv	
  
•  Under	
  the	
  hood:	
  
– CreaJng	
  a	
  virtual	
  environment.	
  
– Installing	
  build	
  requirements.	
  
– Installing	
  your	
  resolved	
  dependencies.	
  
– Installing	
  your	
  project.	
  
– Running	
  tests	
  
– Packaging	
  arJfacts	
  
python-sdist	
  
•  Under	
  the	
  hood:	
  
– Applying	
  python-venv
– Invoking	
  ./setup.py sdist
python-wheel	
  
•  Under	
  the	
  hood:	
  
– Applying	
  python-venv
– Invoking	
  pip wheel
•  Making	
  Python's	
  wheel	
  file	
  compaJble	
  with	
  
Ivy	
  is	
  hard.	
  
python-pex	
  
•  Under	
  the	
  hood:	
  
– Applying	
  python-venv
– Invoking	
  pex
•  Prepare	
  to	
  baHle	
  with	
  pex's	
  dependency	
  
resolver.	
  
python-???	
  
•  ExisJng	
  plugins	
  easy	
  to	
  add	
  now.	
  
•  AddiJonal	
  plugins	
  easy	
  to	
  add	
  later.	
  
•  Mix	
  and	
  match	
  any	
  way	
  we	
  like.	
  
– We	
  might	
  want	
  a	
  source	
  and	
  a	
  wheel	
  distribuJon.	
  
Python+Gradle	
  
•  Report	
  card	
  
– Ecosystem	
  (great)	
  
– Build	
  System	
  (good)	
  
– Packaging	
  (good)	
  
– Metadata	
  (good)	
  
– Dependency	
  Management	
  (great)	
  
What	
  is	
  Gradle	
  doing?	
  
•  Reading	
  specificaJon	
  files	
  
•  Dependency	
  and	
  conflict	
  resoluJon	
  
•  Downloading	
  and	
  caching	
  
•  OrchestraJng	
  creaJon	
  of	
  Python	
  arJfacts	
  
•  CreaJng	
  build	
  metadata	
  
•  Uploading	
  arJfacts	
  
•  PyPI	
  
What	
  is	
  Gradle	
  not	
  doing?	
  
•  Changing	
  how	
  you	
  develop	
  with	
  Python	
  
•  Changing	
  how	
  Python	
  packages	
  arJfacts	
  
•  Changing	
  Python	
  arJfacts	
  themselves	
  
•  Pushing	
  Gradle-­‐isms	
  into	
  Python	
  
Major	
  Wins	
  
•  Dependency	
  Management	
  
•  Plugin	
  Architecture	
  
•  Reusable	
  Logic	
  
•  MulJ-­‐language	
  Builds	
  
MulJ-­‐language	
  Builds	
  
•  One	
  build	
  system	
  to	
  rule	
  them	
  all.	
  
– Java	
  
– Scala	
  
– C/C++	
  
– Javascript	
  
– Python	
  
•  Products	
  can	
  contain	
  different	
  languages	
  
Why	
  Python?	
  
•  Why	
  was	
  Python	
  so	
  easy	
  to	
  build	
  with	
  Gradle?	
  
– Can	
  decouple	
  dep.	
  mgmt.	
  from	
  setuptools
– Can	
  decouple	
  dep.	
  mgmt.	
  from	
  PyPI	
  
– Can	
  represent	
  dependencies	
  with	
  Ivy	
  
•  Other	
  languages	
  like	
  Python	
  can	
  also	
  easily	
  
use	
  Gradle	
  
QuesJons?	
  

Contenu connexe

Tendances

Tendances (20)

AWSとオンプレミスを繋ぐときに知っておきたいルーティングの基礎知識(CCSI監修!)
AWSとオンプレミスを繋ぐときに知っておきたいルーティングの基礎知識(CCSI監修!)AWSとオンプレミスを繋ぐときに知っておきたいルーティングの基礎知識(CCSI監修!)
AWSとオンプレミスを繋ぐときに知っておきたいルーティングの基礎知識(CCSI監修!)
 
Announcing AWS Shield - Protect Web Applications from DDoS Attacks
Announcing AWS Shield - Protect Web Applications from DDoS AttacksAnnouncing AWS Shield - Protect Web Applications from DDoS Attacks
Announcing AWS Shield - Protect Web Applications from DDoS Attacks
 
20210317 AWS Black Belt Online Seminar Amazon MQ
20210317 AWS Black Belt Online Seminar Amazon MQ 20210317 AWS Black Belt Online Seminar Amazon MQ
20210317 AWS Black Belt Online Seminar Amazon MQ
 
AWS Summit Seoul 2023 | LG유플러스 IPTV 서비스, 무중단 클라우드 마이그레이션 이야기
AWS Summit Seoul 2023 | LG유플러스 IPTV 서비스, 무중단 클라우드 마이그레이션 이야기AWS Summit Seoul 2023 | LG유플러스 IPTV 서비스, 무중단 클라우드 마이그레이션 이야기
AWS Summit Seoul 2023 | LG유플러스 IPTV 서비스, 무중단 클라우드 마이그레이션 이야기
 
20191126 AWS Black Belt Online Seminar Amazon AppStream 2.0
20191126 AWS Black Belt Online Seminar Amazon AppStream 2.020191126 AWS Black Belt Online Seminar Amazon AppStream 2.0
20191126 AWS Black Belt Online Seminar Amazon AppStream 2.0
 
How to migrate an application in IBM APIc, and preserve its client credential
How to migrate an application in IBM APIc, and preserve its client credentialHow to migrate an application in IBM APIc, and preserve its client credential
How to migrate an application in IBM APIc, and preserve its client credential
 
20210309 AWS Black Belt Online Seminar AWS Audit Manager
20210309 AWS Black Belt Online Seminar AWS Audit Manager20210309 AWS Black Belt Online Seminar AWS Audit Manager
20210309 AWS Black Belt Online Seminar AWS Audit Manager
 
AWS Black Belt Online Seminar Elastic Load Balancing
AWS Black Belt Online Seminar Elastic Load BalancingAWS Black Belt Online Seminar Elastic Load Balancing
AWS Black Belt Online Seminar Elastic Load Balancing
 
AWSではじめるDNSSEC
AWSではじめるDNSSECAWSではじめるDNSSEC
AWSではじめるDNSSEC
 
Advanced Traffic Management with Amazon Route 53 Traffic Flow (NET407-R1) - A...
Advanced Traffic Management with Amazon Route 53 Traffic Flow (NET407-R1) - A...Advanced Traffic Management with Amazon Route 53 Traffic Flow (NET407-R1) - A...
Advanced Traffic Management with Amazon Route 53 Traffic Flow (NET407-R1) - A...
 
20180220 AWS Black Belt Online Seminar - Amazon Container Services
20180220 AWS Black Belt Online Seminar - Amazon Container Services20180220 AWS Black Belt Online Seminar - Amazon Container Services
20180220 AWS Black Belt Online Seminar - Amazon Container Services
 
AWS Summit Seoul 2023 | 가격은 저렴, 성능은 최대로! 확 달라진 Amazon EC2 알아보기
AWS Summit Seoul 2023 | 가격은 저렴, 성능은 최대로! 확 달라진 Amazon EC2 알아보기AWS Summit Seoul 2023 | 가격은 저렴, 성능은 최대로! 확 달라진 Amazon EC2 알아보기
AWS Summit Seoul 2023 | 가격은 저렴, 성능은 최대로! 확 달라진 Amazon EC2 알아보기
 
AWS OpsWorksハンズオン
AWS OpsWorksハンズオンAWS OpsWorksハンズオン
AWS OpsWorksハンズオン
 
개발자를 위한 클라우드 기술 트렌드- 윤석찬, AWS 테크에반젤리스트 :: Hello T 개발자 컨퍼런스
개발자를 위한 클라우드 기술 트렌드- 윤석찬, AWS 테크에반젤리스트 :: Hello T 개발자 컨퍼런스개발자를 위한 클라우드 기술 트렌드- 윤석찬, AWS 테크에반젤리스트 :: Hello T 개발자 컨퍼런스
개발자를 위한 클라우드 기술 트렌드- 윤석찬, AWS 테크에반젤리스트 :: Hello T 개발자 컨퍼런스
 
ZabbixによるAWS監視のコツ
ZabbixによるAWS監視のコツZabbixによるAWS監視のコツ
ZabbixによるAWS監視のコツ
 
AWS Summit Seoul 2023 | 클라우드를 통한 온/오프라인 비즈니스의 통합, GS리테일의 현대화
AWS Summit Seoul 2023 | 클라우드를 통한 온/오프라인 비즈니스의 통합, GS리테일의 현대화AWS Summit Seoul 2023 | 클라우드를 통한 온/오프라인 비즈니스의 통합, GS리테일의 현대화
AWS Summit Seoul 2023 | 클라우드를 통한 온/오프라인 비즈니스의 통합, GS리테일의 현대화
 
AWS CDK Introduction
AWS CDK IntroductionAWS CDK Introduction
AWS CDK Introduction
 
Spring Day 2016 - Web API アクセス制御の最適解
Spring Day 2016 - Web API アクセス制御の最適解Spring Day 2016 - Web API アクセス制御の最適解
Spring Day 2016 - Web API アクセス制御の最適解
 
CloudFront와 S3를 이용한 컨텐츠 배포 전략 - 박현우 CTO, SMARTSTUDY
CloudFront와 S3를 이용한 컨텐츠 배포 전략 - 박현우 CTO, SMARTSTUDYCloudFront와 S3를 이용한 컨텐츠 배포 전략 - 박현우 CTO, SMARTSTUDY
CloudFront와 S3를 이용한 컨텐츠 배포 전략 - 박현우 CTO, SMARTSTUDY
 
OAuth & OpenID Connect Deep Dive
OAuth & OpenID Connect Deep DiveOAuth & OpenID Connect Deep Dive
OAuth & OpenID Connect Deep Dive
 

En vedette (7)

{py}gradle
{py}gradle{py}gradle
{py}gradle
 
{py}gradle
{py}gradle{py}gradle
{py}gradle
 
Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc.Testing: Python, Java, Groovy, etc.
Testing: Python, Java, Groovy, etc.
 
Learning R via Python…or the other way around
Learning R via Python…or the other way aroundLearning R via Python…or the other way around
Learning R via Python…or the other way around
 
Androidで動かすはじめてのDeepLearning
Androidで動かすはじめてのDeepLearningAndroidで動かすはじめてのDeepLearning
Androidで動かすはじめてのDeepLearning
 
DI(依存性注入)について
DI(依存性注入)についてDI(依存性注入)について
DI(依存性注入)について
 
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGHDeploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
 

Similaire à Python+gradle

Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chef
LeanDog
 
Using the pip package manager for Odoo
Using the pip package manager for OdooUsing the pip package manager for Odoo
Using the pip package manager for Odoo
Odoo
 

Similaire à Python+gradle (20)

Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!Pipfile, pipenv, pip… what?!
Pipfile, pipenv, pip… what?!
 
Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
ASP.NET 5 auf Raspberry PI & docker
ASP.NET 5 auf Raspberry PI & dockerASP.NET 5 auf Raspberry PI & docker
ASP.NET 5 auf Raspberry PI & docker
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
 
Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chef
 
Using the pip package manager for Odoo
Using the pip package manager for OdooUsing the pip package manager for Odoo
Using the pip package manager for Odoo
 
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
 
First python project
First python projectFirst python project
First python project
 
Python packaging and dependency resolution
Python packaging and dependency resolutionPython packaging and dependency resolution
Python packaging and dependency resolution
 
The Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session IThe Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session I
 
ASP.NET 5 on the Raspberry PI 2
ASP.NET 5 on the Raspberry PI 2ASP.NET 5 on the Raspberry PI 2
ASP.NET 5 on the Raspberry PI 2
 
Docker to the Rescue of an Ops Team
Docker to the Rescue of an Ops TeamDocker to the Rescue of an Ops Team
Docker to the Rescue of an Ops Team
 
Docker to the Rescue of an Ops Team
Docker to the Rescue of an Ops TeamDocker to the Rescue of an Ops Team
Docker to the Rescue of an Ops Team
 
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
 
Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in Django
 
Welcome to the Cheese Shop: setuptools, virtualenv and PyPUG
Welcome to the Cheese Shop: setuptools, virtualenv and PyPUGWelcome to the Cheese Shop: setuptools, virtualenv and PyPUG
Welcome to the Cheese Shop: setuptools, virtualenv and PyPUG
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
 

Dernier

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Dernier (20)

WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

Python+gradle

  • 3. What  is  setuptools?   #!/usr/bin/env python from setuptools import setup setup( description=README, author='Stephen Holsapple', author_email='sholsapp@linkedin.com', packages=['foo'], install_requires=[], )
  • 4. What  is  setuptools?  Everything.   •  To  Python,  setuptools  is  everything.   – Is  the  core  API  that  most  tools  nowadays  use.   – Is  the  brains  behind:   •  Build   •  Packaging   •  Metadata  discovery   •  Dependency  management  
  • 5. Building  w/  setuptools •  Tools  like  virtualenv  and  pip  make  life   preHy  good.  
  • 6. More  about  virtualenv   $ virtualenv my-env $ source my-env/bin/activate (my-env)$ python Python 2.7.5 >>> import sys >>> sys.path ['./my-env/lib/python2.7/site- packages'] (my-env) $ deactivate $
  • 7. More  about  virtualenv •  A  command  line  tool  useful  for:   – CreaJng  isolated  Python  environments.   •  Really,  a  plaLorm  to  solve  dependency  and   version  problems.  
  • 8. More  about  pip •  A  command  line  tool  useful  for:   – Finding  dependencies   – Installing  dependencies   – ArJfact  management   – Caching   •  Really,  an  implementaJon  of  the   setuptools  programming  interface.  
  • 9. More  about  pip (my-env)$ pip install requests Downloading/unpacking requests Downloading requests-2.7.0-py2.py3-none- any.whl (470kB): 470kB downloaded Installing collected packages: requests Successfully installed requests Cleaning up...
  • 10. Building  w/  setuptools   (my-env)$ pip install requests (my-env)$ python >>> import requests >>> ...
  • 11. Packaging  w/  setuptools •  Tools  like  setuptools,  pip, pex  make  life   preHy  good.   – Source  distribuJons   – Binary  distribuJons   – Deployable  distribuJon  
  • 12. Metadata  w/  setuptools •  Doesn't  provide  great  ways  to:   – Reason  about  builds  before/aOer   – Reason  about  arJfacts  programaJcally   •  Does  expose  programming  interfaces  to   integrate  with  exisJng  metadata  systems.   •  Requires  us  to  evaluate  Python  to  query  about   metadata.  
  • 13. Metadata  w/  setuptools (my-env)$ pip show requests --- Name: requests Version: 2.7.0 Location: my-env/lib/python2.7/site-packages Requires: (my-env)$ pip freeze requests==2.7.0 wsgiref==0.1.2
  • 14. Dependencies  w/  setuptools #!/usr/bin/env python import setuptools setuptools.setup(, # ... install_requires=[ "requests>=2.6", "pyOpenSSL==0.15", "urllib3", ], # ... )
  • 15. Dependencies  w/  pip $ cat requirements.txt requests>=2.6 pyOpenSSL==0.15 urllib3
  • 16. [pip/issues/988] “Requirements  files  are   used  to  force  pip  to   properly  resolve   dependencies.  As  it  is  now,   pip  doesn't  have  true   dependency  resolu=on,   but  instead  simply  uses   the  first  specifica=on  it   finds  for  a  project.”  
  • 17. pkg_resources  is  greedy   •  Simply  use  the  first  specificaJon  found  for  a   dependency.   •  Ask  developers  to  pin  all  of  their   dependencies.   – pip freeze > requirements.txt
  • 20.
  • 21.
  • 22.
  • 23. Future  Work   •  Sincere  thanks  to   Donald  StuS  et  al.  on   PyPA  working  to   improve  state  of   Python  packaging.   •  Python  is  rapidly   changing  for  the   beHer.  
  • 24. Python   •  Report  card   – Ecosystem  (great)   – Build  System  (good)   – Packaging  (good)   – Metadata  (okay)   – Dependency  Management  (bad)  
  • 25. Scaling  Products   •  Builds   •  ArJfacts   – Downloading   – Caching   – Metadata   •  Dependencies   – Dependency  ResoluJon   – Conflict  ResoluJon   •  TesJng  
  • 26. Building  BeHer  Building  Systems   •  We  have  a  core  set  of  great  tools  to  work   with:   – virtualenv – setuptools – pip – pex
  • 27. A  polite  tool   •  The  pip  tool  is  polite  because:   – Allows  for  customizaJon  or  disabling  of   setuptools  and  pip  features:   •  --index-url •  --extra-index-url •  --no-deps – Allows  us  to  use  local  repositories.   – Allows  us  to  solve  our  problems  our  way.  
  • 28. #!/bin/build.sh   vinit && source activate python setup.py install py.test python setup.py sdist
  • 29. #!/bin/build.sh   vinit && source activate python setup.py install py.test python setup.py sdist pip wheel .
  • 30. #!/bin/build.sh vinit && source activate for dep in $( cache/ ); do pip install --no-deps dep done python setup.py install py.test python setup.py sdist
  • 31. #!/bin/build.sh vinit && source activate for dep in $( ???/ ); do pip install --no-deps dep done python setup.py install py.test python setup.py sdist
  • 33. #!/bin/build.sh vinit && source activate for dep in $( gradle/ ); do pip install --no-deps dep done python setup.py install py.test python setup.py sdist
  • 34. Philosophy   Let’s  let  Python  do  what  Python  is   good  at  and  let  Gradle  do  what  Gradle   is  good  at.  
  • 35.
  • 36. Gradle  as  a  Build  Orchestrator   •  First,  resolve  my  dependencies •  Second,  run  my  build – pip install --no-deps dep •  Third,  run  my  package – python setup.py sdist •  Last,  run  my  publish
  • 37. build.gradle apply plugin: 'python-venv' apply plugin: 'python-sdist' sdist { sourceDirectory 'src' }
  • 38. build.gradle apply plugin: 'python-venv' apply plugin: 'python-pex' sdist { sourceDirectory 'src' }
  • 39. Enhancing  Python   •  Represent  arJfacts  and  dependencies  in  a  way   Gradle  can  understand.   •  Integrate  exisJng  metadata  with  setuptools   using  custom  distribuJon  class.  
  • 40. RepresenJng  Dependencies   <ivy-module version="1.0"> <info module="cryptography" revision="0.8.2" /> <publications> <artifact name="cryptography" conf="default"/> </publications> <dependencies> <dependency name="pyasn1" rev="0.1.7" /> <dependency name="six" rev="1.9.0" /> <dependency name="setuptools" rev="3.4.4" /> <dependency name="enum34" rev="1.0.4" /> <dependency name="cffi" rev="0.9.2" /> </dependencies> </ivy-module>
  • 41. The  Cheese  Shop   •  Python  Package  Index  (PyPI)   – Community  hosts  packages  here   – Cannot  modify  packages  here   •  Internal  Python  Package  Index   – ArJfactory   – Add  Ivy  metadata  for  packages  
  • 42. IntegraJng  Metadata   •  How  to  marry  setuptools  with  custom   metadata  systems.   – Product  names   – Product  versions   – SpecificaJon  files   – Dependencies  
  • 43. IntegraJng  Metadata   #!/usr/bin/env python2.6 import setuptools from distgradle import GradleDistribution setuptools.setup( distclass=GradleDistribution, package_dir={'': 'src'}, packages=setuptools.find_packages('src'), include_package_data=True, namespace_packages=['linkedin'], )
  • 44. Gradle  Infrastructure   •  python-product – Your  enterprise  build  logic,  covering  everything   from  your  resoluJon  strategies,  your  repositories,   your  metadata,  and  more.   – You  could  write  a  simple  plugin  that  simply  defers   to  setuptools,  if  you  want.  
  • 45. Gradle  Plugins   •  python-venv – Builds  a  local  environment   •  python-sdist – Build  a  source  distribuJon  using  setuptools.   •  python-wheel   – Build  a  wheel  distribuJon  using  setuptools.   •  python-pex – Build  a  pex  distribuJon  using  pex.  
  • 46. python-venv   •  Under  the  hood:   – CreaJng  a  virtual  environment.   – Installing  build  requirements.   – Installing  your  resolved  dependencies.   – Installing  your  project.   – Running  tests   – Packaging  arJfacts  
  • 47. python-sdist   •  Under  the  hood:   – Applying  python-venv – Invoking  ./setup.py sdist
  • 48. python-wheel   •  Under  the  hood:   – Applying  python-venv – Invoking  pip wheel •  Making  Python's  wheel  file  compaJble  with   Ivy  is  hard.  
  • 49. python-pex   •  Under  the  hood:   – Applying  python-venv – Invoking  pex •  Prepare  to  baHle  with  pex's  dependency   resolver.  
  • 50. python-???   •  ExisJng  plugins  easy  to  add  now.   •  AddiJonal  plugins  easy  to  add  later.   •  Mix  and  match  any  way  we  like.   – We  might  want  a  source  and  a  wheel  distribuJon.  
  • 51. Python+Gradle   •  Report  card   – Ecosystem  (great)   – Build  System  (good)   – Packaging  (good)   – Metadata  (good)   – Dependency  Management  (great)  
  • 52. What  is  Gradle  doing?   •  Reading  specificaJon  files   •  Dependency  and  conflict  resoluJon   •  Downloading  and  caching   •  OrchestraJng  creaJon  of  Python  arJfacts   •  CreaJng  build  metadata   •  Uploading  arJfacts   •  PyPI  
  • 53. What  is  Gradle  not  doing?   •  Changing  how  you  develop  with  Python   •  Changing  how  Python  packages  arJfacts   •  Changing  Python  arJfacts  themselves   •  Pushing  Gradle-­‐isms  into  Python  
  • 54. Major  Wins   •  Dependency  Management   •  Plugin  Architecture   •  Reusable  Logic   •  MulJ-­‐language  Builds  
  • 55. MulJ-­‐language  Builds   •  One  build  system  to  rule  them  all.   – Java   – Scala   – C/C++   – Javascript   – Python   •  Products  can  contain  different  languages  
  • 56. Why  Python?   •  Why  was  Python  so  easy  to  build  with  Gradle?   – Can  decouple  dep.  mgmt.  from  setuptools – Can  decouple  dep.  mgmt.  from  PyPI   – Can  represent  dependencies  with  Ivy   •  Other  languages  like  Python  can  also  easily   use  Gradle