[sage-support] Re: Best way to develop Sage packages?

2012-04-02 Thread Volker Braun
I agree that you don't have to modify module_list.py (which probably should 
be replaced at one point by something that doesn't rely on a single file 
having information about all modules, but I digress). Emil mentioned in his 
OP that he is editing modules_list for some reason.



On Monday, April 2, 2012 12:17:53 AM UTC+1, Keshav Kini wrote:

 Correct me if I'm wrong, but random distutils-based packages can utilize
 Cython just as well as the Sage library distutils-based package, no? I
 seem to recall making such an SPKG once upon a time... In which case it
 wouldn't do anything to Sage's module_list.py, just have its own one.




-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-04-02 Thread Emil
Thanks for everyone's help. I decided to make it a package that can be
installed like:

sage -python setup.py install

My setup.py is as follows (except I changed the name of the package).
I arrived at its contents by trial and error, so if anyone could have
a quick look at it to see if there is anything really silly, then that
would be appreciated! -Emil

--
import os

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

if not os.environ.has_key('SAGE_ROOT'):
print ERROR: The environment variable SAGE_ROOT must be defined.
sys.exit(1)
else:
SAGE_ROOT  = os.environ['SAGE_ROOT']
SAGE_LOCAL = SAGE_ROOT + '/local'
SAGE_DEVEL = SAGE_ROOT + '/devel'

setup(
name='MyPackage',
packages=['mypackage'],
version='1.0',
cmdclass = {'build_ext': build_ext},
ext_modules = [
Extension('mypackage.thing', sources=['mypackage/thing.pyx'],
include_dirs = [SAGE_LOCAL + 
'/lib/python/site-packages/numpy/core/include',
SAGE_LOCAL + '/include/csage',
SAGE_DEVEL + '/sage/sage/ext',
SAGE_DEVEL + '/sage'],
library_dirs = [SAGE_LOCAL + '/lib'])
]
)

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-04-02 Thread John H Palmieri


On Monday, April 2, 2012 8:32:18 AM UTC-7, Emil wrote:

 Thanks for everyone's help. I decided to make it a package that can be
 installed like:

 sage -python setup.py install

 My setup.py is as follows (except I changed the name of the package).
 I arrived at its contents by trial and error, so if anyone could have
 a quick look at it to see if there is anything really silly, then that
 would be appreciated! -Emil

 --
 import os

 from distutils.core import setup
 from distutils.extension import Extension
 from Cython.Distutils import build_ext

 if not os.environ.has_key('SAGE_ROOT'):

Using if not 'SAGE_ROOT' in os.environ is better. has_key has been 
deprecated.
 

 print ERROR: The environment variable SAGE_ROOT must be defined.
 sys.exit(1)
 else:
 SAGE_ROOT  = os.environ['SAGE_ROOT']
 SAGE_LOCAL = SAGE_ROOT + '/local'

It's better to use

   SAGE_LOCAL = os.path.join(SAGE_ROOT, 'local')

I don't have comments about any of the rest of it.

-- 
John

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-04-02 Thread Emil
Thanks! Actually, I have a little problem. In setup.py I have:

Extension('thing',
sources=['mypackage/thing.pyx'],
include_dirs = [SAGE_LOCAL + 
'/lib/python/site-packages/numpy/core/include',
SAGE_LOCAL + '/include/csage',
SAGE_DEVEL + '/sage/sage/ext',
SAGE_DEVEL + '/sage'],
library_dirs = [SAGE_LOCAL + '/lib']

Now, thing.pyx has a class Thing, which in Sage is then called
thing.Thing. However, I would like it to be called
'mypackage.thing.Thing'. Is this possible?

(If in the above code I change the first argument of Extension to
'mypackage.thing', I am unable to import it at the sage: prompt -
although thing.so gets put inside the site-packages/mypackage
directory instead of in its parent.)

Emil

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-04-01 Thread Volker Braun
On Saturday, March 31, 2012 11:42:08 PM UTC+1, Emil wrote:

 not pollute the name space (It contains classes with quite generic
 names like Problem and Construction.)

Whats wrong with the module foo having a foo.Problem class?

How is your spkg going to add cython modules to module_list.py? You can 
monkey-patch it in the spkg-install script but thats just a bad idea. For 
starters, it is definitely going to break down the road.


-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-04-01 Thread Robert Bradshaw
On Sat, Mar 31, 2012 at 3:42 PM, Emil emi...@gmail.com wrote:
 On 31 March 2012 12:47, Volker Braun vbraun.n...@gmail.com wrote:
 If it is of interest to an academic community then it probably should be
 part of Sage ;-)

 I'm not against it being incorporated into Sage at some point, but
 right now I'd rather keep it as a separate package that people can
 install, and import if they want to use it; but if they don't it will
 not pollute the name space (It contains classes with quite generic
 names like Problem and Construction.)

 From what I can tell, I can use Python distutils, and I can get the
 SAGE_ROOT from environment variables, so that I can set the
 include_dirs for the Cython compilation. Then I just give people a tar
 ball and tell them to run sage -python setup.py.

