Skip to content

Commit

Permalink
[develop2] remove api_method decorator (#13091)
Browse files Browse the repository at this point in the history
* [develop2] remove api_method decorator

* remove dead test
  • Loading branch information
memsharded authored Feb 10, 2023
1 parent d43b1c3 commit df521af
Show file tree
Hide file tree
Showing 15 changed files with 2 additions and 131 deletions.
26 changes: 0 additions & 26 deletions conan/api/subapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +0,0 @@
import functools
import os

from conans.util.tracer import log_conan_api_call


def api_method(f):
"""Useful decorator to manage Conan API methods"""

@functools.wraps(f)
def wrapper(subapi, *args, **kwargs):
try: # getcwd can fail if Conan runs on an non-existing folder
old_curdir = os.getcwd()
except EnvironmentError:
old_curdir = None

try:
# FIXME: Fix this hack if we want to keep the action recorder
subapi_name = str(subapi.__class__.__name__).replace("API", "").lower()
log_conan_api_call("{}.{}".format(subapi_name, f.__name__), kwargs)
return f(subapi, *args, **kwargs)
finally:
if old_curdir:
os.chdir(old_curdir)

return wrapper
8 changes: 0 additions & 8 deletions conan/api/subapi/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from conan.api.subapi import api_method
from conan.internal.conan_app import ConanApp
from conan.internal.integrity_check import IntegrityChecker
from conans.errors import ConanException
Expand All @@ -12,49 +11,42 @@ class CacheAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def export_path(self, ref: RecipeReference):
app = ConanApp(self.conan_api.cache_folder)
ref = _resolve_latest_ref(app, ref)
ref_layout = app.cache.ref_layout(ref)
return ref_layout.export()

@api_method
def export_source_path(self, ref: RecipeReference):
app = ConanApp(self.conan_api.cache_folder)
ref = _resolve_latest_ref(app, ref)
ref_layout = app.cache.ref_layout(ref)
return ref_layout.export_sources()

@api_method
def source_path(self, ref: RecipeReference):
app = ConanApp(self.conan_api.cache_folder)
ref = _resolve_latest_ref(app, ref)
ref_layout = app.cache.ref_layout(ref)
return ref_layout.source()

@api_method
def build_path(self, pref: PkgReference):
app = ConanApp(self.conan_api.cache_folder)
pref = _resolve_latest_pref(app, pref)
ref_layout = app.cache.pkg_layout(pref)
return ref_layout.build()

@api_method
def package_path(self, pref: PkgReference):
app = ConanApp(self.conan_api.cache_folder)
pref = _resolve_latest_pref(app, pref)
ref_layout = app.cache.pkg_layout(pref)
return ref_layout.package()

@api_method
def check_integrity(self, package_list):
"""Check if the recipes and packages are corrupted (it will raise a ConanExcepcion)"""
app = ConanApp(self.conan_api.cache_folder)
checker = IntegrityChecker(app)
checker.check(package_list)

@api_method
def clean(self, package_list, source=None, build=None, download=None):
"""
Remove non critical folders from the cache, like source, build and download (.tgz store)
Expand Down
4 changes: 0 additions & 4 deletions conan/api/subapi/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from conan.api.subapi import api_method
from conan.internal.conan_app import ConanApp


Expand All @@ -7,11 +6,9 @@ class ConfigAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def home(self):
return self.conan_api.cache_folder

@api_method
def install(self, path_or_url, verify_ssl, config_type=None, args=None,
source_folder=None, target_folder=None):
# TODO: We probably want to split this into git-folder-http cases?
Expand All @@ -21,7 +18,6 @@ def install(self, path_or_url, verify_ssl, config_type=None, args=None,
config_type=config_type, args=args,
source_folder=source_folder, target_folder=target_folder)

@api_method
def get(self, name, default=None, check_type=None):
app = ConanApp(self.conan_api.cache_folder)
return app.cache.new_config.get(name, default=default, check_type=check_type)
3 changes: 0 additions & 3 deletions conan/api/subapi/download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from conan.api.model import Remote
from conan.api.subapi import api_method
from conan.api.output import ConanOutput
from conan.internal.conan_app import ConanApp
from conans.client.source import retrieve_exports_sources
Expand All @@ -13,7 +12,6 @@ class DownloadAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def recipe(self, ref: RecipeReference, remote: Remote):
output = ConanOutput()
app = ConanApp(self.conan_api.cache_folder)
Expand All @@ -34,7 +32,6 @@ def recipe(self, ref: RecipeReference, remote: Remote):
retrieve_exports_sources(app.remote_manager, layout, conanfile, ref, [remote])
return True

@api_method
def package(self, pref: PkgReference, remote: Remote):
output = ConanOutput()
app = ConanApp(self.conan_api.cache_folder)
Expand Down
3 changes: 0 additions & 3 deletions conan/api/subapi/export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from conan.api.output import ConanOutput
from conan.api.subapi import api_method
from conan.internal.conan_app import ConanApp
from conans.client.cmd.export import cmd_export
from conans.client.conanfile.package import run_package_method
Expand All @@ -13,13 +12,11 @@ class ExportAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def export(self, path, name, version, user, channel, lockfile=None, remotes=None):
app = ConanApp(self.conan_api.cache_folder)
return cmd_export(app, path, name, version, user, channel, graph_lock=lockfile,
remotes=remotes)

@api_method
def export_pkg(self, deps_graph, source_folder, output_folder):
app = ConanApp(self.conan_api.cache_folder)
cache, hook_manager = app.cache, app.hook_manager
Expand Down
7 changes: 0 additions & 7 deletions conan/api/subapi/graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from conan.api.output import ConanOutput
from conan.api.subapi import api_method
from conan.internal.conan_app import ConanApp
from conan.cli.printers.graph import print_graph_basic
from conans.client.graph.graph import Node, RECIPE_CONSUMER, CONTEXT_HOST, RECIPE_VIRTUAL
Expand Down Expand Up @@ -49,7 +48,6 @@ def _load_root_consumer_conanfile(self, path, profile_host, profile_build,
path=path)
return root_node

@api_method
def load_root_test_conanfile(self, path, tested_reference, profile_host, profile_build,
update=None, remotes=None, lockfile=None,
tested_python_requires=None):
Expand Down Expand Up @@ -110,7 +108,6 @@ def _scope_options(profile, requires, tool_requires):
if tool_requires and len(tool_requires) == 1 and not requires:
profile.options.scope(tool_requires[0])

@api_method
def load_graph_requires(self, requires, tool_requires, profile_host, profile_build,
lockfile, remotes, update, check_updates=False, allow_error=False):
requires = [RecipeReference.loads(r) if isinstance(r, str) else r for r in requires] \
Expand Down Expand Up @@ -145,7 +142,6 @@ def load_graph_requires(self, requires, tool_requires, profile_host, profile_bui

return deps_graph

@api_method
def load_graph_consumer(self, path, name, version, user, channel,
profile_host, profile_build, lockfile, remotes, update,
allow_error=False, check_updates=False):
Expand Down Expand Up @@ -173,7 +169,6 @@ def load_graph_consumer(self, path, name, version, user, channel,

return deps_graph

@api_method
def load_graph(self, root_node, profile_host, profile_build, lockfile=None, remotes=None,
update=False, check_update=False):
""" Compute the dependency graph, starting from a root package, evaluation the graph with
Expand Down Expand Up @@ -203,7 +198,6 @@ def load_graph(self, root_node, profile_host, profile_build, lockfile=None, remo
deps_graph = builder.load_graph(root_node, profile_host, profile_build, lockfile)
return deps_graph

@api_method
def analyze_binaries(self, graph, build_mode=None, remotes=None, update=None, lockfile=None):
""" Given a dependency graph, will compute the package_ids of all recipes in the graph, and
evaluate if they should be built from sources, downloaded from a remote server, of if the
Expand All @@ -221,7 +215,6 @@ def analyze_binaries(self, graph, build_mode=None, remotes=None, update=None, lo
binaries_analyzer = GraphBinariesAnalyzer(conan_app)
binaries_analyzer.evaluate_graph(graph, build_mode, lockfile, remotes, update)

@api_method
def load_conanfile_class(self, path):
""" Given a path to a conanfile.py file, it loads its class (not instance) to allow
inspecting the class attributes, like 'name', 'version', 'description', 'options' etc"""
Expand Down
5 changes: 1 addition & 4 deletions conan/api/subapi/install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from conan.api.subapi import api_method
from conan.internal.conan_app import ConanApp
from conan.internal.deploy import do_deploys
from conans.client.generators import write_generators
Expand All @@ -12,7 +11,6 @@ class InstallAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def install_binaries(self, deps_graph, remotes=None):
""" Install binaries for dependency graph
:param deps_graph: Dependency graph to intall packages for
Expand All @@ -23,7 +21,6 @@ def install_binaries(self, deps_graph, remotes=None):
installer.install_system_requires(deps_graph) # TODO: Optimize InstallGraph computation
installer.install(deps_graph, remotes)

@api_method
def install_system_requires(self, graph, only_info=False):
""" Install binaries for dependency graph
:param only_info: Only allow reporting and checking, but never install
Expand All @@ -33,9 +30,9 @@ def install_system_requires(self, graph, only_info=False):
installer = BinaryInstaller(app)
installer.install_system_requires(graph, only_info)

@api_method
def install_sources(self, graph, remotes):
""" Install sources for dependency graph
:param remotes:
:param graph: Dependency graph to install packages for
"""
app = ConanApp(self.conan_api.cache_folder)
Expand Down
2 changes: 0 additions & 2 deletions conan/api/subapi/lockfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from conan.api.output import ConanOutput
from conan.api.subapi import api_method
from conan.cli.commands import make_abs_path
from conans.errors import ConanException
from conans.model.graph_lock import Lockfile, LOCKFILE
Expand All @@ -12,7 +11,6 @@ class LockfileAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def get_lockfile(self, lockfile=None, conanfile_path=None, cwd=None, partial=False):
""" obtain a lockfile, following this logic:
- If lockfile is explicitly defined, it would be either absolute or relative to cwd and
Expand Down
4 changes: 0 additions & 4 deletions conan/api/subapi/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from jinja2 import Template, StrictUndefined

from conan.api.subapi import api_method
from conans.util.files import load
from conans import __version__

Expand All @@ -14,7 +13,6 @@ class NewAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def get_builtin_template(self, template_name):
from conan.internal.api.new.basic import basic_file
from conan.internal.api.new.alias_new import alias_file
Expand Down Expand Up @@ -43,14 +41,12 @@ def get_builtin_template(self, template_name):
template_files = new_templates.get(template_name)
return template_files

@api_method
def get_template(self, template_folder):
""" Load a template from a user absolute folder
"""
if os.path.isdir(template_folder):
return self._read_files(template_folder)

@api_method
def get_home_template(self, template_name):
""" Load a template from the Conan home templates/command/new folder
"""
Expand Down
14 changes: 0 additions & 14 deletions conan/api/subapi/remotes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fnmatch

from conan.api.subapi import api_method
from conan.internal.conan_app import ConanApp
from conans.client.cache.remote_registry import Remote
from conans.client.cmd.user import user_set, users_clean, users_list
Expand All @@ -12,7 +11,6 @@ class RemotesAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def list(self, pattern=None, only_enabled=True):
"""
:param pattern: if None, all remotes will be listed
Expand Down Expand Up @@ -45,70 +43,58 @@ def list(self, pattern=None, only_enabled=True):
remotes = filtered_remotes
return remotes

@api_method
def disable(self, pattern):
remotes = self.list(pattern, only_enabled=False)
for r in remotes:
r.disabled = True
self.update(r)

@api_method
def enable(self, pattern):
remotes = self.list(pattern, only_enabled=False)
for r in remotes:
r.disabled = False
self.update(r)

@api_method
def get(self, remote_name):
app = ConanApp(self.conan_api.cache_folder)
return app.cache.remotes_registry.read(remote_name)

@api_method
def add(self, remote: Remote):
app = ConanApp(self.conan_api.cache_folder)
app.cache.remotes_registry.add(remote)

@api_method
def remove(self, remote_name):
app = ConanApp(self.conan_api.cache_folder)
remotes = self.list(remote_name, only_enabled=False)
for remote in remotes:
app.cache.remotes_registry.remove(remote.name)
users_clean(app.cache.localdb, remote.url)

@api_method
def update(self, remote: Remote):
app = ConanApp(self.conan_api.cache_folder)
app.cache.remotes_registry.update(remote)

@api_method
def move(self, remote: Remote, index: int):
app = ConanApp(self.conan_api.cache_folder)
app.cache.remotes_registry.move(remote, index)

@api_method
def rename(self, remote: Remote, new_name: str):
app = ConanApp(self.conan_api.cache_folder)
app.cache.remotes_registry.rename(remote, new_name)

@api_method
def user_info(self, remote: Remote):
app = ConanApp(self.conan_api.cache_folder)
return users_list(app.cache.localdb, remotes=[remote])[0]

@api_method
def login(self, remote: Remote, username, password):
app = ConanApp(self.conan_api.cache_folder)
app.remote_manager.authenticate(remote, username, password)

@api_method
def logout(self, remote: Remote):
app = ConanApp(self.conan_api.cache_folder)
# The localdb only stores url + username + token, not remote name, so use URL as key
users_clean(app.cache.localdb, remote.url)

@api_method
def user_set(self, remote: Remote, username):
app = ConanApp(self.conan_api.cache_folder)
return user_set(app.cache.localdb, username, remote)
4 changes: 0 additions & 4 deletions conan/api/subapi/remove.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from conan.api.model import Remote
from conan.api.subapi import api_method
from conan.internal.conan_app import ConanApp
from conans.model.package_ref import PkgReference
from conans.model.recipe_ref import RecipeReference
Expand All @@ -10,7 +9,6 @@ class RemoveAPI:
def __init__(self, conan_api):
self.conan_api = conan_api

@api_method
def recipe(self, ref: RecipeReference, remote: Remote=None):
assert ref.revision, "Recipe revision cannot be None to remove a recipe"
"""Removes the recipe (or recipe revision if present) and all the packages (with all prev)"""
Expand All @@ -22,7 +20,6 @@ def recipe(self, ref: RecipeReference, remote: Remote=None):
recipe_layout = app.cache.ref_layout(ref)
app.cache.remove_recipe_layout(recipe_layout)

@api_method
def all_recipe_packages(self, ref: RecipeReference, remote: Remote = None):
assert ref.revision, "Recipe revision cannot be None to remove a recipe"
"""Removes all the packages from the provided reference"""
Expand All @@ -44,7 +41,6 @@ def _remove_all_local_packages(app, ref):
package_layout = app.cache.pkg_layout(pref)
app.cache.remove_package_layout(package_layout)

@api_method
def package(self, pref: PkgReference, remote: Remote):
assert pref.ref.revision, "Recipe revision cannot be None to remove a package"
assert pref.revision, "Package revision cannot be None to remove a package"
Expand Down
Loading

0 comments on commit df521af

Please sign in to comment.