Skip to content

Commit

Permalink
Migrate is part of the full api now
Browse files Browse the repository at this point in the history
  • Loading branch information
AbrilRBS committed Jan 14, 2025
1 parent 954c501 commit 021cece
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
10 changes: 9 additions & 1 deletion conan/api/conan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from conan.api.subapi.upload import UploadAPI
from conan.errors import ConanException
from conan.internal.paths import get_conan_user_home
from conans.client.migrations import ClientMigrator
from conans.model.version_range import validate_conan_version


Expand All @@ -34,10 +35,10 @@ def __init__(self, cache_folder=None):
self.workspace = WorkspaceAPI(self)
self.cache_folder = self.workspace.home_folder() or cache_folder or get_conan_user_home()
self.home_folder = self.cache_folder # Lets call it home, deprecate "cache"
self.migrate()

# This API is depended upon by the subsequent ones, it should be initialized first
self.config = ConfigAPI(self)
self.config.migrate()

self.remotes = RemotesAPI(self)
self.command = CommandAPI(self)
Expand Down Expand Up @@ -66,6 +67,13 @@ def reinit(self):

_check_conan_version(self)

def migrate(self):
# Migration system
# TODO: A prettier refactoring of migrators would be nice
from conan import conan_version
migrator = ClientMigrator(self.cache_folder, conan_version)
migrator.migrate()


def _check_conan_version(conan_api):
required_range_new = conan_api.config.global_conf.get("core:required_conan_version")
Expand Down
9 changes: 1 addition & 8 deletions conan/api/subapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from conan.internal.cache.home_paths import HomePaths
from conan.internal.conan_app import ConanApp
from conan.internal.default_settings import default_settings_yml
from conans.client.migrations import ClientMigrator
from conans.client.graph.graph import CONTEXT_HOST, RECIPE_VIRTUAL, Node
from conans.client.graph.graph_builder import DepsGraphBuilder
from conans.client.graph.profile_node_definer import consumer_definer
Expand Down Expand Up @@ -193,12 +192,6 @@ def appending_recursive_dict_update(d, u):

return Settings(settings)

def migrate(self):
# Migration system
# TODO: A prettier refactoring of migrators would be nice
migrator = ClientMigrator(self.home(), conan_version)
migrator.migrate()

def clean(self):
contents = os.listdir(self.home())
for content in contents:
Expand All @@ -211,7 +204,7 @@ def clean(self):
else:
remove(content_path)
# CHECK: This also generates a remotes.json that is not there after a conan profile show?
self.migrate()
self.conan_api.migrate()

def reinit(self):
self._new_config = None
2 changes: 1 addition & 1 deletion test/integration/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ def test_back_default_compatibility_migration():
# simulate that we are in 2.3.2 and the old one is latest conan_version
migrator = ClientMigrator(t.cache_folder, Version("2.3.2"))

with patch('conan.api.subapi.config.ClientMigrator', new=lambda *args, **kwargs: migrator):
with patch('conan.api.conan_api.ClientMigrator', new=lambda *args, **kwargs: migrator):
t.run("-v") # Fire the backward migration
assert f"WARN: Downgrading cache from Conan {conan_version} to 2.3.2" in t.out

0 comments on commit 021cece

Please sign in to comment.