SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
Python-Builds mit ant
          Thomas Aglassinger
   <roskakori@users.sourceforge.net>
Agenda
●   Was ist ant?
●   Grundkonzepte und allgemeine Verwendung.
●   Konkrete Beispiele für Python.
●   Ausgewählte Features von ant.
Was ist ant?
●   Ant ist ein Build-Tool.
●   Ursprung in der Java-Welt.
●   Bewährt seit 2000.
●   Einfache Einbindung in Jenkins.


●   Auch für Python-Projekte verwendbar als
    Ergänzung zu distutils / setup.py.
●   Sehr gutes Handbuch mit vielen Beispielen.
Vergleich mit anderen Build-Tools
●   Oft kompakter als distutils / setup.py. → Standard-
    Aufgaben und leistungsfähige Dateimuster statt
    komplexe shutils-Aufrufe.
●   Weiter verbreitet als Scons.
    http://www.scons.org/
●   Robuster als Shell-Scripts → Abbruch bei Fehlern.
●   Deterministischeres Verhalten als Make.
    http://en.wikipedia.org/wiki/Make_(software)
●   Einfacher zu verwenden als Maven.
    http://maven.apache.org/
Grundlagen zu ant
●   Build.xml beschreibt Projekt.
●   Projekt besteht aus Zielen („targets“).
●   Ziele führen Aufgaben („tasks“) aus und erstellen Dateien.
●   Ziele können von anderen Zielen abhängig sein.
●   Aufgaben sind i.d.R. auf mehrere Dateien anwendbar –
    ausgewählt mit leistungsfähigen Dateimustern.
●   Eigenschaften („properties“) sind verwendbar als Variablen
    oder Konstante. Allerdings kaum Funktionen für String-
    Manipulation oder mathematische Berechnungen.
●   Einfache Makros zum parameterisierten Aufruf von
    mehreren Aufgaben.
Beispiel für build.xml
<project name="hello" default="build" basedir=".">
                                                              Setzt Eigenschaft
 <description>Say hello.</description>                       „greeting“ auf „Hello“

 <property name="greeting" value="Hello" />          Setzt Präfix für Zugriff auf
 <property environment="env" />                       Umgebungsvariablen.


 <target name="build" depends="hello">                Definiert Ziel „build“ mit
  <!-- Do nothing. -->                               Abhängigkeit zu Ziel „hello“
 </target>

                                                       Definiert Ziel „hello“ zur
 <target name="hello">                                Ausgabe einer Begrüßung.
  <echo message="${greeting} ${env.USER}! How are you?" />
 </target>
</project>
Aufruf und Ausgabe
$ ant
Buildfile: /Users/someone/hello/build.xml
                                            Bearbeitung von
                                              Ziel „hello“
hello:
   [echo] Hello someone! How are you?
                                            Bearbeitung von
                                              Ziel „build“
build:


BUILD SUCCESSFUL
Total time: 0 seconds
Beispiel-Ziele
●   PEP8 Style-Prüfung.
●   Anzahl der Quellcode-Zeilen.
●   Tests inklusive Testabdeckung.
●   Aufrufe von setup.py.


Quelle für vollständiges build.xml:
http://sourceforge.net/apps/trac/cutplace/browser/t
runk/build.xml
PEP8 Style-Prüfung
  <target name="pep8" description="build pep8 violations report">
     <echo message="build pep8 violations report" />
     <exec executable="pep8">
        <arg value="--repeat" />
        <arg value="--ignore" />
                                    Zeilen dürfen mehr
        <arg value="E501" />
                                   als 80 Zeichen haben
        <arg value="cutplace" />
        <redirector output="pep8.txt" />       Lenkt Ausgabe um
     </exec>                                   in Datei „pep8.txt“.

  </target>
Entspricht:
 pep8 –-repeat –-ignore E501 cutplace >pep8.txt