That would work fine, or even a pointer to a repository that then can
clone/contribute to.

 Does this sound a good strategy? Or would it be best to distribute an
 .spkg ? Can .spkg's install stuff into the site-packages directory
 outside the sage folder?

Spks would work fine. IIRC, the default is to run setup.py if there's
a setup.py in the sources (though note that all the code lives under a
scr directory, and one needs a couple of metadata files. They're just
bzipped tarballs, so the easiest way is to understand them unpack some
and take a look.

That being said, I would suggest contribute to the main library unless
there's a strong reason not to.

 Also, is there any documentation on sage -pkg?

 Emil

 --
 To post to this group, send email to sage-support@googlegroups.com
 To unsubscribe from this group, send email to 
 sage-support+unsubscr...@googlegroups.com
 For more options, visit this group at 
 http://groups.google.com/group/sage-support
 URL: http://www.sagemath.org

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Best way to develop Sage packages?

2012-04-01 Thread Keshav Kini
Volker Braun vbraun.n...@gmail.com writes:
 How is your spkg going to add cython modules to module_list.py? You can
 monkey-patch it in the spkg-install script but thats just a bad idea. For
 starters, it is definitely going to break down the road.

Correct me if I'm wrong, but random distutils-based packages can utilize
Cython just as well as the Sage library distutils-based package, no? I
seem to recall making such an SPKG once upon a time... In which case it
wouldn't do anything to Sage's module_list.py, just have its own one.

-Keshav


Join us in #sagemath on irc.freenode.net !

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-04-01 Thread William Stein
On Apr 1, 2012 7:18 PM, Keshav Kini keshav.k...@gmail.com wrote:

 Volker Braun vbraun.n...@gmail.com writes:
  How is your spkg going to add cython modules to module_list.py? You can
  monkey-patch it in the spkg-install script but thats just a bad idea.
For
  starters, it is definitely going to break down the road.

 Correct me if I'm wrong, but random distutils-based packages can utilize
 Cython just as well as the Sage library distutils-based package, no? I
 seem to recall making such an SPKG once upon a time... In which case it
 wouldn't do anything to Sage's module_list.py, just have its own one.

 -Keshav

Keshav, you are of course right.  Psage is a large example of this, and
there are probably thousands of others (every python library ever released
that uses Cython).


 
 Join us in #sagemath on irc.freenode.net !

 --
 To post to this group, send email to sage-support@googlegroups.com
 To unsubscribe from this group, send email to
sage-support+unsubscr...@googlegroups.com
 For more options, visit this group at
http://groups.google.com/group/sage-support
 URL: http://www.sagemath.org

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-03-31 Thread Volker Braun
If it is of interest to an academic community then it probably should be 
part of Sage ;-)

On Friday, March 30, 2012 11:04:00 PM UTC+1, Emil wrote:

 3) probably shouldn't be made part of everyone's Sage, but it would be
 good if people could install it easily, as it will be of interest to a
 certain community. 


PS: For testing a single command I find the 

sage -b  sage -c print 1+1 

command line useful. Then edit and re-run the command to check that your 
edit worked as intended. For simple things attach()-ing is fine but once it 
gets to Cython and/or category code you'll run into its limitations.
 



-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-03-31 Thread Emil
On 31 March 2012 12:47, Volker Braun vbraun.n...@gmail.com wrote:
 If it is of interest to an academic community then it probably should be
 part of Sage ;-)

I'm not against it being incorporated into Sage at some point, but
right now I'd rather keep it as a separate package that people can
install, and import if they want to use it; but if they don't it will
not pollute the name space (It contains classes with quite generic
names like Problem and Construction.)

From what I can tell, I can use Python distutils, and I can get the
SAGE_ROOT from environment variables, so that I can set the
include_dirs for the Cython compilation. Then I just give people a tar
ball and tell them to run sage -python setup.py.

Does this sound a good strategy? Or would it be best to distribute an
.spkg ? Can .spkg's install stuff into the site-packages directory
outside the sage folder?

Also, is there any documentation on sage -pkg?

Emil

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-03-31 Thread Maarten Derickx
I think you should make it an spkg because that is how people using sage expect 
to install it.
Note that the install script in an spkg can contain arbitrary bash code so it 
can do everything you want it to.

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Best way to develop Sage packages?

2012-03-31 Thread Dima Pasechnik
On 2012-03-31, Emil emi...@gmail.com wrote:
 On 31 March 2012 12:47, Volker Braun vbraun.n...@gmail.com wrote:
 If it is of interest to an academic community then it probably should be
 part of Sage ;-)

 I'm not against it being incorporated into Sage at some point, but
 right now I'd rather keep it as a separate package that people can
 install, and import if they want to use it; but if they don't it will
 not pollute the name space (It contains classes with quite generic
 names like Problem and Construction.)

 From what I can tell, I can use Python distutils, and I can get the
 SAGE_ROOT from environment variables, so that I can set the
 include_dirs for the Cython compilation. Then I just give people a tar
 ball and tell them to run sage -python setup.py.

 Does this sound a good strategy? Or would it be best to distribute an
 .spkg ? Can .spkg's install stuff into the site-packages directory
 outside the sage folder?
