shiv icon indicating copy to clipboard operation
shiv copied to clipboard

Incorrect value for sys.argv[0] when built with shiv>=0.5.0

Open Thirdegree opened this issue 4 years ago • 4 comments

Minimal reproduction: https://github.com/Thirdegree/shiv-issue-reproduction

Output when built with shiv<0.5.0 (expected output):

$ pip install 'shiv<0.5.0'                     
[...]
$ shiv -c example . -o my-other-example        
[...]
$ ./my-other-example                           
['./my-other-example']                         

and shiv>=0.5.0:

$ pip install 'shiv>=0.5.0'                                                                                                                 
[...]
$ shiv -c example . -o my-other-example      
[...]                                                                                               
$ ./my-other-example                                                                                                                        
['/home/<snip>/.shiv/my-other-example_4e97fbfbe05adc1827d2cf3da93d0600d4eb83fdb7b83d1230c1127d42c9e4e0/site-packages/bin/example']          

This seems to only be an issue when built with -c:

$ shiv -e reproduce.main:main -o my-example . 
$ ./my-example                                
['./my-example']   

Thirdegree avatar Apr 29 '21 12:04 Thirdegree

Hi @Thirdegree,

Thanks for the report! I didn’t expect this, but as soon as I saw the ~/.shiv path in your example output I knew what happened ☹️. The environment variable override I added in the last commit changed how we look up the entry point when -c is provided.

I’ll get a fix out ASAP

lorencarvalho avatar Apr 29 '21 15:04 lorencarvalho

Awesome, thanks!

Thirdegree avatar Apr 29 '21 18:04 Thirdegree

Hi @Thirdegree, got this fixed and released to PyPI @ 0.5.2

$ ~/bin/shiv --version
0.5.2
$ ~/bin/shiv -c example . -o my-other-example2
$ ./my-other-example2
['./my-other-example2']

However, the problem will still manifest if you override the entry_point/console_script supplied at build-time:

$ SHIV_CONSOLE_SCRIPT=example ./my-other-example2
['/Users/lcarvalh/.shiv/my-other-example2_3aaa187b0d2d5d093bdc271d42071aaf32c71523b0c117b485bf3a1dffc47fae/site-packages/bin/example']

I have an idea for how to fix that, and I'd like to add a regression test as well, so I'm going to leave this issue open until I can get to those. I just don't have access to my regular workstation right now, but I will by Tuesday. Thanks for your patience!

lorencarvalho avatar Apr 30 '21 16:04 lorencarvalho

Hey, no problem, thanks for the help! I don't use that particular feature, so that's no issue for me. Thanks for being so quick!

Thirdegree avatar May 03 '21 08:05 Thirdegree