Anzahl der Quellcode-Zeilen
<target name="sloccount" description="build sloccount report">
  <echo message="build sloccount report" />
  <exec executable="sloccount" failonerror="true">
    <arg value="--details" />
    <arg value="--wide" />
                                           Download über Package Manager oder
                                            http://www.dwheeler.com/sloccount/
    <arg value="cutplace" />
    <redirector output="sloccount.sc">
       <outputfilterchain>                       Entfernt Zeilen mit „.svn“,
            <linecontains negate="true">          um interne Kopie von
              <contains value=".svn" />
                                                   Subversion nicht mit
                                                        zu zählen.
            </linecontains>
       </outputfilterchain>
    </redirector>
  </exec>
</target>
Tests inklusive Testabdeckung (1/2)
●   Unter Verwendung von nose und coverage.
    http://pypi.python.org/pypi/nose/
    http://pypi.python.org/pypi/coverage/

●   Ausgabe von nose im Format von JUnit.
●   Ausgabe von coverage im Format von
    Cobertura.
Tests inklusive Testabdeckung (2/2)
<target name="test" depends="testdata" description="run test suite">

  <exec executable="nosetests" failonerror="false">

     <arg value="--with-coverage" />

     <arg value="--with-doctest" />

     <arg value="--with-xunit" />                         Nach fehlgeschlagenen Tests
     <arg value="--cover-erase" />                          den Build fortsetzen und
                                                           Jenkins-Berichte erzeugen.
     <arg value="--exclude" />

     <arg value="(.*setup.*)|(.*test_performance.*)" />

  </exec>

  <exec executable="coverage" failonerror="true">

     <arg value="xml" />

  </exec>
                                                           Keine Testabdeckung für
</target>
                                                          setup.py („Test“ im Rahmen
                                                              des builds) und des
                                                           Performance-Test (erfolgt
                                                              mit eigenem Ziel).
Performance-Test
<target name="performance" description="run performance test" ...>
  <exec executable="nosetests" failonerror="false">
    <arg value="--with-xunit" />
    <arg value="--xunit-file" />
    <arg file="nosetests_performance.xml" />
    <arg file="cutplace/test_performance.py" />
  </exec>
</target>
Aufruf von setup.py (1/2)
<macrodef name="pyst">           Definiert Macro <pyst>

  <!-- Macro to run a setup.py command. -->
  <attribute name="command" />            Definiert Parameter „command“
  <sequential>
    <exec executable="python" failonerror="true">              Aufruf von
                                                            python setup.py
      <arg value="setup.py" />
      <arg value="@{command}" />             Übergabe von Parameter
                                              „command“ mit @{...}
    </exec>                                        statt ${...}.
  </sequential>
</macrodef>
Aufruf von setup.py (2/2)
  <target name="bdist_egg" depends="docs"
     description="build binary distribution">
     <pyst command="bdist_egg" />                        Entspricht:
  </target>
                                                  python setup.py bdist_egg



  <target name="develop" depends="bdist_egg"
      description="install current development version">
     <pyst command="develop" />
                                                       Entspricht:
  </target>                                      python setup.py develop


Aufruf:
$ ant bdist_egg
$ sudo ant develop
Nützliche Ant-Aufgaben
●   <copy>, <delete>, <move> - Dateioperationen.
●   <mkdir> - Ordner anlegen (auch verschachtelt).
●   <get> - Download einer URL.
●   <replace> - Suchen und Ersetzen von Texten.
●   <FixCRLF> - Zeilenenden vereinheitlichen.
●   <scp> - Secure remote copy.
●   <zip>, <unzip> - Dateien und Ordner komprimieren.
●   <XmlValidate> - XML mit DTD prüfen.
●   <xslt> - XSL Transformationen.
Plugins, Muster, Filter
<taskdef classname="org.acm.seguin.ant.Pretty"
     classpath="lib/pretty.jar;lib/JavaStyle.jar"            Import einer
                                                           externen Aufgabe
     name="pretty"/>
 <target depends="init" description="reformat java source code"
      name="reformat-java">                   Aufruf der
                                             importierten
  <pretty settingsDir="${settings.dir}">
                                               Aufgabe        Dateien, auf die
   <fileset dir="${source.dir}">                              Aufgabe an zu
                                                                wenden ist.
    <include name="**/*.java"/>
     <not><contains text="/*@"/></not>
   </fileset>                                        „**“ = alle Ordner und
                                                    enthaltene Unterordner
  </pretty>
 </target>
