setuptools: bug in run_script
Ben Bangert encountered a problem where pkg_resources.WorkingSet.run_script didn't work; from line 407: self.require(requires)[0].run_script(script_name, ns) If all the packages are already loaded for some reason, then self.require() returns []. I don't really understand how we got in this state -- that apparently packages are available before they are being required. But so it is; it might be from a script wrapper created with 0.6a2?
Ian Bicking wrote:
Ben Bangert encountered a problem where pkg_resources.WorkingSet.run_script didn't work; from line 407:
self.require(requires)[0].run_script(script_name, ns)
If all the packages are already loaded for some reason, then self.require() returns [].
Looking at it, I think self.require(requires)[0] would only work if the package was installed multi-version. When all the packages are activated by default, of course require() should return nothing.
Ian Bicking wrote:
Ian Bicking wrote:
Ben Bangert encountered a problem where pkg_resources.WorkingSet.run_script didn't work; from line 407:
self.require(requires)[0].run_script(script_name, ns)
If all the packages are already loaded for some reason, then self.require() returns [].
Looking at it, I think self.require(requires)[0] would only work if the package was installed multi-version. When all the packages are activated by default, of course require() should return nothing.
Nevermind that. The problem is the generated scripts: #!/usr/local/bin/python # EASY-INSTALL-SCRIPT: 'PasteScript==0.1dev-r3260','paster' __requires__ = 'PasteScript==0.1dev-r3260' import pkg_resources pkg_resources.run_script('PasteScript==0.1dev-r3260', 'paster') The __requires__ variable causes pkg_resources to require that package. So later when .run_script() is called, the package has already been loaded, and .requires() returns [], and it fails. I actually don't know what situation it would work in. But I also realize setuptools has had a hard time updating my scripts, so I didn't notice it myself. While we're at it, the explicit version in these scripts causes me no end of problems. Since scripts are generally not installed in a multi-version manner (only one script by a particular name can be access on $PATH), it seems they should have versionless requires, thus getting the newest version. Or, at least, they should load the "active" version, whatever that is (typically the newest version).
Ian Bicking wrote:
The __requires__ variable causes pkg_resources to require that package. So later when .run_script() is called, the package has already been loaded, and .requires() returns [], and it fails. I actually don't know what situation it would work in. But I also realize setuptools has had a hard time updating my scripts, so I didn't notice it myself.
Well, okay, maybe not quite that. Anyway, I was able to confirm the problem after doing a more insulated install, and the attached diff against pkg_resources.py fixes it. It would be nice if there was a require-and-find method, whenever I want to get a distribution I find I have to do: pkg_resources.require('Package') dist = pkg_resources.working_set.find(pkg_resources.Require('Package')) at least that's the best combination I've figured out so far.
At 03:09 PM 9/25/2005 -0500, Ian Bicking wrote:
Ian Bicking wrote:
The __requires__ variable causes pkg_resources to require that package. So later when .run_script() is called, the package has already been loaded, and .requires() returns [], and it fails. I actually don't know what situation it would work in. But I also realize setuptools has had a hard time updating my scripts, so I didn't notice it myself.
Well, okay, maybe not quite that. Anyway, I was able to confirm the problem after doing a more insulated install, and the attached diff against pkg_resources.py fixes it.
There wasn't a diff attached, but in the meantime I've sent a diff that fixes the problem.
It would be nice if there was a require-and-find method, whenever I want to get a distribution I find I have to do:
pkg_resources.require('Package') dist = pkg_resources.working_set.find(pkg_resources.Require('Package'))
at least that's the best combination I've figured out so far.
See: http://peak.telecommunity.com/DevCenter/PkgResources#getting-or-creating-dis... The correct API is get_distribution(), but you need a correctly working pkg_resources, which sadly is not possible with 0.6a3. Downgrade to a2 or use the patch I posted.
participants (2)
-
Ian Bicking
-
Phillip J. Eby