First steps with Python and Eclipse IDE

I am beginning my new academic year at MSWL and my first subject is Development and Tools. I opened my eyes, closed them, opened again and three weeks are gone!
Israel Herraiz introduced Git and Python, and Micael Gallego introduced Eclipse IDE.

About Git

In other post I will explain my adventures with git, I already played a little bit and made several mistakes, so they deserve a special blog post.

About Python

Last week I began to write a Python script to recursively get the links present in a website. This is part of my homework. I called it larjona-crawler, and uploaded my project to my git repo (dt branch) and to the Python Package Index (PyPI). Here is the page of the project.

About Eclipse

This week I am trying to continue the development of my crawler, but using Eclipse IDE.

I already had java packages installed in my Debian Squeeze so I downloaded version Indigo from official website and uncompressed it in /home/larjona

I wanted to install EGit and PyDev plugins. Installed EGit with no problems from Eclipse Marketplace. With PyDev I had an error:

No repository found at http://pydev.org/updates/.

I went to pydev.org and downloaded the zip file (in fact, from SourceForge), uncompressed it in eclipse folder (the files were then copied to features and plugins folders) and opened Eclipse. It worked.

I configured PyDev going to Window > Preferences > PyDev > Python Interpreter and pressing the Auto Config button.

Then I had to configure EGit: went to Window > Preferences and search “Git”, under Git I set the default repository folder to my Documents folder, and in Configuration I checked that my .gitconfig options were there.

Then, I tried to put into Eclipse my git repo, with its dt branch and of course the larjona-crawler script. I imported my local git repo going to File > Import > Git > Projects from git. There I could add the local repo pressing the button “Add” and setting the location, or clone my Gitorious repo. I chose the first one and everything went ok.

I wanted to try the “Clone” option, so I went again to File > Import > Git > Projects from git, and clicked on “Clone”. I tried with the HTTPS URI https://git.gitorious.org/mswl-larjona-docs/mswl-larjona-docs.git, and also with the git one: git://gitorious.org/mswl-larjona-docs/mswl-larjona-docs.git, both of them accessing my remote repo and letting me choose the branches to clone (this is interesting, because I want to use Eclipse only in my dt branch, at least for now). I pressed “Finish” and a dialog appeared “Cloning from https://git.gitorious.org/mswl-larjona-docs/mswl-larjona-docs.git …” with a progress bar. Five minutes passed and nothing happened, no progress shown (the folder was created, but it stayed empty). I canceled the operation. Tried again this time with the git protocol, and went ok. Tried again with the https protocol, and went ok.

Using Eclipse IDE for Git commits

Before continuing the development I wanted to get familiar with this new interface for git. I made some commits: the creation of an Eclipse project and subsequent creation of .project and .pydevproject file, remove the folder and files created by registering the script in PyPI website.
For each change, I made the commit by right-clicking in any file of the project and selecting Team > Commit.
Later I pushed the changes to my gitorious repo by right-clicking the project main folder and selecting Team > Push to upstream. Quite easy (but for this basic commands, the command-line is quite easy too!).

Writing Python with Eclipse IDE

My main script, larjona-crawler, is written in Python but has no .py extension. So the source code is shown as plain text, with no colors and all its beauty :S
I renamed the file to larjona-crawler.py, opened with double click, closed, and renamed the file again to remove the extension: Eclipse still “remembers” that is written in Python. Later I learned that you can right-click on the file and choose Open with > Other > Python editor, with the same effect.

Here is how my Eclipse workspace looks like now:

eclipse-pydevFor testing my script, I created a “Run configuration” with the comandline arguments.

run-configuration

Finally, I wanted to change the name of a variable, so I right-clicked on the variable and selected Refactorize > Rename. The new name was set in the two ocurrences of that variable. Commited the changes.

And enough for today!

About larjona

My name is Laura Arjona, I am a libre software user and fan of the free culture. If you want to contact me you can write an email to larjona [at] larjona [dot] net I am @larjona at identi.ca in the Pump.io social network. --- Me llamo Laura Arjona, soy usuaria de software libre y fan de la cultura libre. Si quieres contactar conmigo puedes escribir a larjona [en] larjona [punto] net Soy @larjona en el servidor identi.ca, de la red social Pump.io.
This entry was posted in My experiences and opinion and tagged , , , , , , . Bookmark the permalink.