[GRASS-dev] what do you think about re-organized the /lib/python files?

Hi all!

What do you think of:

1) create a new directory /lib/python/script and move (the following
modules: array.py core.py db.py raster.py raster3d.py setup.py.sed
task.py vector.py) inside.
in this way the struct in /lib/python would be:

/lib/python
├── ctypes/
├── pygrass/
├── script/
├── temporal/
├── Makefile
├── __init__.py
└── pythonlib.dox

For me it's clearer and more consistent with other python modules.

2) change the module setup.py, that at the moment is generated during
the compilation (setup.py.sed => setup.py), to use something like:

{{{
27a28,31

LD_LIB_OS = {'win': 'PATH', #Windows
             'dar': 'LD_LIBRARY_PATH', #Mac OS X
             }

45,48c49,53
< # define LD_LIBRARY_PATH
< if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
< os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
< os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep +
os.path.join(gisbase, 'lib')
---

    # define LD_LIBRARY_PATH default is: 'LD_LIBRARY_PATH'
    ld_lib = LD_LIB_OS.get(sys.platform[:3], 'LD_LIBRARY_PATH')
    os.environ[ld_lib] = os.environ.get(ld_lib, '') + os.pathsep +\
                         os.path.join(gisbase, 'lib')

}}}

3) change the __init__.py contained in /lib/python, at the moment we
have this behaviour:

import grass
grass.script.core.run_command('r.info', map='elevation')

Traceback (most recent call last):
  File "<ipython-input-5-c3c1814cb046>", line 1, in <module>
    grass.script.core
AttributeError: 'module' object has no attribute 'script'

dir(grass)

['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'os']

grass.__all__

['script', 'temporal', 'lib']

I would prefer something more explicit like:

import grass
dir(grass)

['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'lib', 'os', 'pygrass', 'script',
'temporal']

What do you think?

Best regards.

Pietro

Hmm, maybe now is the right time for me to ask:

Why the directory layout in source codes differs form the layout in
dist directory?

On 5 December 2012 20:31, Pietro <peter.zamb@gmail.com> wrote:

Hi all!

What do you think of:

1) create a new directory /lib/python/script and move (the following
modules: array.py core.py db.py raster.py raster3d.py setup.py.sed
task.py vector.py) inside.
in this way the struct in /lib/python would be:

/lib/python
├── ctypes/
├── pygrass/
├── script/
├── temporal/
├── Makefile
├── __init__.py
└── pythonlib.dox

For me it's clearer and more consistent with other python modules.

2) change the module setup.py, that at the moment is generated during
the compilation (setup.py.sed => setup.py), to use something like:

{{{
27a28,31

LD_LIB_OS = {'win': 'PATH', #Windows
             'dar': 'LD_LIBRARY_PATH', #Mac OS X
             }

45,48c49,53
< # define LD_LIBRARY_PATH
< if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
< os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
< os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep +
os.path.join(gisbase, 'lib')
---

    # define LD_LIBRARY_PATH default is: 'LD_LIBRARY_PATH'
    ld_lib = LD_LIB_OS.get(sys.platform[:3], 'LD_LIBRARY_PATH')
    os.environ[ld_lib] = os.environ.get(ld_lib, '') + os.pathsep +\
                         os.path.join(gisbase, 'lib')

}}}

3) change the __init__.py contained in /lib/python, at the moment we
have this behaviour:

import grass
grass.script.core.run_command('r.info', map='elevation')

Traceback (most recent call last):
  File "<ipython-input-5-c3c1814cb046>", line 1, in <module>
    grass.script.core
AttributeError: 'module' object has no attribute 'script'

dir(grass)

['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'os']

grass.__all__

['script', 'temporal', 'lib']

I would prefer something more explicit like:

import grass
dir(grass)

['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'lib', 'os', 'pygrass', 'script',
'temporal']

What do you think?

Best regards.

Pietro
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

2012/12/5 Pietro <peter.zamb@gmail.com>:

Hi all!

Hi Pietro

What do you think of:

1) create a new directory /lib/python/script and move (the following
modules: array.py core.py db.py raster.py raster3d.py setup.py.sed
task.py vector.py) inside.
in this way the struct in /lib/python would be:

/lib/python
├── ctypes/
├── pygrass/
├── script/
├── temporal/
├── Makefile
├── __init__.py
└── pythonlib.dox

For me it's clearer and more consistent with other python modules.

2) change the module setup.py, that at the moment is generated during
the compilation (setup.py.sed => setup.py), to use something like:

{{{
27a28,31

LD_LIB_OS = {'win': 'PATH', #Windows
             'dar': 'LD_LIBRARY_PATH', #Mac OS X
             }

45,48c49,53
< # define LD_LIBRARY_PATH
< if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
< os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
< os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep +
os.path.join(gisbase, 'lib')
---

    # define LD_LIBRARY_PATH default is: 'LD_LIBRARY_PATH'
    ld_lib = LD_LIB_OS.get(sys.platform[:3], 'LD_LIBRARY_PATH')
    os.environ[ld_lib] = os.environ.get(ld_lib, '') + os.pathsep +\
                         os.path.join(gisbase, 'lib')

}}}

3) change the __init__.py contained in /lib/python, at the moment we
have this behaviour:

