Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step...

29
WaterGisWeb AG Donnerbühlweg 41 CH-3012 Bern www.watergisweb.ch [email protected] Tel. 031 / 305 18 11 Fax 031 305 18 14 Python und Geoprocessing mit Eclipse und PyDev Yvo Weidmann Dipl. Ing. Geomatik FHNW MAS Software Engineering FHB

Transcript of Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step...

Page 1: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

WaterGisWeb AG

Donnerbühlweg 41CH-3012 Bern

[email protected]

Tel. 031 / 305 18 11Fax 031 305 18 14

Python und Geoprocessing mit Eclipse und PyDev

Yvo WeidmannDipl. Ing. Geomatik FHNW

MAS Software Engineering FHB

Page 2: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Inhalt

• Eclipse, Bezug und Installation

• Geoprocessing

• PyDev

• Code Coverage

• PyUnit

• Debugging

• Dokumentation

• Versionierung

• Zusammenfassung

Page 3: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Übersichtskarte

Eclipse

Dokumentation

Python

Geoprocessing

Versionierung

PyDev

PyUnit

Code Coverage

Debugging

Page 4: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Eclipse

Eclipse Project: 2001 von IBM und verschiedensten

Software Herstellern gegründet

Eclipse Foundation: 2004 als unabhängige not-for-

profit reorganisiert

Breit abgestützte Open-Source Community in

Entwicklung und Nutzung

Quasi-Industriestandard in Java-Entwicklung

Unzählige Open-Source und kommerzielle PlugIns

Framework für verschiedenste Programmiersprachen

Eclipse ist eine integrierte Software

Entwicklungsumgebung (IDE)

Page 5: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Eclipse > Bezug

Direkt von Eclipse

Download verschiedensten Konfigurationen von

http://www.eclipse.org

Freier Eclipse Download Service

Download individuellen Konfigurationen von

http://ondemand.yoxos.com/geteclipse/start

Page 6: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Eclipse > Bezug > yoxos

Page 7: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Eclipse > Installation

Benötigt keinen Installationsvorgang auf dem lokalen

Rechner

Aktuelle Java-Laufzeitumgebung ist Bedingung

Verschiedene Konfigurationen parallel auf dem

lokalen Rechner lauffähig

Auspacken der von yoxos bereitgestellten und

heruntergeladenen ZIP-Datei

PlugIns über Find and Install direkt aus Eclipse

installierbar

Page 8: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Eclipse > IDE

Projekt

Explorer

Editor

Objekt

Katalog

Weiter Info (Tasks, Console, ...)

Page 9: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Übersichtskarte

Eclipse

Dokumentation

Python

Geoprocessing

Versionierung

PyDev

PyUnit

Code Coverage

Debugging

Page 10: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

PyDev

Open-Source PlugIn in Eclipse

Entwicklung von Python-Programmen

http://pydev.sourceforge.net/

• Interaktive Python Konsole (ab Version 1.3.19)

• Debugging

• Code Coverage

• Unit Test

• Autocompletion

Einige Features:

• Refactoring

Page 11: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Übersichtskarte

Eclipse

Dokumentation

Python

Geoprocessing

Versionierung

PyDev

PyUnit

Code Coverage

Debugging

Page 12: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

PyDev > Geoprocessing

Vorbereitung: Pfad der ArcGIS-Installation in

PYTHONPATH integrieren

ArcGIS Geoprocessor mit PyDev

Das Geoprocessor Programming Model kann direkt

verwendet werden.

Page 13: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Übersichtskarte

Eclipse

Dokumentation

Python

Geoprocessing

Versionierung

PyDev

Code Coverage

Debugging

PyUnit

Page 14: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

PyDev > PyUnit

Testgetriebene Entwicklung

PyDev integriert die Unit-Test Umgebung PyUnit. Diese

kann für normale Python- und Geoprocessing-

Anwendungen verwendet werden.

• Implementation von Test-Klassen und -Methoden

• Zusammenfassung in Test-Suiten

• Automatisierte Testabläufe

• Ausgabe der Test-Erfolge

Geschäfts-Klassen

Test-Klassen

Test-Methoden

Page 15: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

testAreFieldsEquals (TableHandlingTest.CTableHandlingTest) ... ok

testCTableParameter (TableHandlingTest.CTableHandlingTest) ... ok

testCreateTable (TableHandlingTest.CTableHandlingTest) ... ok

testCreateTableWA (TableHandlingTest.CTableHandlingTest) ... FAIL

testToStringField (TableHandlingTest.CTableHandlingTest) ... ok

