|
Hi.
In a package, I have gettext catalog messages, and I want to compile them when the package is build. I looked at the Mercurial setup.py script, and what it does is: from distutils.command.build import build build.sub_commands.insert(0, ('build_mo', None)) Is this the correct way? Thanks Manlio _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
|
At 05:08 PM 5/14/2010 +0200, Manlio Perillo wrote:
>Hi. > >In a package, I have gettext catalog messages, and I want to compile >them when the package is build. > >I looked at the Mercurial setup.py script, and what it does is: > >from distutils.command.build import build >build.sub_commands.insert(0, ('build_mo', None)) > > >Is this the correct way? No. The correct way is to subclass the build command and use a cmdclass dictionary in the setup() call. Something like: from distutils.command.build import build class build(build): sub_commands = [('build_mo', None)]+ build.sub_commands setup( ... cmdclass = dict(build=build) ) The way Mercurial is doing it is monkeypatching that will break if the current Python process runs more than one setup()... e.g. when the setup script is being run by easy_install or some similar tool. (As you can see, though, it only adds one line of code to do it the correct way, as documented in the distutils manual.) _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
|
P.J. Eby ha scritto:
> At 05:08 PM 5/14/2010 +0200, Manlio Perillo wrote: >> Hi. >> >> In a package, I have gettext catalog messages, and I want to compile >> them when the package is build. >> >> I looked at the Mercurial setup.py script, and what it does is: >> >> from distutils.command.build import build >> build.sub_commands.insert(0, ('build_mo', None)) >> >> >> Is this the correct way? > > No. The correct way is to subclass the build command and use a cmdclass > dictionary in the setup() call. Something like: > > from distutils.command.build import build > class build(build): > sub_commands = [('build_mo', None)]+ build.sub_commands > Ok, thanks. By the way: in order to get messages compiled, should I just subclass build and develop commands? Regards Manlio _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
|
At 05:53 PM 5/14/2010 +0200, Manlio Perillo wrote:
>By the way: in order to get messages compiled, should I just subclass >build and develop commands? I don't understand your question. Do you mean "should I just subclass the 'build' command and the 'develop' command"? or "should I just subclass the 'build' command and develop my own commands based on that?" or "should I just subclass the 'build' command and develop my own commands from scratch without subclassing?" Personally, however, if I had to do what you're doing, I'd package a build_mo command as a setuptools plugin, and add it to my build_requires dependencies. That way, I could use it with multiple projects. I'd still have to do the short 'build' subclass in the setup.py, but it's not a lot of code to add. _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
|
P.J. Eby ha scritto:
> At 05:53 PM 5/14/2010 +0200, Manlio Perillo wrote: >> By the way: in order to get messages compiled, should I just subclass >> build and develop commands? > > I don't understand your question. > I want messages to be compiled (using compile_catalog distutils command from babel) in all these cases: 1) create a binary distribution 2) create an egg 3) running the setup using develop command > [...] > > Personally, however, if I had to do what you're doing, I'd package a > build_mo command as a setuptools plugin, and add it to my build_requires > dependencies. That way, I could use it with multiple projects. This is indeed what I'm doing, using babel. However I noted that running python setup.py develop does not execute the compile_catalog command. > I'd > still have to do the short 'build' subclass in the setup.py, but it's > not a lot of code to add. > Thanks Manlio _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
|
At 06:10 PM 5/14/2010 +0200, Manlio Perillo wrote:
>P.J. Eby ha scritto: > > At 05:53 PM 5/14/2010 +0200, Manlio Perillo wrote: > >> By the way: in order to get messages compiled, should I just subclass > >> build and develop commands? > > > > I don't understand your question. > > > >I want messages to be compiled (using compile_catalog distutils command >from babel) in all these cases: >1) create a binary distribution >2) create an egg >3) running the setup using develop command > > > > [...] > > > > Personally, however, if I had to do what you're doing, I'd package a > > build_mo command as a setuptools plugin, and add it to my build_requires > > dependencies. That way, I could use it with multiple projects. > >This is indeed what I'm doing, using babel. > >However I noted that running > python setup.py develop > >does not execute the compile_catalog command. Ah. Okay, so yes, you'd need to subclass develop as well as bdist_egg. An easier way, however, might be to define aliases in setup.cfg: [alias] develop = build_mo develop bdist_egg = build_mo bdist_egg ... etc. Another alternative would be to use an egg_info.writers entry point -- the egg_info command gets called for install, develop, bdist_egg, and all other bdist_* installation scenarios. The doc is here: http://peak.telecommunity.com/DevCenter/setuptools#adding-new-egg-info-files It's a bit of a hack, in that you wouldn't actually be generating an egg-info file. You'd do something like: def my_writer(cmd, basename, filename): cmd.run_command('build_mo') as your writer function. Sadly, this is perhaps the easiest way to extend the build process in the current distribution tools environment. (Hopefully, the build_mo command will not do too much unnecessary processing.) Still another way to accomplish this, would be to add your built files to your source distribution(s), so that recipients don't need to do it themselves. (Of course, that won't work if the files are platform-specific.) _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
|
P.J. Eby ha scritto:
> [...] >> I want messages to be compiled (using compile_catalog distutils command >> from babel) in all these cases: >> 1) create a binary distribution >> 2) create an egg >> 3) running the setup using develop command >> >> >> > [...] > [...] >> However I noted that running >> python setup.py develop >> >> does not execute the compile_catalog command. > > Ah. Okay, so yes, you'd need to subclass develop as well as bdist_egg. I have subclassed develop command: class develop(develop): sub_commands = [('compile_catalog', None)] + develop.sub_commands cmdclass = dict(build=build, develop=develop), However compile_catalog is not called. > An easier way, however, might be to define aliases in setup.cfg: > > [alias] > develop = build_mo develop > bdist_egg = build_mo bdist_egg Thanks, this seems a good solution. I think I will use this. Note however that the configuration group is "aliases", not "alias". It is unfortunate that aliases are not executed internally. That is, I would really like to define an alias for the "build" command, and have it expanded when "build" command is called by other commands like "bdist". > [...] > Still another way to accomplish this, would be to add your built files > to your source distribution(s), so that recipients don't need to do it > themselves. (Of course, that won't work if the files are > platform-specific.) > In my case this is not a problem, but I prefer to generate them during setup, if this is not inconvenient. Regards Manlio _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
|
In reply to this post by PJ Eby
Hello
For the record, I wondered whether aliases in config files were a feature of Distutils or Setuptools, and it turns out it’s Setuptools. Would that be worth inclusion in Distutils2? Regards _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
|
In reply to this post by Manlio Perillo-3
At 07:22 PM 5/14/2010 +0200, Manlio Perillo wrote:
>P.J. Eby ha scritto: > > [...] > >> I want messages to be compiled (using compile_catalog distutils command > >> from babel) in all these cases: > >> 1) create a binary distribution > >> 2) create an egg > >> 3) running the setup using develop command > >> > >> > >> > [...] > > [...] > >> However I noted that running > >> python setup.py develop > >> > >> does not execute the compile_catalog command. > > > > Ah. Okay, so yes, you'd need to subclass develop as well as bdist_egg. > >I have subclassed develop command: > >class develop(develop): > sub_commands = [('compile_catalog', None)] + develop.sub_commands > >cmdclass = dict(build=build, develop=develop), > >However compile_catalog is not called. Develop doesn't have or run any subcommands; that's specific to the 'build' command. Any command you subclass, you'll have to investigate the source of to find out what it does and the best place to hook into it. > > An easier way, however, might be to define aliases in setup.cfg: > > > > [alias] > > develop = build_mo develop > > bdist_egg = build_mo bdist_egg > >Thanks, this seems a good solution. >I think I will use this. > >Note however that the configuration group is "aliases", not "alias". Ah, yes, sorry. >It is unfortunate that aliases are not executed internally. >That is, I would really like to define an alias for the "build" command, >and have it expanded when "build" command is called by other commands >like "bdist". Yeah, that could lead to other problems in the current distutils architecture. A redesigned distutils system would hopefully have a better way to accomplish this. _______________________________________________ Distutils-SIG maillist - [hidden email] http://mail.python.org/mailman/listinfo/distutils-sig |
| Powered by Nabble | Edit this page |
