Filed Under (Mercurial, Pylons, Python) by Marcin Kuźmiński on 27-07-2010
Tagged Under : , , , ,

It’s been some time, hg-app is still in rapid development.

DEMO: http://hg.python-works.com

TRACKER: http://bitbucket.org/marcinkuzminski/hg-app/issues

Since last time hg-app got:

  • Full permissions per repository system.
  • Yui float graphs
  • New gui
  • Database based settings and hooks
  • Huge number of bugfixes.

Below few screenshots of new hg-app gui.



Filed Under (Mercurial, Pylons) by Marcin Kuźmiński on 07-06-2010
Tagged Under : , ,

After some code fixups, and corrections i manage to set up a working demo of hg app.
This demo, has all functionality of hg app and will be updated during application life to current version.

Demo is available at http://hg.python-works.com

Any feedback is welcomed and can be posted to http://bitbucket.org/marcinkuzminski/hg-app/issues

Thank you !



Filed Under (Mercurial, Pylons, SqlAlchemy, Threads) by Marcin Kuźmiński on 01-06-2010
Tagged Under : , , , , ,

Since, me and Lukasz fine tuned the vcs library i manage to setup a beta version of hg app. I was tired of the boring looks, and poor source code browsing capabilities of the hgwebdir.
So i started to write my own app, at the beginning it was just a simple hgwebdir wrapper, to pylons, now it’s fully standalone replacement. Including abilities to push/pull thrum the application.

