Skip to content

use Rscript path relative to $R_HOME/bin/...#2301

Merged
asottile merged 1 commit intopre-commit:mainfrom
jeff-m-sullivan:rscript-path
Apr 2, 2022
Merged

use Rscript path relative to $R_HOME/bin/...#2301
asottile merged 1 commit intopre-commit:mainfrom
jeff-m-sullivan:rscript-path

Conversation

@jeff-m-sullivan
Copy link
Contributor

I'm not familiar enough with developing pre-commit to know how to test out my branch in the same environment where I experienced the bug, but I would be happy to do so with a little more guidance.

I believe this fixes the Rscript path issue I noticed using the built-in Terminal from RStudio Server on Ubuntu.

@lorenzwalthert
Copy link
Contributor

lorenzwalthert commented Mar 23, 2022

This currently does not work because we also need to account for the fact that R_HOME might not be set (as it seems in the test suite). In that case,bin/Rscript Is returned.

To be true to the name of the function return value, maybe we should (Edit: rename the function) and look up if Rscript is on the PATH and return that full path or - if Rscript is not on the PATH - return $R_HOME/bin/Rscript, and error if $R_HOME is not set.

@asottile asottile changed the title Closes #2300 use bin dir relative to R_HOME Mar 23, 2022
@jeff-m-sullivan
Copy link
Contributor Author

Of course! Sorry I missed that. I'll put together something more thorough along those lines.

@lorenzwalthert
Copy link
Contributor

lorenzwalthert commented Mar 24, 2022

Cool. Let me know if you need help. Also, we should rename the function _rscript_exec to _path_rscript_exec() as it now always returns a path to the executable and it would be great if you could also test to tests/languages/r_test.py. You can ensure the same env as in the execution is present and set R home in a similar way:

from pre_commit.languages.r import in_env, _path_rscript_exec
from pre_commit.envcontext import envcontext

@pytest.mark.parametrize(('r_home_env', 'rscript_path_expected') [("/usr/bin/local", "/user/bin/local/Rscript"), (UNSET, 'location is os specific: get it dynamically)])
def test_path_rscript_exec(r_home_env, rscript_path_expected):
    with in_env(hook.prefix, hook.language_version):
        with envcontext(("R_HOME", r_home_env)): 
            assert _path_rscript_exec() == rscript_path_expected

If it gives an error or takes too long to create a test, I can figure that out later.

@lorenzwalthert
Copy link
Contributor

Actually we should not really need with in_env…

Co-authored-by: Lorenz Walthert <lorenz.walthert@icloud.com>
@asottile asottile changed the title use bin dir relative to R_HOME use Rscript path relative to $R_HOME/bin/... Apr 2, 2022
@asottile
Copy link
Member

asottile commented Apr 2, 2022

I went ahead and added that test and adjusted the code

@asottile asottile merged commit e11163d into pre-commit:main Apr 2, 2022
@lorenzwalthert
Copy link
Contributor

thank you, seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants