Wednesday, December 01, 2010

How to set up buildAPI locally

I wanted to give a hand to one of our Seneca students (Andrew Singh) that are contributing to release engineering. He is working on creating a report for buildapi.
To do so I had to set up buildapi locally and I was so lucky to be the guinea pig for Mac OS X ;)

Big thanks for ssalbiz and catlee for helping me debug this.

I followed the instructions that ssalbiz wrote https://wiki.mozilla.org/ReleaseEngineering/BuildAPI#Getting_Started:
  • Downloaded MySQL Community Server(Current Generally Available Release: 5.1.53)
  • Add mysql to your path:
export PATH=/usr/local/mysql/bins:$PATH 
echo "export PATH=/usr/local/mysql/bins:$PATH" > ~/.bash_profile
  • Create a new user to use with buildapi. I read this documentation.
mysql --user=root mysql

mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' WITH GRANT OPTION;
  • Create the databases and import them.
mysql -u -p
mysql> create database schedulerdb; create database statusdb;
mysql> exit
mysql -u -p schedulerdb < schedulerdb.sql
mysql -u -p statusdb < statusdb.sql
  • Setup buildapi:
hg clone http://hg.mozilla.org/build/buildapi
cd buildapi; sudo python setup.py install; cd ..

mkdir dist
cd dist; wget http://google-visualization-python.googlecode.com/files/gviz_api_py-1.7.0.tar.gz
sudo easy_install gviz_api_py-1.7.0.tar.gz
cd ..

paster make-config buildapi config.ini

# edit your config.ini with the right information
# sqlalchemy.scheduler_db.url = mysql://monty:some_pass@localhost/schedulerdb
# sqlalchemy.status_db.url = mysql://monty:some_pass@localhost/statusdb
  • Start buildapi
paster serve --reload --daemon config.ini

NOTE: I believe that if the following is respected you should not hit all the problems that I hit in the next section:
  • Install the 64-bit version of MySQL
  • Install buildapi with "python setup.py install" instead of "easy_install buildapi"

PROBLEMS

I tried to load http://localhost:5000 but it didn't work.

Now I tried it without --daemon and I got this:
armenzg-laptop $ paster serve --reload config.ini
Starting subprocess with file monitor
Traceback (most recent call last):
File "/usr/local/bin/paster", line 8, in
load_entry_point('PasteScript==1.7.3', 'console_scripts', 'paster')()
File "/Library/Python/2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/command.py", line 84, in run
invoke(command, command_name, options, args[1:])
File "/Library/Python/2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/command.py", line 123, in invoke
exit_code = runner.run(args)
File "/Library/Python/2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/command.py", line 218, in run
result = self.command()
File "/Library/Python/2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/serve.py", line 276, in command
relative_to=base, global_conf=vars)
File "/Library/Python/2.6/site-packages/PasteScript-1.7.3-py2.6.egg/paste/script/serve.py", line 313, in loadapp
**kw)
File "/Library/Python/2.6/site-packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py", line 204, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/Library/Python/2.6/site-packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py", line 225, in loadobj
return context.create()
File "/Library/Python/2.6/site-packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py", line 625, in create
return self.object_type.invoke(self)
File "/Library/Python/2.6/site-packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py", line 110, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/Library/Python/2.6/site-packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/util/fixtypeerror.py", line 57, in fix_call
val = callable(*args, **kw)
File "/Library/Python/2.6/site-packages/buildapi-0.1dev-py2.6.egg/buildapi/config/middleware.py", line 37, in make_app
config = load_environment(global_conf, app_conf)
File "/Library/Python/2.6/site-packages/buildapi-0.1dev-py2.6.egg/buildapi/config/environment.py", line 48, in load_environment
scheduler_engine = engine_from_config(config, 'sqlalchemy.scheduler_db.')
File "/Library/Python/2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/__init__.py", line 272, in engine_from_config
return create_engine(url, **opts)
File "/Library/Python/2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/__init__.py", line 254, in create_engine
return strategy.create(*args, **kwargs)
File "/Library/Python/2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/strategies.py", line 60, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/Library/Python/2.6/site-packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/dialects/mysql/mysqldb.py", line 101, in dbapi
return __import__('MySQLdb')
ImportError: No module named MySQLdb
I will now list the SOLUTION and after that the other route I first took and lead me to nowhere.

For reference, this problem is hit in many different ways by many different people:

SOLUTION

rm -rf /Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg
easy_install mysql-python
  • This should work now:
python -c 'import MySQLdb'
  • I think it should work now
paster serve config.ini

FAILED ATTEMPT

NOTE: I am just typing this failed attempt for the record and to maybe bring some frustrated people with the same problem to "a solution".

Resuming from ImportError: No module named MySQLdb.

It seems that I am missing the MySQLdb for python:
sudo easy_install mysql-python
which errors on me:
EnvironmentError: mysql_config not found
The problem is that mysql_config in the package's site.cfg file (download the source package if you want to see that file) points to mysql_config = /usr/local/bin/mysql_config
You can fix this in several ways:
  1. Add a symlink "ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config"
  2. Add /usr/local/mysql/bin to your PATH
  3. Download the mysql-python package and modify site.cfg

I thought that installing mysql-python would fix things but I as you can see I can't even do this on python:
armenzg-laptop $ python -c 'import MySQLdb'
Traceback (most recent call last):
  File "", line 1, in
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/armenzg/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
        /Users/armenzg/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture
For the record I also tried this:
pip install -I mysql-python

OTHER

Something that I found to be interesting/nit:
armenzg-laptop $ file $(which python)
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc
armenzg-laptop $ file $(which mysql)
/usr/local/mysql/bin/mysql: Mach-O executable i386
After I installed MySQL 64-bit:
armenzg-laptop $ file $(which mysql)
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64



Creative Commons License
This work by Zambrano Gasparnian, Armen is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

No comments:

Post a Comment