===================================================================

FAIL: testCreateTableWithAttributes

(TableHandlingTest.CTableHandlingTest)

-------------------------------------------------------------------

self.assertEqual

AssertionError: 7 != 6

-------------------------------------------------------------------

Ran 5 tests in 47.422s

FAILED (failures=1)

PyDev > PyUnit

Ausgabe: Die Resultate werden in der Konsole ausgegeben.

Durchführung

Nach der Implementation der Test-Klassen und -Methoden

können die Tests automatisiert durchlaufen werden.

testAreFieldsEquals (TableHandlingTest.CTableHandlingTest) ... ok

testCTableParameter (TableHandlingTest.CTableHandlingTest) ... ok

testCreateTable (TableHandlingTest.CTableHandlingTest) ... ok

testCreateTableWA (TableHandlingTest.CTableHandlingTest) ... ok

testToStringField (TableHandlingTest.CTableHandlingTest) ... ok

-------------------------------------------------------------------

---

Ran 5 tests in 114.813s

OK

Page 16: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Übersichtskarte

Eclipse

Dokumentation

Python

Geoprocessing

Versionierung

PyDev

PyUnit

Code Coverage

Debugging

Page 17: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

PyDev > Debugging

• Step In, Step Over, Step Return

• Breakpoints / Conditional Breakpoints

Debugging von Python und Geoprocessing Projekten

PyDev integriert die Unit-Test Umgebung PyUnit. Diese

kann für normale Python- und Geoprocessing-

Anwendungen verwendet werden.

Vorbereitung: Jedes lauffähige Python-Modul kann mit

dem Debugger durchlaufen werden.

Einige Features:

• Anzeige der aktuellen Werte von Variablen

Page 18: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

PyDev > Debugging

ThreadsBreakpoints

Variables

Tools

Editor mit Breakpoints und

Debugger

Page 19: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

PyDev > Debugging

Variables

Name Typ: Wert

Page 20: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

PyDev > Debugging

Breakpoints

Conditional Breakpoint

Aktive und inaktive Breakpoints

Page 21: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Editor

PyDev > Debugging

Schrittweises Debugging

Mit den Tools Step In, Step Over und Step Return lässt sich

der Code schrittweise durchlaufen.

Debugging-Tools

Aktuelle Position des Debuggers

Toolbar

Page 22: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Übersichtskarte

Eclipse

Dokumentation

Python

Geoprocessing

Versionierung

PyDev

PyUnit

Code Coverage

Debugging

Page 23: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

PyDev > Code Coverage

Code Coverage

Mit der Code Coverage Analyse lassen sich beliebige

Module analysieren

-> Anzeige von nicht verwendeten Code Zeilen und Anzahl

der Ausführungen.

• Auffinden von „totem“ Code

• Suche von nicht getestetem Code bei Unit-Tests

Anwendung:

Module Resultat

Page 24: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Übersichtskarte

Eclipse

Dokumentation

Python

Geoprocessing

Versionierung

PyDev

PyUnit

Code Coverage

Debugging

Page 25: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Versionierung

Versionierung von Python Modulen

Es existieren PlugIns für die gängigen Versionierungs-

plattformen:

• Visual Source Safe

• CVS

• Subversion

Page 26: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Übersichtskarte

Eclipse

Dokumentation

Python

Geoprocessing

Versionierung

PyDev

PyUnit

Code Coverage

Debugging

Page 27: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Dokumentation

Doxygen auch für Python

Doxygen (www.stack.nl/~dimitri/doxygen/) als externes Tool

in Eclipse eingebunden:

• Check der Kommentarsyntax, Prüfung Vollständigkeit

• Verwendung von XML-Kommentarsyntax

• Ausgabe in u.a. in HTML

Page 28: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Zusammenfassung

Unterstützung der Sprache Python

Eclipse mit PyDev

bildet eine geeignete Plattform für die

Entwicklung für Geoprocessing.

Grosser Memory-Verbrauch von Eclipse

Hilfreich bei grösseren Projekten

(Packages, Objektorientierte Lösungen, ...)

Zahlreiche Hilfsmittel moderner IDE's

(Unit-Test, Coverage, Refactoring, ...)

Schwerfällig bei „Alltagsproblemen“

(Console)

Overhead bei kleinen Projekten /Skripten

+

-

Page 29: Python und Geoprocessing mit Eclipse und PyDev...2008/11/19  · PyDev > Debugging •Step In, Step Over, Step Return •Breakpoints / Conditional Breakpoints Debugging von Python

Schluss