Python For Human

6 views
Skip to first unread message

sweemeng ng

unread,
Jan 3, 2012, 10:10:54 AM1/3/12
to python.my
http://python-for-humans.heroku.com/#1

This is a insightful slides on problem with python. 

Real interesting stuff

--
Just a random living organic computer code generator

Mohd Izhar Firdaus Ismail

unread,
Jan 3, 2012, 10:18:44 AM1/3/12
to pyth...@googlegroups.com
one thing i discover with buildout , it forces me to write proper setup.py ..

friends tell friends to NEVER import non-core modules in setup.py .. NEVER! ..

> --
> You received this message because you are subscribed to the Google Groups
> "python.my" group.
> To post to this group, send email to pyth...@googlegroups.com.
> To unsubscribe from this group, send email to
> pythonmy+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pythonmy?hl=en.

--
Mohd Izhar Firdaus Bin Ismail / KageSenshi
Inigo Consulting (FOSS/Plone Development, Training & Services)
http://www.inigo-tech.com
Fedora Malaysia Contributor & Ambassador
http://blog.kagesenshi.org
92C2 B295 B40B B3DC 6866  5011 5BD2 584A 8A5D 7331

Mohd Kamal Bin Mustafa

unread,
Jan 3, 2012, 5:18:46 PM1/3/12
to pyth...@googlegroups.com
On Tue, Jan 3, 2012 at 11:18 PM, Mohd Izhar Firdaus Ismail
<kagese...@gmail.com> wrote:
> one thing i discover with buildout , it forces me to write proper setup.py ..
>
> friends tell friends to NEVER import non-core modules in setup.py .. NEVER! ..

The reason buildout fail to import any modules in the current
directory is because it remove current directory from sys.path. Some
people take advantage that python can do relative import and importing
from current directory is possible to implement some functionality
that they need from their own module. For example, you might want to
provide an API for user to get the current version of your module so
yourmodule.get_version() seem logical here and of course since you
already implement that function you want to use it in setup.py.
Buildout break this assumption and default behavior of python.

Mohd Izhar Firdaus Ismail

unread,
Jan 3, 2012, 7:50:30 PM1/3/12
to pyth...@googlegroups.com

no ,it fails because not everyone run setup.py, inside the directory
.. buildout doesnt remove the current path .. but the current path is
different.. scripts especially ..

importing from current path is a frail assumption, and shouldnt be done ..

Mohd Kamal Bin Mustafa

unread,
Jan 3, 2012, 8:40:42 PM1/3/12
to pyth...@googlegroups.com
On Wed, Jan 4, 2012 at 8:50 AM, Mohd Izhar Firdaus Ismail
<kagese...@gmail.com> wrote:
> no ,it fails because not everyone run setup.py, inside the directory
> .. buildout doesnt remove the current path .. but the current path is

Ok, you're right. Look like I misunderstood what slice assignment
sys.path[0:0] mean. I thought it replace the list with new one. That's
why I assume buildout remove current directory from sys.path when
looking at generated bin/buildout script:-

import sys
sys.path[0:0] = [
'/home/kamal/python/buildout/eggs/setuptools-0.6c12dev_r88846-py2.6.egg',
'/home/kamal/python/buildout/eggs/zc.buildout-1.5.2-py2.6.egg',
]

Importing from mymodule in setup.py seem to work. Now I'm left (again)
with unanswered question why certain package that import itself in
setup.py failed with buildout.

E A Faisal

unread,
Jan 3, 2012, 8:41:07 PM1/3/12
to pyth...@googlegroups.com
os.path.dirname(__file__) maybe?

Mohd Izhar Firdaus Ismail

unread,
Jan 3, 2012, 9:54:12 PM1/3/12
to pyth...@googlegroups.com
On Wed, Jan 4, 2012 at 9:40 AM, Mohd Kamal Bin Mustafa <ka...@smach.net> wrote:
> On Wed, Jan 4, 2012 at 8:50 AM, Mohd Izhar Firdaus Ismail
> <kagese...@gmail.com> wrote:
>> no ,it fails because not everyone run setup.py, inside the directory
>> .. buildout doesnt remove the current path .. but the current path is
>
> Ok, you're right. Look like I misunderstood what slice assignment
> sys.path[0:0] mean. I thought it replace the list with new one. That's
> why I assume buildout remove current directory from sys.path when
> looking at generated bin/buildout script:-

that line clean the buildout to only include proper eggs _in the
context of the buildout directory_ ...

add develop = . if the current directory is an egg .. buildout forces
you to do everything as an egg.. if you still want to include current
directory where the buildout contains modules, include it as
extra-paths=. .. but imo, that approach is a hack , and not what ure
supposed to do unless really necessary (eg: old legacy stuff) ..
package all your stuff into eggs properly ..

the issue with importing stuff in setup.py fails _in the context of
installing it using easy_install to a specific root, where the
imported module, is not yet installed, and, setup.py is run not from
inside the egg directory_ (ie: python /path/to/egg/setup.py instead of
cd /path/to/egg/ && python setup.py) .. this part is the fragile
assumption ..

let setuptools/distribute manage your versions, dont import the
version info from the module but put it there as a static string ..
heck, dont import anything in setup.py .. if you are importing stuff
for some reason, theres something wrong with your packaging and
library .. setup.py is not supposed to be a program, its a package
definition ..

'if __version__' checks is a hack ... set version dependencies
requirement in setup.py install_requires..

>
> import sys
> sys.path[0:0] = [
>    '/home/kamal/python/buildout/eggs/setuptools-0.6c12dev_r88846-py2.6.egg',
>    '/home/kamal/python/buildout/eggs/zc.buildout-1.5.2-py2.6.egg',
>    ]
>
> Importing from mymodule in setup.py seem to work. Now I'm left (again)
> with unanswered question why certain package that import itself in
> setup.py failed with buildout.
>

> --
> You received this message because you are subscribed to the Google Groups "python.my" group.
> To post to this group, send email to pyth...@googlegroups.com.
> To unsubscribe from this group, send email to pythonmy+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pythonmy?hl=en.
>

--

Reply all
Reply to author
Forward
0 new messages