Skip to content

Commit

Permalink
Run pyenv to assert the pyenv root path exists
Browse files Browse the repository at this point in the history
To support Windows (which will be done in a subsequent commit), we'll
need to translate Windows-style paths to Cygwin-style paths (for
example, C:\foo\bar -> /c/foo/bar). The fileExists step only supports
Windows-style paths when run on Windows, which means that we need to
actually run pyenv to assert that it exists.
  • Loading branch information
nre-ableton committed Sep 14, 2023
1 parent 9126435 commit 1fe0f95
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/com/ableton/Pyenv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class Pyenv implements Serializable {
protected void assertPyenvRoot() {
assert pyenvRoot

if (!script.fileExists(pyenvRoot)) {
script.error "pyenv root path '${pyenvRoot}' does not exist"
if (script.sh(returnStatus: true, script: "${pyenvRoot}/bin/pyenv --version")) {
script.error "pyenv executable not found in '${pyenvRoot}'"
}
}
}
7 changes: 3 additions & 4 deletions test/com/ableton/PyenvTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class PyenvTest extends BasePipelineTest {
@Test
void assertPyenvRootInvalidRoot() {
String pyenvRoot = '/mock/pyenv/root'
helper.registerAllowedMethod('fileExists', [String]) { return false }
helper.registerAllowedMethod('isUnix', []) { return true }
helper.addShMock("${pyenvRoot}/bin/pyenv --version", '1.2.3', 0)

assertThrows(Exception) { new Pyenv(script, '1.2.3', pyenvRoot).createVirtualEnv() }
}
Expand All @@ -52,8 +52,8 @@ class PyenvTest extends BasePipelineTest {
void createVirtualEnv() {
String pythonVersion = '1.2.3'
String pyenvRoot = '/mock/pyenv/root'
helper.registerAllowedMethod('fileExists', [String]) { return true }
helper.registerAllowedMethod('isUnix', []) { return true }
helper.addShMock("${pyenvRoot}/bin/pyenv --version", '1.2.3', 0)
helper.addShMock(installCommands(pyenvRoot, pythonVersion), '', 0)

Object venv = new Pyenv(script, pyenvRoot).createVirtualEnv(pythonVersion, 1)
Expand All @@ -74,7 +74,6 @@ class PyenvTest extends BasePipelineTest {
String pyenvRoot = '/mock/pyenv/root'
boolean errorCalled = false
helper.registerAllowedMethod('error', [String]) { errorCalled = true }
helper.registerAllowedMethod('fileExists', [String]) { return true }
helper.registerAllowedMethod('isUnix', []) { return true }
helper.addShMock("${pyenvRoot}/bin/pyenv --version", '1.2.3', 0)
helper.addShMock(installCommands(pyenvRoot, pythonVersion), '', 1)
Expand All @@ -93,8 +92,8 @@ class PyenvTest extends BasePipelineTest {
2.3.7
'''
String pyenvRoot = '/pyenv'
helper.addShMock("${pyenvRoot}/bin/pyenv --version", '1.2.3', 0)
helper.addShMock("${pyenvRoot}/bin/pyenv install --list", mockPyenvVersions, 0)
helper.registerAllowedMethod('fileExists', [String]) { return true }
helper.registerAllowedMethod('isUnix', []) { return true }

assertTrue(new Pyenv(script, pyenvRoot).versionSupported('2.1.3'))
Expand Down

0 comments on commit 1fe0f95

Please sign in to comment.