Zusammenfassung
●   Bewährtes Werkzeug aus der Java-Welt.
●   Vergleichsweise einfach und deterministisch.
●   Viele fertige Aufgaben (Tasks).
●   Einfache Einbindung von Python-Projekten in
    Jenkins.

Más contenido relacionado

La actualidad más candente

Einführung React Native
Einführung React NativeEinführung React Native
Einführung React NativeMarkus Günther
 
An Introduction to Ruby On Rails
An Introduction to Ruby On RailsAn Introduction to Ruby On Rails
An Introduction to Ruby On RailsJonathan Weiss
 
Java Batch: Der neue Standard für‘s Stapeln
Java Batch: Der neue Standard für‘s StapelnJava Batch: Der neue Standard für‘s Stapeln
Java Batch: Der neue Standard für‘s Stapelngedoplan
 
Introduction into Oracle Data Pump 11g/12c - Export and Import Data
Introduction into Oracle Data Pump 11g/12c - Export and Import DataIntroduction into Oracle Data Pump 11g/12c - Export and Import Data
Introduction into Oracle Data Pump 11g/12c - Export and Import DataGunther Pippèrr
 
Seminar Joomla 1.5 SEF-Mechanismus
Seminar Joomla 1.5 SEF-MechanismusSeminar Joomla 1.5 SEF-Mechanismus
Seminar Joomla 1.5 SEF-MechanismusFabian Becker
 
Versionskontrolle in Machine-Learning-Projekten
Versionskontrolle in Machine-Learning-ProjektenVersionskontrolle in Machine-Learning-Projekten
Versionskontrolle in Machine-Learning-Projektencusy GmbH
 
Opensource Tools für das Data Center Management
Opensource Tools für das Data Center ManagementOpensource Tools für das Data Center Management
Opensource Tools für das Data Center Managementinovex GmbH
 
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...NETWAYS
 
Verteilte Anwendungen bei Azure mit Docker und Kubernetes
Verteilte Anwendungen bei Azure mit Docker und KubernetesVerteilte Anwendungen bei Azure mit Docker und Kubernetes
Verteilte Anwendungen bei Azure mit Docker und KubernetesGregor Biswanger
 
Powerful mostly unknown Javascript-Features
Powerful mostly unknown Javascript-FeaturesPowerful mostly unknown Javascript-Features
Powerful mostly unknown Javascript-FeaturesSascha Hameister
 
Konfigurationsmanagement mit Opscode Chef
Konfigurationsmanagement mit Opscode ChefKonfigurationsmanagement mit Opscode Chef
Konfigurationsmanagement mit Opscode ChefKonrad Ferdinand Heimel
 
Object-orientied way of using mysqli interface - Workshop
Object-orientied way of using mysqli interface - WorkshopObject-orientied way of using mysqli interface - Workshop
Object-orientied way of using mysqli interface - WorkshopWaldemar Dell
 
Welches Webframework passt zu mir? (WJAX)
Welches Webframework passt zu mir? (WJAX)Welches Webframework passt zu mir? (WJAX)
Welches Webframework passt zu mir? (WJAX)Alexander Casall
 
C++ Dependency Management 2.0
C++ Dependency Management 2.0C++ Dependency Management 2.0
C++ Dependency Management 2.0Patrick Charrier
 
Auszug Seminarunterlagen "Tomcat 6.x"
Auszug Seminarunterlagen "Tomcat 6.x"Auszug Seminarunterlagen "Tomcat 6.x"
Auszug Seminarunterlagen "Tomcat 6.x"schellsoft
 

La actualidad más candente (20)

Einführung React Native
Einführung React NativeEinführung React Native
Einführung React Native
 
FLOW3-Workshop F3X12
FLOW3-Workshop F3X12FLOW3-Workshop F3X12
FLOW3-Workshop F3X12
 
An Introduction to Ruby On Rails
An Introduction to Ruby On RailsAn Introduction to Ruby On Rails
An Introduction to Ruby On Rails
 
