Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behaviour when invoking .py script through symlink #404

Closed
blueyed opened this issue Jul 8, 2015 · 4 comments
Closed

Different behaviour when invoking .py script through symlink #404

blueyed opened this issue Jul 8, 2015 · 4 comments

Comments

@blueyed
Copy link
Contributor

blueyed commented Jul 8, 2015

When calling a Python script via its shebang line, the following part in the python shim kicks in:

  if [ -f "$arg" ]; then
    export PYENV_DIR="${arg%/*}"
    break
  fi

However, that should resolve symlinks probably:

    arg=$(readlink -f $arg)

Otherwise calling it via a symlink from e.g. ~/bin pyenv-version-file will not pick up a .python-version file from the final destination, but only from ~/bin.

The current behaviour could be seen as a feature: by using symlinks you could have different Python versions (depending on where the symlink's file is), but I think it makes more sense to use the real script's dir.

btw: this code currently does not handle python2/python3 in the shebang line properly (#379) - I will re-open that PR.

blueyed added a commit to blueyed/pyenv that referenced this issue Jul 8, 2015
`PYENV_FILE_ARG` is used here to make use of `abs_dirname` later in
`libexec/pyenv`.

Fixes pyenv#404
@blueyed
Copy link
Contributor Author

blueyed commented Jul 8, 2015

I've added a proposed fix for this to #379: blueyed@dab4742

@blueyed
Copy link
Contributor Author

blueyed commented Jul 8, 2015

If that's the way to go there should be some test for this then.

@blueyed blueyed changed the title Different behaviour when invoking .py script as symlink Different behaviour when invoking .py script through symlink Jul 8, 2015
blueyed added a commit to blueyed/pyenv that referenced this issue Jul 8, 2015
`PYENV_FILE_ARG` is used here to make use of `abs_dirname` later in
`libexec/pyenv`.

Fixes pyenv#404
@yyuu
Copy link
Contributor

yyuu commented Jul 9, 2015

Thanks for reporting. Please provide me some minimum script to reproduce the issue (or, test case) if you're available.

@blueyed
Copy link
Contributor Author

blueyed commented Jul 9, 2015

Create a test.py file that you call then with the full path or it's symlink,
with a local version at the symlink target and symlink's place:

% cd /tmp
% cat > test.py
#!/usr/bin/env python
import sys

print(sys.version_info)

% chmod +x test.py
% pyenv local 2.7.10

% cd ~/tmp
% pyenv local 3.4.3

% /tmp/test.py
sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0)

% ln -s /tmp/test.py
% ./test.py
sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)

yyuu added a commit to yyuu/rbenv that referenced this issue Nov 21, 2015
I believe there are 2 weird behaviour relating to `RBENV_DIR`.  This should fix both 2.

1. file argument does not follow symlink (pyenv/pyenv#404)
2. file argument works weirdly if first argument doesn't contain `/` (pyenv/pyenv#479)

Both can be reproduced with the following setup.

```sh
$ mkdir -p ./foo
$ echo 2.2.3 > ./foo/.ruby-version
$ echo 'puts(RUBY_DESCRIPTION)' > ./foo/test.rb
$ mkdir -p ./foo/bar
$ echo jruby-9.0.0.0 > ./foo/bar/.ruby-version
$ ln -sf ${PWD}/foo/test.rb ./foo/bar/
```

If the first file argument to `ruby` interpreter is a symlink, it'd be
better to follow the link.

```sh
$ ruby ./foo/test.rb
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ ruby ./foo/bar/test.rb
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.72-b05 on 1.8.0_72-internal-b05 +jit [linux-amd64]
```

`RBENV_DIR` just not working if the first file argument doesn't contain `/`.

```sh
$ cd ./foo
$ ruby test.rb
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ ruby test.rb ./bar/test.rb
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.72-b05 on 1.8.0_72-internal-b05 +jit [linux-amd64] # <-- this would be better to be 2.2.3
```
yyuu added a commit to yyuu/rbenv that referenced this issue Nov 25, 2015
I believe there are 2 weird behaviour relating to `RBENV_DIR`.  This should fix both 2.

1. file argument does not follow symlink (pyenv/pyenv#404)
2. file argument works weirdly if first argument doesn't contain `/` (pyenv/pyenv#479)

Both can be reproduced with the following setup.

```sh
$ mkdir -p ./foo
$ echo 2.2.3 > ./foo/.ruby-version
$ echo 'puts(RUBY_DESCRIPTION)' > ./foo/test.rb
$ mkdir -p ./foo/bar
$ echo jruby-9.0.0.0 > ./foo/bar/.ruby-version
$ ln -sf ${PWD}/foo/test.rb ./foo/bar/
```

If the first file argument to `ruby` interpreter is a symlink, it'd be
better to follow the link.

```sh
$ ruby ./foo/test.rb
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ ruby ./foo/bar/test.rb
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.72-b05 on 1.8.0_72-internal-b05 +jit [linux-amd64]
```

`RBENV_DIR` just not working if the first file argument doesn't contain `/`.

```sh
$ cd ./foo
$ ruby test.rb
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ ruby test.rb ./bar/test.rb
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.72-b05 on 1.8.0_72-internal-b05 +jit [linux-amd64] # <-- this would be better to be 2.2.3
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants