Re: Running a script to build docs from setup.py

2009-07-10 Thread Tony Houghton
On Fri, 10 Jul 2009 11:06:34 +1000
Ben Finney ben+pyt...@benfinney.id.au wrote:

 Tony Houghton h...@realh.co.uk writes:
 
  I've looked through the manual but I can't find any hooks in distutils
  for generating files at install time other than extension modules and
  .pyc files. Should I just run the script from somewhere in my setup.py
  before calling distutils' setup function?
 
 Indirectly related: Ian Bicking's article on using Python's ‘setup.py’
 as a ‘Makefile’ replacement:
 
 URL:http://blog.ianbicking.org/pythons-makefile.html

Thanks, but I don't think that adds much to the distutils manual.

 If one is writing a ‘setup.py’ anyway, I think it makes sense to use
 that as the build program for the whole project if possible. Good
 hunting!

Yes. Really I only want to write a setup.py because it makes it easier
to make a debian package, but the more of the installation that's done
by setup.py the better I suppose, then other people might find it
useful.

-- 
TH * http://www.realh.co.uk

-- 
http://mail.python.org/mailman/listinfo/python-list


Running a script to build docs from setup.py

2009-07-09 Thread Tony Houghton
I want to write a setup.py script, using distutils, for a python library
called ROX-Lib2 (package name rox). The library includes a script to
build HTML documentation from the pydoc strings. I'd like to run that
script from setup.py but I don't know the best way to do that. I've
looked through the manual but I can't find any hooks in distutils for
generating files at install time other than extension modules and .pyc
files. Should I just run the script from somewhere in my setup.py before
calling distutils' setup function?

-- 
TH * http://www.realh.co.uk

-- 
http://mail.python.org/mailman/listinfo/python-list


How to declare python ints in C extensions?

2009-01-04 Thread Tony Houghton
I want to write python wrappers for the Linux DVB API. The underlying
structures and constants may change from time to time, and some of the
constants are generated from macros, so I think it would be better to
write the module in C rather than just copying the constants into pure
python code and using python's ioctl and struct modules.

The trouble is I can't find out how to define a simple python int
variable/constant in a C extension. The docs only seem to tell you how
to define functions/methods and new types.

For example, where the kernel header dvb/frontend.h defines:

typedef enum fe_type {
FE_QPSK,
FE_QAM,
FE_OFDM,
FE_ATSC
} fe_type_t;

I want to make them available as if there was a python module
dvb/frontend.py containing:

FE_QPSK = 0
FE_QAM = 1
FE_OFDM = 2
FE_ATSC = 3

but in real life the module would be dvb/frontendmodule.c.

-- 
TH * http://www.realh.co.uk

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to declare python ints in C extensions?

2009-01-04 Thread Tony Houghton
On Sun, 04 Jan 2009 21:05:14 +0100
Christian Heimes li...@cheimes.de wrote:

 Philip Semanchuk schrieb:
  This works for me:
 PyModule_AddIntConstant(module, O_CREAT, O_CREAT);
  
  I've had to learn a lot about writing extensions from looking at the
  Python source code. Lots of valuable tricks to be learned there.

Thanks, that's perfect. I see it is documented, but I didn't know where
to look.

 This trick makes it even easier:
 
 #ifndef PyModule_AddIntMacro
 #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
 #endif

Good idea, but I'm a lot more experienced with C in general than in
interfacing it with python, so I already thought of it :-).

-- 
TH * http://www.realh.co.uk

--
http://mail.python.org/mailman/listinfo/python-list


Determining encoding of a file

2007-02-03 Thread Tony Houghton
In Linux it's possible for filesystems to have a different encoding from
the system's setting. Given a filename, is there a (preferably) portable
way to determine its encoding?

-- 
TH * http://www.realh.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python Right for Me?

2007-02-03 Thread Tony Houghton
In [EMAIL PROTECTED],
Stuart D. Gathman [EMAIL PROTECTED] wrote:

 On Fri, 02 Feb 2007 15:09:20 -0500, Mister Newbie wrote:

 I want to make small, 2D games. I have no programming experience. Is
 Python a good choice?

 Definitely.  I teach a class for 7th to 12th grade where I use this
 tutorial to introduce programming:

 http://www.livewires.org.uk/python/
 http://www.livewires.org.uk/python/pdfsheets.html

 As an adult, just skip rapidly through the elementary material.  The final
 module (Games sheets) walks you through creating 3 2D games with pygame!

The OP should also look at pygame http://www.pygame.org/ if that isn't
what the livewires module is based on. And if it is based on pygame he
should look at pygame anyway.

-- 
TH * http://www.realh.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determining encoding of a file

2007-02-03 Thread Tony Houghton
In [EMAIL PROTECTED],
Ben Finney [EMAIL PROTECTED] wrote:

 Tony Houghton [EMAIL PROTECTED] writes:

 In Linux it's possible for filesystems to have a different encoding
 from the system's setting. Given a filename, is there a (preferably)
 portable way to determine its encoding?

 If there were, PEP 263 would not be necessary.

 URL:http://www.python.org/dev/peps/pep-0263/

 It's possible to *guess*, with no guarantee of getting the right
 answer; but it's far better to be explicitly *told* what the encoding
 is.

That seems to be specific to the encoding used in py source files
anyway. What I want to be able to do is guess the encoding of any file
for loading into a text editor based on gtksourceview which is pure
utf-8. The best I can do is assume it's in the system encoding with
locale.getdefaultlocale()[1]. Come to think of it, I wouldn't really be
any better off knowing if the filesystem has a diferent encoding anyway
because it doesn't necessarily determine what's used in the contents of
its files, only its filenames. And Linux at least seems to be able to
translate those on the fly.

-- 
TH * http://www.realh.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


sizeof(struct timeval)

2006-03-13 Thread Tony Houghton
I'm writing a python program which reads input device events so it needs
to know sizeof(struct timeval). By using the struct module I should be
able to work out sizeof(long) from python, but I can't think of a way to
measure non-fundamental types without including a little bit of C,
which I'd rather avoid.

How safe would I be assuming that 

sizeof(struct timeval) == 2 * sizeof(long)

is always true on Linux on different architectures? AFAIK the input
device interface is Linux-specific so I don't need to worry about other
OS's.

-- 
The address in the Reply-To is genuine and should not be edited.
See http://www.realh.co.uk/contact.html for more reliable contact addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sizeof(struct timeval)

2006-03-13 Thread Tony Houghton
In [EMAIL PROTECTED],
Big and Blue [EMAIL PROTECTED] wrote:

 Big and Blue wrote:
  Tony Houghton wrote:
 
  How safe would I be assuming that
  sizeof(struct timeval) == 2 * sizeof(long)
 
  is always true on Linux on different architectures?
 
 Based on what I was looking at today (well, yesterday now), you might
  be wrong.

 However, it looks as though I was wrong:

[Snip headers showing my assumption is correct for his PC too]

I've already looked at those headers too. But most of the definitions
look like internal types and I'm not confident I can rely on them
staying the same size. But I don't think there's a strong enough case
for changing them to justify the glibc ABI change etc, so I'm probably
safe.

-- 
The address in the Reply-To is genuine and should not be edited.
See http://www.realh.co.uk/contact.html for more reliable contact addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sizeof(struct timeval)

2006-03-13 Thread Tony Houghton
In [EMAIL PROTECTED],
Big and Blue [EMAIL PROTECTED] wrote:

 Tony Houghton wrote:
 
 How safe would I be assuming that 
 
 sizeof(struct timeval) == 2 * sizeof(long)
 
 is always true on Linux on different architectures? 

 Based on what I was looking at today (well, yesterday now), you might 
 be wrong.

 I do know that the size of a struct utmp differs between a Linux 
 Itanium system and a Linux x86_64 system, and I seem to recall it migh be 
 related to timeval.  I could be wrong - I wasn't interested in the timeval 
 part - but this part of the bits/utmp.h include file indicates the issue:

So is __WORDSIZE_COMPAT32 defined for one of Itanium or x86_64 but not
the other? The comment in the code below implies the opposite of what
you're saying: the size in 64-bit mode has to be the same as in 32-bit
mode, and as both CPUs have the same 32-bit architecture they should
therefore both use the same sized struct in 64-bit mode.

In any case, it does imply that timeval can be relied on to be 2 *
32-bits (2 * long) in 32-bit architectures and something else in 64-bit
architectures - where long is 64-bit.

 /* The ut_session and ut_tv fields must be the same size when compiled
 32- and 64-bit.  This allows data files and shared memory to be
 shared between 32- and 64-bit applications.  */
 #if __WORDSIZE == 64  defined __WORDSIZE_COMPAT32
int32_t ut_session;   /* Session ID, used for windowing.  */
struct
{
  int32_t tv_sec; /* Seconds.  */
  int32_t tv_usec;/* Microseconds.  */
   } ut_tv;  /* Time entry was made.  */
 #else
long int ut_session;  /* Session ID, used for windowing.  */
struct timeval ut_tv; /* Time entry was made.  */
 #endif

-- 
The address in the Reply-To is genuine and should not be edited.
See http://www.realh.co.uk/contact.html for more reliable contact addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding where to store application data portably

2005-09-22 Thread Tony Houghton
Ron Adam wrote:
  Tony Houghton wrote:
 
 
  I'm using pygame to write a game called Bombz which needs to save some
  data in a directory associated with it. In Unix/Linux I'd probably use
  ~/.bombz, in Windows something like
  C:\Documents And Settings\user\Applicacation Data\Bombz.
 
  There are plenty of messages in the archives for this group about how to
  find the correct location in Windows, but what about Mac OS? There I
  don't know the correct location for this sort of thing at all. And there
  are other, more obscure systems like RISC OS (it may not have pygame but
  it definitely has python). Surely this is something that's crying out
  for an official function in os or sys.
 
  This works on Win XP.  Not sure if it will work on Linux.
 
  import os
 
  parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0]
  file = parent + os.sep + '.bombz'

Ooh, no, I don't want saved data to go in the installation directory. In
general that practice encourages people to run with Admin access, and
it's about time Windows users were discouraged from that.

-- 
The address in the Reply-To is genuine and should not be edited.
See http://www.realh.co.uk/contact.html for more reliable contact 
addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding where to store application data portably

2005-09-22 Thread Tony Houghton
In [EMAIL PROTECTED],
Ron Adam [EMAIL PROTECTED] wrote:

 Tony Houghton wrote:

   This works on Win XP.  Not sure if it will work on Linux.
  
   import os
  
   parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0]
   file = parent + os.sep + '.bombz'
 
 Ooh, no, I don't want saved data to go in the installation directory. In
 general that practice encourages people to run with Admin access, and
 it's about time Windows users were discouraged from that.

 Yes, it occurred to me you didn't want to do that after I posted.

 Looks like maybe the correct place would be as you suggested, but maybe 
 doing it this way would be better.

 import os
 user = os.path.join( os.environ[USERPROFILE],
   'Application Data',
   'Bombz' )

I like that, it's nice and simple. It doesn't look like it's supported
on Win 9x though, but on 9x using the installation directory would be
acceptable.

-- 
The address in the Reply-To is genuine and should not be edited.
See http://www.realh.co.uk/contact.html for more reliable contact addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding where to store application data portably

2005-09-21 Thread Tony Houghton
Steven D'Aprano wrote:
  On Tue, 20 Sep 2005 23:03:52 +0100, Tony Houghton wrote:
 
 
 I'm using pygame to write a game called Bombz which needs to save some
 data in a directory associated with it. In Unix/Linux I'd probably use
 ~/.bombz, in Windows something like
 C:\Documents And Settings\user\Applicacation Data\Bombz.
 
  In Windows, you shouldn't hard-code the drive letter. I don't know 
how you
  find out what the correct value is, but hard-coding it is just Bad.

That's why I said something like. It seems there is a definitive way
of finding the correct value, but it needs extra W32 extensions
installed. You could also start from os.path.expanduser('~') I suppose.

  As a Linux user, I really am sick of every damn application, script and
  program under the sun filling the top level of my home directory with
  dot-files.
 
  I wish the Linux Standard Base folks would specify that settings files
  should all go into a subdirectory like ~/settings rather than filling up
  the home directory with cruft. That was acceptable in the days when 
people
  only looked at their files with ls, but in these days of GUI file
  managers, it is ridiculous that there are more than 100 dot files and
  directories in my home directory.

Don't all file managers have an option to hide files beginning with '.'?

  tilting at windmills
 
  Can I ask developers to break with the obsolete and annoying habit of
  creating user-specific config files as ~/.app-name and use
  ~/settings/app-name instead?
 
  /tilting at windmills

You'll probably like the XDG basedir spec then:
http://freedesktop.org/wiki/Standards_2fbasedir_2dspec

I suppose I should really use that, but the trouble is it can be very
difficult to decide whether some files are config or data, so it would
be nice to have a standard that doesn't segregate the two.

Thanks to everyone else who's replied. I've saved Trent Mick's script
for later reference.

-- 
The address in the Reply-To is genuine and should not be edited.
See http://www.realh.co.uk/contact.html for more reliable contact 
addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Intermediate to expert book

2005-09-21 Thread Tony Houghton

Can anyone recommend a good book for intermediate up to expert level?
I'm an experienced C programmer and I learnt Python from the Learning
Python O'Reilly book because it had good reviews. I was disappointed
though. It was difficult to read because it was so verbose. It would
sometimes take more than a page to explain something where all the
information I needed could have been conveyed in one sentence. If
anyone's seen Leendert Ammeraal's C For Programmers, that's more the
sort of style I'm after. Something that covers 2.3 and preferably even
2.4 would be a bonus.

I've heard good things about Dive Into Python. I see it can be
downloaded or read online, and on a very quick browse it seems to be
suitably to the point and cover some useful stuff that was missing from
or too deeply buried in Learning Python. I find it easier to read
printed material though, so I'd consider buying it. What sort of
opinions do people here have of it?

-- 
The address in the Reply-To is genuine and should not be edited.
See http://www.realh.co.uk/contact.html for more reliable contact 
addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding where to store application data portably

2005-09-20 Thread Tony Houghton

I'm using pygame to write a game called Bombz which needs to save some
data in a directory associated with it. In Unix/Linux I'd probably use
~/.bombz, in Windows something like
C:\Documents And Settings\user\Applicacation Data\Bombz.

There are plenty of messages in the archives for this group about how to
find the correct location in Windows, but what about Mac OS? There I
don't know the correct location for this sort of thing at all. And there
are other, more obscure systems like RISC OS (it may not have pygame but
it definitely has python). Surely this is something that's crying out
for an official function in os or sys.

-- 
The address in the Reply-To is genuine and should not be edited.
See http://www.realh.co.uk/contact.html for more reliable contact 
addresses.
-- 
http://mail.python.org/mailman/listinfo/python-list