Einsteiger Workshop
Einsteiger WorkshopEinsteiger Workshop
Einsteiger Workshop
 
Automatisierungmit NANT
Automatisierungmit NANTAutomatisierungmit NANT
Automatisierungmit NANT
 
Java Batch: Der neue Standard für‘s Stapeln
Java Batch: Der neue Standard für‘s StapelnJava Batch: Der neue Standard für‘s Stapeln
Java Batch: Der neue Standard für‘s Stapeln
 
Introduction into Oracle Data Pump 11g/12c - Export and Import Data
Introduction into Oracle Data Pump 11g/12c - Export and Import DataIntroduction into Oracle Data Pump 11g/12c - Export and Import Data
Introduction into Oracle Data Pump 11g/12c - Export and Import Data
 
Seminar Joomla 1.5 SEF-Mechanismus
Seminar Joomla 1.5 SEF-MechanismusSeminar Joomla 1.5 SEF-Mechanismus
Seminar Joomla 1.5 SEF-Mechanismus
 
Versionskontrolle in Machine-Learning-Projekten
Versionskontrolle in Machine-Learning-ProjektenVersionskontrolle in Machine-Learning-Projekten
Versionskontrolle in Machine-Learning-Projekten
 
Opensource Tools für das Data Center Management
Opensource Tools für das Data Center ManagementOpensource Tools für das Data Center Management
Opensource Tools für das Data Center Management
 
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
 
Mvc public
Mvc publicMvc public
Mvc public
 
Verteilte Anwendungen bei Azure mit Docker und Kubernetes
Verteilte Anwendungen bei Azure mit Docker und KubernetesVerteilte Anwendungen bei Azure mit Docker und Kubernetes
Verteilte Anwendungen bei Azure mit Docker und Kubernetes
 
Powerful mostly unknown Javascript-Features
Powerful mostly unknown Javascript-FeaturesPowerful mostly unknown Javascript-Features
Powerful mostly unknown Javascript-Features
 
Konfigurationsmanagement mit Opscode Chef
Konfigurationsmanagement mit Opscode ChefKonfigurationsmanagement mit Opscode Chef
Konfigurationsmanagement mit Opscode Chef
 
Object-orientied way of using mysqli interface - Workshop
Object-orientied way of using mysqli interface - WorkshopObject-orientied way of using mysqli interface - Workshop
Object-orientied way of using mysqli interface - Workshop
 
Welches Webframework passt zu mir? (WJAX)
Welches Webframework passt zu mir? (WJAX)Welches Webframework passt zu mir? (WJAX)
Welches Webframework passt zu mir? (WJAX)
 
C++ Dependency Management 2.0
C++ Dependency Management 2.0C++ Dependency Management 2.0
C++ Dependency Management 2.0
 
Einführung in React
Einführung in ReactEinführung in React
Einführung in React
 
Auszug Seminarunterlagen "Tomcat 6.x"
Auszug Seminarunterlagen "Tomcat 6.x"Auszug Seminarunterlagen "Tomcat 6.x"
Auszug Seminarunterlagen "Tomcat 6.x"
 

Similar a Python builds mit ant

Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...GFU Cyrus AG
 
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...gedoplan
 
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...gedoplan
 
Java Batch – Der Standard für's Stapeln
Java Batch – Der Standard für's StapelnJava Batch – Der Standard für's Stapeln
Java Batch – Der Standard für's Stapelngedoplan
 
Automatisierte Linux Administration mit (R)?ex
Automatisierte Linux Administration mit (R)?ex Automatisierte Linux Administration mit (R)?ex
Automatisierte Linux Administration mit (R)?ex Jan Gehring
 
Docker und Kubernetes Patterns & Anti-Patterns
Docker und Kubernetes Patterns & Anti-PatternsDocker und Kubernetes Patterns & Anti-Patterns
Docker und Kubernetes Patterns & Anti-PatternsQAware GmbH
 
