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

allow removing plugin files #14376

Merged
merged 5 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions conans/client/graph/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,22 @@ def cppstd_compat(conanfile):
"""


def get_binary_compatibility_file_paths(cache):
def migrate_compatibility_files(cache):
from conans.client.migrations import update_file
compatible_folder = os.path.join(cache.plugins_path, "compatibility")
compatibility_file = os.path.join(compatible_folder, "compatibility.py")
cppstd_compat_file = os.path.join(compatible_folder, "cppstd_compat.py")
return compatibility_file, cppstd_compat_file


def migrate_compatibility_files(cache):
from conans.client.migrations import update_file

compatibility_file, cppstd_compat_file = get_binary_compatibility_file_paths(cache)
update_file(compatibility_file, _default_compat)
update_file(cppstd_compat_file, _default_cppstd_compat)


class BinaryCompatibility:

def __init__(self, cache):
compatibility_file, cppstd_compat_file = get_binary_compatibility_file_paths(cache)
compatibility_file = os.path.join(cache.plugins_path, "compatibility", "compatibility.py")
if not os.path.exists(compatibility_file):
raise ConanException("The 'compatibility.py' plugin file doesn't exist. If you want "
"to disable it, edit its contents instead of removing it")
mod, _ = load_python_file(compatibility_file)
self._compatibility = mod.compatibility

Expand Down
4 changes: 4 additions & 0 deletions conans/client/profile_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def get_default_build(self):

def _load_profile_plugin(self):
profile_plugin = os.path.join(self._cache.plugins_path, "profile.py")
if not os.path.exists(profile_plugin):
raise ConanException("The 'profile.py' plugin file doesn't exist. If you want "
"to disable it, edit its contents instead of removing it")

mod, _ = load_python_file(profile_plugin)
if hasattr(mod, "profile_plugin"):
return mod.profile_plugin
Expand Down
7 changes: 7 additions & 0 deletions conans/test/integration/configuration/test_profile_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ def profile_plugin(profile):
c.run("install --requires=zlib/1.2.3", assert_error=True)
assert "Error while processing 'profile.py' plugin, line 2" in c.out
assert "settings = profile.kk" in c.out

def test_remove_plugin_file(self):
c = TestClient()
c.run("version") # to trigger the creation
os.remove(os.path.join(c.cache.plugins_path, "profile.py"))
c.run("profile show", assert_error=True)
assert "ERROR: The 'profile.py' plugin file doesn't exist" in c.out
8 changes: 8 additions & 0 deletions conans/test/integration/package_id/test_cache_compatibles.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,11 @@ def compatibility(conanfile):
assert "Error while processing 'compatibility.py' plugin for 'dep/0.1', line 3" in c.out
assert "while calling 'debug_compat', line 2" in c.out
assert "while calling 'other', line 5" in c.out

def test_remove_plugin_file(self):
c = TestClient()
c.run("version") # to trigger the creation
os.remove(os.path.join(c.cache.plugins_path, "compatibility", "compatibility.py"))
c.save({"conanfile.txt": ""})
c.run("install .", assert_error=True)
assert "ERROR: The 'compatibility.py' plugin file doesn't exist" in c.out