Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Saturday, August 5, 2017

Debugging Dependencies of Django Project in Eclipse

This is another one of those posts to help myself in the future.  I've got some legacy python projects whose directions only get you a django app running in a virtualenv within eclipse but the dependencies themselves are not debuggable.

It was straightforward once I found the right advice.

If you're like me and have a build that creates a virtualenv with everything installed already by pip and a requirements.txt file.  Here's how to get the environment and eclipse changed so that you can debug any dependency.

#Step 1.  Remove the dependencies files from the virtualenv


This works for mac and uninstalls files that might have spaces in them too
python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then:
tr
'\n' '\0' < files.txt | xargs -0 sudo rm -f --

I figured that out after a few different attempts and the best way to do it came from StackOverflow here:  https://stackoverflow.com/a/25209129

 

#Step 2. Add the source folder as an external build dependency on the Python Interpreter Path


Add source folder to eclipse for debugging dependency

 

 

 

 

 

Credit for this step goes to a small sentence buried here:  https://lukeplant.me.uk/blog/posts/eclipse-pydev-and-virtualenv/

 

That's it.  Restart your django server and set a breakpoint inside that internal dependency.

This will save you a ton of time vs. all those import pdb; pdb.set_trace() statements

Drawbacks


This will break the virtualenv from the command line so for things like python manage.py commands.  For those items, I went ahead and set up a second virtualenv.

Monday, March 15, 2010

Mechanize vs. Scrape:

In the process of automating functional tests, I have ran across another python library, mechanize, that looks to be very promising. Perhaps, even more so than scrape.py?

http://wwwsearch.sourceforge.net/mechanize/
http://stockrt.github.com/p/emulating-a-browser-in-python-with-mechanize/

So far it seems that the mechanize platform is more powerful, as it is able to handle complex tasks like managing a gmail inbox( see http://libgmail.sourceforge.net/ ).

My take so far is that scrape.py offers some nice features for validating that a given page has the tags and elements I am looking for. I'm still new to both of these libraries so if anyone out there has experience with both and could help nudge me in the right direction, it would be much appreciated.

Monday, March 8, 2010

Installing the PIL: Mac OS X 10.6 and Python 2.6.4

In short, learn from others:

Install python manually: http://twitter.com/delagoya/status/9883676332

Setup PIL w/jpeg support in a virtualenv: http://breadandpepper.com/blog/2009/oct/2/django-development-snow-leopard/

And now you've got a top notch django dev env running py 2.6.4.

Monday, March 1, 2010

scrape.py for functional website testing

This solution is perfect for testing your website's functional capabilities. Scrape.py supports sessions and cookies so hitting your authenticated resources is cake.

Here's a quick sample i wrote to test things out:
from scrape import *
s.go("http://www.google.com")
s.follow("Sign in")
x = s.doc.first('form')
params = x.get_params()
params['Email']='keithentzeroth'
params['Passwd']='xxxxxx'
s.submit(x,params)
s.go("http://www.google.com")
print s.doc

Try it out with your google account. To verify you're logged in look for the Sign Out link or alternatively look for a GAUSR cookie in s.cookiejar.

Thanks to Ka-Ping himself for clearing up some of my confusion.

My plan is to use this to test the site as if there were no script/styles enabled. Then to layer on browser behavior ( AJAX etc...), I'll look to Selenium or something of the kind.

Thursday, January 14, 2010

Appengine + Django 1.1

So i got past my previous post with a different cell phone number. Now I know getting an appengine account is a more difficult than most online accounts. It makes sense too given free website hosting is at stake.

Anyhow, after a short time i was able to get django 1.1 up and running on appengine. For a little clarity, this provides all the glory of django templates, urls.py, middleware, forms, settings. But because of the big table db implementation of appengine, the admin tool, auth, session, and anything else built-in and dependent on django models will not work.

I found some other blogs that were close, but none of the step by steps worked for me. I followed instructions found at goole python libraries - django.

Since i learn best from code, I checked a basic project into github that i'll continue to update on git as i make updates.

Browse the code on git.

Monday, October 12, 2009

Django Web Framework

So i slammed my old XP machine with Ubuntu this weekend and set to go through the django tutorial.

I'd already had a little experience with django, but hadn't gone through the basics as another team member had set up our project.

After going through the tutorial, http://docs.djangoproject.com/en/dev/intro/tutorial01, i am confident that the way django encompasses the business model in its use of models.py, maps urls in urls.py, and provides a free admin tool makes it the best "framework" for creating web sites quick and easy. Pair this framework with what is already known to be an easy language, python, and you've got a winner.

I've yet to use django/python on anything over a month project, so i can't really comment on whether or not Cal Henderson's, www.iamcal.com, statement that if you need to build a "serious" website than the advantages of using a framework like django will at some point come crashing down by the need to modify and adapt the framework for your specific usages.