Docker und Kubernetes Patterns & Anti-Patterns
Docker und Kubernetes Patterns & Anti-PatternsDocker und Kubernetes Patterns & Anti-Patterns
Docker und Kubernetes Patterns & Anti-PatternsJosef Adersberger
 
Angular von 0 auf 100
Angular von 0 auf 100Angular von 0 auf 100
Angular von 0 auf 100Yvette Teiken
 
Lightweight AOP with CDI and JPA
Lightweight AOP with CDI and JPALightweight AOP with CDI and JPA
Lightweight AOP with CDI and JPAmh0708
 
JSF 2 Kompositkomponenten (JAX 2012)
JSF 2 Kompositkomponenten (JAX 2012)JSF 2 Kompositkomponenten (JAX 2012)
JSF 2 Kompositkomponenten (JAX 2012)Michael Kurz
 
Dokumentation schreiben kann spass machen
Dokumentation schreiben kann spass machenDokumentation schreiben kann spass machen
Dokumentation schreiben kann spass machenSebastian Hempel
 
Slides__Splunk_UserGroup_20220407.pdf
Slides__Splunk_UserGroup_20220407.pdfSlides__Splunk_UserGroup_20220407.pdf
Slides__Splunk_UserGroup_20220407.pdfAlexanderStz1
 
Microservices mit Rust
Microservices mit RustMicroservices mit Rust
Microservices mit RustJens Siebert
 
Creasoft - Windows powershell
Creasoft - Windows powershellCreasoft - Windows powershell
Creasoft - Windows powershellCreasoft AG
 
MicroProfile-Anwendungen mit Quarkus
MicroProfile-Anwendungen mit QuarkusMicroProfile-Anwendungen mit Quarkus
MicroProfile-Anwendungen mit Quarkusgedoplan
 

Similar a Python builds mit ant (20)

Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
 
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
 
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
 
Java Batch – Der Standard für's Stapeln
Java Batch – Der Standard für's StapelnJava Batch – Der Standard für's Stapeln
Java Batch – Der Standard für's Stapeln
 
Automatisierte Linux Administration mit (R)?ex
Automatisierte Linux Administration mit (R)?ex Automatisierte Linux Administration mit (R)?ex
Automatisierte Linux Administration mit (R)?ex
 
Automatisierung mit grunt
Automatisierung mit gruntAutomatisierung mit grunt
Automatisierung mit grunt
 
Docker und Kubernetes Patterns & Anti-Patterns
Docker und Kubernetes Patterns & Anti-PatternsDocker und Kubernetes Patterns & Anti-Patterns
Docker und Kubernetes Patterns & Anti-Patterns
 
Docker und Kubernetes Patterns & Anti-Patterns
Docker und Kubernetes Patterns & Anti-PatternsDocker und Kubernetes Patterns & Anti-Patterns
Docker und Kubernetes Patterns & Anti-Patterns
 
Angular von 0 auf 100
Angular von 0 auf 100Angular von 0 auf 100
Angular von 0 auf 100
 
Einführung in Docker
Einführung in DockerEinführung in Docker
Einführung in Docker
 
Backbase Intro
Backbase IntroBackbase Intro
Backbase Intro
 
Grunt
GruntGrunt
Grunt
 
Lightweight AOP with CDI and JPA
Lightweight AOP with CDI and JPALightweight AOP with CDI and JPA
Lightweight AOP with CDI and JPA
 
Feature Flags mit Togglz
Feature Flags mit TogglzFeature Flags mit Togglz
Feature Flags mit Togglz
 
JSF 2 Kompositkomponenten (JAX 2012)
JSF 2 Kompositkomponenten (JAX 2012)JSF 2 Kompositkomponenten (JAX 2012)
JSF 2 Kompositkomponenten (JAX 2012)
 
Dokumentation schreiben kann spass machen
Dokumentation schreiben kann spass machenDokumentation schreiben kann spass machen
Dokumentation schreiben kann spass machen
 
Slides__Splunk_UserGroup_20220407.pdf
Slides__Splunk_UserGroup_20220407.pdfSlides__Splunk_UserGroup_20220407.pdf
Slides__Splunk_UserGroup_20220407.pdf
 
