Skip to content

Commit 127971a

Browse files
authored
disallow relative paths in ConanAPI constructor (#17851)
1 parent 899a74d commit 127971a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

conan/api/conan_api.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23

34
from conan.api.output import init_colorama
@@ -35,6 +36,8 @@ def __init__(self, cache_folder=None):
3536
version = sys.version_info
3637
if version.major == 2 or version.minor < 6:
3738
raise ConanException("Conan needs Python >= 3.6")
39+
if cache_folder is not None and not os.path.isabs(cache_folder):
40+
raise ConanException("cache_folder has to be an absolute path")
3841

3942
init_colorama(sys.stderr)
4043
self.workspace = WorkspaceAPI(self)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
from conan.api.conan_api import ConanAPI
4+
from conan.errors import ConanException
5+
6+
7+
def test_profile_api():
8+
# It must be an absolute path
9+
with pytest.raises(ConanException) as e:
10+
ConanAPI(cache_folder="test")
11+
assert "cache_folder has to be an absolute path" in str(e.value)

0 commit comments

Comments
 (0)