Pylons based replacement for hgwebdir. Fully customizable,
with authentication, permissions. Based on vcs library.

  • has it’s own middleware to handle mercurial protocol request each request can
    be logged and authenticated +threaded performance unlikely to hgweb. Middleware recognises a mercurial protocol
    and skips any functionality for pure web request
  • mimics full functionality of hgwebdir including feeds,archives,diffs,raw-diffs,annotations,file history etc.
  • mako templates let’s you customize look and feel of the application.
    Possibly visual merge with your company systems
  • diffs annotations and source code all colored by pygments (see screenshots).
  • admin interface for performing user/permission managements as well as repository
    managements. Out of beta version should have fully customizable permission system, with
    private repos, and repo permissions
  • added cache with invalidation on push/repo managment for high performance and
    always upto date data.
  • rss / atom feeds
  • future support for git (thanks to vcs mercurial/git api should be 1:1
  • based on pylons 1.0 / sqlalchemy 0.6 /sqlite(possibly mysql/postgres thanks to sqlalchemy models)

Below are the beta version screenshots. Now I’m not good at designing webapps, so excuse me if you feel the look&feel to be to simple or bad looking.
It’s all i could come up with. Most of my expiration was taken from hgwebdir/bitbucket and github. I tried to take all best parts from all of them and combine into this app.
It’s still in beta but i think it’s production ready in this stage I’m using it for few weeks, and had no troubles or crashes with it. The code can be grabbed at bitbucket repo http://bitbucket.org/marcinkuzminski/hg-app/



Filed Under (Django, Mercurial, Pylons, Python) by Marcin Kuźmiński on 02-05-2010
Tagged Under : , , , , , ,

Since Me and Lukasz started this project a while ago, it’s time to announce that we shipped out first public Beta release.

It’s available on PyPi as “vcs”, so you can install it using PIP or EASY_INSTALL.

Simply run to download and install it.

easy_install vcs
pip install vcs

Lukasz made a nice documentation, and quick starts available here http://packages.python.org/vcs/

The vcs API:

Features

  • Common API for SCM backends (mercurial is the first and only one available right now)
  • Fetching repositories data lazily (performance and easy of use)
  • Simple caching mechanism so we don’t hit repo too often (so a refresh on a 2000 commit repo wont kill  the cpu)

Incoming

  • Django app for mercurial hgserve replacement – this is probably going to be a part of the vcs library
  • Pylons app for mercurial replacement – this is my little project which i finished roughly in 70% of functionality that hgwebdir does.
  • Command line client

Few things are worth mentioning.
The key point of vcs to have the same api for various SCM-s so mercurial,git,subversion(maybe others) will have
a same way for data access,objects structures and so on. Imagine how fast and simple you could extend an web app which uses
mercurial as a SCM to GIT, simply replace the repo path to git and all should work. Of Course there are some differences between git and mercurial
that could be handled in the same maner, and this is also simply handled by a private methods, specific for a SCM.

This is of course an open source project and any contributors are always welcomed.



Filed Under (SqlAlchemy) by Marcin Kuźmiński on 22-04-2010
Tagged Under : , , ,

Few days ago there’s been a mayor release of SqlAlchemy.
There are a lot of bugfixes new features in tis release, but four things
are worth mentioning in this major release. Beaker caching for Query.
- RETURNING Support on insert, update and delete – might come in very handy.
- Pickable query result. Means sqlAlchemy objects could be kept in sessions (did not check that)

After some checks i decided to move my projects to the new version, since i did that i needed to
update my model generator for SqlAlchemy it’s been rewritten for sqlalchemy 0.6
and now works with 0.5 and 0.6 versions. Additionally i made some small fixes i found. Any feedback is welcomed.



Filed Under (Python) by Marcin Kuźmiński on 14-03-2010
Tagged Under : , , , ,

I love Setuptools, and easy_install. Since most of my time i work on virtualenv, I’m using setuptools quite frequently, but
few things i always missed about easy install,and I’m not going to write here what easy_install is missing, but rather how to
make it more flexible. The great tool i found recently on some python forum is yolk.

Yolk is “Command-line tool querying PyPI and Python packages installed on your system”
Yolk can list your current environment packages including some useful additional information about them like ‘active’ or
‘non-active’ packages, it can list packages that could be upgrade (simply yolk -U).

Before I’d had to manually search my python path and copy/paste each package to easy_install -U, what was quite annoying.
Now in few seconds i can get the list of upgradable packages and upgrade them.

Another great tool in yolk is PyPI quering. For example:

$ yolk -F Paste
     Download source tarball for latest version of Paste to your current directory

$ yolk -F Paste -T svn
     Do a subversion checkout for Paste to a directory named Paste_svn in your current directory.

$ yolk -L 2
     Show list of CheeseShop releases in the last two hours

So you can always get the news from PyPI and maybe find some interesting packages.
If your using easy_install i’m quite sure you will love yolk.



Filed Under (Django, Python) by Łukasz Balcerzak on 21-02-2010
Tagged Under : , , ,

We have no time for creating documentation for our project… wrong! Documentation and tests are crucial in all software projects. Sure, it is more important that our software would work fine but package of unit tests almost always save time (in future as less bugs are produced) and without documentation shouldn’t be treated as “user guide”.

It doesn’t matter if you are creating project for your company or you plan to release it as an open source – by providing documentation you make life easier for other contributors and end-users, of course. And if you know how to write restructuredText documents then you already own necessary skills to create documentation lighting fast!

Prepare!

First of all, you would need to have Distutils and Sphinx installed. You can install it using one of the Python package management tools, in example easy_install would do the job. I prefer to use pip:

pip install distutils
pip install sphinx

Simply use any project you’d like to create documentation for, I would use django-richtemplates. Create a new directory for your documentation and run sphinx-quickstart command:

hg clone https://bitbucket.org/lukaszb/django-richtemplates/ django-richtemplates-temp
cd django-richtemplates-temp
sphinx-quickstart

Just answer some questions – they are very straightforward. You should probably turn autodoc option on.
Sphinx would create some directories for internal usage and static content storage (_build, _static and _templates), configuration file (conf.py) and index file (index.html). Ok, enough of this crap, lets create our first documentation page!

First page

Create new file, lets call it installation.rst and write the document itself:

.. _installation:

============
Installation
============

Fake installation for `django-richtemplates`_ project.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.

.. note::
   Yeah, this would be a note.
   Very simple, indeed.

Some more crap
--------------

If you would like to highlight a code snippet, it is as easy as::

   from mycompany.auth import AuthenticationBackend

   class MyClass(object):
       """
       Docstring.
       """
       def __init__(self, *args, **kwargs):
           """
           Some *business* logic.
           """
           pass
       def authenticate(self, username, password):
           """
           External authentication process.
           """
           auth = AuthenticationBackend(username, password)
           return auth.is_authenticated()

Or choose language explicit:

.. code-block:: bash

   cd django-richtemplates
   sudo python setup.py install

Yeah, `restructuredText `_ is great!
And easy, too.

External-internal hyperlinks
----------------------------

You may also use ``sphinx`` features, like linking to other *documents*, like
this: go to :ref:`configuration`.

.. _django-richtemplates: http://bitbucket.org/lukaszb/django-richtemplates/

This is standard restructured text document. The only sphinx specific parts are first line (need to add relation with file itself – this is needed for table of contents generation) and reference to other file (which is done with ref:`configuration`). Yup, we haven’t created configuration.rst file, yet. So do this now, and paste following:

.. _configuration:

=========================
Configuring richtemplates
=========================

I hope you have already read chapter :ref:`installation`.

Lorem ipsum!
------------

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.

Don’t forget about the main page!

I once hoped that the first page (namely index.rst) is generated automatically, yet, I was wrong. But in order
to supply needed data for sphinx generator you have to make very simple changes to the index.rst. Just add
:glob: option to the toctree directive. Finally, mark that all (*) restructuredText documents should
be used.

.. django-richtemplates documentation master file, created by
   sphinx-quickstart on Sat Feb 20 21:42:53 2010.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to django-richtemplates's documentation!
================================================

Contents:

.. toctree::
   :maxdepth: 2
   :glob:

   *

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

Now in mydocs directory run

make html

and open file located at mydocs/_build/html/index.html. You should see your documentation!

Final words

Ok, this was very simple and the effect is – for such a little work done – quite amazing if you’d ask me.
However, we still haven’t used autodoc Sphinx’s extension. Let’s do that now – create new file
api.rst and paste whats below:

.. _api:

===
API
===

You can find some basic API information here.

Forms API
---------

In this section we cover some basics about the `django-richtemplates`'s forms
API.

.. automodule:: richtemplates.forms
   :members:

.. _django-richtemplates: http://bitbucket.org/lukaszb/django-richtemplates/

Again, run make command and see your documentation. Ok, so where is your API, you ask? Well, if you look at the output
of make html command you’d see that there was a warning – richtemplates.forms couldn’t be found.
Which is completely correct, as Sphinx doesn’t try to guess where your modules are, you have to configure it by yourself.
Change sys.path by uncommenting existing line and change it to this:

sys.path.append(os.path.abspath('..'))

If you are not sure why why put .. there, it’s simple – Sphinx would go a one directory up (..) and try to find richtemplates there. Try to build your documentation now. Warning again? Yeah, Sphinx now complains about not
having DJANGO_SETTINGS_MODULE which is, again, totally correct. As importing richtemplates won’t
raise exception, but trying to get deeper into the module (richtemplates.forms) would be impossible without
being within Django context (same would happen if you try to run python interpreter and run from django import forms).
So add this line into your conf.py file:

os.environ['DJANGO_SETTINGS_MODULE'] = 'django.conf.global_settings'

More information about autodoc extension could be found here.

Hope this would help anyone trying to start with his/her own documentation :)
If you have any suggestions – let me know.