import grass
grass.script.core.run_command('r.info', map='elevation')

Traceback (most recent call last):
  File "<ipython-input-5-c3c1814cb046>", line 1, in <module>
    grass.script.core
AttributeError: 'module' object has no attribute 'script'

dir(grass)

['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'os']

grass.__all__

['script', 'temporal', 'lib']

I would prefer something more explicit like:

import grass
dir(grass)

['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'lib', 'os', 'pygrass', 'script',
'temporal']

What do you think?

We already spoke about this and I really like this solution.
Maybe you should provide a patch so everybody can test it?

Best regards.

Pietro

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

Vaclav Petras wrote:

Why the directory layout in source codes differs form the layout in
dist directory?

Originally, the only Python code was the grass.script library (which
was just called "grass"). ctypes, temporal and pygrass were added
later.

--
Glynn Clements <glynn@gclements.plus.com>

On Thu, Dec 6, 2012 at 7:53 AM, Glynn Clements <glynn@gclements.plus.com> wrote:

Vaclav Petras wrote:

Why the directory layout in source codes differs form the layout in
dist directory?

Originally, the only Python code was the grass.script library (which
was just called "grass"). ctypes, temporal and pygrass were added
later.

But do you think that there are some good reasons that suggest to not
touch the current layout?
Because, as Vaclav, I would prefer a consistent layout between source
and dist directories.

Piero

Hi Luca,

On Thu, Dec 6, 2012 at 12:46 AM, Luca Delucchi <lucadeluge@gmail.com> wrote:

What do you think?

We already spoke about this and I really like this solution.
Maybe you should provide a patch so everybody can test it?

Yes, we do, but before to change the layout of the python directory I
would like to understand what the other developers think about it? May
be we should not change, or may be we should change in another way?
Which layout should we use?

Hi Pietro,
i definitely like the idea. The current layout has historical reasons.
IMHO there is no need to keep it.
But care must be taken so that existing Python scripts will not break.

Best regards
Soeren

2012/12/5 Pietro <peter.zamb@gmail.com>:

Hi all!

What do you think of:

1) create a new directory /lib/python/script and move (the following
modules: array.py core.py db.py raster.py raster3d.py setup.py.sed
task.py vector.py) inside.
in this way the struct in /lib/python would be:

/lib/python
├── ctypes/
├── pygrass/
├── script/
├── temporal/
├── Makefile
├── __init__.py
└── pythonlib.dox

For me it's clearer and more consistent with other python modules.

2) change the module setup.py, that at the moment is generated during
the compilation (setup.py.sed => setup.py), to use something like:

{{{
27a28,31

LD_LIB_OS = {'win': 'PATH', #Windows
             'dar': 'LD_LIBRARY_PATH', #Mac OS X
             }

45,48c49,53
< # define LD_LIBRARY_PATH
< if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
< os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
< os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep +
os.path.join(gisbase, 'lib')
---

    # define LD_LIBRARY_PATH default is: 'LD_LIBRARY_PATH'
    ld_lib = LD_LIB_OS.get(sys.platform[:3], 'LD_LIBRARY_PATH')
    os.environ[ld_lib] = os.environ.get(ld_lib, '') + os.pathsep +\
                         os.path.join(gisbase, 'lib')

}}}

3) change the __init__.py contained in /lib/python, at the moment we
have this behaviour:

import grass
grass.script.core.run_command('r.info', map='elevation')

Traceback (most recent call last):
  File "<ipython-input-5-c3c1814cb046>", line 1, in <module>
    grass.script.core
AttributeError: 'module' object has no attribute 'script'

dir(grass)

['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'os']

grass.__all__

['script', 'temporal', 'lib']

I would prefer something more explicit like:

import grass
dir(grass)

['__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'lib', 'os', 'pygrass', 'script',
'temporal']

What do you think?

Best regards.

Pietro
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Hi,

2012/12/6 Sören Gebbert <soerengebbert@googlemail.com>:

i definitely like the idea. The current layout has historical reasons.
IMHO there is no need to keep it.
But care must be taken so that existing Python scripts will not break.

already spoken with Pietro via chat. I think that it's good idea to
change the current layout. Having *.py files in lib/python has
historical reasons as Glynn already noted. It's time to update the
layout since we have more python libs at this moment.

Martin

--
Martin Landa <landa.martin gmail.com> * http://geo.fsv.cvut.cz/~landa

Hi Sören,

On Thu, Dec 6, 2012 at 11:26 AM, Sören Gebbert
<soerengebbert@googlemail.com> wrote:

Hi Pietro,
i definitely like the idea. The current layout has historical reasons.
IMHO there is no need to keep it.
But care must be taken so that existing Python scripts will not break.

I'm completely agree with you.

Unfortunately I'm not comfortable with Makefiles, therefore I will do
this with Luca, probably in January.

Thank you for your feedback.

Pietro

Pietro wrote:

>> Why the directory layout in source codes differs form the layout in
>> dist directory?
>
> Originally, the only Python code was the grass.script library (which
> was just called "grass"). ctypes, temporal and pygrass were added
> later.

But do you think that there are some good reasons that suggest to not
touch the current layout?

No. It's only like that by historical accident, not by deliberate
intent.

--
Glynn Clements <glynn@gclements.plus.com>