From db23cef3079fdf78ab60e027ac1387d4be9ff3d7 Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 15 Jan 2025 23:40:23 +0100 Subject: [PATCH] adding migration warnings for internal model --- .../cli/formatters/list/binary_html_table.py | 141 ------------------ conans/model/__init__.py | 0 conans/model/package_ref.py | 28 ++++ conans/model/recipe_ref.py | 29 ++++ 4 files changed, 57 insertions(+), 141 deletions(-) delete mode 100644 conan/cli/formatters/list/binary_html_table.py create mode 100644 conans/model/__init__.py create mode 100644 conans/model/package_ref.py create mode 100644 conans/model/recipe_ref.py diff --git a/conan/cli/formatters/list/binary_html_table.py b/conan/cli/formatters/list/binary_html_table.py deleted file mode 100644 index 6b0e0ac1ba1..00000000000 --- a/conan/cli/formatters/list/binary_html_table.py +++ /dev/null @@ -1,141 +0,0 @@ -from collections import OrderedDict, defaultdict - -from conan.internal.model.package_ref import PkgReference - - -class RowResult(object): - def __init__(self, remote, reference, data): - self.remote = remote - self.reference = reference - self._data = data - - @property - def recipe(self): - return self.reference - - @property - def package_id(self): - return self._data['id'] - - def row(self, headers): - """ Returns package data according to headers """ - assert isinstance(headers, Headers), "Wrong type: {}".format(type(headers)) - - for it in headers.keys: - try: - yield getattr(self, it) - except AttributeError: - yield self._data[it] - for it in headers.settings: - yield self._data['settings'].get(it, None) - for it in headers.options: - yield self._data['options'].get(it, None) - if headers.requires: - prefs = [PkgReference.loads(it) for it in self._data['requires']] - yield ', '.join(map(str, [it.ref for it in prefs])) - - -class Headers(object): - _preferred_ordering = ['os', 'arch', 'compiler', 'build_type'] - - def __init__(self, settings, options, requires, keys): - # Keys: columns to classify - self.keys = keys - self.options = options - self.requires = requires - - # - Order settings - _settings = defaultdict(list) - for it in settings: - try: - category, _ = it.split('.', 1) - except ValueError: - _settings[it].append(it) - else: - _settings[category].append(it) - - self.settings = [] - for it in self._preferred_ordering: - if it in _settings: - self.settings.extend(sorted(_settings[it])) - for it, values in _settings.items(): - if it not in self._preferred_ordering: - self.settings.extend(sorted(values)) - - def row(self, n_rows=2): - """ - Retrieve list of headers as a single list (1-row) or as a list of tuples with - settings organized by categories (2-row). - - Example output: - 1-row: ['os', 'arch', 'compiler', 'compiler.version', 'compiler.libcxx', 'build_type'] - 2-row: [('os', ['']), ('arch', ['']), ('compiler', ['', 'version', 'libcxx']),] - """ - headers = list(self.keys) - if n_rows == 1: - headers.extend(self.settings + self.options) - if self.requires: - headers.append('requires') - return headers - elif n_rows == 2: - headers = [(it, ['']) for it in headers] - settings = self._group_settings(self.settings) - headers.extend(settings) - headers.append(('options', self.options)) - if self.requires: - headers.append(('requires', [''])) - return headers - else: - raise NotImplementedError("not yet") - - @staticmethod - def _group_settings(settings): - """ - From one row to two-rows using '.' as separator - """ - ret = OrderedDict() - for setting in settings: - try: - category, value = setting.split(".", 1) - except ValueError: - ret.setdefault(setting, []).append('') - else: - ret.setdefault(category, []).append(value) - return [(key, values) for key, values in ret.items()] - - -class Results(object): - def __init__(self, results): - self._results = results - - # Collect data inspecting the packages - _settings = set() - _options = set() - _remotes = set() - self.requires = False - - for it in results: - _remotes.add(it['remote']) - for p in it['items'][0]['packages']: - _settings = _settings.union(list(p['settings'].keys())) - _options = _options.union(list(p['options'].keys())) - if len(p['requires']): - self.requires = True - - self.settings = list(_settings) - self.options = list(_options) - self.remotes = list(_remotes) - - def get_headers(self, keys=('remote', 'reference', 'package_id')): - return Headers(self.settings, self.options, self.requires, keys=keys) - - def packages(self): - for it in self._results: - remote = it['remote'] - reference = it['items'][0]['recipe']['id'] - for p in it['items'][0]['packages']: - r = RowResult(remote, reference, p) - yield r - - - diff --git a/conans/model/__init__.py b/conans/model/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/conans/model/package_ref.py b/conans/model/package_ref.py new file mode 100644 index 00000000000..78761396e5d --- /dev/null +++ b/conans/model/package_ref.py @@ -0,0 +1,28 @@ +from conan.api.output import ConanOutput +from conan.internal.model.package_ref import PkgReference as _PkgReference + +_msg = """ +******************************************************************* +private '{}' +detected in user code (custom commands, extensions, recipes, etc). +Stop using it, use only public documented APIs. +******************************************************************* +""" + + +class PkgReference(_PkgReference): + usage_counter = 0 + + def __init__(self, *args, **kwargs): + if PkgReference.usage_counter == 0: + ConanOutput().warning(_msg.format("from conans.model.package_ref import PkgReference")) + PkgReference.usage_counter += 1 + super(PkgReference, self).__init__(*args, **kwargs) + + @staticmethod + def loads(*args, **kwargs): + if PkgReference.usage_counter == 0: + ConanOutput().warning(_msg.format("from conans.model.package_ref import PkgReference"), + warn_tag="deprecated") + PkgReference.usage_counter += 1 + return _PkgReference.loads(*args, **kwargs) diff --git a/conans/model/recipe_ref.py b/conans/model/recipe_ref.py new file mode 100644 index 00000000000..a2262ac92b3 --- /dev/null +++ b/conans/model/recipe_ref.py @@ -0,0 +1,29 @@ +from conan.api.output import ConanOutput +from conan.internal.model.recipe_ref import RecipeReference as _RecipeReference + +_msg = """ +******************************************************************* +private '{}' +detected in user code (custom commands, extensions, recipes, etc). +Stop using it, use only public documented APIs. +******************************************************************* +""" + + +class RecipeReference(_RecipeReference): + usage_counter = 0 + + def __init__(self, *args, **kwargs): + if RecipeReference.usage_counter == 0: + ConanOutput().warning(_msg.format("from conans.model.recipe_ref import RecipeReference"), + warn_tag="deprecated") + RecipeReference.usage_counter += 1 + super(RecipeReference, self).__init__(*args, **kwargs) + + @staticmethod + def loads(*args, **kwargs): + if RecipeReference.usage_counter == 0: + ConanOutput().warning(_msg.format("from conans.model.recipe_ref import RecipeReference"), + warn_tag="deprecated") + RecipeReference.usage_counter += 1 + return _RecipeReference.loads(*args, **kwargs)