Comments (16)
(I first commented on #61 but realized my problem is unrelated so I opened a new issue)
from argcomplete.
Just to verify... does it work with regular setup (setup.py install
)?
from argcomplete.
Yeah just verified that with regular setup it resolves correctly.
And it works correctly under develop if I change the line mentioned above to pkg_resources.get_distribution(dist).get_metadata('../scripts/'+script)
from argcomplete.
Just confirmed that I'm getting the same behavior with python 2.6 as well.
Is this already working correctly for others on another operating systems? If that's the case this patch should fix it dcosson@3a0db1a
Alternatively it could just use a try/catch to attempt both locations
from argcomplete.
I also have a similar problem in OS X. setuptools
somehow changes the first line of my scripts when I run python setup.py install
. So instead of the scripts starting with
#!/usr/bin/env python
They start with
#!/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
This means that when python-argcomplete-check-easy-install-script
runs it will not even check if the program is argcomplete compatible. This is because in line 19 it says:
assert(line1.startswith('#') and 'py' in line1)
Since the first line does not have py
in it it fails. This can be fixed if we modify it to this:
assert(line1.startswith('#') and ('py' in line1 or 'Py' in line1))
Now it can check for OS X in case macports
or whatever other source you are using changes python
to Python
.
The other problem that @dcosson mentions also happens in my system when I try to develop. It seems that pkg_resources.get_distribution(dist).get_metadata('scripts/'+script):
assumes that distribution is under:
'/path/to/package/packagename.egg-info/
@dcosson solution would not work for my system since I did not write my scripts in the scripts
directory, I called the directory bin
. At this moment I'm trying to figure out how to let setuptools create the correct script under packagename.egg-info
.
from argcomplete.
@dcosson, did you try removing the directory my_package.egg-info
? I just happen to run my clean routine in which I remove that directory and now it works, no need to perform your patch since that requires that you place your scripts in the script
directory. My only concern is when setuptools
modifies the first line. Can you verify if this works for you?
@kislyuk, If dcosson can confirm that removing the egg-info
folder then I suppose we can close this issue. The only request I have is to update python-argcomplete-check-easy-install-script
so that it can also look for Py
in the first line as I mentioned in the above comment.
from argcomplete.
@jmlopez-rod, I put in a fix for your first problem in af0606c.
from argcomplete.
Released in v0.6.8, please test.
from argcomplete.
@jmlopez-rod that doesn't work for me - running python setup.py develop
creates the .egg-info file in the directory containing my package, so if I delete it just gets created again. Also the line you referenced pkg_resources.get_distribution(dist).get_metadata('scripts/'+script):
already hard-codes the scripts directory, so I didn't introduce any additional dependencies.
For the record my first patch doesn't actually work, my colleague did not experience the bug I'm reporting here and the only difference between our two setups is he is using the OSX system python rather than a homebrew-installed verison. This patch dcosson@f747317 is what we're currently using.
from argcomplete.
@dcosson, indeed, running python setup.py develop
creates the directory .egg-info
again. For that reason you should have a Makefile
so that it runs the command python setup.py develop; rm -rf my_package.egg-info
. The question still stands, does this work? If so, then v0.6.8 should fix this issue.
@kislyuk, v.0.6.8 is now active and working. Thank you.
from argcomplete.
@dcosson, @jmlopez-rod: there shouldn't be a need to modify the package installation semantics imposed by setuptools/distribute/easy-install. Instead what I want to figure out is: how would pkg_resources find the script? I cribbed the line pkg_resources.get_distribution(dist).get_metadata(...)
from the code path that I saw in my copy of pkg_resources. I'm not fully satisfied with your solution of scanning scripts/
and then ../scripts
, because I want to understand the underlying difference in how pkg_resources treats the installation.
from argcomplete.
So if you can find a more faithful way to reproduce what pkg_resources is doing that works in both cases, that would be the ideal solution.
from argcomplete.
@kislyuk, I think I know what is going on. The reason why it works after I delete the the package.egg-info
folder is because pkg_resources.get_distribution(dist)
points to the distribution I had installed before (the one that got setup by python setup.py install
). In such case, it will have no problem looking for the script and so it will not fail.
Consider the following, if I perform the regular installation then my script looks as follows:
#!/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
# EASY-INSTALL-SCRIPT: 'lexor==0.0.7b1','lexor'
__requires__ = 'lexor==0.0.7b1'
import pkg_resources
pkg_resources.run_script('lexor==0.0.7b1', 'lexor')
This has no problems. However, with development installation we have the following:
#!/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
# EASY-INSTALL-DEV-SCRIPT: 'lexor==0.0.7b1','lexor'
__requires__ = 'lexor==0.0.7b1'
import sys
from pkg_resources import require
require('lexor==0.0.7b1')
del require
__file__ = '/Users/jmlopez/math-jmlopez/lexor/bin/lexor'
if sys.version_info < (3, 0):
execfile(__file__)
else:
exec(compile(open(__file__).read(), __file__, 'exec'))
My proposed solution is to have two cases and a slight modification:
file_lines = lines.split('\n', 10)
for num, line in enumerate(file_lines):
if line.startswith("# EASY-INSTALL-SCRIPT"):
wt, dist, script = re.match("# EASY-INSTALL-(SCRIPT|DEV-SCRIPT): '(.+)','(.+)'", line).groups()
if "PYTHON_ARGCOMPLETE_OK" in pkg_resources.get_distribution(dist).get_metadata('scripts/'+script):
exit(0)
elif line.startswith("# EASY-INSTALL-DEV-SCRIPT"):
for line2 in file_lines[num+1:]:
if line2.startswith('__file__'):
fname = re.match("__file__ = '(.+)'", line2).groups()[0]
if "PYTHON_ARGCOMPLETE_OK" in open(fname).read(1024):
exit(0)
I don't think pkg_resources
will be able to obtain the metadata from the dev installation, otherwise why would they have bother to hardcode the script path in the script? In the above solution I simply gather the path and check to see if it has PYTHON_ARGCOMPLETE_OK
.
from argcomplete.
That's what I was looking for, thanks. Will patch the script shortly.
from argcomplete.
Released in v0.6.9, please test
from argcomplete.
@kislyuk, works in my machine. Thanks for release.
from argcomplete.
Related Issues (20)
- Contributing guidelines for argcomplete? HOT 2
- How do I exclude files in the users directory from the tab completion? HOT 2
- Unable to get completion to work for NetExec HOT 2
- zsh: completion fails with script path starting with '~/' HOT 1
- 3.2.2: pytest is failing HOT 1
- Output of `argcomplete.warn` does not show HOT 4
- Generating lazy completion scripts for Bash/Zsh HOT 1
- Problem with os.get_terminal_size() and argcomplete HOT 2
- completion with a leading dash HOT 2
- Problems with trust path when packaging HOT 6
- No automatic testing on windows? HOT 2
- Python 3.13: Some tests fail when run with latest Python pre-release HOT 5
- Check recent argparse API changes for compatibility HOT 2
- completer falls back to Bash filename completion
- Python 3.12.3: Test suite fails HOT 1
- autocompletion is slow and stuck HOT 2
- Issue with File Path Autocompletion in Argparse Outside Virtual Environment HOT 4
- Inconsistent completion when using a custom validator between `fish` and `bash` HOT 1
- zsh global completion should not be "-default-" HOT 7
- Filesystem style double tab output HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from argcomplete.