No, I don't think this is supported in any way, and this is not what 
a Sage spkg would or should do. But surely, if you'd install your spkg
as a superuser you can overwrite anything, up to including rm -rf /
in your spkg-install...

Would would be the purpose of this?
It looks like a recipe for distaster.


 Also, is there any documentation on sage -pkg?
I assume you read this:
http://www.sagemath.org/doc/developer/producing_spkgs.html

sage -pkg just creates a compressed tarball and does few basic checks on
the consistency of mercurial repository.


 Emil


-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Best way to develop Sage packages?

2012-03-30 Thread Pedro Cruz

I don't know if this below is a standard way but it works to develop stand 
alone packages:

At sage package directory, for example, 

 /opt/sage-some-version/local/lib/python2.6/site-packages/

execute

ln -s /home/user1/newpackage/

where newpackage is a directory with all files including all.py.

That  produces the symbolic link:

/opt/sage/local/lib/python2.6/site-packages/newpackage/

Testing:

sage: from newpackage.all import *

and it should work.

Now one can change files on
 /home/user1/newpackage/ 
and keep testing without upgrading, etc.

When everything is ready command

   sage -pkg newpackage

produces a stand alone package for delivery into other sage system.

Any best way? Please let me know (few months ago I've read the developer 
guide and found nothing special abut this).
Thank you.

Pedro



 Sexta-feira, 30 de Março de 2012 18h14min15s UTC+1, Emil escreveu:

 Hi, I'm working on a Sage package. I'm new to Sage, and learning as I
 go along...

 My source code is a mixture of .py and .spyx files, that (until now) I
 have been attaching() at the sage: prompt. This seems to work quite
 well.

 However, I'd like to do things in the proper way. So I made a
 directory in SAGE_ROOT/devel/sage/sage/, created __init__.py, all.py,
 and updated the module_list and setup.py files. Then I can build the
 source with sage -b. This works ok as well.

 I was wondering, is there a way that I can rebuild the source from the
 sage: prompt, for example using %upgrade? I get the following message
 when I try that:

 Delete the following files manually (and rerun %upgrade)
 if you need a full upgrade:
 /Users/ev/.sage/ipython/ipy_user_conf.py

 My questions are:
 1) do people develop sage in this way, or is it more normal to just
 attach() things?
 2) is it possible to use %upgrade to rebuild by source from the sage: 
 prompt?

 Thanks,


 Emil





-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Best way to develop Sage packages?

2012-03-30 Thread John H Palmieri


On Friday, March 30, 2012 10:14:15 AM UTC-7, Emil wrote:

 Hi, I'm working on a Sage package. I'm new to Sage, and learning as I
 go along...

 My source code is a mixture of .py and .spyx files, that (until now) I
 have been attaching() at the sage: prompt. This seems to work quite
 well.

 However, I'd like to do things in the proper way. So I made a
 directory in SAGE_ROOT/devel/sage/sage/, created __init__.py, all.py,
 and updated the module_list and setup.py files. Then I can build the
 source with sage -b. This works ok as well.

 I was wondering, is there a way that I can rebuild the source from the
 sage: prompt, for example using %upgrade? I get the following message
 when I try that:

 Delete the following files manually (and rerun %upgrade)
 if you need a full upgrade:
 /Users/ev/.sage/ipython/ipy_user_conf.py

 My questions are:
 1) do people develop sage in this way, or is it more normal to just
 attach() things?

You can definitely develop things this way. If, as you say, you're planning 
to have files in the Sage library, you should use .py and .pyx files, but 
perhaps not .spyx files. You need to modify module_list.py and setup.py, as 
you said, and then everything should be fine. You might also consider 
modifying devel/sage/sage/all.py, if you want any of your code to be 
imported by default on startup.

At some point, you should save your work as a Mercurial patch, too. From 
the command line:

  $ sage --hg qnew 'my great patch'
  $ sage --hg qrefresh  # run this whenever you want to update to reflect 
recent changes
  $ sage --hg export tip -o /home/my_account/patches/new_sage_stuff.patch

See the Sage developer's guide and Mercurial documentation for more.

2) is it possible to use %upgrade to rebuild by source from the sage: 
 prompt?

I don't know. The standard way to do it is to quit sage and run 'sage -b' 
to rebuild the source, or 'sage -br' to rebuild the source and then run 
Sage.

-- 
John

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Best way to develop Sage packages?

2012-03-30 Thread Emil
Pedro, John - thanks for your replies! It is a shame that you can't
recompile bits of Sage from within Sage, but I guess there are good
reasons for this.

My package has the following characteristics:
1) it uses lots of Sage things
2) it is a mixture of Cython and Python
3) probably shouldn't be made part of everyone's Sage, but it would be
good if people could install it easily, as it will be of interest to a
certain community.

Because of (3), I would lean towards Pedro's idea of using
site-packages, however, I have lines like this in my .pyx files:

include ../ext/interrupt.pxi

So I guess this means that I need to be part of the sage directory
structure, rather than being in site-packages? Or could I use
SAGE_ROOT or something to always guarantee to be able to find these
files?

Emil

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org