Skip to content
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
1 change: 0 additions & 1 deletion conan/api/conan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,3 @@ def settings_yml(self):
@property
def requester(self):
return self._requester

2 changes: 1 addition & 1 deletion conan/api/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def request_boolean(self, msg, default_option=None):
"""Request user to input a boolean"""
ret = None
while ret is None:
if default_option is True:
if default_option:
s = self.request_string("%s (YES/no)" % msg)
elif default_option is False:
s = self.request_string("%s (NO/yes)" % msg)
Expand Down
17 changes: 10 additions & 7 deletions conan/api/subapi/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def get_provider(self, provider_name):
)

raise ConanException(
f"Provider '{provider_name}' not found. Please specify a valid provider name or add it using: "
f"'conan audit provider add {provider_name} {add_arguments} --token=<token>'\n"
f"{register_message}"
f"Provider '{provider_name}' not found. Please specify a valid provider name or add "
f"it using: 'conan audit provider add {provider_name} {add_arguments} "
f"--token=<token>'\n{register_message}"
)

provider_data = providers[provider_name]
Expand All @@ -82,9 +82,11 @@ def get_provider(self, provider_name):
provider_data["token"] = env_token
elif "token" in provider_data:
try:
provider_data["token"] = decode(base64.standard_b64decode(provider_data["token"]).decode(), CYPHER_KEY)
except binascii.Error as e:
raise ConanException(f"Invalid token format for provider '{provider_name}'. The token might be corrupt.")
enc_token = base64.standard_b64decode(provider_data["token"]).decode()
provider_data["token"] = decode(enc_token, CYPHER_KEY)
except binascii.Error:
raise ConanException(f"Invalid token format for provider '{provider_name}'. "
f"The token might be corrupt.")

provider_cls = self._provider_cls.get(provider_data["type"])

Expand Down Expand Up @@ -142,7 +144,8 @@ def auth_provider(self, provider, token):
providers = _load_providers(self._providers_path)

assert provider.name in providers
providers[provider.name]["token"] = base64.standard_b64encode(encode(token, CYPHER_KEY).encode()).decode()
encode_token = encode(token, CYPHER_KEY).encode()
providers[provider.name]["token"] = base64.standard_b64encode(encode_token).decode()
setattr(provider, "token", token)
_save_providers(self._providers_path, providers)