Microservices mit Rust
Microservices mit RustMicroservices mit Rust
Microservices mit Rust
 
Creasoft - Windows powershell
Creasoft - Windows powershellCreasoft - Windows powershell
Creasoft - Windows powershell
 
MicroProfile-Anwendungen mit Quarkus
MicroProfile-Anwendungen mit QuarkusMicroProfile-Anwendungen mit Quarkus
MicroProfile-Anwendungen mit Quarkus
 

Más de roskakori

Expanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on designExpanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on designroskakori
 
Django trifft Flutter
Django trifft FlutterDjango trifft Flutter
Django trifft Flutterroskakori
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginxroskakori
 
Helpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and DjangoHelpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and Djangoroskakori
 
Startmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU GrazStartmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU Grazroskakori
 
Helpful logging with python
Helpful logging with pythonHelpful logging with python
Helpful logging with pythonroskakori
 
Helpful logging with Java
Helpful logging with JavaHelpful logging with Java
Helpful logging with Javaroskakori
 
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-EntwicklerEinführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-Entwicklerroskakori
 
Analyzing natural language feedback using python
Analyzing natural language feedback using pythonAnalyzing natural language feedback using python
Analyzing natural language feedback using pythonroskakori
 
Microsoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and DockerMicrosoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and Dockerroskakori
 
Migration to Python 3 in Finance
Migration to Python 3 in FinanceMigration to Python 3 in Finance
Migration to Python 3 in Financeroskakori
 
Introduction to pygments
Introduction to pygmentsIntroduction to pygments
Introduction to pygmentsroskakori
 
Lösungsorientierte Fehlerbehandlung
Lösungsorientierte FehlerbehandlungLösungsorientierte Fehlerbehandlung
Lösungsorientierte Fehlerbehandlungroskakori
 
XML namespaces and XPath with Python
XML namespaces and XPath with PythonXML namespaces and XPath with Python
XML namespaces and XPath with Pythonroskakori
 
Erste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit PythonErste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit Pythonroskakori
 
Introduction to trader bots with Python
Introduction to trader bots with PythonIntroduction to trader bots with Python
Introduction to trader bots with Pythonroskakori
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with pythonroskakori
 
Kanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-AnforderungenKanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-Anforderungenroskakori
 

Más de roskakori (18)

Expanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on designExpanding skill sets - Broaden your perspective on design
Expanding skill sets - Broaden your perspective on design
 
Django trifft Flutter
Django trifft FlutterDjango trifft Flutter
Django trifft Flutter
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginx
 
Helpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and DjangoHelpful pre commit hooks for Python and Django
Helpful pre commit hooks for Python and Django
 
Startmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU GrazStartmeeting Interessengruppe NLP NLU Graz
Startmeeting Interessengruppe NLP NLU Graz
 
Helpful logging with python
Helpful logging with pythonHelpful logging with python
Helpful logging with python
 
Helpful logging with Java
Helpful logging with JavaHelpful logging with Java
Helpful logging with Java
 
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-EntwicklerEinführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
 
Analyzing natural language feedback using python
Analyzing natural language feedback using pythonAnalyzing natural language feedback using python
Analyzing natural language feedback using python
 
Microsoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and DockerMicrosoft SQL Server with Linux and Docker
Microsoft SQL Server with Linux and Docker
 
Migration to Python 3 in Finance
Migration to Python 3 in FinanceMigration to Python 3 in Finance
Migration to Python 3 in Finance
 
Introduction to pygments
Introduction to pygmentsIntroduction to pygments
Introduction to pygments
 
Lösungsorientierte Fehlerbehandlung
Lösungsorientierte FehlerbehandlungLösungsorientierte Fehlerbehandlung
Lösungsorientierte Fehlerbehandlung
 
XML namespaces and XPath with Python
XML namespaces and XPath with PythonXML namespaces and XPath with Python
XML namespaces and XPath with Python
 
Erste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit PythonErste-Hilfekasten für Unicode mit Python
Erste-Hilfekasten für Unicode mit Python
 
