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

Add barebones Remote object, make _caching private #17639

Merged
merged 2 commits into from
Jan 27, 2025
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
10 changes: 6 additions & 4 deletions conan/api/model/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@


class Remote:

"""
The ``Remote`` class represents a remote registry of packages. It's a read-only opaque object that
should not be created directly, but obtained from the relevant ``RemotesAPI`` subapi methods.
"""
def __init__(self, name, url, verify_ssl=True, disabled=False, allowed_packages=None,
remote_type=None):
self.name = name # Read only, is the key
Expand All @@ -11,7 +14,7 @@ def __init__(self, name, url, verify_ssl=True, disabled=False, allowed_packages=
self.disabled = disabled
self.allowed_packages = allowed_packages
self.remote_type = remote_type
self.caching = {}
self._caching = {}
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

def __eq__(self, other):
if other is None:
Expand All @@ -33,5 +36,4 @@ def __repr__(self):
return str(self)

def invalidate_cache(self):
# TODO: make it private
self.caching = {}
self._caching = {}
26 changes: 13 additions & 13 deletions conan/api/subapi/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def reinit(self):

def list(self, pattern=None, only_enabled=True):
"""
Obtain a list of ``Remote`` objects matching the pattern.
Obtain a list of :ref:`Remote <conan.api.model.Remote>` objects matching the pattern.
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

:param pattern: ``None``, single ``str`` or list of ``str``. If it is ``None``,
all remotes will be returned (equivalent to ``pattern="*"``).
:param only_enabled: boolean, by default return only enabled remotes
:return: A list of ``Remote`` objects
:return: A list of :ref:`Remote <conan.api.model.Remote>` objects

"""
remotes = _load(self._remotes_file)
Expand All @@ -61,7 +61,7 @@ def disable(self, pattern):

:param pattern: single ``str`` or list of ``str``. If the pattern is an exact name without
wildcards like "*" and no remote is found matching that exact name, it will raise an error.
:return: the list of disabled ``Remote`` objects (even if they were already disabled)
:return: the list of disabled :ref:`Remote <conan.api.model.Remote>` objects (even if they were already disabled)
"""
remotes = _load(self._remotes_file)
disabled = _filter(remotes, pattern, only_enabled=False)
Expand All @@ -79,7 +79,7 @@ def enable(self, pattern):

:param pattern: single ``str`` or list of ``str``. If the pattern is an exact name without
wildcards like "*" and no remote is found matching that exact name, it will raise an error.
:return: the list of enabled ``Remote`` objects (even if they were already enabled)
:return: the list of enabled :ref:`Remote <conan.api.model.Remote>` objects (even if they were already enabled)
"""
remotes = _load(self._remotes_file)
enabled = _filter(remotes, pattern, only_enabled=False)
Expand All @@ -93,10 +93,10 @@ def enable(self, pattern):

def get(self, remote_name):
"""
Obtain a ``Remote`` object
Obtain a :ref:`Remote <conan.api.model.Remote>` object

:param remote_name: the exact name of the remote to be returned
:return: the ``Remote`` object, or raise an Exception if the remote does not exist.
:return: the :ref:`Remote <conan.api.model.Remote>` object, or raise an Exception if the remote does not exist.
"""
remotes = _load(self._remotes_file)
try:
Expand All @@ -106,11 +106,11 @@ def get(self, remote_name):

def add(self, remote: Remote, force=False, index=None):
"""
Add a new ``Remote`` object to the existing ones
Add a new :ref:`Remote <conan.api.model.Remote>` object to the existing ones


:param remote: a ``Remote`` object to be added
:param force: do not fail if the remote already exist (but default it failes)
:param remote: a :ref:`Remote <conan.api.model.Remote>` object to be added
:param force: do not fail if the remote already exist (but default it fails)
:param index: if not defined, the new remote will be last one. Pass an integer to insert
the remote in that position instead of the last one
"""
Expand Down Expand Up @@ -143,7 +143,7 @@ def remove(self, pattern):

:param pattern: single ``str`` or list of ``str``. If the pattern is an exact name without
wildcards like "*" and no remote is found matching that exact name, it will raise an error.
:return: The list of removed ``Remote`` objects
:return: The list of removed :ref:`Remote <conan.api.model.Remote>` objects
"""
remotes = _load(self._remotes_file)
removed = _filter(remotes, pattern, only_enabled=False)
Expand Down Expand Up @@ -220,7 +220,7 @@ def user_login(self, remote: Remote, username: str, password: str):
"""
Perform user authentication against the given remote with the provided username and password

:param remote: a ``Remote`` object
:param remote: a :ref:`Remote <conan.api.model.Remote>` object
:param username: the user login as ``str``
:param password: password ``str``
"""
Expand All @@ -229,9 +229,9 @@ def user_login(self, remote: Remote, username: str, password: str):

def user_logout(self, remote: Remote):
"""
Logout from the given ``Remote``
Logout from the given :ref:`Remote <conan.api.model.Remote>`

:param remote: The ``Remote`` object to logout
:param remote: The :ref:`Remote <conan.api.model.Remote>` object to logout
"""
localdb = LocalDB(self._home_folder)
# The localdb only stores url + username + token, not remote name, so use URL as key
Expand Down
4 changes: 2 additions & 2 deletions conans/client/remote_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _get_package(self, layout, pref, remote, scoped_output, metadata):
raise

def search_recipes(self, remote, pattern):
cached_method = remote.caching.setdefault("search_recipes", {})
cached_method = remote._caching.setdefault("search_recipes", {})
try:
return cached_method[pattern]
except KeyError:
Expand Down Expand Up @@ -241,7 +241,7 @@ def get_latest_package_reference(self, pref, remote, info=None) -> PkgReference:
if options:
headers['Conan-PkgID-Options'] = ';'.join(options)

cached_method = remote.caching.setdefault("get_latest_package_reference", {})
cached_method = remote._caching.setdefault("get_latest_package_reference", {})
try:
return cached_method[pref]
except KeyError:
Expand Down
Loading