Expand Down
14 changes: 9 additions & 5 deletions conan/api/subapi/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from conan.api.output import ConanOutput
from conan.internal.api.uploader import compress_files
from conan.internal.cache.cache import PkgCache
from conan.internal.cache.conan_reference_layout import EXPORT_SRC_FOLDER, EXPORT_FOLDER, SRC_FOLDER, \
METADATA, DOWNLOAD_EXPORT_FOLDER
from conan.internal.cache.conan_reference_layout import (EXPORT_SRC_FOLDER, EXPORT_FOLDER,
SRC_FOLDER, METADATA,
DOWNLOAD_EXPORT_FOLDER)
from conan.internal.cache.home_paths import HomePaths
from conan.internal.cache.integrity_check import IntegrityChecker
from conan.internal.rest.download_cache import DownloadCache
Expand Down Expand Up @@ -104,7 +105,8 @@ def clean(self, package_list, source=True, build=True, download=True, temp=True,
if not os.path.exists(manifest) or not os.path.exists(info):
rmdir(folder)
if backup_sources:
backup_files = self._conan_api.cache.get_backup_sources(package_list, exclude=False, only_upload=False)
backup_files = self._conan_api.cache.get_backup_sources(package_list, exclude=False,
only_upload=False)
ConanOutput().verbose(f"Cleaning {len(backup_files)} backup sources")
for f in backup_files:
remove(f)
Expand Down Expand Up @@ -175,7 +177,8 @@ def save(self, package_list, tgz_path, no_source=False):
pkglist_path = os.path.join(tempfile.gettempdir(), "pkglist.json")
save(pkglist_path, serialized)
tar_files["pkglist.json"] = pkglist_path
compress_files(tar_files, os.path.basename(tgz_path), os.path.dirname(tgz_path), compresslevel, recursive=True)
compress_files(tar_files, os.path.basename(tgz_path), os.path.dirname(tgz_path),
compresslevel, recursive=True)
remove(pkglist_path)

def restore(self, path):
Expand Down Expand Up @@ -260,7 +263,8 @@ def get_backup_sources(self, package_list=None, exclude=True, only_upload=True):
download_cache_path = config.get("core.sources:download_cache")
download_cache_path = download_cache_path or HomePaths(
self._conan_api.cache_folder).default_sources_backup_folder
excluded_urls = config.get("core.sources:exclude_urls", check_type=list, default=[]) if exclude else []
excluded_urls = config.get("core.sources:exclude_urls",
check_type=list, default=[]) if exclude else []
download_cache = DownloadCache(download_cache_path)
return download_cache.get_backup_sources_files(excluded_urls, package_list, only_upload)

Expand Down
7 changes: 4 additions & 3 deletions conan/api/subapi/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def load_root_test_conanfile(self, path, tested_reference, profile_host, profile
return root_node

def _load_root_virtual_conanfile(self, profile_host, profile_build, requires, tool_requires,
lockfile, remotes, update, check_updates=False, python_requires=None):
lockfile, remotes, update, check_updates=False,
python_requires=None):
if not python_requires and not requires and not tool_requires:
raise ConanException("Provide requires or tool_requires")
app = ConanApp(self._conan_api)
Expand Down Expand Up @@ -164,8 +165,8 @@ def load_graph(self, root_node, profile_host, profile_build, lockfile=None, remo
""" Compute the dependency graph, starting from a root package, evaluation the graph with
the provided configuration in profile_build, and profile_host. The resulting graph is a
graph of recipes, but packages are not computed yet (package_ids) will be empty in the
result. The result might have errors, like version or configuration conflicts, but it is still
possible to inspect it. Only trying to install such graph will fail
result. The result might have errors, like version or configuration conflicts, but it is
still possible to inspect it. Only trying to install such graph will fail

:param root_node: the starting point, an already initialized Node structure, as
returned by the "load_root_node" api
Expand Down
7 changes: 4 additions & 3 deletions conan/api/subapi/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def install_sources(self, graph, remotes):

# TODO: Look for a better name
def install_consumer(self, deps_graph, generators=None, source_folder=None, output_folder=None,
deploy=False, deploy_package=None, deploy_folder=None, envs_generation=None):
deploy=False, deploy_package=None, deploy_folder=None,
envs_generation=None):
""" Once a dependency graph has been installed, there are things to be done, like invoking
generators for the root consumer.
This is necessary for example for conanfile.txt/py, or for "conan install <ref> -g
Expand Down Expand Up @@ -101,5 +102,5 @@ def install_consumer(self, deps_graph, generators=None, source_folder=None, outp
envs_generation=envs_generation)

def deploy(self, graph, deployer, deploy_package=None, deploy_folder=None):
return do_deploys(self._conan_api.home_folder, graph, deployer, deploy_package=deploy_package,
deploy_folder=deploy_folder)
return do_deploys(self._conan_api.home_folder, graph, deployer,
deploy_package=deploy_package, deploy_folder=deploy_folder)
9 changes: 6 additions & 3 deletions conan/api/subapi/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ 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 :ref:`Remote <conan.api.model.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 @@ -76,7 +77,8 @@ 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 :ref:`Remote <conan.api.model.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,7 +95,8 @@ def get(self, remote_name):
Obtain a :ref:`Remote <conan.api.model.Remote>` object

:param remote_name: the exact name of the remote to be returned
:return: the :ref:`Remote <conan.api.model.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 Down
2 changes: 2 additions & 0 deletions conan/api/subapi/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _source(path_to_conanfile, reference):
"dst_prefix": dst_prefix,
}


def _configure_source(conan_api, hook_manager, conanfile_path, ref, remotes):
app = ConanApp(conan_api)
conanfile = app.loader.load_consumer(conanfile_path, name=ref.name, version=str(ref.version),
Expand All @@ -100,6 +101,7 @@ def _configure_source(conan_api, hook_manager, conanfile_path, ref, remotes):
conanfile.folders.set_base_recipe_metadata(recipe_layout.metadata())
config_source(export_source_folder, conanfile, hook_manager)


def _get_ref_from_cache_or_remote(conan_api, reference, enabled_remotes):
ref = RecipeReference.loads(reference)
full_ref, matching_remote = None, False
Expand Down
14 changes: 8 additions & 6 deletions conan/cli/commands/remote.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import argparse
import json
import os
from collections import OrderedDict
Expand All @@ -19,7 +18,7 @@ def _print_remotes_json(remotes):
"verify_ssl": r.verify_ssl,
"enabled": not r.disabled,
"allowed_packages": r.allowed_packages,
"recipes_only": r.recipes_only,}
"recipes_only": r.recipes_only}
for r in remotes]
cli_out_write(json.dumps(info, indent=4))

Expand Down Expand Up @@ -128,15 +127,17 @@ def remote_update(conan_api, parser, subparser, *args):
subparser.add_argument("--index", action=OnceArgument, type=int,
help="Insert the remote at a specific position in the remote list")
subparser.add_argument("-ap", "--allowed-packages", action="append", default=None,
help="Add recipe reference pattern to the list of allowed packages for this remote")
help="Add recipe reference pattern to the list of allowed packages "
"for this remote")
subparser.add_argument("--recipes-only", default=None, const="True", nargs="?",
choices=["True", "False"],
help="Disallow binary downloads from this remote, only recipes will be downloaded")
help="Disallow binary downloads from this remote, only recipes will "
"be downloaded")

subparser.set_defaults(secure=None)
args = parser.parse_args(*args)
if (args.url is None and args.secure is None and args.index is None and
args.allowed_packages is None and args.recipes_only is None):
args.allowed_packages is None and args.recipes_only is None):
subparser.error("Please add at least one argument to update")
args.recipes_only = None if args.recipes_only is None else args.recipes_only == "True"
conan_api.remotes.update(args.remote, args.url, args.secure, index=args.index,
Expand Down Expand Up @@ -277,7 +278,8 @@ def _print_auth_json(results):
@conan_subcommand(formatters={"text": _print_auth, "json": _print_auth_json})
def remote_auth(conan_api, parser, subparser, *args):
"""
Authenticate in the defined remotes. Use CONAN_LOGIN_USERNAME* and CONAN_PASSWORD* variables if available.
Authenticate in the defined remotes. Use CONAN_LOGIN_USERNAME* and CONAN_PASSWORD* variables
if available.
Ask for username and password interactively in case (re-)authentication is required and there are
no CONAN_LOGIN* and CONAN_PASSWORD* variables available which could be used.
Usually you'd use this method over conan remote login for scripting which needs to run in CI
Expand Down
1 change: 1 addition & 0 deletions conan/internal/api/config/config_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def _process_file(directory, filename, config, cache_folder, folder):
output.info("Copying file %s to %s" % (filename, target_folder))
_filecopy(directory, filename, target_folder)


def _process_folder(config, folder, cache_folder, ignore=None):
if not os.path.isdir(folder):
raise ConanException("No such directory: '%s'" % str(folder))
Expand Down
1 change: 1 addition & 0 deletions conan/internal/api/detect/detect_vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def vs_detect_update(version):
if len(components) > 1:
return components[1]


def _vs_installation_path(version):
# TODO: Preference hardcoded, [conf] must be defined
preference = ["Enterprise", "Professional", "Community", "BuildTools"]
Expand Down
1 change: 1 addition & 0 deletions conan/internal/api/new/basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
def inject_get_or_else(variable, default):
return variable + ' = "{% if ' + variable + " is defined %}{{ " + variable + " }}{% else %}" + default + '{% endif %}"'


_conanfile_header = f'''\
{inject_get_or_else("name", "pkg")}
{inject_get_or_else("version", "1.0")}
Expand Down
2 changes: 1 addition & 1 deletion conan/internal/api/new/bazel_7_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def test(self):
"MODULE.bazel": _bazel_workspace,
".bazelrc": _bazel_rc,
"test_package/conanfile.py": test_conanfile_exe_v2
}
}
2 changes: 1 addition & 1 deletion conan/internal/cache/db/packages_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PackagesDBTable(BaseDbTable):
('rrev', str),
('pkgid', str, True),
('prev', str, True),
('path', str, False, None, True),
('path', str, False, True),
('timestamp', float),
('build_id', str, True),
('lru', int)]
Expand Down
2 changes: 1 addition & 1 deletion conan/internal/cache/db/recipes_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RecipesDBTable(BaseDbTable):
table_name = 'recipes'
columns_description = [('reference', str),
('rrev', str),
('path', str, False, None, True),
('path', str, False, True),
('timestamp', float),
('lru', int)]
unique_together = ('reference', 'rrev')
Expand Down
26 changes: 6 additions & 20 deletions conan/internal/cache/db/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import threading
from collections import defaultdict, namedtuple
from contextlib import contextmanager
from typing import Tuple, List, Optional
from typing import Tuple, List


class BaseDbTable:
Expand Down Expand Up @@ -32,25 +32,19 @@ def db_connection(self):
self._lock.release()

def create_table(self):
def field(name, typename, nullable=False, check_constraints: Optional[List] = None,
unique=False):
def field(name, typename, nullable=False, unique=False):
field_str = name
if typename in [str, ]:
if typename is str:
field_str += ' text'
elif typename in [int, ]:
elif typename is int:
field_str += ' integer'
elif typename in [float, ]:
field_str += ' real'
else:
assert False, f"sqlite3 type not mapped for type '{typename}'"
assert typename is float, f"sqlite3 type not mapped for type '{typename}'"
field_str += ' real'

if not nullable:
field_str += ' NOT NULL'

if check_constraints:
constraints = ', '.join([str(it) for it in check_constraints])
field_str += f' CHECK ({name} IN ({constraints}))'

if unique:
field_str += ' UNIQUE'

Expand All @@ -61,11 +55,3 @@ def field(name, typename, nullable=False, check_constraints: Optional[List] = No
table_checks = f", UNIQUE({', '.join(self.unique_together)})" if self.unique_together else ''
with self.db_connection() as conn:
conn.execute(f"CREATE TABLE {guard} {self.table_name} ({fields} {table_checks});")

def dump(self):
print(f"********* BEGINTABLE {self.table_name}*************")
with self.db_connection() as conn:
r = conn.execute(f'SELECT rowid, * FROM {self.table_name}')
for it in r.fetchall():
print(str(it))
print(f"********* ENDTABLE {self.table_name}*************")
2 changes: 1 addition & 1 deletion conan/internal/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def load_basic_module(self, conanfile_path, graph_lock=None, display="", remotes
elif tested_python_requires:
if getattr(conanfile, "python_requires", None) != "tested_reference_str":
ConanOutput().warning("test_package/conanfile.py should declare 'python_requires"
" = \"tested_reference_str\"'", warn_tag="deprecated")
" = \"tested_reference_str\"'", warn_tag="deprecated")
conanfile.python_requires = tested_python_requires

if self._pyreq_loader:
Expand Down
7 changes: 0 additions & 7 deletions conan/internal/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,6 @@ def compose_conf(self, other):
existing.compose_conf_value(v)
return self

def filter_user_modules(self):
result = Conf()
for k, v in self._values.items():
if _is_profile_module(k):
result._values[k] = v
return result

def copy_conaninfo_conf(self):
"""
Get a new `Conf()` object with all the configurations required by the consumer
Expand Down
1 change: 1 addition & 0 deletions conan/internal/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def find_file_walk_up(start, filename, end=None):
path = path.parent
return None


def get_conan_user_home():

def _user_home_from_conanrc_file():
Expand Down
3 changes: 2 additions & 1 deletion conan/internal/runner/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def _instans_or_error(value, obj):
)
)


class DockerRunner:
def __init__(self, conan_api: ConanAPI, command: str, host_profile: Profile, build_profile: Profile, args: Namespace, raw_args: list[str]):
self.logger = ConanOutput()
Expand Down Expand Up @@ -119,7 +120,7 @@ def run(self) -> None:
raise ConanException(f'"{e.command}" inside docker fail')
finally:
if self.container:
error = sys.exc_info()[0] is not None # Check if error has been raised
error = sys.exc_info()[0] is not None # Check if error has been raised
log = self.logger.error if error else self.logger.status
log('Stopping container')
self.container.stop()
Expand Down
1 change: 1 addition & 0 deletions conan/internal/runner/output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from conan.api.output import Color, ConanOutput


class RunnerOutput(ConanOutput):
def __init__(self, runner_info: str):
super().__init__()
Expand Down
3 changes: 2 additions & 1 deletion conan/tools/android/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def android_abi(conanfile, context="host"):
:return: Android-NDK ABI
"""
if context not in ("host", "build", "target"):
raise ConanException(f"context argument must be either 'host', 'build' or 'target', was '{context}'")
raise ConanException(f"context argument must be either 'host', 'build' or 'target', "
f"was '{context}'")

try:
settings = getattr(conanfile, f"settings_{context}")
Expand Down
Loading
Loading