Introduction to trader bots with Python
Introduction to trader bots with PythonIntroduction to trader bots with Python
Introduction to trader bots with Python
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
 
Kanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-AnforderungenKanban zur Abwicklung von Reporting-Anforderungen
Kanban zur Abwicklung von Reporting-Anforderungen
 

Python builds mit ant

  • 1. Python-Builds mit ant Thomas Aglassinger <roskakori@users.sourceforge.net>
  • 2. Agenda ● Was ist ant? ● Grundkonzepte und allgemeine Verwendung. ● Konkrete Beispiele für Python. ● Ausgewählte Features von ant.
  • 3. Was ist ant? ● Ant ist ein Build-Tool. ● Ursprung in der Java-Welt. ● Bewährt seit 2000. ● Einfache Einbindung in Jenkins. ● Auch für Python-Projekte verwendbar als Ergänzung zu distutils / setup.py. ● Sehr gutes Handbuch mit vielen Beispielen.
  • 4. Vergleich mit anderen Build-Tools ● Oft kompakter als distutils / setup.py. → Standard- Aufgaben und leistungsfähige Dateimuster statt komplexe shutils-Aufrufe. ● Weiter verbreitet als Scons. http://www.scons.org/ ● Robuster als Shell-Scripts → Abbruch bei Fehlern. ● Deterministischeres Verhalten als Make. http://en.wikipedia.org/wiki/Make_(software) ● Einfacher zu verwenden als Maven. http://maven.apache.org/
  • 5. Grundlagen zu ant ● Build.xml beschreibt Projekt. ● Projekt besteht aus Zielen („targets“). ● Ziele führen Aufgaben („tasks“) aus und erstellen Dateien. ● Ziele können von anderen Zielen abhängig sein. ● Aufgaben sind i.d.R. auf mehrere Dateien anwendbar – ausgewählt mit leistungsfähigen Dateimustern. ● Eigenschaften („properties“) sind verwendbar als Variablen oder Konstante. Allerdings kaum Funktionen für String- Manipulation oder mathematische Berechnungen. ● Einfache Makros zum parameterisierten Aufruf von mehreren Aufgaben.
  • 6. Beispiel für build.xml <project name="hello" default="build" basedir="."> Setzt Eigenschaft <description>Say hello.</description> „greeting“ auf „Hello“ <property name="greeting" value="Hello" /> Setzt Präfix für Zugriff auf <property environment="env" /> Umgebungsvariablen. <target name="build" depends="hello"> Definiert Ziel „build“ mit <!-- Do nothing. --> Abhängigkeit zu Ziel „hello“ </target> Definiert Ziel „hello“ zur <target name="hello"> Ausgabe einer Begrüßung. <echo message="${greeting} ${env.USER}! How are you?" /> </target> </project>
  • 7. Aufruf und Ausgabe $ ant Buildfile: /Users/someone/hello/build.xml Bearbeitung von Ziel „hello“ hello: [echo] Hello someone! How are you? Bearbeitung von Ziel „build“ build: BUILD SUCCESSFUL Total time: 0 seconds
  • 8. Beispiel-Ziele ● PEP8 Style-Prüfung. ● Anzahl der Quellcode-Zeilen. ● Tests inklusive Testabdeckung. ● Aufrufe von setup.py. Quelle für vollständiges build.xml: http://sourceforge.net/apps/trac/cutplace/browser/t runk/build.xml
  • 9. PEP8 Style-Prüfung <target name="pep8" description="build pep8 violations report"> <echo message="build pep8 violations report" /> <exec executable="pep8"> <arg value="--repeat" /> <arg value="--ignore" /> Zeilen dürfen mehr <arg value="E501" /> als 80 Zeichen haben <arg value="cutplace" /> <redirector output="pep8.txt" /> Lenkt Ausgabe um </exec> in Datei „pep8.txt“. </target> Entspricht: pep8 –-repeat –-ignore E501 cutplace >pep8.txt
  • 10. Anzahl der Quellcode-Zeilen <target name="sloccount" description="build sloccount report"> <echo message="build sloccount report" /> <exec executable="sloccount" failonerror="true"> <arg value="--details" /> <arg value="--wide" /> Download über Package Manager oder http://www.dwheeler.com/sloccount/ <arg value="cutplace" /> <redirector output="sloccount.sc"> <outputfilterchain> Entfernt Zeilen mit „.svn“, <linecontains negate="true"> um interne Kopie von <contains value=".svn" /> Subversion nicht mit zu zählen. </linecontains> </outputfilterchain> </redirector> </exec> </target>
  • 11. Tests inklusive Testabdeckung (1/2) ● Unter Verwendung von nose und coverage. http://pypi.python.org/pypi/nose/ http://pypi.python.org/pypi/coverage/ ● Ausgabe von nose im Format von JUnit. ● Ausgabe von coverage im Format von Cobertura.
  • 12. Tests inklusive Testabdeckung (2/2) <target name="test" depends="testdata" description="run test suite"> <exec executable="nosetests" failonerror="false"> <arg value="--with-coverage" /> <arg value="--with-doctest" /> <arg value="--with-xunit" /> Nach fehlgeschlagenen Tests <arg value="--cover-erase" /> den Build fortsetzen und Jenkins-Berichte erzeugen. <arg value="--exclude" /> <arg value="(.*setup.*)|(.*test_performance.*)" /> </exec> <exec executable="coverage" failonerror="true"> <arg value="xml" /> </exec> Keine Testabdeckung für </target> setup.py („Test“ im Rahmen des builds) und des Performance-Test (erfolgt mit eigenem Ziel).
  • 13. Performance-Test <target name="performance" description="run performance test" ...> <exec executable="nosetests" failonerror="false"> <arg value="--with-xunit" /> <arg value="--xunit-file" /> <arg file="nosetests_performance.xml" /> <arg file="cutplace/test_performance.py" /> </exec> </target>
  • 14. Aufruf von setup.py (1/2) <macrodef name="pyst"> Definiert Macro <pyst> <!-- Macro to run a setup.py command. --> <attribute name="command" /> Definiert Parameter „command“ <sequential> <exec executable="python" failonerror="true"> Aufruf von python setup.py <arg value="setup.py" /> <arg value="@{command}" /> Übergabe von Parameter „command“ mit @{...} </exec> statt ${...}. </sequential> </macrodef>
  • 15. Aufruf von setup.py (2/2) <target name="bdist_egg" depends="docs" description="build binary distribution"> <pyst command="bdist_egg" /> Entspricht: </target> python setup.py bdist_egg <target name="develop" depends="bdist_egg" description="install current development version"> <pyst command="develop" /> Entspricht: </target> python setup.py develop Aufruf: $ ant bdist_egg $ sudo ant develop
  • 16. Nützliche Ant-Aufgaben ● <copy>, <delete>, <move> - Dateioperationen. ● <mkdir> - Ordner anlegen (auch verschachtelt). ● <get> - Download einer URL. ● <replace> - Suchen und Ersetzen von Texten. ● <FixCRLF> - Zeilenenden vereinheitlichen. ● <scp> - Secure remote copy. ● <zip>, <unzip> - Dateien und Ordner komprimieren. ● <XmlValidate> - XML mit DTD prüfen. ● <xslt> - XSL Transformationen.
  • 17. Plugins, Muster, Filter <taskdef classname="org.acm.seguin.ant.Pretty" classpath="lib/pretty.jar;lib/JavaStyle.jar" Import einer externen Aufgabe name="pretty"/> <target depends="init" description="reformat java source code" name="reformat-java"> Aufruf der importierten <pretty settingsDir="${settings.dir}"> Aufgabe Dateien, auf die <fileset dir="${source.dir}"> Aufgabe an zu wenden ist. <include name="**/*.java"/> <not><contains text="/*@"/></not> </fileset> „**“ = alle Ordner und enthaltene Unterordner </pretty> </target>
  • 18. Zusammenfassung ● Bewährtes Werkzeug aus der Java-Welt. ● Vergleichsweise einfach und deterministisch. ● Viele fertige Aufgaben (Tasks). ● Einfache Einbindung von Python-Projekten in Jenkins.