Take care and make documentation, not war.



Filed Under (Editors, Python) by Marcin Kuźmiński on 10-02-2010
Tagged Under : , , , , ,

makers of a great ruby on rails IDE rubymine, and ever greater Java IDE intelliJ, released
another (probably) great idea product named pycham, a python IDE, written from scratch in Java.

Since IntelliJ is a really the best Java IDE out there, i presume their next product
dedicated to python will be worth switching.

It’s still in preview but as for now it provides:

  • Coding Assistance
  • Project Code Navigation
  • Google App Engine Support
  • Code Analysis
  • Python Refactoring
  • Web Development with Django (some really nice ones)
  • debugger
  • Integrated unit tests
  • Version control integration



I’d tested under linux, seems to be a littler slower than my eclipse home brew version, but I’d expect the final version faster. It has few nice features, easy configuration, code completion are doing fine.
You can grab a free 45 day copy from here.

I’ll for sure fallow this product development. Stay posted for more !



Filed Under (Python, SqlAlchemy) by Marcin Kuźmiński on 09-02-2010
Tagged Under : , ,

I’m in a way of releasing few of my projects to bitbucket.
Starting now I’m releasing the Sqlalchemy model generator. A quick reminder, it’s a project that you
can generate models based on your database. So you don’t need to write models by yourself.
You can see the project here: http://bitbucket.org/marcinkuzminski/sqlalchemy_model_generator/
Any participants are welcomed.



Filed Under (Python) by Marcin Kuźmiński on 08-02-2010
Tagged Under : , , , , , , ,

I’d created another simple application in pylons, final step was to translate it from English to Polish.

I used the babel extractor recommended by pylons and that went really smooth.

My application have a language selector available anytime from menu.
I saw that even this switch worked very well for mako templates and string inside controllers,
it did not work when displaying my custom messages that i over rid in validators
and also did not work in my own custom validators that inherit from FancyValidator.
So i started to investigate this.

The first problem of not translating custom error messages in the regular formencode validators was easily being fixed by using lazy_ugettex method.

def _(s):
    #fix for translation error messages
    return lazy_ugettext(s)

This method allowed me to use lazy_ugettext to translate.
So now when in the validators your translating a string using _(‘this string is for translate’) method it’s actually wrapper for lazy_ugettext function.
Lazy translation is when you translate a string when it is accessed, not when the _() or other functions are called.

The second problem of translating custom error messages in your own validator was a bigger problem

I was looking for a solution for some time, and found a nice trick. You have to use your own
state_obj with static _() function. As example below for custom validation function.

class ValidLoginNames(formencode.validators.FancyValidator):

    messages = {'invalid_name':_('you cannot use %(username)s as login')}

    def validate_python(self, value, state):
        banned_names = ['admin', 'administrator', 'root']
        if value in banned_names:
            raise formencode.Invalid(self.message('invalid_name', state = State_obj, username = value), value, state)

#this is needed to translate the messages using _()
class State_obj(object):
    _ = staticmethod(_)

Those two trick now let’s you translate custom validators without a problem.