Giter Club home page Giter Club logo

Comments (16)

dcosson avatar dcosson commented on July 18, 2024

(I first commented on #61 but realized my problem is unrelated so I opened a new issue)

from argcomplete.

kislyuk avatar kislyuk commented on July 18, 2024

Just to verify... does it work with regular setup (setup.py install)?

from argcomplete.

dcosson avatar dcosson commented on July 18, 2024

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.

dcosson avatar dcosson commented on July 18, 2024

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.

jmlopez-rod avatar jmlopez-rod commented on July 18, 2024

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.

jmlopez-rod avatar jmlopez-rod commented on July 18, 2024

@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.

kislyuk avatar kislyuk commented on July 18, 2024

@jmlopez-rod, I put in a fix for your first problem in af0606c.

from argcomplete.

kislyuk avatar kislyuk commented on July 18, 2024

Released in v0.6.8, please test.

from argcomplete.

dcosson avatar dcosson commented on July 18, 2024

@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.

jmlopez-rod avatar jmlopez-rod commented on July 18, 2024

@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.

kislyuk avatar kislyuk commented on July 18, 2024

@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.

kislyuk avatar kislyuk commented on July 18, 2024

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.

jmlopez-rod avatar jmlopez-rod commented on July 18, 2024

@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.

kislyuk avatar kislyuk commented on July 18, 2024

That's what I was looking for, thanks. Will patch the script shortly.

from argcomplete.

kislyuk avatar kislyuk commented on July 18, 2024

Released in v0.6.9, please test

from argcomplete.

jmlopez-rod avatar jmlopez-rod commented on July 18, 2024

@kislyuk, works in my machine. Thanks for release.

from argcomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.