Skip to content

Commit

Permalink
disallow relative paths in ConanAPI constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Feb 25, 2025
1 parent a21c0cf commit 65120bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions conan/api/conan_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys

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

init_colorama(sys.stderr)
self.workspace = WorkspaceAPI(self)
Expand Down
11 changes: 11 additions & 0 deletions test/integration/conan_api/test_profile_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

from conan.api.conan_api import ConanAPI
from conan.errors import ConanException


def test_profile_api():
# It must be an absolute path
with pytest.raises(ConanException) as e:
ConanAPI(cache_folder="test")
assert "cache_folder has to be an absolute path" in str(e.value)

0 comments on commit 65120bc

Please sign in to comment.