diff --git a/conan/__init__.py b/conan/__init__.py index 93deaa4fe67..4fbd3d04402 100644 --- a/conan/__init__.py +++ b/conan/__init__.py @@ -1,5 +1,5 @@ -from conans.model.conan_file import ConanFile -from conan.tools.scm import Version as _Version +from conan.internal.model.conan_file import ConanFile +from conan.internal.model.version import Version __version__ = '2.12.0-dev' -conan_version = _Version(__version__) +conan_version = Version(__version__) diff --git a/conan/api/conan_api.py b/conan/api/conan_api.py index d63845c4269..091af879fd7 100644 --- a/conan/api/conan_api.py +++ b/conan/api/conan_api.py @@ -22,7 +22,7 @@ from conans.client.migrations import ClientMigrator from conan.errors import ConanException from conan.internal.paths import get_conan_user_home -from conans.model.version_range import validate_conan_version +from conan.internal.model.version_range import validate_conan_version class ConanAPI: diff --git a/conan/api/model/__init__.py b/conan/api/model/__init__.py new file mode 100644 index 00000000000..5cae5c0d3d2 --- /dev/null +++ b/conan/api/model/__init__.py @@ -0,0 +1,3 @@ +from conan.api.model.remote import Remote, LOCAL_RECIPES_INDEX +from conan.api.model.refs import RecipeReference, PkgReference +from conan.api.model.list import PackagesList, MultiPackagesList, ListPattern diff --git a/conan/api/model.py b/conan/api/model/list.py similarity index 88% rename from conan/api/model.py rename to conan/api/model/list.py index 4c6132bbd98..abd43e93cef 100644 --- a/conan/api/model.py +++ b/conan/api/model/list.py @@ -3,51 +3,13 @@ import os from json import JSONDecodeError +from conan.errors import ConanException +from conan.internal.errors import NotFoundException +from conan.api.model import RecipeReference, PkgReference +from conan.internal.model.version_range import VersionRange from conans.client.graph.graph import RECIPE_EDITABLE, RECIPE_CONSUMER, RECIPE_PLATFORM, \ RECIPE_VIRTUAL, BINARY_SKIP, BINARY_MISSING, BINARY_INVALID -from conan.internal.errors import NotFoundException -from conan.errors import ConanException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference from conans.util.files import load -from conans.model.version_range import VersionRange - -LOCAL_RECIPES_INDEX = "local-recipes-index" - - -class Remote: - - def __init__(self, name, url, verify_ssl=True, disabled=False, allowed_packages=None, - remote_type=None): - self.name = name # Read only, is the key - self.url = url - self.verify_ssl = verify_ssl - self.disabled = disabled - self.allowed_packages = allowed_packages - self.remote_type = remote_type - self.caching = {} - - def __eq__(self, other): - if other is None: - return False - return (self.name == other.name and self.url == other.url and - self.verify_ssl == other.verify_ssl and self.disabled == other.disabled) - - def __str__(self): - allowed_msg = "" - if self.allowed_packages: - allowed_msg = ", Allowed packages: {}".format(", ".join(self.allowed_packages)) - if self.remote_type == LOCAL_RECIPES_INDEX: - return "{}: {} [{}, Enabled: {}{}]".format(self.name, self.url, LOCAL_RECIPES_INDEX, - not self.disabled, allowed_msg) - return "{}: {} [Verify SSL: {}, Enabled: {}{}]".format(self.name, self.url, self.verify_ssl, - not self.disabled, allowed_msg) - - def __repr__(self): - return str(self) - - def invalidate_cache(self): - self.caching = {} class MultiPackagesList: diff --git a/conan/api/model/refs.py b/conan/api/model/refs.py new file mode 100644 index 00000000000..41e4a856de5 --- /dev/null +++ b/conan/api/model/refs.py @@ -0,0 +1,306 @@ + +import fnmatch +import re +from functools import total_ordering + +from conan.errors import ConanException +from conan.internal.model.version import Version +from conans.util.dates import timestamp_to_str + + +@total_ordering +class RecipeReference: + """ an exact (no version-range, no alias) reference of a recipe. + Should be enough to locate a recipe in the cache or in a server + Validation will be external to this class, at specific points (export, api, etc) + """ + + def __init__(self, name=None, version=None, user=None, channel=None, revision=None, + timestamp=None): + self.name = name + if version is not None and not isinstance(version, Version): + version = Version(version) + self.version = version # This MUST be a version if we want to be able to order + self.user = user + self.channel = channel + self.revision = revision + self.timestamp = timestamp + + def copy(self): + # Used for creating copy in lockfile-overrides mechanism + return RecipeReference(self.name, self.version, self.user, self.channel, self.revision, + self.timestamp) + + def __repr__(self): + """ long repr like pkg/0.1@user/channel#rrev%timestamp """ + result = self.repr_notime() + if self.timestamp is not None: + result += "%{}".format(self.timestamp) + return result + + def repr_notime(self): + result = self.__str__() + if self.revision is not None: + result += "#{}".format(self.revision) + return result + + def repr_reduced(self): + result = self.__str__() + if self.revision is not None: + result += "#{}".format(self.revision[0:4]) + return result + + def repr_humantime(self): + result = self.repr_notime() + assert self.timestamp + result += " ({})".format(timestamp_to_str(self.timestamp)) + return result + + def __str__(self): + """ shorter representation, excluding the revision and timestamp """ + if self.name is None: + return "" + result = "/".join([self.name, str(self.version)]) + if self.user: + result += "@{}".format(self.user) + if self.channel: + assert self.user + result += "/{}".format(self.channel) + return result + + def __lt__(self, ref): + # The timestamp goes before the revision for ordering revisions chronologically + # In theory this is enough for sorting + # When no timestamp is given, it will always have lower priority, to avoid comparison + # errors float <> None + return (self.name, self.version, self.user or "", self.channel or "", self.timestamp or 0, + self.revision or "") \ + < (ref.name, ref.version, ref.user or "", ref.channel or "", ref.timestamp or 0, + ref.revision or "") + + def __eq__(self, ref): + # Timestamp doesn't affect equality. + # This is necessary for building an ordered list of UNIQUE recipe_references for Lockfile + if ref is None: + return False + # If one revision is not defined, they are equal + if self.revision is not None and ref.revision is not None: + return (self.name, self.version, self.user, self.channel, self.revision) == \ + (ref.name, ref.version, ref.user, ref.channel, ref.revision) + return (self.name, self.version, self.user, self.channel) == \ + (ref.name, ref.version, ref.user, ref.channel) + + def __hash__(self): + # This is necessary for building an ordered list of UNIQUE recipe_references for Lockfile + return hash((self.name, self.version, self.user, self.channel)) + + @staticmethod + def loads(rref): + try: + # timestamp + tokens = rref.rsplit("%", 1) + text = tokens[0] + timestamp = float(tokens[1]) if len(tokens) == 2 else None + + # revision + tokens = text.split("#", 1) + ref = tokens[0] + revision = tokens[1] if len(tokens) == 2 else None + + # name, version always here + tokens = ref.split("@", 1) + name, version = tokens[0].split("/", 1) + assert name and version + # user and channel + if len(tokens) == 2 and tokens[1]: + tokens = tokens[1].split("/", 1) + user = tokens[0] if tokens[0] else None + channel = tokens[1] if len(tokens) == 2 else None + else: + user = channel = None + return RecipeReference(name, version, user, channel, revision, timestamp) + except Exception: + from conan.errors import ConanException + raise ConanException( + f"{rref} is not a valid recipe reference, provide a reference" + f" in the form name/version[@user/channel]") + + def validate_ref(self, allow_uppercase=False): + """ at the moment only applied to exported (exact) references, but not for requires + that could contain version ranges + """ + from conan.api.output import ConanOutput + self_str = str(self) + if self_str != self_str.lower(): + if not allow_uppercase: + raise ConanException(f"Conan packages names '{self_str}' must be all lowercase") + else: + ConanOutput().warning(f"Package name '{self_str}' has uppercase, and has been " + "allowed by temporary config. This will break in later 2.X") + if len(self_str) > 200: + raise ConanException(f"Package reference too long >200 {self_str}") + if ":" in repr(self): + raise ConanException(f"Invalid recipe reference '{repr(self)}' is a package reference") + if not allow_uppercase: + validation_pattern = re.compile(r"^[a-z0-9_][a-z0-9_+.-]{1,100}\Z") + else: + validation_pattern = re.compile(r"^[a-zA-Z0-9_][a-zA-Z0-9_+.-]{1,100}\Z") + if validation_pattern.match(self.name) is None: + raise ConanException(f"Invalid package name '{self.name}'") + if validation_pattern.match(str(self.version)) is None: + raise ConanException(f"Invalid package version '{self.version}'") + if self.user and validation_pattern.match(self.user) is None: + raise ConanException(f"Invalid package user '{self.user}'") + if self.channel and validation_pattern.match(self.channel) is None: + raise ConanException(f"Invalid package channel '{self.channel}'") + + # Warn if they use .+ in the name/user/channel, as it can be problematic for generators + pattern = re.compile(r'[.+]') + if pattern.search(self.name): + ConanOutput().warning(f"Name containing special chars is discouraged '{self.name}'") + if self.user and pattern.search(self.user): + ConanOutput().warning(f"User containing special chars is discouraged '{self.user}'") + if self.channel and pattern.search(self.channel): + ConanOutput().warning(f"Channel containing special chars is discouraged " + f"'{self.channel}'") + + def matches(self, pattern, is_consumer): + negate = False + if pattern.startswith("!") or pattern.startswith("~"): + pattern = pattern[1:] + negate = True + + no_user_channel = False + if pattern.endswith("@"): # it means we want to match only without user/channel + pattern = pattern[:-1] + no_user_channel = True + elif "@#" in pattern: + pattern = pattern.replace("@#", "#") + no_user_channel = True + + condition = ((pattern == "&" and is_consumer) or + fnmatch.fnmatchcase(str(self), pattern) or + fnmatch.fnmatchcase(self.repr_notime(), pattern)) + if no_user_channel: + condition = condition and not self.user and not self.channel + if negate: + return not condition + return condition + + def partial_match(self, pattern): + """ + Finds if pattern matches any of partial sums of tokens of conan reference + """ + tokens = [self.name, "/", str(self.version)] + if self.user: + tokens += ["@", self.user] + if self.channel: + tokens += ["/", self.channel] + if self.revision: + tokens += ["#", self.revision] + partial = "" + for token in tokens: + partial += token + if pattern.match(partial): + return True + + +class PkgReference: + + def __init__(self, ref=None, package_id=None, revision=None, timestamp=None): + self.ref = ref + self.package_id = package_id + self.revision = revision + self.timestamp = timestamp # float, Unix seconds UTC + + def __repr__(self): + """ long repr like pkg/0.1@user/channel#rrev%timestamp """ + if self.ref is None: + return "" + result = repr(self.ref) + if self.package_id: + result += ":{}".format(self.package_id) + if self.revision is not None: + result += "#{}".format(self.revision) + if self.timestamp is not None: + result += "%{}".format(self.timestamp) + return result + + def repr_notime(self): + if self.ref is None: + return "" + result = self.ref.repr_notime() + if self.package_id: + result += ":{}".format(self.package_id) + if self.revision is not None: + result += "#{}".format(self.revision) + return result + + def repr_reduced(self): + if self.ref is None: + return "" + result = self.ref.repr_reduced() + if self.package_id: + result += ":{}".format(self.package_id[0:4]) + if self.revision is not None: + result += "#{}".format(self.revision[0:4]) + return result + + def repr_humantime(self): + result = self.repr_notime() + assert self.timestamp + result += " ({})".format(timestamp_to_str(self.timestamp)) + return result + + def __str__(self): + """ shorter representation, excluding the revision and timestamp """ + if self.ref is None: + return "" + result = str(self.ref) + if self.package_id: + result += ":{}".format(self.package_id) + return result + + def __lt__(self, ref): + # The timestamp goes before the revision for ordering revisions chronologically + raise Exception("WHO IS COMPARING PACKAGE REFERENCES?") + # return (self.name, self.version, self.user, self.channel, self.timestamp, self.revision) \ + # < (ref.name, ref.version, ref.user, ref.channel, ref._timestamp, ref.revision) + + def __eq__(self, other): + # TODO: In case of equality, should it use the revision and timestamp? + # Used: + # at "graph_binaries" to check: cache_latest_prev != pref + # at "installer" to check: if pkg_layout.reference != pref (probably just optimization?) + # at "revisions_test" + return self.ref == other.ref and self.package_id == other.package_id and \ + self.revision == other.revision + + def __hash__(self): + # Used in dicts of PkgReferences as keys like the cached nodes in the graph binaries + return hash((self.ref, self.package_id, self.revision)) + + @staticmethod + def loads(pkg_ref): # TODO: change this default to validate only on end points + try: + tokens = pkg_ref.split(":", 1) + assert len(tokens) == 2 + ref, pkg_id = tokens + + ref = RecipeReference.loads(ref) + + # timestamp + tokens = pkg_id.rsplit("%", 1) + text = tokens[0] + timestamp = float(tokens[1]) if len(tokens) == 2 else None + + # revision + tokens = text.split("#", 1) + package_id = tokens[0] + revision = tokens[1] if len(tokens) == 2 else None + + return PkgReference(ref, package_id, revision, timestamp) + except Exception: + raise ConanException( + f"{pkg_ref} is not a valid package reference, provide a reference" + f" in the form name/version[@user/channel:package_id]") diff --git a/conan/api/model/remote.py b/conan/api/model/remote.py new file mode 100644 index 00000000000..0f6120bd268 --- /dev/null +++ b/conan/api/model/remote.py @@ -0,0 +1,37 @@ +LOCAL_RECIPES_INDEX = "local-recipes-index" + + +class Remote: + + def __init__(self, name, url, verify_ssl=True, disabled=False, allowed_packages=None, + remote_type=None): + self.name = name # Read only, is the key + self.url = url + self.verify_ssl = verify_ssl + self.disabled = disabled + self.allowed_packages = allowed_packages + self.remote_type = remote_type + self.caching = {} + + def __eq__(self, other): + if other is None: + return False + return (self.name == other.name and self.url == other.url and + self.verify_ssl == other.verify_ssl and self.disabled == other.disabled) + + def __str__(self): + allowed_msg = "" + if self.allowed_packages: + allowed_msg = ", Allowed packages: {}".format(", ".join(self.allowed_packages)) + if self.remote_type == LOCAL_RECIPES_INDEX: + return "{}: {} [{}, Enabled: {}{}]".format(self.name, self.url, LOCAL_RECIPES_INDEX, + not self.disabled, allowed_msg) + return "{}: {} [Verify SSL: {}, Enabled: {}{}]".format(self.name, self.url, self.verify_ssl, + not self.disabled, allowed_msg) + + def __repr__(self): + return str(self) + + def invalidate_cache(self): + # TODO: make it private + self.caching = {} diff --git a/conan/api/subapi/cache.py b/conan/api/subapi/cache.py index b3cf0b2159c..b4271507010 100644 --- a/conan/api/subapi/cache.py +++ b/conan/api/subapi/cache.py @@ -11,8 +11,8 @@ from conan.internal.cache.integrity_check import IntegrityChecker from conans.client.downloaders.download_cache import DownloadCache from conan.errors import ConanException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.util.dates import revision_timestamp_now from conans.util.files import rmdir, gzopen_without_timestamps, mkdir, remove diff --git a/conan/api/subapi/config.py b/conan/api/subapi/config.py index 04155f2ecfe..6070802e39d 100644 --- a/conan/api/subapi/config.py +++ b/conan/api/subapi/config.py @@ -16,10 +16,10 @@ from conans.client.graph.graph_builder import DepsGraphBuilder from conans.client.graph.profile_node_definer import consumer_definer from conan.errors import ConanException -from conans.model.conf import ConfDefinition, BUILT_IN_CONFS -from conans.model.pkg_type import PackageType -from conans.model.recipe_ref import RecipeReference -from conans.model.settings import Settings +from conan.internal.model.conf import ConfDefinition, BUILT_IN_CONFS +from conan.internal.model.pkg_type import PackageType +from conan.api.model import RecipeReference +from conan.internal.model.settings import Settings from conans.util.files import load, save diff --git a/conan/api/subapi/download.py b/conan/api/subapi/download.py index 18c2bee9eaa..f94f54c550c 100644 --- a/conan/api/subapi/download.py +++ b/conan/api/subapi/download.py @@ -6,8 +6,8 @@ from conan.api.output import ConanOutput from conan.internal.conan_app import ConanBasicApp from conan.errors import ConanException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference class DownloadAPI: diff --git a/conan/api/subapi/export.py b/conan/api/subapi/export.py index bfba33d9127..5d1d16878f3 100644 --- a/conan/api/subapi/export.py +++ b/conan/api/subapi/export.py @@ -6,7 +6,7 @@ from conan.internal.methods import run_package_method from conans.client.graph.graph import BINARY_BUILD, RECIPE_INCACHE from conans.client.hook_manager import HookManager -from conans.model.package_ref import PkgReference +from conan.api.model import PkgReference from conans.util.files import mkdir diff --git a/conan/api/subapi/graph.py b/conan/api/subapi/graph.py index 8ffaeb06703..d3998e9fd85 100644 --- a/conan/api/subapi/graph.py +++ b/conan/api/subapi/graph.py @@ -1,12 +1,13 @@ from conan.api.output import ConanOutput from conan.internal.conan_app import ConanApp, ConanBasicApp +from conan.internal.model.recipe_ref import ref_matches from conans.client.graph.graph import Node, RECIPE_CONSUMER, CONTEXT_HOST, RECIPE_VIRTUAL, \ - CONTEXT_BUILD + CONTEXT_BUILD, BINARY_MISSING from conans.client.graph.graph_binaries import GraphBinariesAnalyzer from conans.client.graph.graph_builder import DepsGraphBuilder from conans.client.graph.profile_node_definer import initialize_conanfile_profile, consumer_definer from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference class GraphAPI: @@ -200,3 +201,14 @@ def analyze_binaries(self, graph, build_mode=None, remotes=None, update=None, lo binaries_analyzer = GraphBinariesAnalyzer(conan_app, self.conan_api.config.global_conf) binaries_analyzer.evaluate_graph(graph, build_mode, lockfile, remotes, update, build_modes_test, tested_graph) + + @staticmethod + def find_first_missing_binary(graph, missing=None): + """ (Experimental) Given a dependency graph, will return the first node with a + missing binary package + """ + for node in graph.ordered_iterate(): + if ((not missing and node.binary == BINARY_MISSING) # First missing binary or specified + or (missing and ref_matches(node.ref, missing, is_consumer=None))): + return node.ref, node.conanfile.info + raise ConanException("There is no missing binary") diff --git a/conan/api/subapi/install.py b/conan/api/subapi/install.py index 5177992d40a..d3190f07d3b 100644 --- a/conan/api/subapi/install.py +++ b/conan/api/subapi/install.py @@ -75,7 +75,7 @@ def install_consumer(self, deps_graph, generators=None, source_folder=None, outp # Issue related: https://github.com/conan-io/conan/issues/16543 base_folder = os.path.abspath(deploy_folder) if deploy_folder \ else conanfile.folders.base_build - do_deploys(self.conan_api, deps_graph, deploy, deploy_package, base_folder) + do_deploys(self.conan_api.home_folder, deps_graph, deploy, deploy_package, base_folder) final_generators = [] # Don't use set for uniqueness because order matters @@ -89,3 +89,7 @@ def install_consumer(self, deps_graph, generators=None, source_folder=None, outp hook_manager = HookManager(HomePaths(self.conan_api.home_folder).hooks_path) write_generators(conanfile, hook_manager, self.conan_api.home_folder, 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) diff --git a/conan/api/subapi/list.py b/conan/api/subapi/list.py index 9ede07a1868..da4f7657829 100644 --- a/conan/api/subapi/list.py +++ b/conan/api/subapi/list.py @@ -6,12 +6,13 @@ from conan.api.output import ConanOutput, TimedOutput from conan.internal.api.list.query_parse import filter_package_configs from conan.internal.conan_app import ConanBasicApp +from conan.internal.model.recipe_ref import ref_matches from conan.internal.paths import CONANINFO from conan.internal.errors import NotFoundException from conan.errors import ConanException -from conans.model.info import load_binary_info -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference, ref_matches +from conan.internal.model.info import load_binary_info +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.util.dates import timelimit from conans.util.files import load @@ -224,6 +225,8 @@ def msg_format(msg, item, total): return select_bundle def explain_missing_binaries(self, ref, conaninfo, remotes): + """ (Experimental) Explain why a binary is missing in the cache + """ ConanOutput().info(f"Missing binary: {ref}") ConanOutput().info(f"With conaninfo.txt (package_id):\n{conaninfo.dumps()}") conaninfo = load_binary_info(conaninfo.dumps()) diff --git a/conan/api/subapi/local.py b/conan/api/subapi/local.py index 24c47d34e12..9a7ae9d9f6b 100644 --- a/conan/api/subapi/local.py +++ b/conan/api/subapi/local.py @@ -10,7 +10,7 @@ from conan.internal.errors import conanfile_exception_formatter from conan.errors import ConanException from conans.client.hook_manager import HookManager -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.util.files import chdir diff --git a/conan/api/subapi/lockfile.py b/conan/api/subapi/lockfile.py index 76a80717976..c18cc58c05d 100644 --- a/conan/api/subapi/lockfile.py +++ b/conan/api/subapi/lockfile.py @@ -4,7 +4,7 @@ from conan.cli import make_abs_path from conans.client.graph.graph import Overrides from conan.errors import ConanException -from conans.model.graph_lock import Lockfile, LOCKFILE +from conan.internal.model.lockfile import Lockfile, LOCKFILE class LockfileAPI: @@ -80,6 +80,15 @@ def update_lockfile(lockfile, graph, lock_packages=False, clean=False): lockfile.update_lock(graph, lock_packages) return lockfile + @staticmethod + def merge_lockfiles(lockfiles): + result = Lockfile() + for lockfile in lockfiles: + lockfile = make_abs_path(lockfile) + graph_lock = Lockfile.load(lockfile) + result.merge(graph_lock) + return result + @staticmethod def add_lockfile(lockfile=None, requires=None, build_requires=None, python_requires=None, config_requires=None): diff --git a/conan/api/subapi/profiles.py b/conan/api/subapi/profiles.py index 1caf38c14c2..d83e88cbe7e 100644 --- a/conan/api/subapi/profiles.py +++ b/conan/api/subapi/profiles.py @@ -7,7 +7,7 @@ from conan.internal.api.profile.profile_loader import ProfileLoader from conan.internal.errors import scoped_traceback from conan.errors import ConanException -from conans.model.profile import Profile +from conan.internal.model.profile import Profile DEFAULT_PROFILE_NAME = "default" diff --git a/conan/api/subapi/remotes.py b/conan/api/subapi/remotes.py index 45a08d1342a..9e6ae90b1a3 100644 --- a/conan/api/subapi/remotes.py +++ b/conan/api/subapi/remotes.py @@ -290,7 +290,9 @@ def _save(remotes_file, remotes): if r.remote_type: remote["remote_type"] = r.remote_type remote_list.append(remote) - save(remotes_file, json.dumps({"remotes": remote_list}, indent=True)) + # This atomic replace avoids a corrupted remotes.json file if this is killed during the process + save(remotes_file + ".tmp", json.dumps({"remotes": remote_list}, indent=True)) + os.replace(remotes_file + ".tmp", remotes_file) def _filter(remotes, pattern, only_enabled=True): diff --git a/conan/api/subapi/remove.py b/conan/api/subapi/remove.py index d3613fc3c71..24588c461fc 100644 --- a/conan/api/subapi/remove.py +++ b/conan/api/subapi/remove.py @@ -2,8 +2,8 @@ from conan.api.model import Remote from conan.internal.conan_app import ConanBasicApp -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference class RemoveAPI: diff --git a/conan/api/subapi/workspace.py b/conan/api/subapi/workspace.py index 3c51b7b70a1..9485e769e44 100644 --- a/conan/api/subapi/workspace.py +++ b/conan/api/subapi/workspace.py @@ -8,7 +8,7 @@ from conan.errors import ConanException from conans.client.graph.graph import RECIPE_EDITABLE from conans.client.source import retrieve_exports_sources -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.util.files import merge_directories diff --git a/conan/cli/command.py b/conan/cli/command.py index db8bae80579..5447203b37b 100644 --- a/conan/cli/command.py +++ b/conan/cli/command.py @@ -4,7 +4,7 @@ from conan.api.output import ConanOutput from conan.errors import ConanException -from conans.model.conf import CORE_CONF_PATTERN +from conan.internal.model.conf import CORE_CONF_PATTERN class OnceArgument(argparse.Action): @@ -126,7 +126,7 @@ def parse_args(self, args=None, namespace=None): ConanOutput().error("The --lockfile-packages arg is private and shouldn't be used") global_conf = self._conan_api.config.global_conf if args.core_conf: - from conans.model.conf import ConfDefinition + from conan.internal.model.conf import ConfDefinition confs = ConfDefinition() for c in args.core_conf: if not CORE_CONF_PATTERN.match(c): diff --git a/conan/cli/commands/cache.py b/conan/cli/commands/cache.py index cee37527287..a2cffd834aa 100644 --- a/conan/cli/commands/cache.py +++ b/conan/cli/commands/cache.py @@ -7,8 +7,8 @@ from conan.cli.command import conan_command, conan_subcommand, OnceArgument from conan.cli.commands.list import print_list_text, print_list_json from conan.errors import ConanException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference def json_export(data): diff --git a/conan/cli/commands/graph.py b/conan/cli/commands/graph.py index aa1fb298c2e..e493b5133dd 100644 --- a/conan/cli/commands/graph.py +++ b/conan/cli/commands/graph.py @@ -13,11 +13,9 @@ from conan.cli.printers import print_profiles from conan.cli.printers.graph import print_graph_packages, print_graph_basic from conan.errors import ConanException -from conan.internal.deploy import do_deploys -from conans.client.graph.graph import BINARY_MISSING from conans.client.graph.install_graph import InstallGraph, ProfileArgs from conan.internal.errors import NotFoundException -from conans.model.recipe_ref import ref_matches, RecipeReference +from conan.api.model import RecipeReference def explain_formatter_text(data): @@ -239,7 +237,7 @@ def graph_info(conan_api, parser, subparser, *args): conan_api.lockfile.save_lockfile(lockfile, args.lockfile_out, cwd) if args.deployer: base_folder = args.deployer_folder or os.getcwd() - do_deploys(conan_api, deps_graph, args.deployer, None, base_folder) + conan_api.install.deploy(deps_graph, args.deployer, None, base_folder) return {"graph": deps_graph, "field_filter": args.filter, @@ -303,17 +301,8 @@ def graph_explain(conan_api, parser, subparser, *args): print_graph_packages(deps_graph) ConanOutput().title("Retrieving and computing closest binaries") - # compute ref and conaninfo - missing = args.missing - for node in deps_graph.ordered_iterate(): - if ((not missing and node.binary == BINARY_MISSING) # First missing binary or - or (missing and ref_matches(node.ref, missing, is_consumer=None))): # specified one - ref = node.ref - conaninfo = node.conanfile.info - break - else: - raise ConanException("There is no missing binary") - + # compute ref and conaninfo of the first missing binary + ref, conaninfo = conan_api.graph.find_first_missing_binary(deps_graph, args.missing) pkglist = conan_api.list.explain_missing_binaries(ref, conaninfo, remotes) ConanOutput().title("Closest binaries") diff --git a/conan/cli/commands/lock.py b/conan/cli/commands/lock.py index 0d7c3f3952c..35fe47e6f05 100644 --- a/conan/cli/commands/lock.py +++ b/conan/cli/commands/lock.py @@ -6,8 +6,7 @@ from conan.cli import make_abs_path from conan.cli.args import common_graph_args, validate_common_graph_args from conan.cli.printers.graph import print_graph_packages, print_graph_basic -from conans.model.graph_lock import Lockfile, LOCKFILE -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference @conan_command(group="Consumer") @@ -68,17 +67,11 @@ def lock_merge(conan_api, parser, subparser, *args): # noqa Merge 2 or more lockfiles. """ subparser.add_argument('--lockfile', action="append", help='Path to lockfile to be merged') - subparser.add_argument("--lockfile-out", action=OnceArgument, default=LOCKFILE, + subparser.add_argument("--lockfile-out", action=OnceArgument, default="conan.lock", help="Filename of the created lockfile") args = parser.parse_args(*args) - - result = Lockfile() - for lockfile in args.lockfile: - lockfile = make_abs_path(lockfile) - graph_lock = Lockfile.load(lockfile) - result.merge(graph_lock) - + result = conan_api.lockfile.merge_lockfiles(args.lockfile) lockfile_out = make_abs_path(args.lockfile_out) result.save(lockfile_out) ConanOutput().info("Generated lockfile: %s" % lockfile_out) @@ -100,7 +93,7 @@ def lock_add(conan_api, parser, subparser, *args): help='Add python-requires to lockfile') subparser.add_argument('--config-requires', action="append", help='Add config-requires to lockfile') - subparser.add_argument("--lockfile-out", action=OnceArgument, default=LOCKFILE, + subparser.add_argument("--lockfile-out", action=OnceArgument, default="conan.lock", help="Filename of the created lockfile") subparser.add_argument("--lockfile", action=OnceArgument, help="Filename of the input lockfile") args = parser.parse_args(*args) @@ -142,7 +135,7 @@ def lock_remove(conan_api, parser, subparser, *args): help='Remove python-requires from lockfile') subparser.add_argument('--config-requires', action="append", help='Remove config-requires from lockfile') - subparser.add_argument("--lockfile-out", action=OnceArgument, default=LOCKFILE, + subparser.add_argument("--lockfile-out", action=OnceArgument, default="conan.lock", help="Filename of the created lockfile") subparser.add_argument("--lockfile", action=OnceArgument, help="Filename of the input lockfile") args = parser.parse_args(*args) @@ -170,7 +163,7 @@ def lock_update(conan_api, parser, subparser, *args): help='Update python-requires from lockfile') subparser.add_argument('--config-requires', action="append", help='Update config-requires from lockfile') - subparser.add_argument("--lockfile-out", action=OnceArgument, default=LOCKFILE, + subparser.add_argument("--lockfile-out", action=OnceArgument, default="conan.lock", help="Filename of the created lockfile") subparser.add_argument("--lockfile", action=OnceArgument, help="Filename of the input lockfile") args = parser.parse_args(*args) diff --git a/conan/cli/commands/test.py b/conan/cli/commands/test.py index eda4ebafc75..1e057a4a1b8 100644 --- a/conan/cli/commands/test.py +++ b/conan/cli/commands/test.py @@ -7,7 +7,7 @@ from conan.cli.formatters.graph import format_graph_json from conan.cli.printers import print_profiles from conan.cli.printers.graph import print_graph_basic, print_graph_packages -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference @conan_command(group="Creator", formatters={"json": format_graph_json}) 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 266e02ea210..00000000000 --- a/conan/cli/formatters/list/binary_html_table.py +++ /dev/null @@ -1,141 +0,0 @@ -from collections import OrderedDict, defaultdict - -from conans.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/conan/cps/cps.py b/conan/cps/cps.py index 9f47c9959bd..4fab7911a0c 100644 --- a/conan/cps/cps.py +++ b/conan/cps/cps.py @@ -2,7 +2,7 @@ import os from enum import Enum -from conans.model.build_info import CppInfo +from conan.internal.model.cpp_info import CppInfo from conans.util.files import save, load diff --git a/conan/internal/api/detect/detect_api.py b/conan/internal/api/detect/detect_api.py index 96879adf6f6..b429db3080f 100644 --- a/conan/internal/api/detect/detect_api.py +++ b/conan/internal/api/detect/detect_api.py @@ -6,7 +6,7 @@ from conan.api.output import ConanOutput from conan.errors import ConanException -from conans.model.version import Version +from conan.internal.model.version import Version from conans.util.files import load, save from conans.util.runners import check_output_runner, detect_runner diff --git a/conan/internal/api/export.py b/conan/internal/api/export.py index 72d77fa63dd..5c1636e4b8c 100644 --- a/conan/internal/api/export.py +++ b/conan/internal/api/export.py @@ -6,8 +6,8 @@ from conan.tools.scm import Git from conan.internal.errors import conanfile_exception_formatter from conan.errors import ConanException -from conans.model.manifest import FileTreeManifest -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.manifest import FileTreeManifest +from conan.api.model import RecipeReference from conan.internal.paths import DATA_YML from conans.util.files import is_dirty, rmdir, set_dirty, mkdir, clean_dirty, chdir diff --git a/conan/internal/api/local/editable.py b/conan/internal/api/local/editable.py index c2e543e133c..36dbc6f025b 100644 --- a/conan/internal/api/local/editable.py +++ b/conan/internal/api/local/editable.py @@ -4,7 +4,7 @@ import os from os.path import join, normpath -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.util.files import load, save diff --git a/conan/internal/api/profile/profile_loader.py b/conan/internal/api/profile/profile_loader.py index 2d16b5cf2b3..5ed77b1f17a 100644 --- a/conan/internal/api/profile/profile_loader.py +++ b/conan/internal/api/profile/profile_loader.py @@ -10,10 +10,10 @@ from conan.internal.cache.home_paths import HomePaths from conan.tools.env.environment import ProfileEnvironment from conan.errors import ConanException -from conans.model.conf import ConfDefinition, CORE_CONF_PATTERN -from conans.model.options import Options -from conans.model.profile import Profile -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.conf import ConfDefinition, CORE_CONF_PATTERN +from conan.internal.model.options import Options +from conan.internal.model.profile import Profile +from conan.api.model import RecipeReference from conans.util.config_parser import ConfigParser from conans.util.files import mkdir, load_user_encoded diff --git a/conan/internal/cache/cache.py b/conan/internal/cache/cache.py index 4436555c4a4..8363cc4f516 100644 --- a/conan/internal/cache/cache.py +++ b/conan/internal/cache/cache.py @@ -12,8 +12,8 @@ from conan.internal.cache.db.cache_database import CacheDatabase from conan.internal.errors import ConanReferenceAlreadyExistsInDB from conan.errors import ConanException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.util.dates import revision_timestamp_now from conans.util.files import rmdir, renamedir, mkdir diff --git a/conan/internal/cache/conan_reference_layout.py b/conan/internal/cache/conan_reference_layout.py index 9bcd58160c7..e10a8194fbd 100644 --- a/conan/internal/cache/conan_reference_layout.py +++ b/conan/internal/cache/conan_reference_layout.py @@ -1,7 +1,7 @@ import os from contextlib import contextmanager -from conans.model.manifest import FileTreeManifest +from conan.internal.model.manifest import FileTreeManifest from conan.internal.paths import CONANFILE, DATA_YML from conans.util.files import set_dirty, clean_dirty, is_dirty, rmdir diff --git a/conan/internal/cache/db/cache_database.py b/conan/internal/cache/db/cache_database.py index 6cd38b7c70f..7baac7d2f7c 100644 --- a/conan/internal/cache/db/cache_database.py +++ b/conan/internal/cache/db/cache_database.py @@ -4,9 +4,9 @@ from conan.api.output import ConanOutput from conan.internal.cache.db.packages_table import PackagesDBTable from conan.internal.cache.db.recipes_table import RecipesDBTable -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference -from conans.model.version import Version +from conan.api.model import PkgReference +from conan.api.model import RecipeReference +from conan.internal.model.version import Version class CacheDatabase: diff --git a/conan/internal/cache/db/packages_table.py b/conan/internal/cache/db/packages_table.py index 9dceb3fa17e..960987fb0ff 100644 --- a/conan/internal/cache/db/packages_table.py +++ b/conan/internal/cache/db/packages_table.py @@ -2,8 +2,8 @@ from conan.internal.cache.db.table import BaseDbTable from conan.internal.errors import ConanReferenceDoesNotExistInDB, ConanReferenceAlreadyExistsInDB -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.util.dates import timestamp_now diff --git a/conan/internal/cache/db/recipes_table.py b/conan/internal/cache/db/recipes_table.py index d17fe36e8fa..c64d59bd136 100644 --- a/conan/internal/cache/db/recipes_table.py +++ b/conan/internal/cache/db/recipes_table.py @@ -2,7 +2,7 @@ from conan.internal.cache.db.table import BaseDbTable from conan.internal.errors import ConanReferenceDoesNotExistInDB, ConanReferenceAlreadyExistsInDB -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.util.dates import timestamp_now diff --git a/conan/internal/cache/integrity_check.py b/conan/internal/cache/integrity_check.py index 742109721d7..7e48b3a2237 100644 --- a/conan/internal/cache/integrity_check.py +++ b/conan/internal/cache/integrity_check.py @@ -2,8 +2,8 @@ from conan.api.output import ConanOutput from conan.errors import ConanException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference class IntegrityChecker: diff --git a/conan/internal/deploy.py b/conan/internal/deploy.py index c2ff049825c..d3a42d89a86 100644 --- a/conan/internal/deploy.py +++ b/conan/internal/deploy.py @@ -43,7 +43,7 @@ def _load(path): raise ConanException(f"Cannot find deployer '{d}'") -def do_deploys(conan_api, graph, deploy, deploy_package, deploy_folder): +def do_deploys(home_folder, graph, deploy, deploy_package, deploy_folder): try: mkdir(deploy_folder) except Exception as e: @@ -68,7 +68,7 @@ def do_deploys(conan_api, graph, deploy, deploy_package, deploy_folder): with conanfile_exception_formatter(conanfile, "deploy"): conanfile.deploy() # Handle the deploys - cache = HomePaths(conan_api.cache_folder) + cache = HomePaths(home_folder) for d in deploy or []: deployer = _find_deployer(d, cache.deployers_path) # IMPORTANT: Use always kwargs to not break if it changes in the future diff --git a/conan/internal/methods.py b/conan/internal/methods.py index 17050dbef04..b0dbb47b027 100644 --- a/conan/internal/methods.py +++ b/conan/internal/methods.py @@ -4,10 +4,10 @@ from conan.errors import ConanException from conan.internal.errors import conanfile_exception_formatter, conanfile_remove_attr from conan.internal.paths import CONANINFO -from conans.model.manifest import FileTreeManifest -from conans.model.package_ref import PkgReference -from conans.model.pkg_type import PackageType -from conans.model.requires import BuildRequirements, TestRequirements, ToolRequirements +from conan.internal.model.manifest import FileTreeManifest +from conan.api.model import PkgReference +from conan.internal.model.pkg_type import PackageType +from conan.internal.model.requires import BuildRequirements, TestRequirements, ToolRequirements from conans.util.files import mkdir, chdir, save diff --git a/conan/internal/model/__init__.py b/conan/internal/model/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/conans/model/conan_file.py b/conan/internal/model/conan_file.py similarity index 97% rename from conans/model/conan_file.py rename to conan/internal/model/conan_file.py index ac84185159a..3af81e44035 100644 --- a/conans/model/conan_file.py +++ b/conan/internal/model/conan_file.py @@ -4,13 +4,13 @@ from conan.api.output import ConanOutput, Color from conans.client.subsystems import command_env_wrapper from conan.errors import ConanException -from conans.model.build_info import MockInfoProperty -from conans.model.conf import Conf -from conans.model.dependencies import ConanFileDependencies -from conans.model.layout import Folders, Infos, Layouts -from conans.model.options import Options -from conans.model.requires import Requirements -from conans.model.settings import Settings +from conan.internal.model.cpp_info import MockInfoProperty +from conan.internal.model.conf import Conf +from conan.internal.model.dependencies import ConanFileDependencies +from conan.internal.model.layout import Folders, Infos, Layouts +from conan.internal.model.options import Options +from conan.internal.model.requires import Requirements +from conan.internal.model.settings import Settings class ConanFile: diff --git a/conans/model/conanfile_interface.py b/conan/internal/model/conanfile_interface.py similarity index 100% rename from conans/model/conanfile_interface.py rename to conan/internal/model/conanfile_interface.py diff --git a/conans/model/conf.py b/conan/internal/model/conf.py similarity index 99% rename from conans/model/conf.py rename to conan/internal/model/conf.py index 6d7ce915e5f..065af309854 100644 --- a/conans/model/conf.py +++ b/conan/internal/model/conf.py @@ -7,7 +7,7 @@ from collections import OrderedDict from conan.errors import ConanException -from conans.model.recipe_ref import ref_matches +from conan.internal.model.recipe_ref import ref_matches BUILT_IN_CONFS = { "core:required_conan_version": "Raise if current version does not match the defined range.", diff --git a/conans/model/build_info.py b/conan/internal/model/cpp_info.py similarity index 90% rename from conans/model/build_info.py rename to conan/internal/model/cpp_info.py index b578a2de972..05f9af4c2a4 100644 --- a/conans/model/build_info.py +++ b/conan/internal/model/cpp_info.py @@ -7,7 +7,7 @@ from conan.api.output import ConanOutput from conan.errors import ConanException -from conans.model.pkg_type import PackageType +from conan.internal.model.pkg_type import PackageType from conans.util.files import load, save _DIRS_VAR_NAMES = ["_includedirs", "_srcdirs", "_libdirs", "_resdirs", "_bindirs", "_builddirs", @@ -487,7 +487,7 @@ def relocate(el): def parsed_requires(self): return [r.split("::", 1) if "::" in r else (None, r) for r in self.requires] - def _auto_deduce_locations(self, conanfile, component_name): + def _auto_deduce_locations(self, conanfile, library_name): def _lib_match_by_glob(dir_, filename): # Run a glob.glob function to find the file given by the filename @@ -495,7 +495,6 @@ def _lib_match_by_glob(dir_, filename): if matches: return matches - def _lib_match_by_regex(dir_, pattern): ret = set() # pattern is a regex compiled pattern, so let's iterate each file to find the library @@ -515,7 +514,6 @@ def _lib_match_by_regex(dir_, pattern): ret.add(full_path) return list(ret) - def _find_matching(dirs, pattern): for d in dirs: if not os.path.exists(d): @@ -540,6 +538,7 @@ def _find_matching(dirs, pattern): static_location = None shared_location = None dll_location = None + deduced_type = None # libname is exactly the pattern, e.g., ["mylib.a"] instead of ["mylib"] _, ext = os.path.splitext(libname) if ext in (".lib", ".a", ".dll", ".so", ".dylib"): @@ -551,7 +550,7 @@ def _find_matching(dirs, pattern): dll_location = _find_matching(bindirs, libname) else: lib_sanitized = re.escape(libname) - component_sanitized = re.escape(component_name) + component_sanitized = re.escape(library_name) regex_static = re.compile(rf"(?:lib)?{lib_sanitized}(?:[._-].+)?\.(?:a|lib)") regex_shared = re.compile(rf"(?:lib)?{lib_sanitized}(?:[._-].+)?\.(?:so|dylib)") regex_dll = re.compile(rf".*(?:{lib_sanitized}|{component_sanitized}).*\.dll") @@ -564,53 +563,78 @@ def _find_matching(dirs, pattern): if shared_location: out.warning(f"Lib {libname} has both static {static_location} and " f"shared {shared_location} in the same package") - if pkg_type is PackageType.STATIC: + if self._type is PackageType.STATIC or pkg_type is PackageType.STATIC: self._location = static_location - self._type = PackageType.STATIC + deduced_type = PackageType.STATIC else: self._location = shared_location - self._type = PackageType.SHARED + deduced_type = PackageType.SHARED elif dll_location: self._location = dll_location self._link_location = static_location - self._type = PackageType.SHARED + deduced_type = PackageType.SHARED else: self._location = static_location - self._type = PackageType.STATIC + deduced_type = PackageType.STATIC elif shared_location: self._location = shared_location - self._type = PackageType.SHARED + deduced_type = PackageType.SHARED elif dll_location: # Only .dll but no link library self._location = dll_location - self._type = PackageType.SHARED + deduced_type = PackageType.SHARED if not self._location: raise ConanException(f"{conanfile}: Cannot obtain 'location' for library '{libname}' " f"in {libdirs}. You can specify 'cpp_info.location' directly " f"or report in github.com/conan-io/conan/issues if you think it " f"should have been deduced correctly.") + if self._type is not None and self._type != deduced_type: + ConanException(f"{conanfile}: Incorrect deduced type '{deduced_type}' for library" + f" '{libname}' that declared .type='{self._type}'") + self._type = deduced_type if self._type != pkg_type: out.warning(f"Lib {libname} deduced as '{self._type}, but 'package_type={pkg_type}'") def deduce_locations(self, conanfile, component_name=""): + name = f'{conanfile} cpp_info.components["{component_name}"]' if component_name \ + else f'{conanfile} cpp_info' + # executable if self._exe: # exe is a new field, it should have the correct location + if self._type is None: + self._type = PackageType.APP + if self._type is not PackageType.APP: + raise ConanException(f"{name} incorrect .type {self._type} for .exe {self._exe}") + if self.libs: + raise ConanException(f"{name} has both .exe and .libs") + if not self.location: + raise ConanException(f"{name} has .exe and no .location") return - if self._location or self._link_location: - if self._type is None or self._type is PackageType.HEADER: - raise ConanException("Incorrect cpp_info defining location without type or header") + if self._type is PackageType.APP: + # old school Conan application packages withoud defining an exe, not an error return - if self._type is not None and self._type not in [PackageType.SHARED, PackageType.STATIC, - PackageType.APP]: + + # libraries + if len(self.libs) > 1: # it could be 0, as the libs itself is not necessary + raise ConanException(f"{name} has more than 1 library in .libs: {self.libs}, " + "cannot deduce locations") + # fully defined by user in conanfile, nothing to do. + if self._location or self._link_location: + if self._type not in [PackageType.SHARED, PackageType.STATIC]: + raise ConanException(f"{name} location defined without defined library type") return - num_libs = len(self.libs) - if num_libs == 0: + + # possible header only, which allows also an empty header-only only for common flags + if len(self.libs) == 0: + if self._type is None: + self._type = PackageType.HEADER return - elif num_libs > 1: - raise ConanException( - f"More than 1 library defined in cpp_info.libs, cannot deduce CPS ({num_libs} libraries found)") - else: - # If no location is defined, it's time to guess the location - self._auto_deduce_locations(conanfile, component_name=component_name) + + # automatic location deduction from a single .lib=["lib"] + if self._type not in [None, PackageType.SHARED, PackageType.STATIC]: + raise ConanException(f"{name} has a library but .type {self._type} is not static/shared") + + # If no location is defined, it's time to guess the location + self._auto_deduce_locations(conanfile, library_name=component_name or conanfile.ref.name) class CppInfo: @@ -782,12 +806,20 @@ def required_components(self): return ret def deduce_full_cpp_info(self, conanfile): + if conanfile.cpp_info.has_components and (conanfile.cpp_info.exe or conanfile.cpp_info.libs): + raise ConanException(f"{conanfile}: 'cpp_info' contains components and .exe or .libs") + result = CppInfo() # clone it if self.libs and len(self.libs) > 1: # expand in multiple components ConanOutput().warning(f"{conanfile}: The 'cpp_info.libs' contain more than 1 library. " "Define 'cpp_info.components' instead.") assert not self.components, f"{conanfile} cpp_info shouldn't have .libs and .components" + common = self._package.clone() + common.libs = [] + common.type = str(PackageType.HEADER) # the type of components is a string! + result.components["_common"] = common + for lib in self.libs: c = _Component() # Do not do a full clone, we don't need the properties c.type = self.type @@ -795,19 +827,14 @@ def deduce_full_cpp_info(self, conanfile): c.libdirs = self.libdirs c.bindirs = self.bindirs c.libs = [lib] + c.requires = ["_common"] result.components[f"_{lib}"] = c - - common = self._package.clone() - common.libs = [] - common.type = PackageType.HEADER # the type of components is a string! - common.requires = list(result.components.keys()) + (self.requires or []) - result.components["_common"] = common else: result._package = self._package.clone() result.default_components = self.default_components result.components = {k: v.clone() for k, v in self.components.items()} - result._package.deduce_locations(conanfile, component_name=conanfile.ref.name) + result._package.deduce_locations(conanfile) for comp_name, comp in result.components.items(): comp.deduce_locations(conanfile, component_name=comp_name) diff --git a/conans/model/dependencies.py b/conan/internal/model/dependencies.py similarity index 98% rename from conans/model/dependencies.py rename to conan/internal/model/dependencies.py index 31ac64553bd..22353419eab 100644 --- a/conans/model/dependencies.py +++ b/conan/internal/model/dependencies.py @@ -2,8 +2,8 @@ from conans.client.graph.graph import RECIPE_PLATFORM from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference -from conans.model.conanfile_interface import ConanFileInterface +from conan.api.model import RecipeReference +from conan.internal.model.conanfile_interface import ConanFileInterface class UserRequirementsDict(object): diff --git a/conans/model/info.py b/conan/internal/model/info.py similarity index 98% rename from conans/model/info.py rename to conan/internal/model/info.py index c22c310139e..2319ba7775b 100644 --- a/conans/model/info.py +++ b/conan/internal/model/info.py @@ -1,16 +1,16 @@ import hashlib from conan.errors import ConanException -from conans.model.dependencies import UserRequirementsDict -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference, Version +from conan.internal.model.dependencies import UserRequirementsDict +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.util.config_parser import ConfigParser class _VersionRepr: """Class to return strings like 1.Y.Z from a Version object""" - def __init__(self, version: Version): + def __init__(self, version): self._version = version def stable(self): diff --git a/conans/model/layout.py b/conan/internal/model/layout.py similarity index 98% rename from conans/model/layout.py rename to conan/internal/model/layout.py index de453f917fe..5ddacf5431f 100644 --- a/conans/model/layout.py +++ b/conan/internal/model/layout.py @@ -1,7 +1,7 @@ import os -from conans.model.build_info import CppInfo -from conans.model.conf import Conf +from conan.internal.model.cpp_info import CppInfo +from conan.internal.model.conf import Conf class Infos(object): diff --git a/conans/model/graph_lock.py b/conan/internal/model/lockfile.py similarity index 99% rename from conans/model/graph_lock.py rename to conan/internal/model/lockfile.py index b6272acc084..cdae26f598b 100644 --- a/conans/model/graph_lock.py +++ b/conan/internal/model/lockfile.py @@ -6,8 +6,8 @@ from conan.api.output import ConanOutput from conans.client.graph.graph import RECIPE_VIRTUAL, RECIPE_CONSUMER, CONTEXT_BUILD, Overrides from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference -from conans.model.version_range import VersionRange +from conan.api.model import RecipeReference +from conan.internal.model.version_range import VersionRange from conans.util.files import load, save LOCKFILE = "conan.lock" diff --git a/conans/model/manifest.py b/conan/internal/model/manifest.py similarity index 100% rename from conans/model/manifest.py rename to conan/internal/model/manifest.py diff --git a/conans/model/options.py b/conan/internal/model/options.py similarity index 99% rename from conans/model/options.py rename to conan/internal/model/options.py index c4c3d194542..99aff017144 100644 --- a/conans/model/options.py +++ b/conan/internal/model/options.py @@ -1,5 +1,5 @@ from conan.errors import ConanException -from conans.model.recipe_ref import ref_matches +from conan.internal.model.recipe_ref import ref_matches _falsey_options = ["false", "none", "0", "off", ""] diff --git a/conans/model/pkg_type.py b/conan/internal/model/pkg_type.py similarity index 100% rename from conans/model/pkg_type.py rename to conan/internal/model/pkg_type.py diff --git a/conans/model/profile.py b/conan/internal/model/profile.py similarity index 98% rename from conans/model/profile.py rename to conan/internal/model/profile.py index d20fb815aa5..54aa126d1f9 100644 --- a/conans/model/profile.py +++ b/conan/internal/model/profile.py @@ -2,9 +2,9 @@ from collections import OrderedDict, defaultdict from conan.tools.env.environment import ProfileEnvironment -from conans.model.conf import ConfDefinition -from conans.model.options import Options -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.conf import ConfDefinition +from conan.internal.model.options import Options +from conan.api.model import RecipeReference class Profile: diff --git a/conan/internal/model/recipe_ref.py b/conan/internal/model/recipe_ref.py new file mode 100644 index 00000000000..f811600cd46 --- /dev/null +++ b/conan/internal/model/recipe_ref.py @@ -0,0 +1,8 @@ +from conan.api.model import RecipeReference + + +def ref_matches(ref, pattern, is_consumer): + if not ref or not str(ref): + assert is_consumer + ref = RecipeReference.loads("*/*") # FIXME: ugly + return ref.matches(pattern, is_consumer=is_consumer) diff --git a/conans/model/requires.py b/conan/internal/model/requires.py similarity index 99% rename from conans/model/requires.py rename to conan/internal/model/requires.py index 5be2f341315..2c3d034514c 100644 --- a/conans/model/requires.py +++ b/conan/internal/model/requires.py @@ -1,9 +1,9 @@ from collections import OrderedDict from conan.errors import ConanException -from conans.model.pkg_type import PackageType -from conans.model.recipe_ref import RecipeReference -from conans.model.version_range import VersionRange +from conan.internal.model.pkg_type import PackageType +from conan.api.model import RecipeReference +from conan.internal.model.version_range import VersionRange class Requirement: diff --git a/conans/model/settings.py b/conan/internal/model/settings.py similarity index 100% rename from conans/model/settings.py rename to conan/internal/model/settings.py diff --git a/conans/model/version.py b/conan/internal/model/version.py similarity index 100% rename from conans/model/version.py rename to conan/internal/model/version.py diff --git a/conans/model/version_range.py b/conan/internal/model/version_range.py similarity index 99% rename from conans/model/version_range.py rename to conan/internal/model/version_range.py index 841abb3d15f..0b75fb27ae1 100644 --- a/conans/model/version_range.py +++ b/conan/internal/model/version_range.py @@ -1,7 +1,7 @@ from functools import total_ordering from typing import Optional -from conans.model.version import Version +from conan.internal.model.version import Version from conan.errors import ConanException diff --git a/conan/internal/runner/docker.py b/conan/internal/runner/docker.py index ad23e646b96..c21bee192ab 100644 --- a/conan/internal/runner/docker.py +++ b/conan/internal/runner/docker.py @@ -6,11 +6,10 @@ import yaml from conan.api.model import ListPattern from conan.api.output import Color, ConanOutput -from conan.api.conan_api import ConfigAPI from conan.cli import make_abs_path from conan.internal.runner import RunnerException from conan.errors import ConanException -from conans.model.version import Version +from conan.internal.model.version import Version def config_parser(file_path): @@ -63,7 +62,6 @@ def _docker_info(msg, error=False): class DockerRunner: def __init__(self, conan_api, command, host_profile, build_profile, args, raw_args): - import docker import docker.api.build try: docker_base_urls = [ diff --git a/conan/internal/workspace.py b/conan/internal/workspace.py index 5f95ff83625..1abd54ebe1c 100644 --- a/conan/internal/workspace.py +++ b/conan/internal/workspace.py @@ -8,7 +8,7 @@ from conan.internal.conan_app import CmdWrapper, ConanFileHelpers from conans.client.loader import load_python_file from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.util.files import load, save diff --git a/conan/test/assets/genconanfile.py b/conan/test/assets/genconanfile.py index 55f61de546b..b90c3951e4f 100644 --- a/conan/test/assets/genconanfile.py +++ b/conan/test/assets/genconanfile.py @@ -1,4 +1,4 @@ -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference class GenConanfile(object): diff --git a/conan/test/assets/pkg_cmake.py b/conan/test/assets/pkg_cmake.py index fd426210e97..a7b2073aa71 100644 --- a/conan/test/assets/pkg_cmake.py +++ b/conan/test/assets/pkg_cmake.py @@ -1,6 +1,6 @@ import textwrap -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.cmake import gen_cmakelists from conan.test.assets.sources import gen_function_h, gen_function_cpp diff --git a/conan/test/utils/mocks.py b/conan/test/utils/mocks.py index 3e616b70a03..9638b4ad877 100644 --- a/conan/test/utils/mocks.py +++ b/conan/test/utils/mocks.py @@ -4,9 +4,9 @@ from conan import ConanFile from conan.errors import ConanException from conan.internal.conan_app import ConanFileHelpers -from conans.model.conf import Conf -from conans.model.layout import Folders, Infos -from conans.model.options import Options +from conan.internal.model.conf import Conf +from conan.internal.model.layout import Folders, Infos +from conan.internal.model.options import Options class LocalDBMock(object): diff --git a/conan/test/utils/profiles.py b/conan/test/utils/profiles.py index ef15eb8dea6..aa005ce15cd 100644 --- a/conan/test/utils/profiles.py +++ b/conan/test/utils/profiles.py @@ -1,7 +1,7 @@ import os -from conans.model.options import Options -from conans.model.profile import Profile +from conan.internal.model.options import Options +from conan.internal.model.profile import Profile from conans.util.files import save diff --git a/conan/test/utils/tools.py b/conan/test/utils/tools.py index b6afae8f0ed..c7c1a63e403 100644 --- a/conan/test/utils/tools.py +++ b/conan/test/utils/tools.py @@ -36,11 +36,11 @@ from conan.test.utils.env import environment_update from conan.internal.errors import NotFoundException from conan.errors import ConanException -from conans.model.manifest import FileTreeManifest -from conans.model.package_ref import PkgReference -from conans.model.profile import Profile -from conans.model.recipe_ref import RecipeReference -from conans.model.settings import Settings +from conan.internal.model.manifest import FileTreeManifest +from conan.api.model import PkgReference +from conan.internal.model.profile import Profile +from conan.api.model import RecipeReference +from conan.internal.model.settings import Settings from conan.test.assets import copy_assets from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.artifactory import ArtifactoryServer diff --git a/conan/tools/__init__.py b/conan/tools/__init__.py index a8a45d35375..2cc34cc2b85 100644 --- a/conan/tools/__init__.py +++ b/conan/tools/__init__.py @@ -1,4 +1,4 @@ -from conans.model.build_info import CppInfo as _CppInfo +from conan.internal.model.cpp_info import CppInfo as _CppInfo def CppInfo(conanfile): diff --git a/conan/tools/apple/xcodedeps.py b/conan/tools/apple/xcodedeps.py index 369e025ef63..b980df1c5bf 100644 --- a/conan/tools/apple/xcodedeps.py +++ b/conan/tools/apple/xcodedeps.py @@ -6,7 +6,7 @@ from conan.internal import check_duplicated_generator from conan.errors import ConanException -from conans.model.dependencies import get_transitive_requires +from conan.internal.model.dependencies import get_transitive_requires from conans.util.files import load, save from conan.tools.apple.apple import _to_apple_arch diff --git a/conan/tools/build/cppstd.py b/conan/tools/build/cppstd.py index 1bea2f41d84..43c3e9da45f 100644 --- a/conan/tools/build/cppstd.py +++ b/conan/tools/build/cppstd.py @@ -2,7 +2,7 @@ from conan.errors import ConanInvalidConfiguration, ConanException from conan.internal.api.detect.detect_api import default_cppstd as default_cppstd_ -from conans.model.version import Version +from conan.internal.model.version import Version def check_min_cppstd(conanfile, cppstd, gnu_extensions=False): diff --git a/conan/tools/build/cstd.py b/conan/tools/build/cstd.py index 2d69eaba97d..abc594ee1e2 100644 --- a/conan/tools/build/cstd.py +++ b/conan/tools/build/cstd.py @@ -1,7 +1,7 @@ import operator from conan.errors import ConanInvalidConfiguration, ConanException -from conans.model.version import Version +from conan.internal.model.version import Version def check_min_cstd(conanfile, cstd, gnu_extensions=False): diff --git a/conan/tools/build/flags.py b/conan/tools/build/flags.py index 86470d16a4f..c13137339c7 100644 --- a/conan/tools/build/flags.py +++ b/conan/tools/build/flags.py @@ -1,4 +1,4 @@ -from conans.model.version import Version +from conan.internal.model.version import Version def architecture_flag(conanfile): diff --git a/conan/tools/cmake/cmakedeps/cmakedeps.py b/conan/tools/cmake/cmakedeps/cmakedeps.py index 2439a9467b9..d8d60777874 100644 --- a/conan/tools/cmake/cmakedeps/cmakedeps.py +++ b/conan/tools/cmake/cmakedeps/cmakedeps.py @@ -15,7 +15,7 @@ from conan.tools.cmake.cmakedeps.templates.targets import TargetsTemplate from conan.tools.files import save from conan.errors import ConanException -from conans.model.dependencies import get_transitive_requires +from conan.internal.model.dependencies import get_transitive_requires class CMakeDeps(object): diff --git a/conan/tools/cmake/cmakedeps2/cmakedeps.py b/conan/tools/cmake/cmakedeps2/cmakedeps.py index 0847d18485a..a68a9b53e88 100644 --- a/conan/tools/cmake/cmakedeps2/cmakedeps.py +++ b/conan/tools/cmake/cmakedeps2/cmakedeps.py @@ -13,7 +13,7 @@ from conan.tools.cmake.cmakedeps2.targets import TargetsTemplate2 from conan.tools.files import save from conan.errors import ConanException -from conans.model.dependencies import get_transitive_requires +from conan.internal.model.dependencies import get_transitive_requires from conans.util.files import load FIND_MODE_MODULE = "module" @@ -172,6 +172,8 @@ def generate(self): {% endfor %} {% if host_runtime_dirs %} set(CONAN_RUNTIME_LIB_DIRS {{ host_runtime_dirs }} ) + # Only for VS, needs CMake>=3.27 + set(CMAKE_VS_DEBUGGER_ENVIRONMENT "PATH=${CONAN_RUNTIME_LIB_DIRS};%PATH%") {% endif %} {% if cmake_program_path %} list(PREPEND CMAKE_PROGRAM_PATH {{ cmake_program_path }}) @@ -250,7 +252,10 @@ def _get_host_runtime_dirs(self): host_runtime_dirs.setdefault(config, []).append(paths) is_win = self._conanfile.settings.get_safe("os") == "Windows" - for req in self._conanfile.dependencies.host.values(): + + host_req = self._conanfile.dependencies.host + test_req = self._conanfile.dependencies.test + for req in list(host_req.values()) + list(test_req.values()): config = req.settings.get_safe("build_type", self._cmakedeps.configuration) aggregated_cppinfo = req.cpp_info.aggregated_components() runtime_dirs = aggregated_cppinfo.bindirs if is_win else aggregated_cppinfo.libdirs diff --git a/conan/tools/cmake/cmakedeps2/target_configuration.py b/conan/tools/cmake/cmakedeps2/target_configuration.py index 27ed4a0a5bb..be3967ffdc0 100644 --- a/conan/tools/cmake/cmakedeps2/target_configuration.py +++ b/conan/tools/cmake/cmakedeps2/target_configuration.py @@ -7,7 +7,7 @@ from conan.api.output import ConanOutput from conan.errors import ConanException from conans.client.graph.graph import CONTEXT_BUILD, CONTEXT_HOST -from conans.model.pkg_type import PackageType +from conan.internal.model.pkg_type import PackageType class TargetConfigurationTemplate2: @@ -150,7 +150,7 @@ def _get_cmake_lib(self, info, components, pkg_folder, pkg_folder_var): includedirs = ";".join(self._path(i, pkg_folder, pkg_folder_var) for i in info.includedirs) if info.includedirs else "" - requires = " ".join(self._requires(info, components)) + requires = ";".join(self._requires(info, components)) defines = " ".join(info.defines) # TODO: Missing escaping? # TODO: Missing link language @@ -209,9 +209,9 @@ def _add_root_lib_target(self, libs, pkg_name, cpp_info): defaultc) comp_name = target_name or f"{pkg_name}::{defaultc}" all_requires.append(comp_name) - all_requires = " ".join(all_requires) + all_requires = ";".join(all_requires) else: - all_requires = " ".join(libs.keys()) + all_requires = ";".join(libs.keys()) libs[root_target_name] = {"type": "INTERFACE", "requires": all_requires} @@ -219,8 +219,6 @@ def _get_exes(self, cpp_info, pkg_name, pkg_folder, pkg_folder_var): exes = {} if cpp_info.has_components: - assert not cpp_info.exe, "Package has components and exe" - assert not cpp_info.libs, "Package has components and libs" for name, comp in cpp_info.components.items(): if comp.exe or comp.type is PackageType.APP: target_name = self._cmakedeps.get_property("cmake_target_name", self._conanfile, @@ -230,8 +228,6 @@ def _get_exes(self, cpp_info, pkg_name, pkg_folder, pkg_folder_var): exes[target] = exe_location else: if cpp_info.exe: - assert not cpp_info.libs, "Package has exe and libs" - assert cpp_info.location, "Package has exe and no location" target_name = self._cmakedeps.get_property("cmake_target_name", self._conanfile) target = target_name or f"{pkg_name}::{pkg_name}" exe_location = self._path(cpp_info.location, pkg_folder, pkg_folder_var) @@ -344,7 +340,8 @@ def _template(self): "{{lib_info["link_location"]}}") {% endif %} {% if lib_info.get("requires") %} - target_link_libraries({{lib}} INTERFACE {{lib_info["requires"]}}) + set_target_properties({{lib}} PROPERTIES INTERFACE_LINK_LIBRARIES + "{{config_wrapper(config, lib_info["requires"])}}") {% endif %} {% if lib_info.get("system_libs") %} target_link_libraries({{lib}} INTERFACE {{lib_info["system_libs"]}}) diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index d1f4ec55d2c..5372c8560e7 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -19,7 +19,7 @@ from conan.internal.api.install.generators import relativize_path from conans.client.subsystems import deduce_subsystem, WINDOWS from conan.errors import ConanException -from conans.model.version import Version +from conan.internal.model.version import Version from conans.util.files import load @@ -126,7 +126,11 @@ class VSDebuggerEnvironment(Block): # for execution of applications with shared libraries within the VS IDE {% if vs_debugger_path %} + # if the file exists it will be loaded by FindFiles block and the variable defined there + if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/conan_cmakedeps_paths.cmake") + # This variable requires CMake>=3.27 to work set(CMAKE_VS_DEBUGGER_ENVIRONMENT "{{ vs_debugger_path }}") + endif() {% endif %} """) @@ -521,7 +525,7 @@ class FindFiles(Block): template = textwrap.dedent("""\ # Define paths to find packages, programs, libraries, etc. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/conan_cmakedeps_paths.cmake") - message(STATUS "Conan toolchain: Including CMakeDeps generated conan_find_paths.cmake") + message(STATUS "Conan toolchain: Including CMakeDeps generated conan_cmakedeps_paths.cmake") include("${CMAKE_CURRENT_LIST_DIR}/conan_cmakedeps_paths.cmake") else() diff --git a/conan/tools/cmake/toolchain/toolchain.py b/conan/tools/cmake/toolchain/toolchain.py index 6d834ec9b24..36ad0e92559 100644 --- a/conan/tools/cmake/toolchain/toolchain.py +++ b/conan/tools/cmake/toolchain/toolchain.py @@ -21,7 +21,7 @@ from conan.tools.microsoft import VCVars from conan.tools.microsoft.visual import vs_ide_version from conan.errors import ConanException -from conans.model.options import _PackageOption +from conan.internal.model.options import _PackageOption from conans.util.files import save diff --git a/conan/tools/env/environment.py b/conan/tools/env/environment.py index c6f9f6cd9b9..61155fdcecd 100644 --- a/conan/tools/env/environment.py +++ b/conan/tools/env/environment.py @@ -7,7 +7,7 @@ from conan.internal.api.install.generators import relativize_paths from conans.client.subsystems import deduce_subsystem, WINDOWS, subsystem_path from conan.errors import ConanException -from conans.model.recipe_ref import ref_matches +from conan.internal.model.recipe_ref import ref_matches from conans.util.files import save diff --git a/conan/tools/files/files.py b/conan/tools/files/files.py index b3a05026b57..6cbb550cdd2 100644 --- a/conan/tools/files/files.py +++ b/conan/tools/files/files.py @@ -3,7 +3,6 @@ import platform import shutil import subprocess -import sys from contextlib import contextmanager from fnmatch import fnmatch from shutil import which @@ -11,6 +10,7 @@ from conans.client.downloaders.caching_file_downloader import SourcesCachingDownloader from conan.errors import ConanException +from conans.client.rest.file_uploader import FileProgress from conans.util.files import rmdir as _internal_rmdir, human_size, check_with_algorithm_sum @@ -305,20 +305,7 @@ def unzip(conanfile, filename, destination=".", keep_permissions=False, pattern= import zipfile full_path = os.path.normpath(os.path.join(os.getcwd(), destination)) - if hasattr(sys.stdout, "isatty") and sys.stdout.isatty(): - def print_progress(the_size, uncomp_size): - the_size = (the_size * 100.0 / uncomp_size) if uncomp_size != 0 else 0 - txt_msg = "Unzipping %d %%" - if the_size > print_progress.last_size + 1: - output.rewrite_line(txt_msg % the_size) - print_progress.last_size = the_size - if int(the_size) == 99: - output.rewrite_line(txt_msg % 100) - else: - def print_progress(_, __): - pass - - with zipfile.ZipFile(filename, "r") as z: + with FileProgress(filename, msg="Unzipping", mode="r") as file, zipfile.ZipFile(file) as z: zip_info = z.infolist() if pattern: zip_info = [zi for zi in zip_info if fnmatch(zi.filename, pattern)] @@ -343,11 +330,9 @@ def print_progress(_, __): output.info("Unzipping %s" % human_size(uncompress_size)) extracted_size = 0 - print_progress.last_size = -1 if platform.system() == "Windows": for file_ in zip_info: extracted_size += file_.file_size - print_progress(extracted_size, uncompress_size) try: z.extract(file_, full_path) except Exception as e: @@ -355,7 +340,6 @@ def print_progress(_, __): else: # duplicated for, to avoid a platform check for each zipped file for file_ in zip_info: extracted_size += file_.file_size - print_progress(extracted_size, uncompress_size) try: z.extract(file_, full_path) if keep_permissions: @@ -371,7 +355,7 @@ def print_progress(_, __): def untargz(filename, destination=".", pattern=None, strip_root=False, extract_filter=None): # NOT EXPOSED at `conan.tools.files` but used in tests import tarfile - with tarfile.TarFile.open(filename, 'r:*') as tarredgzippedFile: + with FileProgress(filename, msg="Uncompressing") as fileobj, tarfile.TarFile.open(fileobj=fileobj, mode='r:*') as tarredgzippedFile: f = getattr(tarfile, f"{extract_filter}_filter", None) if extract_filter else None tarredgzippedFile.extraction_filter = f or (lambda member_, _: member_) if not pattern and not strip_root: diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index 5a384e8f7cf..e2daf568f39 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -11,7 +11,7 @@ from conan.tools.env import Environment, VirtualBuildEnv from conan.tools.gnu.get_gnu_triplet import _get_gnu_triplet from conan.tools.microsoft import VCVars, msvc_runtime_flag, unix_path, check_min_vs, is_msvc -from conans.model.pkg_type import PackageType +from conan.internal.model.pkg_type import PackageType class AutotoolsToolchain: diff --git a/conan/tools/gnu/gnutoolchain.py b/conan/tools/gnu/gnutoolchain.py index 6407f5c3027..1b22240e8c7 100644 --- a/conan/tools/gnu/gnutoolchain.py +++ b/conan/tools/gnu/gnutoolchain.py @@ -12,7 +12,7 @@ from conan.tools.gnu.get_gnu_triplet import _get_gnu_triplet from conan.tools.microsoft import VCVars, msvc_runtime_flag, unix_path, check_min_vs, is_msvc from conan.errors import ConanException -from conans.model.pkg_type import PackageType +from conan.internal.model.pkg_type import PackageType class GnuToolchain: diff --git a/conan/tools/gnu/pkgconfigdeps.py b/conan/tools/gnu/pkgconfigdeps.py index 561085bd0aa..5ef67d55db0 100644 --- a/conan/tools/gnu/pkgconfigdeps.py +++ b/conan/tools/gnu/pkgconfigdeps.py @@ -8,7 +8,7 @@ from conan.errors import ConanException from conan.internal import check_duplicated_generator from conan.tools.gnu.gnudeps_flags import GnuDepsFlags -from conans.model.dependencies import get_transitive_requires +from conan.internal.model.dependencies import get_transitive_requires from conans.util.files import save @@ -16,6 +16,15 @@ 'cpp_info', 'aliases', 'custom_content']) +def alias_content(name, version, aliased): + return textwrap.dedent(f"""\ + Name: {name} + Description: Alias {name} for {aliased} + Version: {version} + Requires: {aliased} + """) + + class _PCContentGenerator: template = textwrap.dedent("""\ @@ -55,8 +64,6 @@ def _get_pc_variables(self, cpp_info): """ prefix_path = self._get_prefix_path() pc_variables = {"prefix": prefix_path} - if cpp_info is None: - return pc_variables # Already formatted directories pc_variables.update(self._get_formatted_dirs("libdir", cpp_info.libdirs, prefix_path)) pc_variables.update(self._get_formatted_dirs("includedir", cpp_info.includedirs, prefix_path)) @@ -81,12 +88,13 @@ def _get_formatted_dirs(folder_name, folders, prefix_path_): def _get_lib_flags(self, libdirvars, cpp_info): gnudeps_flags = GnuDepsFlags(self._conanfile, cpp_info) libdirsflags = ['-L"${%s}"' % d for d in libdirvars] - system_libs = ["-l%s" % l for l in (cpp_info.libs + cpp_info.system_libs)] + system_libs = ["-l%s" % li for li in (cpp_info.libs + cpp_info.system_libs)] shared_flags = cpp_info.sharedlinkflags + cpp_info.exelinkflags framework_flags = gnudeps_flags.frameworks + gnudeps_flags.framework_paths return " ".join(libdirsflags + system_libs + shared_flags + framework_flags) - def _get_cflags(self, includedirvars, cpp_info): + @staticmethod + def _get_cflags(includedirvars, cpp_info): includedirsflags = ['-I"${%s}"' % d for d in includedirvars] cxxflags = [var.replace('"', '\\"') for var in cpp_info.cxxflags] cflags = [var.replace('"', '\\"') for var in cpp_info.cflags] @@ -114,16 +122,11 @@ def _apply_custom_content(custom_content): "version": info.version, "requires": info.requires, "pc_variables": pc_variables, - "cflags": "", - "libflags": "" - } - if info.cpp_info is not None: - context.update({ - "cflags": self._get_cflags([d for d in pc_variables if d.startswith("includedir")], - info.cpp_info), - "libflags": self._get_lib_flags([d for d in pc_variables if d.startswith("libdir")], - info.cpp_info) - }) + "cflags": self._get_cflags([d for d in pc_variables if d.startswith("includedir")], + info.cpp_info), + "libflags": self._get_lib_flags([d for d in pc_variables if d.startswith("libdir")], + info.cpp_info) + } return context def content(self, info): @@ -141,7 +144,6 @@ def __init__(self, pkgconfigdeps, require, dep): self._properties = pkgconfigdeps._properties # noqa self._require = require self._dep = dep - self._content_generator = _PCContentGenerator(self._conanfile, self._dep) self._transitive_reqs = get_transitive_requires(self._conanfile, dep) self._is_build_context = require.build self._build_context_folder = pkgconfigdeps.build_context_folder @@ -258,38 +260,33 @@ def pc_files(self): * Apart from those PC files, if there are any aliases declared, they will be created too. """ - def _fill_pc_files(pc_info): - content = self._content_generator.content(pc_info) + def _file_name(name): # If no suffix is defined, we can save the *.pc file in the build_context_folder - if self._is_build_context and self._build_context_folder and not self._suffix: - # Issue: https://github.com/conan-io/conan/issues/12342 - # Issue: https://github.com/conan-io/conan/issues/14935 - pc_files[f"{self._build_context_folder}/{pc_info.name}.pc"] = content - else: - # Saving also the suffixed names as usual - pc_files[f"{pc_info.name}.pc"] = content + build = self._is_build_context and self._build_context_folder and not self._suffix + # Issue: https://github.com/conan-io/conan/issues/12342 + # Issue: https://github.com/conan-io/conan/issues/14935 + return f"{self._build_context_folder}/{name}.pc" if build else f"{name}.pc" + + def _add_pc_files(pc_info): + content_generator = _PCContentGenerator(self._conanfile, self._dep) + result = {_file_name(pc_info.name): content_generator.content(pc_info)} + for alias in pc_info.aliases: + result[_file_name(alias)] = alias_content(alias, pc_info.version, pc_info.name) + return result - def _update_pc_files(info): - _fill_pc_files(info) - for alias in info.aliases: - alias_info = _PCInfo(alias, self._dep.ref.version, [info.name], - f"Alias {alias} for {info.name}", None, [], None) - _fill_pc_files(alias_info) - - pc_files = {} # If the package has no components, then we have to calculate only the root pc file if not self._dep.cpp_info.has_components: - package_info = self._package_info() - _update_pc_files(package_info) - return pc_files + pkg_pc_info = self._package_info() + return _add_pc_files(pkg_pc_info) # First, let's load all the components PC files # Loop through all the package's components + pc_files = {} pkg_requires = [] - for component_info in self._components_info(): - _update_pc_files(component_info) + for comp_pc_info in self._components_info(): + pc_files.update(_add_pc_files(comp_pc_info)) # Saving components name as the package requires - pkg_requires.append(component_info.name) + pkg_requires.append(comp_pc_info.name) # Second, let's load the root package's PC file ONLY # if it does not already exist in components one @@ -303,7 +300,7 @@ def _update_pc_files(info): pkg_requires, f"Conan package: {pkg_name}", self._dep.cpp_info, self._get_package_aliases(self._dep), self.get_property("pkg_config_custom_content", self._dep)) - _update_pc_files(package_info) + pc_files.update(_add_pc_files(package_info)) return pc_files @staticmethod diff --git a/conan/tools/google/bazeldeps.py b/conan/tools/google/bazeldeps.py index 4a9a1aca7fd..fa73a9fbc85 100644 --- a/conan/tools/google/bazeldeps.py +++ b/conan/tools/google/bazeldeps.py @@ -7,8 +7,8 @@ from conan.errors import ConanException from conan.internal import check_duplicated_generator -from conans.model.dependencies import get_transitive_requires -from conans.model.pkg_type import PackageType +from conan.internal.model.dependencies import get_transitive_requires +from conan.internal.model.pkg_type import PackageType from conans.util.files import save _BazelTargetInfo = namedtuple("DepInfo", ['repository_name', 'name', 'ref_name', 'requires', 'cpp_info']) diff --git a/conan/tools/meson/helpers.py b/conan/tools/meson/helpers.py index 6e6861abcb9..5f275849e48 100644 --- a/conan/tools/meson/helpers.py +++ b/conan/tools/meson/helpers.py @@ -1,6 +1,6 @@ from conan.api.output import ConanOutput from conan.tools.build.flags import cppstd_msvc_flag -from conans.model.options import _PackageOption +from conan.internal.model.options import _PackageOption __all__ = ["to_meson_machine", "to_meson_value", "to_cppstd_flag", "to_cstd_flag"] diff --git a/conan/tools/microsoft/msbuilddeps.py b/conan/tools/microsoft/msbuilddeps.py index 01bf9f09ec7..4477c5836dc 100644 --- a/conan/tools/microsoft/msbuilddeps.py +++ b/conan/tools/microsoft/msbuilddeps.py @@ -9,7 +9,7 @@ from conan.internal import check_duplicated_generator from conan.errors import ConanException from conan.internal.api.install.generators import relativize_path -from conans.model.dependencies import get_transitive_requires +from conan.internal.model.dependencies import get_transitive_requires from conans.util.files import load, save VALID_LIB_EXTENSIONS = (".so", ".lib", ".a", ".dylib", ".bc") diff --git a/conan/tools/qbs/qbsdeps.py b/conan/tools/qbs/qbsdeps.py index c546e699388..69e9bc89e06 100644 --- a/conan/tools/qbs/qbsdeps.py +++ b/conan/tools/qbs/qbsdeps.py @@ -1,6 +1,6 @@ from conan.tools.files import save from conan.errors import ConanException -from conans.model.dependencies import get_transitive_requires +from conan.internal.model.dependencies import get_transitive_requires import json import os diff --git a/conan/tools/scm/__init__.py b/conan/tools/scm/__init__.py index 9d4097bc7b2..dece8113fd5 100644 --- a/conan/tools/scm/__init__.py +++ b/conan/tools/scm/__init__.py @@ -1,2 +1,2 @@ from conan.tools.scm.git import Git -from conans.model.version import Version +from conan.internal.model.version import Version diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py index f3578e2c9ff..6e0ad9e27c3 100644 --- a/conan/tools/scm/git.py +++ b/conan/tools/scm/git.py @@ -4,7 +4,7 @@ from conan.api.output import Color from conan.tools.files import chdir, update_conandata from conan.errors import ConanException -from conans.model.conf import ConfDefinition +from conan.internal.model.conf import ConfDefinition from conans.util.files import mkdir from conans.util.runners import check_output_runner @@ -137,7 +137,9 @@ def is_dirty(self, repository=False): return bool(status) # Parse the status output, line by line, and match it with "_excluded" lines = [line.strip() for line in status.splitlines()] - lines = [line.split()[1] for line in lines if line] + # line is of the form STATUS PATH, get the path by splitting + # (Taking into account that STATUS is one word, PATH might be many) + lines = [line.split(maxsplit=1)[1].strip('"') for line in lines if line] lines = [line for line in lines if not any(fnmatch.fnmatch(line, p) for p in self._excluded)] self._conanfile.output.debug(f"Filtered git status: {lines}") return bool(lines) diff --git a/conans/client/graph/build_mode.py b/conans/client/graph/build_mode.py index 12b121e091b..042652007f8 100644 --- a/conans/client/graph/build_mode.py +++ b/conans/client/graph/build_mode.py @@ -1,5 +1,5 @@ from conan.errors import ConanException -from conans.model.recipe_ref import ref_matches +from conan.internal.model.recipe_ref import ref_matches class BuildMode: diff --git a/conans/client/graph/compute_pid.py b/conans/client/graph/compute_pid.py index 5852b938763..f6248fd83b9 100644 --- a/conans/client/graph/compute_pid.py +++ b/conans/client/graph/compute_pid.py @@ -3,7 +3,7 @@ from conan.internal.errors import conanfile_remove_attr, conanfile_exception_formatter from conan.errors import ConanException, ConanInvalidConfiguration from conan.internal.methods import auto_header_only_package_id -from conans.model.info import ConanInfo, RequirementsInfo, RequirementInfo, PythonRequiresInfo +from conan.internal.model.info import ConanInfo, RequirementsInfo, RequirementInfo, PythonRequiresInfo def compute_package_id(node, modes, config_version): diff --git a/conans/client/graph/graph.py b/conans/client/graph/graph.py index 6e036d88c50..2b2ef7becba 100644 --- a/conans/client/graph/graph.py +++ b/conans/client/graph/graph.py @@ -1,8 +1,8 @@ from collections import OrderedDict from conans.client.graph.graph_error import GraphError -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference RECIPE_DOWNLOADED = "Downloaded" RECIPE_INCACHE = "Cache" # The previously installed recipe in cache is being used @@ -142,7 +142,7 @@ def check_downstream_exists(self, require): if require.build and (self.context == CONTEXT_HOST or # switch context require.ref.version != self.ref.version): # or different version pass - elif require.visible is False: # and require.ref.version != self.ref.version: + elif require.visible is False: # and require.ref.version != self.ref.version: # Experimental, to support repackaging of openssl previous versions FIPS plugins pass # An invisible require doesn't conflict with itself else: @@ -346,6 +346,10 @@ def __init__(self): self.options_conflicts = {} self.error = False + def lockfile(self): + from conan.internal.model.lockfile import Lockfile + return Lockfile(self) + def overrides(self): return Overrides.create(self.nodes) diff --git a/conans/client/graph/graph_binaries.py b/conans/client/graph/graph_binaries.py index a37cb9f8487..def1835c41b 100644 --- a/conans/client/graph/graph_binaries.py +++ b/conans/client/graph/graph_binaries.py @@ -16,9 +16,9 @@ from conan.internal.errors import conanfile_exception_formatter, ConanConnectionError, NotFoundException, \ PackageNotFoundException from conan.errors import ConanException -from conans.model.info import RequirementInfo, RequirementsInfo -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.info import RequirementInfo, RequirementsInfo +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.util.files import load diff --git a/conans/client/graph/graph_builder.py b/conans/client/graph/graph_builder.py index eb08479bbb8..970d95f95fa 100644 --- a/conans/client/graph/graph_builder.py +++ b/conans/client/graph/graph_builder.py @@ -4,19 +4,20 @@ from conan.internal.cache.conan_reference_layout import BasicLayout from conan.internal.methods import run_configure_method +from conan.internal.model.recipe_ref import ref_matches from conans.client.graph.graph import DepsGraph, Node, CONTEXT_HOST, \ - CONTEXT_BUILD, TransitiveRequirement, RECIPE_VIRTUAL, RECIPE_EDITABLE, RECIPE_CONSUMER + CONTEXT_BUILD, TransitiveRequirement, RECIPE_VIRTUAL, RECIPE_EDITABLE from conans.client.graph.graph import RECIPE_PLATFORM from conans.client.graph.graph_error import GraphLoopError, GraphConflictError, GraphMissingError, \ GraphRuntimeError, GraphError from conans.client.graph.profile_node_definer import initialize_conanfile_profile from conans.client.graph.provides import check_graph_provides from conan.errors import ConanException -from conans.model.conan_file import ConanFile -from conans.model.options import Options, _PackageOptions -from conans.model.pkg_type import PackageType -from conans.model.recipe_ref import RecipeReference, ref_matches -from conans.model.requires import Requirement +from conan.internal.model.conan_file import ConanFile +from conan.internal.model.options import Options, _PackageOptions +from conan.internal.model.pkg_type import PackageType +from conan.api.model import RecipeReference +from conan.internal.model.requires import Requirement class DepsGraphBuilder(object): diff --git a/conans/client/graph/install_graph.py b/conans/client/graph/install_graph.py index 9bd432b7c95..c071b0d3b2a 100644 --- a/conans/client/graph/install_graph.py +++ b/conans/client/graph/install_graph.py @@ -1,14 +1,13 @@ import json import os -import shlex import textwrap from conan.api.output import ConanOutput from conans.client.graph.graph import RECIPE_CONSUMER, RECIPE_VIRTUAL, BINARY_SKIP, \ BINARY_MISSING, BINARY_INVALID, Overrides, BINARY_BUILD, BINARY_EDITABLE_BUILD, BINARY_PLATFORM from conan.errors import ConanException, ConanInvalidConfiguration -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.util.files import load @@ -577,8 +576,8 @@ def _raise_missing(self, missing): missing_pkgs = "', '".join(list(sorted([str(pref.ref) for pref in missing_prefs]))) if self._is_test_package: build_msg = "This is a **test_package** missing binary. You can use --build (for " \ - "all dependencies) or --build-test (exclusive for 'test_package' " \ - "dependencies) to define what can be built from sources" + "all dependencies) or --build-test (exclusive for 'conan create' building " \ + "test_package' dependencies) to define what can be built from sources" else: if len(missing_prefs) >= 5: build_str = "--build=missing" diff --git a/conans/client/graph/profile_node_definer.py b/conans/client/graph/profile_node_definer.py index 1b5bba25bde..748304d03ff 100644 --- a/conans/client/graph/profile_node_definer.py +++ b/conans/client/graph/profile_node_definer.py @@ -1,6 +1,6 @@ from conans.client.graph.graph import CONTEXT_BUILD from conan.errors import ConanException -from conans.model.recipe_ref import ref_matches +from conan.internal.model.recipe_ref import ref_matches def initialize_conanfile_profile(conanfile, profile_build, profile_host, base_context, diff --git a/conans/client/graph/provides.py b/conans/client/graph/provides.py index fd8ab2c8e0d..e08d4ae1d18 100644 --- a/conans/client/graph/provides.py +++ b/conans/client/graph/provides.py @@ -1,5 +1,5 @@ from conans.client.graph.graph_error import GraphProvidesError -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference def check_graph_provides(dep_graph): diff --git a/conans/client/graph/python_requires.py b/conans/client/graph/python_requires.py index b9542ef5f33..a2c1b950610 100644 --- a/conans/client/graph/python_requires.py +++ b/conans/client/graph/python_requires.py @@ -1,8 +1,8 @@ import os from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference -from conans.model.requires import Requirement +from conan.api.model import RecipeReference +from conan.internal.model.requires import Requirement class PyRequire(object): diff --git a/conans/client/graph/range_resolver.py b/conans/client/graph/range_resolver.py index bd21c44d1c1..83e0cfab15b 100644 --- a/conans/client/graph/range_resolver.py +++ b/conans/client/graph/range_resolver.py @@ -1,7 +1,7 @@ from conans.client.graph.proxy import should_update_reference from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference -from conans.model.version_range import VersionRange +from conan.api.model import RecipeReference +from conan.internal.model.version_range import VersionRange class RangeResolver: diff --git a/conans/client/installer.py b/conans/client/installer.py index bcd3ffa8216..2c70382fda5 100644 --- a/conans/client/installer.py +++ b/conans/client/installer.py @@ -13,8 +13,8 @@ from conans.client.source import retrieve_exports_sources, config_source from conan.internal.errors import conanfile_remove_attr, conanfile_exception_formatter from conan.errors import ConanException -from conans.model.build_info import CppInfo, MockInfoProperty -from conans.model.package_ref import PkgReference +from conan.internal.model.cpp_info import CppInfo, MockInfoProperty +from conan.api.model import PkgReference from conan.internal.paths import CONANINFO from conans.util.files import clean_dirty, is_dirty, mkdir, rmdir, save, set_dirty, chdir diff --git a/conans/client/loader.py b/conans/client/loader.py index 8fb865f7526..95769647415 100644 --- a/conans/client/loader.py +++ b/conans/client/loader.py @@ -18,11 +18,11 @@ from conans.client.loader_txt import ConanFileTextLoader from conan.internal.errors import conanfile_exception_formatter, NotFoundException from conan.errors import ConanException -from conans.model.conan_file import ConanFile -from conans.model.options import Options -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.conan_file import ConanFile +from conan.internal.model.options import Options +from conan.api.model import RecipeReference from conan.internal.paths import DATA_YML -from conans.model.version_range import validate_conan_version +from conan.internal.model.version_range import validate_conan_version from conans.util.files import load, chdir, load_user_encoded diff --git a/conans/client/remote_manager.py b/conans/client/remote_manager.py index 1257b889c2c..ae1c860deb0 100644 --- a/conans/client/remote_manager.py +++ b/conans/client/remote_manager.py @@ -12,9 +12,9 @@ from conans.client.pkg_sign import PkgSignaturesPlugin from conan.internal.errors import ConanConnectionError, NotFoundException, PackageNotFoundException from conan.errors import ConanException -from conans.model.info import load_binary_info -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.info import load_binary_info +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.util.files import rmdir, human_size from conan.internal.paths import EXPORT_SOURCES_TGZ_NAME, EXPORT_TGZ_NAME, PACKAGE_TGZ_NAME from conans.util.files import mkdir, tar_extract diff --git a/conans/client/rest/client_routes.py b/conans/client/rest/client_routes.py index 8b60962e478..8f085c030f7 100644 --- a/conans/client/rest/client_routes.py +++ b/conans/client/rest/client_routes.py @@ -1,7 +1,7 @@ from urllib.parse import urlencode -from conans.model.recipe_ref import RecipeReference -from conans.model.rest_routes import RestRoutes +from conan.api.model import RecipeReference +from conans.client.rest.rest_routes import RestRoutes def _format_ref(url, ref): diff --git a/conans/client/rest/file_uploader.py b/conans/client/rest/file_uploader.py index 429150581b0..0b831d2da51 100644 --- a/conans/client/rest/file_uploader.py +++ b/conans/client/rest/file_uploader.py @@ -1,3 +1,4 @@ +import io import os import time @@ -81,27 +82,7 @@ def upload(self, url, abs_path, auth=None, dedup=False, retry=None, retry_wait=N time.sleep(retry_wait) def _upload_file(self, url, abs_path, headers, auth, ref): - class FileProgress: # Wrapper just to provide an upload progress every 10 seconds - def __init__(self, f, total_size): - self._f = f - self._total = total_size - self._name = os.path.basename(f.name) - self._t = TimedOutput(interval=10) - self._read = 0 - - def __getattr__(self, item): - return getattr(self._f, item) - - def read(self, n=-1): - read_bytes = self._f.read(n) - self._read += len(read_bytes) - self._t.info(f"{ref}: Uploading {self._name}: {int(self._read*100/self._total)}%") - return read_bytes - - filesize = os.path.getsize(abs_path) - with open(abs_path, mode='rb') as file_handler: - big_file = filesize > 100000000 # 100 MB - file_handler = FileProgress(file_handler, filesize) if big_file else file_handler + with FileProgress(abs_path, mode='rb', msg=f"{ref}: Uploading") as file_handler: try: response = self._requester.put(url, data=file_handler, verify=self._verify_ssl, headers=headers, auth=auth, @@ -113,3 +94,22 @@ def read(self, n=-1): raise except Exception as exc: raise ConanException(exc) + + +class FileProgress(io.FileIO): + def __init__(self, path: str, msg: str = "Uploading", interval: float = 1, *args, **kwargs): + super().__init__(path, *args, **kwargs) + self._size = os.path.getsize(path) + self._filename = os.path.basename(path) + # Report only on big sizes (>100MB) + self._reporter = TimedOutput(interval=interval) if self._size > 100_000_000 else None + self._bytes_read = 0 + self.msg = msg + + def read(self, size: int = -1) -> bytes: + block = super().read(size) + self._bytes_read += len(block) + if self._reporter: + current_percentage = int(self._bytes_read * 100.0 / self._size) if self._size != 0 else 0 + self._reporter.info(f"{self.msg} {self._filename}: {current_percentage}%") + return block diff --git a/conans/client/rest/rest_client_v2.py b/conans/client/rest/rest_client_v2.py index 627400ad609..97ff280153a 100644 --- a/conans/client/rest/rest_client_v2.py +++ b/conans/client/rest/rest_client_v2.py @@ -16,9 +16,9 @@ from conan.internal.errors import AuthenticationException, ForbiddenException, NotFoundException, \ RecipeNotFoundException, PackageNotFoundException, EXCEPTION_CODE_MAPPING from conan.errors import ConanException -from conans.model.package_ref import PkgReference +from conan.api.model import PkgReference from conan.internal.paths import EXPORT_SOURCES_TGZ_NAME -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.util.dates import from_iso8601_to_timestamp from conans.util.thread import ExceptionThread diff --git a/conans/model/rest_routes.py b/conans/client/rest/rest_routes.py similarity index 100% rename from conans/model/rest_routes.py rename to conans/client/rest/rest_routes.py diff --git a/conans/client/rest_client_local_recipe_index.py b/conans/client/rest_client_local_recipe_index.py index 4fa57964fbe..26b398383bd 100644 --- a/conans/client/rest_client_local_recipe_index.py +++ b/conans/client/rest_client_local_recipe_index.py @@ -15,8 +15,8 @@ from conan.internal.errors import ConanReferenceDoesNotExistInDB, NotFoundException, RecipeNotFoundException, \ PackageNotFoundException from conan.errors import ConanException -from conans.model.conf import ConfDefinition -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.conf import ConfDefinition +from conan.api.model import RecipeReference from conans.util.files import load, save, rmdir, copytree_compat diff --git a/conans/migrations.py b/conans/migrations.py index b47d8a6ef76..96056c9e1cf 100644 --- a/conans/migrations.py +++ b/conans/migrations.py @@ -4,7 +4,7 @@ from conan.api.output import ConanOutput from conans.client.loader import load_python_file from conan.errors import ConanException, ConanMigrationError -from conans.model.version import Version +from conan.internal.model.version import Version from conans.util.files import load, save CONAN_VERSION = "version.txt" diff --git a/conans/model/package_ref.py b/conans/model/package_ref.py index 2980f71a281..0669fc4359c 100644 --- a/conans/model/package_ref.py +++ b/conans/model/package_ref.py @@ -1,104 +1,30 @@ -from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference -from conans.util.dates import timestamp_to_str +from conan.api.output import ConanOutput +from conan.api.model import PkgReference as _PkgReference +_msg = """ +******************************************************************* +Private '{}' +detected in user code (custom commands, extensions, recipes, etc). +Please stop using it, use only public documented APIs, , such as +'from conan.api.model import PkgReference' +as this will break in next releases. +******************************************************************* +""" -class PkgReference: - def __init__(self, ref=None, package_id=None, revision=None, timestamp=None): - self.ref = ref - self.package_id = package_id - self.revision = revision - self.timestamp = timestamp # float, Unix seconds UTC +class PkgReference(_PkgReference): + usage_counter = 0 - def __repr__(self): - """ long repr like pkg/0.1@user/channel#rrev%timestamp """ - if self.ref is None: - return "" - result = repr(self.ref) - if self.package_id: - result += ":{}".format(self.package_id) - if self.revision is not None: - result += "#{}".format(self.revision) - if self.timestamp is not None: - result += "%{}".format(self.timestamp) - return result - - def repr_notime(self): - if self.ref is None: - return "" - result = self.ref.repr_notime() - if self.package_id: - result += ":{}".format(self.package_id) - if self.revision is not None: - result += "#{}".format(self.revision) - return result - - def repr_reduced(self): - if self.ref is None: - return "" - result = self.ref.repr_reduced() - if self.package_id: - result += ":{}".format(self.package_id[0:4]) - if self.revision is not None: - result += "#{}".format(self.revision[0:4]) - return result - - def repr_humantime(self): - result = self.repr_notime() - assert self.timestamp - result += " ({})".format(timestamp_to_str(self.timestamp)) - return result - - def __str__(self): - """ shorter representation, excluding the revision and timestamp """ - if self.ref is None: - return "" - result = str(self.ref) - if self.package_id: - result += ":{}".format(self.package_id) - return result - - def __lt__(self, ref): - # The timestamp goes before the revision for ordering revisions chronologically - raise Exception("WHO IS COMPARING PACKAGE REFERENCES?") - # return (self.name, self.version, self.user, self.channel, self.timestamp, self.revision) \ - # < (ref.name, ref.version, ref.user, ref.channel, ref._timestamp, ref.revision) - - def __eq__(self, other): - # TODO: In case of equality, should it use the revision and timestamp? - # Used: - # at "graph_binaries" to check: cache_latest_prev != pref - # at "installer" to check: if pkg_layout.reference != pref (probably just optimization?) - # at "revisions_test" - return self.ref == other.ref and self.package_id == other.package_id and \ - self.revision == other.revision - - def __hash__(self): - # Used in dicts of PkgReferences as keys like the cached nodes in the graph binaries - return hash((self.ref, self.package_id, self.revision)) + 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(pkg_ref): # TODO: change this default to validate only on end points - try: - tokens = pkg_ref.split(":", 1) - assert len(tokens) == 2 - ref, pkg_id = tokens - - ref = RecipeReference.loads(ref) - - # timestamp - tokens = pkg_id.rsplit("%", 1) - text = tokens[0] - timestamp = float(tokens[1]) if len(tokens) == 2 else None - - # revision - tokens = text.split("#", 1) - package_id = tokens[0] - revision = tokens[1] if len(tokens) == 2 else None - - return PkgReference(ref, package_id, revision, timestamp) - except Exception: - raise ConanException( - f"{pkg_ref} is not a valid package reference, provide a reference" - f" in the form name/version[@user/channel:package_id]") + 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 index 6165ec4c9c1..97960babed2 100644 --- a/conans/model/recipe_ref.py +++ b/conans/model/recipe_ref.py @@ -1,212 +1,31 @@ - -import fnmatch -import re -from functools import total_ordering - -from conan.errors import ConanException -from conans.model.version import Version -from conans.util.dates import timestamp_to_str - - -@total_ordering -class RecipeReference: - """ an exact (no version-range, no alias) reference of a recipe. - Should be enough to locate a recipe in the cache or in a server - Validation will be external to this class, at specific points (export, api, etc) - """ - - def __init__(self, name=None, version=None, user=None, channel=None, revision=None, - timestamp=None): - self.name = name - if version is not None and not isinstance(version, Version): - version = Version(version) - self.version = version # This MUST be a version if we want to be able to order - self.user = user - self.channel = channel - self.revision = revision - self.timestamp = timestamp - - def copy(self): - # Used for creating copy in lockfile-overrides mechanism - return RecipeReference(self.name, self.version, self.user, self.channel, self.revision, - self.timestamp) - - def __repr__(self): - """ long repr like pkg/0.1@user/channel#rrev%timestamp """ - result = self.repr_notime() - if self.timestamp is not None: - result += "%{}".format(self.timestamp) - return result - - def repr_notime(self): - result = self.__str__() - if self.revision is not None: - result += "#{}".format(self.revision) - return result - - def repr_reduced(self): - result = self.__str__() - if self.revision is not None: - result += "#{}".format(self.revision[0:4]) - return result - - def repr_humantime(self): - result = self.repr_notime() - assert self.timestamp - result += " ({})".format(timestamp_to_str(self.timestamp)) - return result - - def __str__(self): - """ shorter representation, excluding the revision and timestamp """ - if self.name is None: - return "" - result = "/".join([self.name, str(self.version)]) - if self.user: - result += "@{}".format(self.user) - if self.channel: - assert self.user - result += "/{}".format(self.channel) - return result - - def __lt__(self, ref): - # The timestamp goes before the revision for ordering revisions chronologically - # In theory this is enough for sorting - # When no timestamp is given, it will always have lower priority, to avoid comparison - # errors float <> None - return (self.name, self.version, self.user or "", self.channel or "", self.timestamp or 0, - self.revision or "") \ - < (ref.name, ref.version, ref.user or "", ref.channel or "", ref.timestamp or 0, - ref.revision or "") - - def __eq__(self, ref): - # Timestamp doesn't affect equality. - # This is necessary for building an ordered list of UNIQUE recipe_references for Lockfile - if ref is None: - return False - # If one revision is not defined, they are equal - if self.revision is not None and ref.revision is not None: - return (self.name, self.version, self.user, self.channel, self.revision) == \ - (ref.name, ref.version, ref.user, ref.channel, ref.revision) - return (self.name, self.version, self.user, self.channel) == \ - (ref.name, ref.version, ref.user, ref.channel) - - def __hash__(self): - # This is necessary for building an ordered list of UNIQUE recipe_references for Lockfile - return hash((self.name, self.version, self.user, self.channel)) +from conan.api.output import ConanOutput +from conan.api.model import RecipeReference as _RecipeReference + +_msg = """ +******************************************************************* +Private '{}' +detected in user code (custom commands, extensions, recipes, etc). +Please stop using it, use only public documented APIs, such as +'from conan.api.model import RecipeReference' +as this will break in next releases. +******************************************************************* +""" + + +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(rref): - try: - # timestamp - tokens = rref.rsplit("%", 1) - text = tokens[0] - timestamp = float(tokens[1]) if len(tokens) == 2 else None - - # revision - tokens = text.split("#", 1) - ref = tokens[0] - revision = tokens[1] if len(tokens) == 2 else None - - # name, version always here - tokens = ref.split("@", 1) - name, version = tokens[0].split("/", 1) - assert name and version - # user and channel - if len(tokens) == 2 and tokens[1]: - tokens = tokens[1].split("/", 1) - user = tokens[0] if tokens[0] else None - channel = tokens[1] if len(tokens) == 2 else None - else: - user = channel = None - return RecipeReference(name, version, user, channel, revision, timestamp) - except Exception: - from conan.errors import ConanException - raise ConanException( - f"{rref} is not a valid recipe reference, provide a reference" - f" in the form name/version[@user/channel]") - - def validate_ref(self, allow_uppercase=False): - """ at the moment only applied to exported (exact) references, but not for requires - that could contain version ranges - """ - from conan.api.output import ConanOutput - self_str = str(self) - if self_str != self_str.lower(): - if not allow_uppercase: - raise ConanException(f"Conan packages names '{self_str}' must be all lowercase") - else: - ConanOutput().warning(f"Package name '{self_str}' has uppercase, and has been " - "allowed by temporary config. This will break in later 2.X") - if len(self_str) > 200: - raise ConanException(f"Package reference too long >200 {self_str}") - if ":" in repr(self): - raise ConanException(f"Invalid recipe reference '{repr(self)}' is a package reference") - if not allow_uppercase: - validation_pattern = re.compile(r"^[a-z0-9_][a-z0-9_+.-]{1,100}\Z") - else: - validation_pattern = re.compile(r"^[a-zA-Z0-9_][a-zA-Z0-9_+.-]{1,100}\Z") - if validation_pattern.match(self.name) is None: - raise ConanException(f"Invalid package name '{self.name}'") - if validation_pattern.match(str(self.version)) is None: - raise ConanException(f"Invalid package version '{self.version}'") - if self.user and validation_pattern.match(self.user) is None: - raise ConanException(f"Invalid package user '{self.user}'") - if self.channel and validation_pattern.match(self.channel) is None: - raise ConanException(f"Invalid package channel '{self.channel}'") - - # Warn if they use .+ in the name/user/channel, as it can be problematic for generators - pattern = re.compile(r'[.+]') - if pattern.search(self.name): - ConanOutput().warning(f"Name containing special chars is discouraged '{self.name}'") - if self.user and pattern.search(self.user): - ConanOutput().warning(f"User containing special chars is discouraged '{self.user}'") - if self.channel and pattern.search(self.channel): - ConanOutput().warning(f"Channel containing special chars is discouraged " - f"'{self.channel}'") - - def matches(self, pattern, is_consumer): - negate = False - if pattern.startswith("!") or pattern.startswith("~"): - pattern = pattern[1:] - negate = True - - no_user_channel = False - if pattern.endswith("@"): # it means we want to match only without user/channel - pattern = pattern[:-1] - no_user_channel = True - elif "@#" in pattern: - pattern = pattern.replace("@#", "#") - no_user_channel = True - - condition = ((pattern == "&" and is_consumer) or - fnmatch.fnmatchcase(str(self), pattern) or - fnmatch.fnmatchcase(self.repr_notime(), pattern)) - if no_user_channel: - condition = condition and not self.user and not self.channel - if negate: - return not condition - return condition - - def partial_match(self, pattern): - """ - Finds if pattern matches any of partial sums of tokens of conan reference - """ - tokens = [self.name, "/", str(self.version)] - if self.user: - tokens += ["@", self.user] - if self.channel: - tokens += ["/", self.channel] - if self.revision: - tokens += ["#", self.revision] - partial = "" - for token in tokens: - partial += token - if pattern.match(partial): - return True - - -def ref_matches(ref, pattern, is_consumer): - if not ref or not str(ref): - assert is_consumer - ref = RecipeReference.loads("*/*") # FIXME: ugly - return ref.matches(pattern, is_consumer=is_consumer) + 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) diff --git a/conans/server/rest/bottle_routes.py b/conans/server/rest/bottle_routes.py index e9ba68d854d..6252b835a89 100644 --- a/conans/server/rest/bottle_routes.py +++ b/conans/server/rest/bottle_routes.py @@ -1,4 +1,4 @@ -from conans.model.rest_routes import RestRoutes +from conans.client.rest.rest_routes import RestRoutes class BottleRoutes(RestRoutes): diff --git a/conans/server/rest/controller/v2/__init__.py b/conans/server/rest/controller/v2/__init__.py index a86271aecf3..5cbcce8c8e9 100644 --- a/conans/server/rest/controller/v2/__init__.py +++ b/conans/server/rest/controller/v2/__init__.py @@ -1,5 +1,5 @@ -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference def get_package_ref(name, version, username, channel, package_id, revision, p_revision): diff --git a/conans/server/rest/controller/v2/conan.py b/conans/server/rest/controller/v2/conan.py index 29c80770ac3..6f7d616c168 100644 --- a/conans/server/rest/controller/v2/conan.py +++ b/conans/server/rest/controller/v2/conan.py @@ -1,7 +1,7 @@ from bottle import request from conan.internal.errors import NotFoundException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.server.rest.bottle_routes import BottleRoutes from conans.server.rest.controller.v2 import get_package_ref from conans.server.service.v2.service_v2 import ConanServiceV2 diff --git a/conans/server/rest/controller/v2/delete.py b/conans/server/rest/controller/v2/delete.py index 92f34bc4fcc..849e4903c4a 100644 --- a/conans/server/rest/controller/v2/delete.py +++ b/conans/server/rest/controller/v2/delete.py @@ -1,4 +1,4 @@ -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.server.rest.bottle_routes import BottleRoutes from conans.server.rest.controller.v2 import get_package_ref from conans.server.service.v2.service_v2 import ConanServiceV2 diff --git a/conans/server/rest/controller/v2/revisions.py b/conans/server/rest/controller/v2/revisions.py index 5ee1c919ba7..47b059f76f4 100644 --- a/conans/server/rest/controller/v2/revisions.py +++ b/conans/server/rest/controller/v2/revisions.py @@ -1,4 +1,4 @@ -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.server.rest.bottle_routes import BottleRoutes from conans.server.rest.controller.v2 import get_package_ref from conans.server.service.v2.service_v2 import ConanServiceV2 diff --git a/conans/server/rest/controller/v2/search.py b/conans/server/rest/controller/v2/search.py index 092694e7f41..16b63f36a4e 100644 --- a/conans/server/rest/controller/v2/search.py +++ b/conans/server/rest/controller/v2/search.py @@ -1,6 +1,6 @@ from bottle import request -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.server.rest.bottle_routes import BottleRoutes from conans.server.service.v2.search import SearchService diff --git a/conans/server/service/authorize.py b/conans/server/service/authorize.py index 67150205f25..29ae2edfda4 100644 --- a/conans/server/service/authorize.py +++ b/conans/server/service/authorize.py @@ -16,7 +16,7 @@ # ############################################ # ############ ABSTRACT CLASSES ############## # ############################################ -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference class Authorizer(object, metaclass=ABCMeta): diff --git a/conans/server/service/v2/search.py b/conans/server/service/v2/search.py index 079f1b37d51..0f03e30e47e 100644 --- a/conans/server/service/v2/search.py +++ b/conans/server/service/v2/search.py @@ -4,8 +4,8 @@ from fnmatch import translate from conan.internal.errors import ForbiddenException, RecipeNotFoundException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.internal.paths import CONANINFO from conans.server.utils.files import list_folder_subdirs from conans.util.files import load diff --git a/conans/server/service/v2/service_v2.py b/conans/server/service/v2/service_v2.py index a7c0f158b55..4d6339ac5ca 100644 --- a/conans/server/service/v2/service_v2.py +++ b/conans/server/service/v2/service_v2.py @@ -5,7 +5,7 @@ from conan.internal.errors import NotFoundException, RecipeNotFoundException, PackageNotFoundException from conan.internal.paths import CONAN_MANIFEST -from conans.model.package_ref import PkgReference +from conan.api.model import PkgReference from conans.server.service.mime import get_mime_type from conans.server.store.server_store import ServerStore from conans.util.files import mkdir diff --git a/conans/server/store/server_store.py b/conans/server/store/server_store.py index 8f3fb78432f..9a28844310b 100644 --- a/conans/server/store/server_store.py +++ b/conans/server/store/server_store.py @@ -4,8 +4,8 @@ from conan.internal.errors import RecipeNotFoundException, PackageNotFoundException from conan.errors import ConanException from conan.internal.paths import CONAN_MANIFEST -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.server.revision_list import RevisionList REVISIONS_FILE = "revisions.txt" diff --git a/test/functional/layout/test_in_cache.py b/test/functional/layout/test_in_cache.py index d539bb24a16..5296e8f2de0 100644 --- a/test/functional/layout/test_in_cache.py +++ b/test/functional/layout/test_in_cache.py @@ -3,8 +3,8 @@ import pytest -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.test_files import temp_folder from conan.test.utils.tools import TestClient, NO_SETTINGS_PACKAGE_ID diff --git a/test/functional/layout/test_layout_autopackage.py b/test/functional/layout/test_layout_autopackage.py index 0231714b6b2..43b7436e3a4 100644 --- a/test/functional/layout/test_layout_autopackage.py +++ b/test/functional/layout/test_layout_autopackage.py @@ -1,7 +1,7 @@ import os -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/functional/only_source_test.py b/test/functional/only_source_test.py index c5f9931ac68..cd6ccc811f7 100644 --- a/test/functional/only_source_test.py +++ b/test/functional/only_source_test.py @@ -1,7 +1,7 @@ import os import unittest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/functional/revisions_test.py b/test/functional/revisions_test.py index d7dd9c37047..d95702980a7 100644 --- a/test/functional/revisions_test.py +++ b/test/functional/revisions_test.py @@ -8,7 +8,7 @@ from conan.test.utils.env import environment_update from conan.internal.errors import RecipeNotFoundException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.server.revision_list import RevisionList from conan.test.utils.tools import TestServer, GenConanfile, TestClient from conans.util.files import load diff --git a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_components_names.py b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_components_names.py index 5f9a9cd2e7b..b146426e5a9 100644 --- a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_components_names.py +++ b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_components_names.py @@ -5,7 +5,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.assets.sources import gen_function_h, gen_function_cpp from conan.test.utils.tools import TestClient diff --git a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py index 044865fe34b..4ee67b740ec 100644 --- a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py +++ b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py @@ -218,36 +218,70 @@ def test_libs_transitive(self, transitive_libraries, shared): assert "Conan: Target declared imported STATIC library 'matrix::matrix'" in c.out assert "Conan: Target declared imported STATIC library 'engine::engine'" in c.out - def test_multilevel_shared(self): + # if not using cmake >= 3.23 the intermediate gamelib_test linkage fail + @pytest.mark.tool("cmake", "3.23") + @pytest.mark.parametrize("shared", [False, True]) + def test_multilevel(self, shared): # TODO: make this shared fixtures in conftest for multi-level shared testing c = TestClient(default_server_user=True) c.run("new cmake_lib -d name=matrix -d version=0.1") - c.run(f"create . -o *:shared=True -c tools.cmake.cmakedeps:new={new_value}") + c.run(f"create . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value}") c.save({}, clean_first=True) c.run("new cmake_lib -d name=engine -d version=0.1 -d requires=matrix/0.1") - c.run(f"create . -o *:shared=True -c tools.cmake.cmakedeps:new={new_value}") + c.run(f"create . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value}") c.save({}, clean_first=True) c.run("new cmake_lib -d name=gamelib -d version=0.1 -d requires=engine/0.1") - c.run(f"create . -o *:shared=True -c tools.cmake.cmakedeps:new={new_value}") + + # This specific CMake fails for shared libraries with old CMakeDeps in Linux + cmake = textwrap.dedent("""\ + cmake_minimum_required(VERSION 3.15) + project(gamelib CXX) + + find_package(engine CONFIG REQUIRED) + + add_library(gamelib src/gamelib.cpp) + target_include_directories(gamelib PUBLIC include) + target_link_libraries(gamelib PRIVATE engine::engine) + + add_executable(gamelib_test src/gamelib_test.cpp) + target_link_libraries(gamelib_test PRIVATE gamelib) + + set_target_properties(gamelib PROPERTIES PUBLIC_HEADER "include/gamelib.h") + install(TARGETS gamelib) + """) + # Testing that a local test executable links correctly with the new CMakeDeps + # It fails with the old CMakeDeps + c.save({"CMakeLists.txt": cmake, + "src/gamelib_test.cpp": '#include "gamelib.h"\nint main() { gamelib(); }'}) + c.run(f"create . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value}") c.save({}, clean_first=True) c.run("new cmake_exe -d name=game -d version=0.1 -d requires=gamelib/0.1") - c.run(f"create . -o *:shared=True -c tools.cmake.cmakedeps:new={new_value}") + c.run(f"create . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value}") assert "matrix/0.1: Hello World Release!" assert "engine/0.1: Hello World Release!" assert "gamelib/0.1: Hello World Release!" assert "game/0.1: Hello World Release!" + # Make sure that transitive headers are private, fails to include, traits work + game_cpp = c.load("src/game.cpp") + for header in ("matrix", "engine"): + new_game_cpp = f"#include <{header}.h>\n" + game_cpp + c.save({"src/game.cpp": new_game_cpp}) + c.run(f"build . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value}", + assert_error=True) + assert f"{header}.h" in c.out + # Make sure it works downloading to another cache c.run("upload * -r=default -c") c.run("remove * -c") c2 = TestClient(servers=c.servers) c2.run("new cmake_exe -d name=game -d version=0.1 -d requires=gamelib/0.1") - c2.run(f"create . -o *:shared=True -c tools.cmake.cmakedeps:new={new_value}") + c2.run(f"create . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value}") assert "matrix/0.1: Hello World Release!" assert "engine/0.1: Hello World Release!" @@ -304,7 +338,8 @@ def package_info(self): c.run(f"install app -c tools.cmake.cmakedeps:new={new_value} -g CMakeDeps") targets_cmake = c.load("app/pkg-Targets-release.cmake") assert "find_dependency(MyDep REQUIRED CONFIG)" in targets_cmake - assert "target_link_libraries(pkg::pkg INTERFACE MyTargetDep)" in targets_cmake + assert 'set_target_properties(pkg::pkg PROPERTIES INTERFACE_LINK_LIBRARIES\n' \ + ' "$<$:MyTargetDep>"' in targets_cmake class TestLibsLinkageTraits: @@ -329,6 +364,28 @@ def test_linkage_shared_static(self): assert "engine/0.1: Hello World Release!" assert "game/0.1: Hello World Release!" + @pytest.mark.parametrize("shared", [False, True]) + def test_transitive_headers(self, shared): + c = TestClient() + c.run("new cmake_lib -d name=matrix -d version=0.1") + c.run(f"create . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value} -tf=") + + c.save({}, clean_first=True) + c.run("new cmake_lib -d name=engine -d version=0.1 -d requires=matrix/0.1") + engine_h = c.load("include/engine.h") + engine_h = "#include \n" + engine_h + c.save({"include/engine.h": engine_h}) + conanfile = c.load("conanfile.py") + conanfile = conanfile.replace('self.requires("matrix/0.1")', + 'self.requires("matrix/0.1", transitive_headers=True)') + c.save({"conanfile.py": conanfile}) + c.run(f"create . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value} -tf=") + + c.save({}, clean_first=True) + c.run("new cmake_exe -d name=game -d version=0.1 -d requires=engine/0.1") + c.run(f"build . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value}") + # it works + @pytest.mark.tool("cmake") class TestLibsComponents: @@ -1246,3 +1303,55 @@ def package_info(self): c.run(f"install --requires=dep/0.1 -g CMakeDeps -c tools.cmake.cmakedeps:new={new_value}") cmake = c.load("dep-config.cmake") assert 'set(dep_PACKAGE_PROVIDED_COMPONENTS MyCompC1 MyC2 c3)' in cmake + + +class TestCppInfoChecks: + def test_check_exe_libs(self): + c = TestClient() + dep = textwrap.dedent(""" + from conan import ConanFile + class Pkg(ConanFile): + name = "dep" + version = "0.1" + def package_info(self): + self.cpp_info.libs = ["mylib"] + self.cpp_info.exe = "myexe" + """) + c.save({"conanfile.py": dep}) + c.run("create .") + args = f"-g CMakeDeps -c tools.cmake.cmakedeps:new={new_value}" + c.run(f"install --requires=dep/0.1 {args}", assert_error=True) + assert "Error in generator 'CMakeDeps': dep/0.1 " 'cpp_info has both .exe and .libs' in c.out + + def test_exe_no_location(self): + c = TestClient() + dep = textwrap.dedent(""" + from conan import ConanFile + class Pkg(ConanFile): + name = "dep" + version = "0.1" + def package_info(self): + self.cpp_info.exe = "myexe" + """) + c.save({"conanfile.py": dep}) + c.run("create .") + args = f"-g CMakeDeps -c tools.cmake.cmakedeps:new={new_value}" + c.run(f"install --requires=dep/0.1 {args}", assert_error=True) + assert "Error in generator 'CMakeDeps': dep/0.1 cpp_info has .exe and no .location" in c.out + + def test_check_exe_wrong_type(self): + c = TestClient() + dep = textwrap.dedent(""" + from conan import ConanFile + class Pkg(ConanFile): + name = "dep" + version = "0.1" + def package_info(self): + self.cpp_info.type = "shared-library" + self.cpp_info.exe = "myexe" + """) + c.save({"conanfile.py": dep}) + c.run("create .") + args = f"-g CMakeDeps -c tools.cmake.cmakedeps:new={new_value}" + c.run(f"install --requires=dep/0.1 {args}", assert_error=True) + assert "dep/0.1 cpp_info incorrect .type shared-library for .exe myexe" in c.out diff --git a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py index 8624447226e..8e73c26982c 100644 --- a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py +++ b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py @@ -42,7 +42,7 @@ def test_cmake_generated(client): c = client c.run("create dep") c.run(f"build pkg -c tools.cmake.cmakedeps:new={new_value}") - assert "Conan toolchain: Including CMakeDeps generated conan_find_paths.cmake" in c.out + assert "Conan toolchain: Including CMakeDeps generated conan_cmakedeps_paths.cmake" in c.out assert "Conan: Target declared imported INTERFACE library 'dep::dep'" in c.out @@ -71,7 +71,7 @@ def package_info(self): c.save({"dep/conanfile.py": dep}) c.run("create dep") c.run(f"build pkg -c tools.cmake.cmakedeps:new={new_value}") - assert "Conan toolchain: Including CMakeDeps generated conan_find_paths.cmake" in c.out + assert "Conan toolchain: Including CMakeDeps generated conan_cmakedeps_paths.cmake" in c.out assert "Hello from dep dep-Config.cmake!!!!!" in c.out @@ -97,6 +97,8 @@ def test_runtime_lib_dirs_multiconf(self): runtime_lib_dirs = re.search(pattern_lib_dirs, contents).group(1) assert "" in runtime_lib_dirs assert "" in runtime_lib_dirs + # too simple of a check, but this is impossible to test automatically + assert "set(CMAKE_VS_DEBUGGER_ENVIRONMENT" in contents @pytest.mark.tool("cmake") diff --git a/test/functional/toolchains/cmake/cmakedeps/test_link_order.py b/test/functional/toolchains/cmake/cmakedeps/test_link_order.py index cc7bf134173..cab212b9ce2 100644 --- a/test/functional/toolchains/cmake/cmakedeps/test_link_order.py +++ b/test/functional/toolchains/cmake/cmakedeps/test_link_order.py @@ -6,7 +6,7 @@ import pytest from jinja2 import Template -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient """ diff --git a/test/functional/toolchains/gnu/test_pkg_config.py b/test/functional/toolchains/gnu/test_pkg_config.py index 6d972f4a130..2b7cb9bfd34 100644 --- a/test/functional/toolchains/gnu/test_pkg_config.py +++ b/test/functional/toolchains/gnu/test_pkg_config.py @@ -33,7 +33,7 @@ def test_pc(self): conanfile = textwrap.dedent(""" from conan import ConanFile from conan.tools.gnu import PkgConfig - from conans.model.build_info import CppInfo + from conan.tools import CppInfo class Pkg(ConanFile): def generate(self): @@ -42,7 +42,7 @@ def generate(self): self.output.info(f"VERSION: {pkg_config.version}") self.output.info(f"VARIABLES: {pkg_config.variables['prefix']}") - cpp_info = CppInfo() + cpp_info = CppInfo(self) pkg_config.fill_cpp_info(cpp_info, is_system=False, system_libs=["m"]) assert cpp_info.includedirs == ['/usr/local/include/libastral'] diff --git a/test/functional/toolchains/meson/test_meson.py b/test/functional/toolchains/meson/test_meson.py index 8298c17b910..889ec8a3ba7 100644 --- a/test/functional/toolchains/meson/test_meson.py +++ b/test/functional/toolchains/meson/test_meson.py @@ -8,7 +8,7 @@ from conan.test.assets.sources import gen_function_cpp, gen_function_h from conan.test.utils.tools import TestClient -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from test.functional.toolchains.meson._base import TestMesonBase diff --git a/test/functional/tools/scm/test_git.py b/test/functional/tools/scm/test_git.py index 7c8df169731..d4211ec6835 100644 --- a/test/functional/tools/scm/test_git.py +++ b/test/functional/tools/scm/test_git.py @@ -26,7 +26,7 @@ class Pkg(ConanFile): version = "0.1" def export(self): - git = Git(self, self.recipe_folder, excluded=["myfile.txt", "mynew.txt"]) + git = Git(self, self.recipe_folder, excluded=["myfile.txt", "mynew.txt", "file with spaces.txt"]) commit = git.get_commit() repo_commit = git.get_commit(repository=True) url = git.get_remote_url() @@ -127,7 +127,8 @@ def test_git_excluded(self): c.run("export . -vvv") assert "pkg/0.1: DIRTY: False" in c.out c.save({"myfile.txt": "changed", - "mynew.txt": "new"}) + "mynew.txt": "new", + "file with spaces.txt": "hello"}) c.run("export .") assert "pkg/0.1: DIRTY: False" in c.out c.save({"other.txt": "new"}) diff --git a/test/integration/build_requires/test_toolchain_packages.py b/test/integration/build_requires/test_toolchain_packages.py index d46a068a43a..d6d1109f9f9 100644 --- a/test/integration/build_requires/test_toolchain_packages.py +++ b/test/integration/build_requires/test_toolchain_packages.py @@ -1,7 +1,7 @@ import json import textwrap -from conans.model.package_ref import PkgReference +from conan.api.model import PkgReference from conan.test.utils.tools import TestClient diff --git a/test/integration/cache/cache2_update_test.py b/test/integration/cache/cache2_update_test.py index d14df60a7f7..6659733aa0d 100644 --- a/test/integration/cache/cache2_update_test.py +++ b/test/integration/cache/cache2_update_test.py @@ -4,7 +4,7 @@ import pytest from mock import patch -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.server.revision_list import RevisionList from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient, TestServer, NO_SETTINGS_PACKAGE_ID diff --git a/test/integration/command/alias_test.py b/test/integration/command/alias_test.py index 8b5c7243e80..d924fef609f 100644 --- a/test/integration/command/alias_test.py +++ b/test/integration/command/alias_test.py @@ -2,7 +2,7 @@ import textwrap import unittest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient, GenConanfile diff --git a/test/integration/command/config_test.py b/test/integration/command/config_test.py index a85a51e2b84..17c552ec4bc 100644 --- a/test/integration/command/config_test.py +++ b/test/integration/command/config_test.py @@ -3,7 +3,7 @@ import textwrap from conan.api.conan_api import ConanAPI -from conans.model.conf import BUILT_IN_CONFS +from conan.internal.model.conf import BUILT_IN_CONFS from conan.test.utils.test_files import temp_folder from conan.test.utils.tools import TestClient from conan.test.utils.env import environment_update diff --git a/test/integration/command/create_test.py b/test/integration/command/create_test.py index bf0cd056e6c..e68f529466f 100644 --- a/test/integration/command/create_test.py +++ b/test/integration/command/create_test.py @@ -3,7 +3,7 @@ import re import textwrap -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient, NO_SETTINGS_PACKAGE_ID, GenConanfile from conans.util.files import load diff --git a/test/integration/command/download/download_selected_packages_test.py b/test/integration/command/download/download_selected_packages_test.py index 16b2061e06a..259133cf291 100644 --- a/test/integration/command/download/download_selected_packages_test.py +++ b/test/integration/command/download/download_selected_packages_test.py @@ -2,7 +2,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient from conans.util.files import load diff --git a/test/integration/command/download/download_test.py b/test/integration/command/download/download_test.py index e46b723f6c5..fa54af2f452 100644 --- a/test/integration/command/download/download_test.py +++ b/test/integration/command/download/download_test.py @@ -3,7 +3,7 @@ from collections import OrderedDict from unittest import mock -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient, TestServer, NO_SETTINGS_PACKAGE_ID, GenConanfile from conans.util.files import load diff --git a/test/integration/command/download/test_download_patterns.py b/test/integration/command/download/test_download_patterns.py index 2a965557dd5..905f60995a7 100644 --- a/test/integration/command/download/test_download_patterns.py +++ b/test/integration/command/download/test_download_patterns.py @@ -9,8 +9,8 @@ @pytest.mark.artifactory_ready class TestDownloadPatterns: - # FIXME The fixture is copied from TestUploadPatterns, reuse it - @pytest.fixture(scope="class") # Takes 6 seconds, reuse it + # The fixture is very similar from TestUploadPatterns, but not worth extracting + @pytest.fixture(scope="class") def client(self): """ create a few packages, with several recipe revisions, several pids, several prevs """ @@ -32,7 +32,6 @@ def client(self): @staticmethod def assert_downloaded(pattern, result, client, only_recipe=False, query=None): - # FIXME: Also common to TestUploadPatterns def ref_map(r): rev1 = "ad55a66b62acb63ffa99ea9b75c16b99" rev2 = "127fb537a658ad6a57153a038960dc53" diff --git a/test/integration/command/export/export_path_test.py b/test/integration/command/export/export_path_test.py index 9a87684f370..f02688b17bd 100644 --- a/test/integration/command/export/export_path_test.py +++ b/test/integration/command/export/export_path_test.py @@ -3,7 +3,7 @@ import pytest -from conans.model.manifest import FileTreeManifest +from conan.internal.model.manifest import FileTreeManifest from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/command/export/export_test.py b/test/integration/command/export/export_test.py index ea2485ac10f..afb9fb04ffe 100644 --- a/test/integration/command/export/export_test.py +++ b/test/integration/command/export/export_test.py @@ -8,8 +8,8 @@ import pytest from parameterized import parameterized -from conans.model.manifest import FileTreeManifest -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.manifest import FileTreeManifest +from conan.api.model import RecipeReference from conan.internal.paths import CONANFILE, CONAN_MANIFEST from conan.test.utils.tools import TestClient, GenConanfile from conans.util.files import load, save diff --git a/test/integration/command/install/install_update_test.py b/test/integration/command/install/install_update_test.py index 42bbed328b6..5a5ab4b77f6 100644 --- a/test/integration/command/install/install_update_test.py +++ b/test/integration/command/install/install_update_test.py @@ -2,7 +2,7 @@ import textwrap from time import sleep -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient, GenConanfile from conans.util.files import load diff --git a/test/integration/command/install/test_install_transitive.py b/test/integration/command/install/test_install_transitive.py index 2a7591012f6..48c3abf893c 100644 --- a/test/integration/command/install/test_install_transitive.py +++ b/test/integration/command/install/test_install_transitive.py @@ -2,8 +2,8 @@ import pytest -from conans.model.info import load_binary_info -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.info import load_binary_info +from conan.api.model import RecipeReference from conan.internal.paths import CONANFILE_TXT, CONANINFO from conan.test.utils.tools import TestClient, GenConanfile from conans.util.files import load diff --git a/test/integration/command/remove_test.py b/test/integration/command/remove_test.py index 46b86c2531d..f9f66066a0e 100644 --- a/test/integration/command/remove_test.py +++ b/test/integration/command/remove_test.py @@ -7,8 +7,8 @@ from conan.api.conan_api import ConanAPI from conan.internal.errors import NotFoundException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, TestServer, GenConanfile from conan.test.utils.env import environment_update diff --git a/test/integration/command/test_graph_build_mode.py b/test/integration/command/test_graph_build_mode.py index 20261017f6f..2dcd8c5862c 100644 --- a/test/integration/command/test_graph_build_mode.py +++ b/test/integration/command/test_graph_build_mode.py @@ -49,7 +49,6 @@ def test_install_build_single(build_all): assert "foo/1.0@user/testing: Forced build from source" in build_all.out assert "bar/1.0@user/testing: Forced build from source" not in build_all.out assert "foobar/1.0@user/testing: Forced build from source" not in build_all.out - assert "No package matching" not in build_all.out def test_install_build_double(build_all): @@ -63,15 +62,13 @@ def test_install_build_double(build_all): assert "foo/1.0@user/testing: Forced build from source" in build_all.out assert "bar/1.0@user/testing: Forced build from source" in build_all.out assert "foobar/1.0@user/testing: Forced build from source" not in build_all.out - assert "No package matching" not in build_all.out -@pytest.mark.parametrize("build_arg,mode", [ - ("--build=", "Cache"), +@pytest.mark.parametrize("build_arg,mode", [("--build=", "Cache"), ("--build=*", "Build")]) def test_install_build_only(build_arg, mode, build_all): - """ When only --build is passed, all packages must be built from sources - When only --build= is passed, it's considered an error + """ When only --build is passed wo args, that is a command arg error + When only --build= is passed, it's a no-op, same as not passing any value When only --build=* is passed, all packages must be built from sources """ build_all.run("install --requires=foobar/1.0@user/testing {}".format(build_arg)) @@ -85,12 +82,10 @@ def test_install_build_only(build_arg, mode, build_all): assert "foo/1.0@user/testing: Forced build from source" in build_all.out assert "bar/1.0@user/testing: Forced build from source" in build_all.out assert "foobar/1.0@user/testing: Forced build from source" in build_all.out - # FIXME assert "No package matching" not in build_all.out else: assert "foo/1.0@user/testing: Forced build from source" not in build_all.out assert "bar/1.0@user/testing: Forced build from source" not in build_all.out assert "foobar/1.0@user/testing: Forced build from source" not in build_all.out - # FIXME assert "No package matching" in build_all.out @pytest.mark.parametrize("build_arg,bar,foo,foobar", [("--build=", "Cache", "Build", "Cache"), diff --git a/test/integration/command/test_package_test.py b/test/integration/command/test_package_test.py index 727fa9872da..413312a99cb 100644 --- a/test/integration/command/test_package_test.py +++ b/test/integration/command/test_package_test.py @@ -3,7 +3,7 @@ import textwrap import unittest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.internal.paths import CONANFILE from conan.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, GenConanfile from conans.util.files import load diff --git a/test/integration/command/upload/syncronize_test.py b/test/integration/command/upload/syncronize_test.py deleted file mode 100644 index 27dd539e1cd..00000000000 --- a/test/integration/command/upload/syncronize_test.py +++ /dev/null @@ -1,120 +0,0 @@ -import os -import unittest - -from conan.tools.files.files import untargz # FIXME: DO not import from tools -from conans.model.manifest import FileTreeManifest -from conans.model.recipe_ref import RecipeReference -from conan.internal.paths import EXPORT_TGZ_NAME -from conan.test.assets.genconanfile import GenConanfile -from conan.test.utils.test_files import temp_folder -from conan.test.utils.tools import TestClient, TestServer -from conans.util.files import load - - -class SynchronizeTest(unittest.TestCase): - - def test_upload(self): - client = TestClient(servers={"default": TestServer()}, inputs=["admin", "password"]) - ref = RecipeReference.loads("hello/0.1@lasote/stable") - files = {"conanfile.py": GenConanfile("hello", "0.1").with_exports("*"), - "to_be_deleted.txt": "delete me", - "to_be_deleted2.txt": "delete me2"} - remote_paths = client.servers["default"].server_store - - client.save(files) - client.run("export . --user=lasote --channel=stable") - ref_with_rev = client.cache.get_latest_recipe_reference(ref) - # Upload conan file - client.run("upload %s -r default" % str(ref)) - - server_conan_path = remote_paths.export(ref_with_rev) - self.assertTrue(os.path.exists(os.path.join(server_conan_path, EXPORT_TGZ_NAME))) - tmp = temp_folder() - untargz(os.path.join(server_conan_path, EXPORT_TGZ_NAME), tmp) - self.assertTrue(load(os.path.join(tmp, "to_be_deleted.txt")), "delete me") - self.assertTrue(load(os.path.join(tmp, "to_be_deleted2.txt")), "delete me2") - - # Now delete local files export and upload and check that they are not in server - os.remove(os.path.join(client.current_folder, "to_be_deleted.txt")) - client.run("export . --user=lasote --channel=stable") - ref_with_rev = client.cache.get_latest_recipe_reference(ref) - client.run("upload %s -r default" % str(ref)) - server_conan_path = remote_paths.export(ref_with_rev) - self.assertTrue(os.path.exists(os.path.join(server_conan_path, EXPORT_TGZ_NAME))) - tmp = temp_folder() - untargz(os.path.join(server_conan_path, EXPORT_TGZ_NAME), tmp) - self.assertFalse(os.path.exists(os.path.join(tmp, "to_be_deleted.txt"))) - self.assertTrue(os.path.exists(os.path.join(tmp, "to_be_deleted2.txt"))) - - # Now modify a file, and delete other, and put a new one. - files["to_be_deleted2.txt"] = "modified content" - files["new_file.lib"] = "new file" - del files["to_be_deleted.txt"] - client.save(files) - client.run("export . --user=lasote --channel=stable") - ref_with_rev = client.cache.get_latest_recipe_reference(ref) - client.run("upload %s -r default" % str(ref)) - - server_conan_path = remote_paths.export(ref_with_rev) - - # Verify all is correct - self.assertTrue(os.path.exists(os.path.join(server_conan_path, EXPORT_TGZ_NAME))) - tmp = temp_folder() - untargz(os.path.join(server_conan_path, EXPORT_TGZ_NAME), tmp) - self.assertTrue(load(os.path.join(tmp, "to_be_deleted2.txt")), "modified content") - self.assertTrue(load(os.path.join(tmp, "new_file.lib")), "new file") - self.assertFalse(os.path.exists(os.path.join(tmp, "to_be_deleted.txt"))) - - ########################## - # Now try with the package - ########################## - - client.run("install --requires=%s --build missing" % str(ref)) - # Upload package - ref_with_rev = client.cache.get_latest_recipe_reference(ref) - pkg_ids = client.cache.get_package_references(ref_with_rev) - pref = client.cache.get_latest_package_reference(pkg_ids[0]) - client.run("upload %s:%s -r default -c" % (str(ref), str(pkg_ids[0].package_id))) - - # Check that package exists on server - package_server_path = remote_paths.package(pref) - self.assertTrue(os.path.exists(package_server_path)) - - # TODO: cache2.0 check if this makes sense in new cache - # # Add a new file to package (artificially), upload again and check - # layout = client.cache.package_layout(pref.ref) - # pack_path = layout.package(pref) - # new_file_source_path = os.path.join(pack_path, "newlib.lib") - # save(new_file_source_path, "newlib") - # shutil.rmtree(layout.download_package(pref)) # Force new tgz - # - # self._create_manifest(client, pref) - # client.run("upload %s -p %s" % (str(ref), str(package_ids[0]))) - # - # folder = uncompress_packaged_files(remote_paths, pref) - # remote_file_path = os.path.join(folder, "newlib.lib") - # self.assertTrue(os.path.exists(remote_file_path)) - # - # # Now modify the file and check again - # save(new_file_source_path, "othercontent") - # self._create_manifest(client, pref) - # client.run("upload %s -p %s" % (str(ref), str(package_ids[0]))) - # folder = uncompress_packaged_files(remote_paths, pref) - # remote_file_path = os.path.join(folder, "newlib.lib") - # self.assertTrue(os.path.exists(remote_file_path)) - # self.assertTrue(load(remote_file_path), "othercontent") - # - # # Now delete the file and check again - # os.remove(new_file_source_path) - # self._create_manifest(client, pref) - # shutil.rmtree(layout.download_package(pref)) # Force new tgz - # client.run("upload %s -p %s" % (str(ref), str(package_ids[0]))) - # folder = uncompress_packaged_files(remote_paths, pref) - # remote_file_path = os.path.join(folder, "newlib.lib") - - @staticmethod - def _create_manifest(client, pref): - # Create the manifest to be able to upload the package - pack_path = client.get_latest_pkg_layout(pref).package() - expected_manifest = FileTreeManifest.create(pack_path) - expected_manifest.save(pack_path) diff --git a/test/integration/command/upload/upload_compression_test.py b/test/integration/command/upload/upload_compression_test.py index 3eb271638e6..3d0768d97ce 100644 --- a/test/integration/command/upload/upload_compression_test.py +++ b/test/integration/command/upload/upload_compression_test.py @@ -1,6 +1,6 @@ import os -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.test_files import uncompress_packaged_files from conan.test.utils.tools import TestClient diff --git a/test/integration/command/upload/upload_test.py b/test/integration/command/upload/upload_test.py index ab57218c241..8b4cef28157 100644 --- a/test/integration/command/upload/upload_test.py +++ b/test/integration/command/upload/upload_test.py @@ -12,8 +12,8 @@ from requests import Response from conan.errors import ConanException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.internal.paths import EXPORT_SOURCES_TGZ_NAME, PACKAGE_TGZ_NAME from conan.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, TestServer, \ GenConanfile, TestRequester, TestingResponse diff --git a/test/integration/command_v2/search_test.py b/test/integration/command_v2/search_test.py index 7262f6d814c..72463aef096 100644 --- a/test/integration/command_v2/search_test.py +++ b/test/integration/command_v2/search_test.py @@ -6,12 +6,11 @@ from conan.internal.errors import ConanConnectionError from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient, TestServer -# FIXME: we could remove this whenever @conan_alias_command will be implemented class TestSearch: @pytest.fixture diff --git a/test/integration/conan_api/list_test.py b/test/integration/conan_api/list_test.py index ee7ca6a53a2..12ce4499f29 100644 --- a/test/integration/conan_api/list_test.py +++ b/test/integration/conan_api/list_test.py @@ -1,7 +1,7 @@ from conan.api.conan_api import ConanAPI from conan.test.utils.env import environment_update -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/conan_api/search_test.py b/test/integration/conan_api/search_test.py index 1aaa07f0a20..4a57e568df7 100644 --- a/test/integration/conan_api/search_test.py +++ b/test/integration/conan_api/search_test.py @@ -1,8 +1,7 @@ import pytest from conan.api.conan_api import ConanAPI -from conan.api.model import Remote -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/conan_api/test_local_api.py b/test/integration/conan_api/test_local_api.py index df681ce29a0..8f3eafcab01 100644 --- a/test/integration/conan_api/test_local_api.py +++ b/test/integration/conan_api/test_local_api.py @@ -3,7 +3,7 @@ from conan.api.conan_api import ConanAPI from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.test_files import temp_folder -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.util.files import save diff --git a/test/integration/conan_v2/test_legacy_cpp_info.py b/test/integration/conan_v2/test_legacy_cpp_info.py index e25c3904658..3f204392983 100644 --- a/test/integration/conan_v2/test_legacy_cpp_info.py +++ b/test/integration/conan_v2/test_legacy_cpp_info.py @@ -1,6 +1,6 @@ import textwrap -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient from conans.util.files import load, save diff --git a/test/integration/conanfile/conan_data_test.py b/test/integration/conanfile/conan_data_test.py index 64aa2a86f9a..69f04b557b0 100644 --- a/test/integration/conanfile/conan_data_test.py +++ b/test/integration/conanfile/conan_data_test.py @@ -7,7 +7,7 @@ import pytest import yaml -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.file_server import TestFileServer from conan.test.utils.test_files import tgz_with_contents from conan.test.utils.tools import TestClient, GenConanfile diff --git a/test/integration/configuration/conf/test_conf_copy.py b/test/integration/configuration/conf/test_conf_copy.py index 79ffc70d9b9..46597afd816 100644 --- a/test/integration/configuration/conf/test_conf_copy.py +++ b/test/integration/configuration/conf/test_conf_copy.py @@ -1,4 +1,4 @@ -from conans.model.conf import Conf +from conan.internal.model.conf import Conf def test_copy_conaninfo_conf(): diff --git a/test/integration/configuration/profile_test.py b/test/integration/configuration/profile_test.py index 9709bd682b1..b8a6f339687 100644 --- a/test/integration/configuration/profile_test.py +++ b/test/integration/configuration/profile_test.py @@ -272,7 +272,7 @@ def test_info_with_profiles(self): self.client.run("remove '*' -c") # Create a simple recipe to require winreq_conanfile = ''' -from conans.model.conan_file import ConanFile +from conan import ConanFile class winrequireDefaultNameConan(ConanFile): name = "winrequire" @@ -286,7 +286,7 @@ class winrequireDefaultNameConan(ConanFile): self.client.run("export . --user=lasote --channel=stable") # Now require the first recipe depending on OS=windows - conanfile = '''from conans.model.conan_file import ConanFile + conanfile = '''from conan import ConanFile import os class DefaultNameConan(ConanFile): @@ -339,7 +339,7 @@ class ProfileAggregationTest(unittest.TestCase): """) conanfile = dedent(""" - from conans.model.conan_file import ConanFile + from conan import ConanFile import os class DefaultNameConan(ConanFile): @@ -352,7 +352,7 @@ def build(self): """) consumer = dedent(""" - from conans.model.conan_file import ConanFile + from conan import ConanFile import os class DefaultNameConan(ConanFile): diff --git a/test/integration/configuration/requester_test.py b/test/integration/configuration/requester_test.py index 5acb473602f..ee0e9ba6592 100644 --- a/test/integration/configuration/requester_test.py +++ b/test/integration/configuration/requester_test.py @@ -6,7 +6,7 @@ from conan import __version__ from conans.client.rest.conan_requester import ConanRequester -from conans.model.conf import ConfDefinition +from conan.internal.model.conf import ConfDefinition from conan.test.utils.tools import temp_folder from conans.util.files import save diff --git a/test/integration/export_sources_test.py b/test/integration/export_sources_test.py index a18defe3303..9d4a94056c2 100644 --- a/test/integration/export_sources_test.py +++ b/test/integration/export_sources_test.py @@ -1,7 +1,7 @@ import os import textwrap -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/graph/core/graph_manager_base.py b/test/integration/graph/core/graph_manager_base.py index 7303cb6bc69..97d85b96f49 100644 --- a/test/integration/graph/core/graph_manager_base.py +++ b/test/integration/graph/core/graph_manager_base.py @@ -8,12 +8,12 @@ from conan.internal.cache.cache import PkgCache from conan.internal.cache.home_paths import HomePaths from conan.internal.default_settings import default_settings_yml -from conans.model.conf import ConfDefinition -from conans.model.manifest import FileTreeManifest -from conans.model.options import Options -from conans.model.profile import Profile -from conans.model.recipe_ref import RecipeReference -from conans.model.settings import Settings +from conan.internal.model.conf import ConfDefinition +from conan.internal.model.manifest import FileTreeManifest +from conan.internal.model.options import Options +from conan.internal.model.profile import Profile +from conan.api.model import RecipeReference +from conan.internal.model.settings import Settings from conan.test.utils.test_files import temp_folder from conan.test.utils.tools import GenConanfile from conans.util.dates import revision_timestamp_now @@ -41,25 +41,16 @@ def recipe_cache(self, reference, requires=None, option_shared=None): conanfile.with_option("shared", [True, False]) conanfile.with_default_option("shared", option_shared) - self._put_in_cache(ref, conanfile) + self._cache_recipe(ref, conanfile) def recipe_conanfile(self, reference, conanfile): ref = RecipeReference.loads(reference) - self._put_in_cache(ref, conanfile) + self._cache_recipe(ref, conanfile) - def _put_in_cache(self, ref, conanfile): - ref = RecipeReference.loads("{}#123".format(ref)) - ref.timestamp = revision_timestamp_now() - layout = self.cache.create_ref_layout(ref) - save(layout.conanfile(), str(conanfile)) - manifest = FileTreeManifest.create(layout.export()) - manifest.save(layout.export()) - - def _cache_recipe(self, ref, test_conanfile, revision=None): - # FIXME: This seems duplicated + def _cache_recipe(self, ref, test_conanfile): if not isinstance(ref, RecipeReference): ref = RecipeReference.loads(ref) - ref = RecipeReference.loads(repr(ref) + "#{}".format(revision or 123)) # FIXME: Make access + ref.revision = "123" ref.timestamp = revision_timestamp_now() recipe_layout = self.cache.create_ref_layout(ref) save(recipe_layout.conanfile(), str(test_conanfile)) @@ -73,7 +64,7 @@ def alias_cache(self, alias, target): class Alias(ConanFile): alias = "%s" """ % target) - self._put_in_cache(ref, conanfile) + self._cache_recipe(ref, conanfile) @staticmethod def recipe_consumer(reference=None, requires=None, build_requires=None, tool_requires=None): @@ -102,16 +93,14 @@ def consumer_conanfile(conanfile): save(path, str(conanfile)) return path - def build_graph(self, content, profile_build_requires=None, ref=None, create_ref=None, - install=True, options_build=None): + def build_graph(self, content, profile_build_requires=None, install=True, options_build=None): path = temp_folder() path = os.path.join(path, "conanfile.py") save(path, str(content)) - return self.build_consumer(path, profile_build_requires, ref, create_ref, install, + return self.build_consumer(path, profile_build_requires, install, options_build=options_build) - def build_consumer(self, path, profile_build_requires=None, ref=None, create_ref=None, - install=True, options_build=None): + def build_consumer(self, path, profile_build_requires=None, install=True, options_build=None): profile_host = Profile() profile_host.settings["os"] = "Linux" profile_build = Profile() diff --git a/test/integration/graph/core/test_build_requires.py b/test/integration/graph/core/test_build_requires.py index a3945956a9f..4e7e3b40037 100644 --- a/test/integration/graph/core/test_build_requires.py +++ b/test/integration/graph/core/test_build_requires.py @@ -5,7 +5,7 @@ from parameterized import parameterized from conans.client.graph.graph_error import GraphConflictError, GraphLoopError, GraphRuntimeError -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from test.integration.graph.core.graph_manager_base import GraphManagerTest from conan.test.utils.tools import GenConanfile, NO_SETTINGS_PACKAGE_ID, TestClient diff --git a/test/integration/graph/test_dependencies_visit.py b/test/integration/graph/test_dependencies_visit.py index 718e1f06bf1..63d3b4191d2 100644 --- a/test/integration/graph/test_dependencies_visit.py +++ b/test/integration/graph/test_dependencies_visit.py @@ -2,7 +2,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/graph/test_replace_requires.py b/test/integration/graph/test_replace_requires.py index 707524c7196..b7b55957c42 100644 --- a/test/integration/graph/test_replace_requires.py +++ b/test/integration/graph/test_replace_requires.py @@ -3,7 +3,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient @@ -513,7 +513,8 @@ class App(ConanFile): cmake = c.load("app/openssl-Targets-release.cmake") assert "find_dependency(ZLIB REQUIRED CONFIG)" in cmake assert "add_library(openssl::crypto STATIC IMPORTED)" in cmake - assert "target_link_libraries(openssl::crypto INTERFACE ZLIB::ZLIB)" in cmake + assert "set_target_properties(openssl::crypto PROPERTIES INTERFACE_LINK_LIBRARIES\n" \ + ' "$<$:ZLIB::ZLIB>")' in cmake @pytest.mark.parametrize("diamond", [True, False]) @pytest.mark.parametrize("explicit_requires", [True, False]) @@ -582,7 +583,8 @@ class App(ConanFile): assert "find_dependency(ZLIB REQUIRED CONFIG)" in cmake assert "add_library(openssl::openssl STATIC IMPORTED)" in cmake # It should access the generic zlib-ng target - assert "target_link_libraries(openssl::openssl INTERFACE zlib-ng::zlib-ng)" in cmake + assert "set_target_properties(openssl::openssl PROPERTIES INTERFACE_LINK_LIBRARIES\n" \ + ' "$<$:zlib-ng::zlib-ng>")' in cmake @pytest.mark.parametrize("diamond", [True, False]) @pytest.mark.parametrize("package_requires", [False, True]) @@ -653,6 +655,9 @@ class App(ConanFile): assert "find_dependency(ZLIB REQUIRED CONFIG)" in cmake assert "add_library(openssl::crypto STATIC IMPORTED)" in cmake if package_requires: - assert "target_link_libraries(openssl::crypto INTERFACE zlib-ng::zlib-ng)" in cmake + # The generic package requirement uses the package name zlib-ng + assert "set_target_properties(openssl::crypto PROPERTIES INTERFACE_LINK_LIBRARIES\n" \ + ' "$<$:zlib-ng::zlib-ng>")' in cmake else: - assert "target_link_libraries(openssl::crypto INTERFACE ZLIB::ZLIB)" in cmake + assert "set_target_properties(openssl::crypto PROPERTIES INTERFACE_LINK_LIBRARIES\n" \ + ' "$<$:ZLIB::ZLIB>")' in cmake diff --git a/test/integration/graph/version_ranges/version_ranges_cached_test.py b/test/integration/graph/version_ranges/version_ranges_cached_test.py index 8466c0cfd0f..8000b4a057b 100644 --- a/test/integration/graph/version_ranges/version_ranges_cached_test.py +++ b/test/integration/graph/version_ranges/version_ranges_cached_test.py @@ -4,7 +4,7 @@ from mock import patch from conans.client.remote_manager import RemoteManager -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient, TestServer diff --git a/test/integration/hooks/test_post_export.py b/test/integration/hooks/test_post_export.py index 260ab1cb7cc..f9a22e26bc1 100644 --- a/test/integration/hooks/test_post_export.py +++ b/test/integration/hooks/test_post_export.py @@ -1,7 +1,7 @@ import os import textwrap -from conans.model.manifest import FileTreeManifest +from conan.internal.model.manifest import FileTreeManifest from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient from conans.util.files import save diff --git a/test/integration/hooks/test_post_package.py b/test/integration/hooks/test_post_package.py index fef17b7c40b..de6b1cf4339 100644 --- a/test/integration/hooks/test_post_package.py +++ b/test/integration/hooks/test_post_package.py @@ -1,7 +1,7 @@ import os import textwrap -from conans.model.manifest import FileTreeManifest +from conan.internal.model.manifest import FileTreeManifest from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient from conans.util.files import save diff --git a/test/integration/lockfile/test_ci.py b/test/integration/lockfile/test_ci.py index 542dbd47e3d..d421e19c45d 100644 --- a/test/integration/lockfile/test_ci.py +++ b/test/integration/lockfile/test_ci.py @@ -3,7 +3,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/lockfile/test_ci_overrides.py b/test/integration/lockfile/test_ci_overrides.py index a6f2221f6b8..1860c313f6b 100644 --- a/test/integration/lockfile/test_ci_overrides.py +++ b/test/integration/lockfile/test_ci_overrides.py @@ -2,7 +2,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/lockfile/test_ci_revisions.py b/test/integration/lockfile/test_ci_revisions.py index 12952fc0d52..7cb8a9be7d6 100644 --- a/test/integration/lockfile/test_ci_revisions.py +++ b/test/integration/lockfile/test_ci_revisions.py @@ -3,7 +3,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient conanfile = textwrap.dedent(""" diff --git a/test/integration/lockfile/test_lock_requires.py b/test/integration/lockfile/test_lock_requires.py index 167f291f848..200dbb534f3 100644 --- a/test/integration/lockfile/test_lock_requires.py +++ b/test/integration/lockfile/test_lock_requires.py @@ -5,7 +5,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/metadata/test_metadata_logs.py b/test/integration/metadata/test_metadata_logs.py index a3911b70346..a2d02d0be16 100644 --- a/test/integration/metadata/test_metadata_logs.py +++ b/test/integration/metadata/test_metadata_logs.py @@ -3,7 +3,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient from conans.util.files import load, save diff --git a/test/integration/options/options_in_requirements_test.py b/test/integration/options/options_in_requirements_test.py index c0d52a35311..e9d611b8a27 100644 --- a/test/integration/options/options_in_requirements_test.py +++ b/test/integration/options/options_in_requirements_test.py @@ -1,7 +1,7 @@ import os import unittest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient diff --git a/test/integration/package_id/full_revision_mode_test.py b/test/integration/package_id/full_revision_mode_test.py index d6789d3badd..3c3e92afc55 100644 --- a/test/integration/package_id/full_revision_mode_test.py +++ b/test/integration/package_id/full_revision_mode_test.py @@ -2,7 +2,7 @@ from textwrap import dedent -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient, GenConanfile from conans.util.files import save diff --git a/test/integration/py_requires/python_requires_test.py b/test/integration/py_requires/python_requires_test.py index ac032298a42..48d90f9810d 100644 --- a/test/integration/py_requires/python_requires_test.py +++ b/test/integration/py_requires/python_requires_test.py @@ -3,7 +3,7 @@ import time import unittest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient, GenConanfile diff --git a/test/integration/remote/auth_test.py b/test/integration/remote/auth_test.py index 90c4c83b733..d4720917784 100644 --- a/test/integration/remote/auth_test.py +++ b/test/integration/remote/auth_test.py @@ -8,7 +8,7 @@ from conan.internal.api.remotes.localdb import LocalDB from conan.internal.errors import AuthenticationException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.internal.paths import CONANFILE from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.test_files import temp_folder diff --git a/test/integration/remote/multi_remote_test.py b/test/integration/remote/multi_remote_test.py index 3ab4d074d56..c50e7111150 100644 --- a/test/integration/remote/multi_remote_test.py +++ b/test/integration/remote/multi_remote_test.py @@ -2,7 +2,7 @@ from collections import OrderedDict from time import sleep -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.internal.paths import CONANFILE from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient, TestServer diff --git a/test/integration/remote/rest_api_test.py b/test/integration/remote/rest_api_test.py index 56855079674..9c5d704c7d0 100644 --- a/test/integration/remote/rest_api_test.py +++ b/test/integration/remote/rest_api_test.py @@ -1,24 +1,19 @@ import os import unittest -from mock import Mock - -from conans.client.remote_manager import Remote -from conans.client.rest.auth_manager import ConanApiAuthManager -from conans.client.rest.conan_requester import ConanRequester -from conans.client.rest.rest_client import RestApiClient -from conans.model.conf import ConfDefinition -from conan.test.utils.env import environment_update -from conan.api.input import UserInput -from conans.model.manifest import FileTreeManifest -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import Remote +from conan.internal.model.conf import ConfDefinition +from conan.internal.model.manifest import FileTreeManifest +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.internal.paths import CONANFILE, CONANINFO, CONAN_MANIFEST from conan.test.assets.genconanfile import GenConanfile -from conan.test.utils.mocks import LocalDBMock +from conan.test.utils.env import environment_update from conan.test.utils.server_launcher import TestServerLauncher from conan.test.utils.test_files import temp_folder from conan.test.utils.tools import get_free_port +from conans.client.rest.conan_requester import ConanRequester +from conans.client.rest.rest_client import RestApiClient from conans.util.files import md5, save @@ -39,25 +34,12 @@ def setUpClass(cls): write_permissions=write_perms) cls.server.start() - filename = os.path.join(temp_folder(), "conan.conf") - save(filename, "") config = ConfDefinition() requester = ConanRequester(config) - localdb = LocalDBMock() - - mocked_user_input = UserInput(non_interactive=False) - mocked_user_input.get_username = Mock(return_value="private_user") - mocked_user_input.get_password = Mock(return_value="private_pass") - - # FIXME: Missing mock - cls.auth_manager = ConanApiAuthManager(requester, temp_folder(), localdb, config) - cls.remote = Remote("myremote", "http://127.0.0.1:%s" % str(cls.server.port), True, - True) - cls.api = RestApiClient(cls.remote, localdb.access_token, requester, config) - cls.auth_manager._authenticate(cls.api, cls.remote, user="private_user", - password="private_pass") - # Need to define again with new token - cls.api = RestApiClient(cls.remote, localdb.access_token, requester, config) + + remote = Remote("myremote", f"http://127.0.0.1:{cls.server.port}", True, True) + cls.api = RestApiClient(remote, None, requester, config) + cls.api._token = cls.api.authenticate(user="private_user", password="private_pass") @classmethod def tearDownClass(cls): diff --git a/test/integration/settings/settings_override_test.py b/test/integration/settings/settings_override_test.py index e1959a2bf84..a26d952f3cd 100644 --- a/test/integration/settings/settings_override_test.py +++ b/test/integration/settings/settings_override_test.py @@ -2,7 +2,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.internal.paths import CONANINFO from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.tools import TestClient diff --git a/test/integration/symlinks/symlinks_test.py b/test/integration/symlinks/symlinks_test.py index 48cbe16ff4f..3e08556217c 100644 --- a/test/integration/symlinks/symlinks_test.py +++ b/test/integration/symlinks/symlinks_test.py @@ -4,8 +4,8 @@ import pytest -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.internal.paths import PACKAGE_TGZ_NAME from conan.test.assets.genconanfile import GenConanfile from conan.test.utils.test_files import temp_folder diff --git a/test/integration/test_migrations.py b/test/integration/test_migrations.py index f8454443150..233b0972975 100644 --- a/test/integration/test_migrations.py +++ b/test/integration/test_migrations.py @@ -10,7 +10,7 @@ from conan.test.utils.test_files import temp_folder from conan.test.utils.tools import TestClient from conans.client.migrations import ClientMigrator -from conans.model.version import Version +from conan.internal.model.version import Version from conans.util.files import save, load diff --git a/test/integration/test_package_python_files.py b/test/integration/test_package_python_files.py index 2c2032143f6..6eb8bfece28 100644 --- a/test/integration/test_package_python_files.py +++ b/test/integration/test_package_python_files.py @@ -1,7 +1,7 @@ import os import textwrap -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conans.util.files import load from conan.test.utils.tools import TestClient, NO_SETTINGS_PACKAGE_ID diff --git a/test/integration/tgz_macos_dot_files_test.py b/test/integration/tgz_macos_dot_files_test.py index 8da10dae7d7..ebf62b59fd5 100644 --- a/test/integration/tgz_macos_dot_files_test.py +++ b/test/integration/tgz_macos_dot_files_test.py @@ -9,7 +9,7 @@ import pytest from conans.client.remote_manager import uncompress_file -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.internal.paths import EXPORT_SOURCES_TGZ_NAME from conan.test.utils.tools import TestClient, NO_SETTINGS_PACKAGE_ID diff --git a/test/integration/toolchains/gnu/test_pkgconfigdeps.py b/test/integration/toolchains/gnu/test_pkgconfigdeps.py index 7284a382f85..7af64850c50 100644 --- a/test/integration/toolchains/gnu/test_pkgconfigdeps.py +++ b/test/integration/toolchains/gnu/test_pkgconfigdeps.py @@ -496,8 +496,6 @@ def package_info(self): pc_content = client.load("compo1_alias.pc") content = textwrap.dedent(f"""\ - {prefix} - Name: compo1_alias Description: Alias compo1_alias for compo1 Version: 0.3 @@ -525,8 +523,6 @@ def package_info(self): pc_content = client.load("pkg_alias1.pc") content = textwrap.dedent(f"""\ - {prefix} - Name: pkg_alias1 Description: Alias pkg_alias1 for pkg_other_name Version: 0.3 @@ -536,8 +532,6 @@ def package_info(self): pc_content = client.load("pkg_alias2.pc") content = textwrap.dedent(f"""\ - {prefix} - Name: pkg_alias2 Description: Alias pkg_alias2 for pkg_other_name Version: 0.3 diff --git a/test/integration/tools/fix_symlinks_test.py b/test/integration/tools/fix_symlinks_test.py index e3e7fef4f23..26a91ddf797 100644 --- a/test/integration/tools/fix_symlinks_test.py +++ b/test/integration/tools/fix_symlinks_test.py @@ -5,7 +5,7 @@ import pytest -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.tools import TestClient diff --git a/test/integration/tools/system/package_manager_test.py b/test/integration/tools/system/package_manager_test.py index 25bcb90f0fb..1309469b987 100644 --- a/test/integration/tools/system/package_manager_test.py +++ b/test/integration/tools/system/package_manager_test.py @@ -8,7 +8,7 @@ from conan.tools.system.package_manager import Apt, Apk, Dnf, Yum, Brew, Pkg, PkgUtil, Chocolatey, \ Zypper, PacMan, _SystemPackageManagerTool from conan.errors import ConanException -from conans.model.settings import Settings +from conan.internal.model.settings import Settings from conan.test.utils.mocks import ConanFileMock, MockSettings diff --git a/test/unittests/client/build/cpp_std_flags_test.py b/test/unittests/client/build/cpp_std_flags_test.py index 282b7decde2..dcf1e1fa3fe 100644 --- a/test/unittests/client/build/cpp_std_flags_test.py +++ b/test/unittests/client/build/cpp_std_flags_test.py @@ -2,7 +2,7 @@ from conan.internal.api.detect.detect_api import default_cppstd from conan.tools.build import cppstd_flag -from conans.model.version import Version +from conan.internal.model.version import Version from conan.test.utils.mocks import MockSettings, ConanFileMock diff --git a/test/unittests/client/file_copier/test_report_copied_files.py b/test/unittests/client/file_copier/test_report_copied_files.py index ffc1ce82f75..c51ca00e06b 100644 --- a/test/unittests/client/file_copier/test_report_copied_files.py +++ b/test/unittests/client/file_copier/test_report_copied_files.py @@ -1,7 +1,7 @@ import unittest from conan.api.output import ConanOutput -from conans.model.manifest import FileTreeManifest +from conan.internal.model.manifest import FileTreeManifest from conan.test.utils.mocks import RedirectedTestOutput from conan.test.utils.tools import redirect_output diff --git a/test/unittests/client/graph/build_mode_test.py b/test/unittests/client/graph/build_mode_test.py index 653dd053a51..65418d984b7 100644 --- a/test/unittests/client/graph/build_mode_test.py +++ b/test/unittests/client/graph/build_mode_test.py @@ -2,7 +2,7 @@ from conans.client.graph.build_mode import BuildMode from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.mocks import ConanFileMock, RedirectedTestOutput from conan.test.utils.tools import redirect_output diff --git a/test/unittests/client/graph/deps_graph_test.py b/test/unittests/client/graph/deps_graph_test.py index b09df4b2752..384bcf8989b 100644 --- a/test/unittests/client/graph/deps_graph_test.py +++ b/test/unittests/client/graph/deps_graph_test.py @@ -4,8 +4,8 @@ from conans.client.graph.graph import CONTEXT_HOST from conans.client.graph.graph_builder import DepsGraph, Node -from conans.model.conan_file import ConanFile -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.conan_file import ConanFile +from conan.api.model import RecipeReference class DepsGraphTest(unittest.TestCase): diff --git a/test/unittests/client/profile_loader/compiler_cppstd_test.py b/test/unittests/client/profile_loader/compiler_cppstd_test.py index f2468f7a054..c62c9bb0c12 100644 --- a/test/unittests/client/profile_loader/compiler_cppstd_test.py +++ b/test/unittests/client/profile_loader/compiler_cppstd_test.py @@ -10,8 +10,8 @@ from conan.internal.api.profile.profile_loader import ProfileLoader from conan.internal.default_settings import default_settings_yml from conan.errors import ConanException -from conans.model.conf import ConfDefinition -from conans.model.settings import Settings +from conan.internal.model.conf import ConfDefinition +from conan.internal.model.settings import Settings from conan.test.utils.test_files import temp_folder from conans.util.files import save diff --git a/test/unittests/client/profile_loader/profile_loader_test.py b/test/unittests/client/profile_loader/profile_loader_test.py index 9e20d9c5e9b..f36a1545768 100644 --- a/test/unittests/client/profile_loader/profile_loader_test.py +++ b/test/unittests/client/profile_loader/profile_loader_test.py @@ -5,7 +5,7 @@ from conan.internal.api.profile.profile_loader import _ProfileParser, ProfileLoader from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.mocks import ConanFileMock, MockSettings from conan.test.utils.test_files import temp_folder from conans.util.files import save diff --git a/test/unittests/client/toolchain/autotools/autotools_test.py b/test/unittests/client/toolchain/autotools/autotools_test.py index 42a51d1966c..58388c4c959 100644 --- a/test/unittests/client/toolchain/autotools/autotools_test.py +++ b/test/unittests/client/toolchain/autotools/autotools_test.py @@ -3,7 +3,7 @@ from conan.tools.build import save_toolchain_args from conan.tools.gnu import Autotools from conan import ConanFile -from conans.model.conf import Conf +from conan.internal.model.conf import Conf from test.unittests.util.tools_test import RunnerMock from conan.test.utils.mocks import MockSettings from conan.test.utils.test_files import temp_folder diff --git a/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py b/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py index ae7c2a6e4a1..0879043d03c 100644 --- a/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py +++ b/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py @@ -10,7 +10,7 @@ from conan.tools.build import load_toolchain_args from conan.tools.files import save from conan.tools.gnu import AutotoolsToolchain -from conans.model.conf import Conf +from conan.internal.model.conf import Conf def test_modify_environment(): diff --git a/test/unittests/client/tools/apple/test_xcodebuild.py b/test/unittests/client/tools/apple/test_xcodebuild.py index b2c191c0d67..32cf2575bfa 100644 --- a/test/unittests/client/tools/apple/test_xcodebuild.py +++ b/test/unittests/client/tools/apple/test_xcodebuild.py @@ -1,7 +1,7 @@ import pytest from conan.tools.apple import XcodeBuild -from conans.model.conf import ConfDefinition +from conan.internal.model.conf import ConfDefinition from conan.test.utils.mocks import ConanFileMock, MockSettings diff --git a/test/unittests/model/build_info/components_test.py b/test/unittests/model/build_info/components_test.py index a1656333a7c..ff4c2259b62 100644 --- a/test/unittests/model/build_info/components_test.py +++ b/test/unittests/model/build_info/components_test.py @@ -1,6 +1,6 @@ import unittest -from conans.model.build_info import CppInfo +from conan.internal.model.cpp_info import CppInfo class CppInfoComponentsTest(unittest.TestCase): diff --git a/test/unittests/model/build_info/generic_properties_test.py b/test/unittests/model/build_info/generic_properties_test.py index 689be06af42..c99daf6053e 100644 --- a/test/unittests/model/build_info/generic_properties_test.py +++ b/test/unittests/model/build_info/generic_properties_test.py @@ -1,4 +1,4 @@ -from conans.model.build_info import CppInfo +from conan.internal.model.cpp_info import CppInfo def test_set_get_properties(): diff --git a/test/unittests/model/build_info/new_build_info_test.py b/test/unittests/model/build_info/new_build_info_test.py index 4bfcdee1da0..c554de8d048 100644 --- a/test/unittests/model/build_info/new_build_info_test.py +++ b/test/unittests/model/build_info/new_build_info_test.py @@ -1,6 +1,6 @@ import pytest -from conans.model.build_info import CppInfo, _DIRS_VAR_NAMES, _FIELD_VAR_NAMES +from conan.internal.model.cpp_info import CppInfo, _DIRS_VAR_NAMES, _FIELD_VAR_NAMES def test_components_order(): diff --git a/test/unittests/model/build_info/test_deduce_locations.py b/test/unittests/model/build_info/test_deduce_locations.py index 5a3d0a8830b..3c4e99ad994 100644 --- a/test/unittests/model/build_info/test_deduce_locations.py +++ b/test/unittests/model/build_info/test_deduce_locations.py @@ -4,13 +4,12 @@ import pytest -from conan.errors import ConanException from conan.test.utils.mocks import ConanFileMock from conan.test.utils.test_files import temp_folder from conan.tools.files import save -from conans.model.build_info import CppInfo -from conans.model.pkg_type import PackageType -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.cpp_info import CppInfo +from conan.internal.model.pkg_type import PackageType +from conan.api.model import RecipeReference from conans.util.files import save diff --git a/test/unittests/model/conanfile_test.py b/test/unittests/model/conanfile_test.py index b8adb93b314..03c9cabc761 100644 --- a/test/unittests/model/conanfile_test.py +++ b/test/unittests/model/conanfile_test.py @@ -1,7 +1,7 @@ import textwrap import unittest -from conans.model.conan_file import ConanFile +from conan.internal.model.conan_file import ConanFile from conan.test.utils.tools import TestClient diff --git a/test/unittests/model/info_test.py b/test/unittests/model/info_test.py index ba14cf468d3..16c8216e90a 100644 --- a/test/unittests/model/info_test.py +++ b/test/unittests/model/info_test.py @@ -1,6 +1,6 @@ -from conans.model.info import ConanInfo, RequirementsInfo, PythonRequiresInfo -from conans.model.options import Options -from conans.model.settings import Settings +from conan.internal.model.info import ConanInfo, RequirementsInfo, PythonRequiresInfo +from conan.internal.model.options import Options +from conan.internal.model.settings import Settings def test_false_values_affect_none(): diff --git a/test/unittests/model/manifest_test.py b/test/unittests/model/manifest_test.py index 830b372819a..3d2e222957b 100644 --- a/test/unittests/model/manifest_test.py +++ b/test/unittests/model/manifest_test.py @@ -3,7 +3,7 @@ import pytest -from conans.model.manifest import FileTreeManifest +from conan.internal.model.manifest import FileTreeManifest from conan.test.utils.test_files import temp_folder from conans.util.files import load, md5, save diff --git a/test/unittests/model/options_test.py b/test/unittests/model/options_test.py index 24ddc72dac2..f8cf27e069c 100644 --- a/test/unittests/model/options_test.py +++ b/test/unittests/model/options_test.py @@ -3,8 +3,8 @@ import pytest from conan.errors import ConanException -from conans.model.options import Options -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.options import Options +from conan.api.model import RecipeReference class TestOptions: diff --git a/test/unittests/model/other_settings_test.py b/test/unittests/model/other_settings_test.py index 4abbb1b0e99..71a3d2fbe2d 100644 --- a/test/unittests/model/other_settings_test.py +++ b/test/unittests/model/other_settings_test.py @@ -2,8 +2,8 @@ import textwrap import unittest -from conans.model.info import load_binary_info -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.info import load_binary_info +from conan.api.model import RecipeReference from conan.internal.paths import CONANFILE from conan.test.utils.tools import TestClient from conans.util.files import load, save diff --git a/test/unittests/model/profile_test.py b/test/unittests/model/profile_test.py index 88cea61274a..d67f982297c 100644 --- a/test/unittests/model/profile_test.py +++ b/test/unittests/model/profile_test.py @@ -2,7 +2,7 @@ from collections import OrderedDict from conan.tools.env.environment import ProfileEnvironment -from conans.model.profile import Profile +from conan.internal.model.profile import Profile class ProfileTest(unittest.TestCase): diff --git a/test/unittests/model/settings_test.py b/test/unittests/model/settings_test.py index 0c63f49f187..749aa7f5974 100644 --- a/test/unittests/model/settings_test.py +++ b/test/unittests/model/settings_test.py @@ -5,7 +5,7 @@ from conan.internal.default_settings import default_settings_yml from conan.errors import ConanException -from conans.model.settings import Settings, bad_value_msg, undefined_field +from conan.internal.model.settings import Settings, bad_value_msg, undefined_field def undefined_value(v): diff --git a/test/unittests/model/test_conf.py b/test/unittests/model/test_conf.py index 841a87bf7d4..25dfbdedfaf 100644 --- a/test/unittests/model/test_conf.py +++ b/test/unittests/model/test_conf.py @@ -3,7 +3,7 @@ import pytest from conan.errors import ConanException -from conans.model.conf import ConfDefinition +from conan.internal.model.conf import ConfDefinition @pytest.fixture() diff --git a/test/unittests/model/test_package_reference.py b/test/unittests/model/test_package_reference.py index 941c093270a..d0b68a97333 100644 --- a/test/unittests/model/test_package_reference.py +++ b/test/unittests/model/test_package_reference.py @@ -1,4 +1,4 @@ -from conans.model.package_ref import PkgReference +from conan.api.model import PkgReference def test_package_reference(): diff --git a/test/unittests/model/test_recipe_reference.py b/test/unittests/model/test_recipe_reference.py index 382424c1c35..7e9288213b4 100644 --- a/test/unittests/model/test_recipe_reference.py +++ b/test/unittests/model/test_recipe_reference.py @@ -1,7 +1,7 @@ import pytest from conan.errors import ConanException -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference def test_recipe_reference(): diff --git a/test/unittests/model/version/test_version_bump.py b/test/unittests/model/version/test_version_bump.py index 23b3e1a2610..180d8860c38 100644 --- a/test/unittests/model/version/test_version_bump.py +++ b/test/unittests/model/version/test_version_bump.py @@ -1,6 +1,6 @@ import pytest -from conans.model.version import Version +from conan.internal.model.version import Version values = [ ['1.0.0', 0, "2.0.0"], diff --git a/test/unittests/model/version/test_version_comparison.py b/test/unittests/model/version/test_version_comparison.py index da480377edf..f35cd9796bb 100644 --- a/test/unittests/model/version/test_version_comparison.py +++ b/test/unittests/model/version/test_version_comparison.py @@ -1,6 +1,6 @@ import pytest -from conans.model.version import Version +from conan.internal.model.version import Version v = [("1", "2"), ("1.0", "1.1"), diff --git a/test/unittests/model/version/test_version_parse.py b/test/unittests/model/version/test_version_parse.py index e68f77dddb0..bdd4e27ba58 100644 --- a/test/unittests/model/version/test_version_parse.py +++ b/test/unittests/model/version/test_version_parse.py @@ -1,6 +1,6 @@ import pytest -from conans.model.version import Version +from conan.internal.model.version import Version v = [("1.2.3", (1, 2, 3), None, None), diff --git a/test/unittests/model/version/test_version_range.py b/test/unittests/model/version/test_version_range.py index b380de47bc1..8b172c2c3dd 100644 --- a/test/unittests/model/version/test_version_range.py +++ b/test/unittests/model/version/test_version_range.py @@ -3,8 +3,8 @@ import pytest from conan.errors import ConanException -from conans.model.version import Version -from conans.model.version_range import VersionRange +from conan.internal.model.version import Version +from conan.internal.model.version_range import VersionRange from conan.test.utils.tools import TestClient values = [ diff --git a/test/unittests/model/version/test_version_range_intersection.py b/test/unittests/model/version/test_version_range_intersection.py index 1ad131974a2..a379a96738b 100644 --- a/test/unittests/model/version/test_version_range_intersection.py +++ b/test/unittests/model/version/test_version_range_intersection.py @@ -1,6 +1,6 @@ import pytest -from conans.model.version_range import VersionRange +from conan.internal.model.version_range import VersionRange values = [ # empty / any ranges diff --git a/test/unittests/model/versionrepr_test.py b/test/unittests/model/versionrepr_test.py index 59b2b13f7b1..d28ef3b164c 100644 --- a/test/unittests/model/versionrepr_test.py +++ b/test/unittests/model/versionrepr_test.py @@ -1,7 +1,7 @@ import unittest -from conans.model.info import _VersionRepr -from conans.model.version import Version +from conan.internal.model.info import _VersionRepr +from conan.internal.model.version import Version class VersionReprTest(unittest.TestCase): diff --git a/test/unittests/server/service/authorizer_test.py b/test/unittests/server/service/authorizer_test.py index 1424dad615b..f4386fc64bc 100644 --- a/test/unittests/server/service/authorizer_test.py +++ b/test/unittests/server/service/authorizer_test.py @@ -1,8 +1,8 @@ import unittest from conan.internal.errors import InternalErrorException, AuthenticationException, ForbiddenException -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conans.server.service.authorize import BasicAuthorizer diff --git a/test/unittests/server/service/service_test.py b/test/unittests/server/service/service_test.py index 8e3e1f7d413..bdb8f9dc14f 100644 --- a/test/unittests/server/service/service_test.py +++ b/test/unittests/server/service/service_test.py @@ -3,9 +3,9 @@ import unittest from conan.internal.errors import NotFoundException -from conans.model.manifest import FileTreeManifest -from conans.model.package_ref import PkgReference -from conans.model.recipe_ref import RecipeReference +from conan.internal.model.manifest import FileTreeManifest +from conan.api.model import PkgReference +from conan.api.model import RecipeReference from conan.internal.paths import CONANINFO, CONAN_MANIFEST from conans.server.service.authorize import BasicAuthorizer from conans.server.service.v2.search import SearchService diff --git a/test/unittests/tools/build/test_cppstd.py b/test/unittests/tools/build/test_cppstd.py index 1a4f6f80dbb..1997c72bbde 100644 --- a/test/unittests/tools/build/test_cppstd.py +++ b/test/unittests/tools/build/test_cppstd.py @@ -3,7 +3,7 @@ from conan.internal.api.detect.detect_api import detect_cppstd from conan.tools.build import supported_cppstd, check_min_cppstd, valid_min_cppstd from conan.errors import ConanException, ConanInvalidConfiguration -from conans.model.version import Version +from conan.internal.model.version import Version from conan.test.utils.mocks import MockSettings, ConanFileMock diff --git a/test/unittests/tools/cmake/test_cmake_cmd_line_args.py b/test/unittests/tools/cmake/test_cmake_cmd_line_args.py index b8848cda9c4..ffc3c4c0c17 100644 --- a/test/unittests/tools/cmake/test_cmake_cmd_line_args.py +++ b/test/unittests/tools/cmake/test_cmake_cmd_line_args.py @@ -3,7 +3,7 @@ import pytest from conan.tools.cmake.cmake import _cmake_cmd_line_args -from conans.model.conf import ConfDefinition +from conan.internal.model.conf import ConfDefinition from conan.test.utils.mocks import ConanFileMock diff --git a/test/unittests/tools/cmake/test_cmake_install.py b/test/unittests/tools/cmake/test_cmake_install.py index 8460406061d..d6bf9fa6c87 100644 --- a/test/unittests/tools/cmake/test_cmake_install.py +++ b/test/unittests/tools/cmake/test_cmake_install.py @@ -1,8 +1,8 @@ from conan.internal.default_settings import default_settings_yml from conan.tools.cmake import CMake from conan.tools.cmake.presets import write_cmake_presets -from conans.model.conf import Conf -from conans.model.settings import Settings +from conan.internal.model.conf import Conf +from conan.internal.model.settings import Settings from conan.test.utils.mocks import ConanFileMock from conan.test.utils.test_files import temp_folder diff --git a/test/unittests/tools/cmake/test_cmake_presets_definitions.py b/test/unittests/tools/cmake/test_cmake_presets_definitions.py index 0d15efc1292..2b474c8fd09 100644 --- a/test/unittests/tools/cmake/test_cmake_presets_definitions.py +++ b/test/unittests/tools/cmake/test_cmake_presets_definitions.py @@ -3,9 +3,9 @@ from conan.tools.cmake import CMake from conan.tools.cmake.presets import write_cmake_presets -from conans.model.conan_file import ConanFile -from conans.model.conf import Conf -from conans.model.settings import Settings +from conan.internal.model.conan_file import ConanFile +from conan.internal.model.conf import Conf +from conan.internal.model.settings import Settings from conan.test.utils.test_files import temp_folder diff --git a/test/unittests/tools/cmake/test_cmake_test.py b/test/unittests/tools/cmake/test_cmake_test.py index 901fb3f451b..8caf8603a66 100644 --- a/test/unittests/tools/cmake/test_cmake_test.py +++ b/test/unittests/tools/cmake/test_cmake_test.py @@ -3,8 +3,8 @@ from conan.internal.default_settings import default_settings_yml from conan.tools.cmake import CMake from conan.tools.cmake.presets import write_cmake_presets -from conans.model.conf import Conf -from conans.model.settings import Settings +from conan.internal.model.conf import Conf +from conan.internal.model.settings import Settings from conan.test.utils.mocks import ConanFileMock from conan.test.utils.test_files import temp_folder diff --git a/test/unittests/tools/cmake/test_cmaketoolchain.py b/test/unittests/tools/cmake/test_cmaketoolchain.py index 5eb8d43bea7..26169deceff 100644 --- a/test/unittests/tools/cmake/test_cmaketoolchain.py +++ b/test/unittests/tools/cmake/test_cmaketoolchain.py @@ -8,9 +8,9 @@ from conan.tools.cmake import CMakeToolchain from conan.tools.cmake.toolchain.blocks import Block from conan.errors import ConanException -from conans.model.conf import Conf -from conans.model.options import Options -from conans.model.settings import Settings +from conan.internal.model.conf import Conf +from conan.internal.model.options import Options +from conan.internal.model.settings import Settings @pytest.fixture diff --git a/test/unittests/tools/env/test_env.py b/test/unittests/tools/env/test_env.py index a3384cc0e78..156484905dc 100644 --- a/test/unittests/tools/env/test_env.py +++ b/test/unittests/tools/env/test_env.py @@ -8,7 +8,7 @@ from conan.tools.env import Environment from conan.tools.env.environment import ProfileEnvironment from conans.client.subsystems import WINDOWS -from conans.model.recipe_ref import RecipeReference +from conan.api.model import RecipeReference from conan.test.utils.mocks import ConanFileMock, MockSettings from conan.test.utils.test_files import temp_folder from conan.test.utils.env import environment_update diff --git a/test/unittests/tools/files/collect_lib_test.py b/test/unittests/tools/files/collect_lib_test.py index 73c62d4d4e3..aaa2c154a3a 100644 --- a/test/unittests/tools/files/collect_lib_test.py +++ b/test/unittests/tools/files/collect_lib_test.py @@ -4,7 +4,7 @@ import pytest from conan.tools.files import collect_libs -from conans.model.build_info import CppInfo +from conan.internal.model.cpp_info import CppInfo from conan.test.utils.mocks import ConanFileMock, RedirectedTestOutput from conan.test.utils.test_files import temp_folder from conan.test.utils.tools import redirect_output diff --git a/test/unittests/tools/gnu/autotoolschain_test.py b/test/unittests/tools/gnu/autotoolschain_test.py index 37096e97030..eec8d7cce0e 100644 --- a/test/unittests/tools/gnu/autotoolschain_test.py +++ b/test/unittests/tools/gnu/autotoolschain_test.py @@ -5,7 +5,7 @@ from conan.tools.build import cmd_args_to_string from conan.tools.gnu import AutotoolsToolchain from conan.errors import ConanException -from conans.model.conf import Conf +from conan.internal.model.conf import Conf from conan.test.utils.mocks import ConanFileMock, MockSettings diff --git a/test/unittests/tools/gnu/test_gnutoolchain.py b/test/unittests/tools/gnu/test_gnutoolchain.py index c53f9d7bb83..48fffbe9420 100644 --- a/test/unittests/tools/gnu/test_gnutoolchain.py +++ b/test/unittests/tools/gnu/test_gnutoolchain.py @@ -1,11 +1,9 @@ -from unittest.mock import patch - import pytest from conan.tools.build import cmd_args_to_string from conan.tools.gnu import GnuToolchain from conan.errors import ConanException -from conans.model.conf import Conf +from conan.internal.model.conf import Conf from conan.test.utils.mocks import ConanFileMock, MockSettings diff --git a/test/unittests/tools/intel/test_intel_cc.py b/test/unittests/tools/intel/test_intel_cc.py index 39ef3446e1e..6fcc8e3e179 100644 --- a/test/unittests/tools/intel/test_intel_cc.py +++ b/test/unittests/tools/intel/test_intel_cc.py @@ -7,7 +7,7 @@ from conan.tools.build.flags import architecture_flag, cppstd_flag from conan.tools.intel import IntelCC from conan.errors import ConanException -from conans.model.conf import ConfDefinition +from conan.internal.model.conf import ConfDefinition from conan.test.utils.mocks import ConanFileMock, MockSettings diff --git a/test/unittests/tools/meson/test_meson.py b/test/unittests/tools/meson/test_meson.py index 8998347a7b2..4f80ea8af3c 100644 --- a/test/unittests/tools/meson/test_meson.py +++ b/test/unittests/tools/meson/test_meson.py @@ -1,7 +1,7 @@ import textwrap from conan.tools.meson import Meson -from conans.model.conf import ConfDefinition +from conan.internal.model.conf import ConfDefinition from conan.test.utils.mocks import ConanFileMock, MockSettings diff --git a/test/unittests/tools/microsoft/test_msbuild.py b/test/unittests/tools/microsoft/test_msbuild.py index 3039fbefd7b..b4c96296ac5 100644 --- a/test/unittests/tools/microsoft/test_msbuild.py +++ b/test/unittests/tools/microsoft/test_msbuild.py @@ -4,8 +4,8 @@ from conan import ConanFile from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, is_msvc_static_runtime -from conans.model.conf import ConfDefinition, Conf -from conans.model.settings import Settings +from conan.internal.model.conf import ConfDefinition, Conf +from conan.internal.model.settings import Settings from conan.test.utils.mocks import MockSettings, ConanFileMock, MockOptions from conan.test.utils.test_files import temp_folder from conans.util.files import load diff --git a/test/unittests/tools/microsoft/test_subsystem.py b/test/unittests/tools/microsoft/test_subsystem.py index be4ae1ef10c..3404d37d38f 100644 --- a/test/unittests/tools/microsoft/test_subsystem.py +++ b/test/unittests/tools/microsoft/test_subsystem.py @@ -3,7 +3,7 @@ import pytest from conan.tools.microsoft import unix_path, unix_path_package_info_legacy -from conans.model.conf import ConfDefinition +from conan.internal.model.conf import ConfDefinition from conan.test.utils.mocks import MockSettings, ConanFileMock expected_results = [ diff --git a/test/unittests/util/apple_test.py b/test/unittests/util/apple_test.py index 4827a292bd0..1b861a4854b 100644 --- a/test/unittests/util/apple_test.py +++ b/test/unittests/util/apple_test.py @@ -1,36 +1,9 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import unittest - import pytest -from conan.tools.apple.apple import _to_apple_arch, apple_min_version_flag, \ - is_apple_os +from conan.tools.apple.apple import _to_apple_arch, apple_min_version_flag, is_apple_os from conan.test.utils.mocks import MockSettings, ConanFileMock -class FakeSettings(object): - def __init__(self, _os, arch, os_sdk=None, os_version=None, subsystem=None): - self._os = _os - self._arch = arch - self._os_sdk = os_sdk - self._os_version = os_version - self._os_subystem = subsystem - - def get_safe(self, name): - if name == 'os': - return self._os - elif name == 'arch': - return self._arch - elif name == 'os.sdk': - return self._os_sdk - elif name == "os.version": - return self._os_version - elif name == "os.subsystem": - return self._os_subystem - - class TestApple: @pytest.mark.parametrize("os_, version, sdk, subsystem, flag", [("Macos", "10.1", "macosx", None, '-mmacosx-version-min=10.1'), @@ -57,31 +30,23 @@ def test_deployment_target_flag_name(self, os_, version, sdk, subsystem, flag): conanfile.settings = settings assert apple_min_version_flag(conanfile) == flag - -class AppleTest(unittest.TestCase): - - def test_is_apple_os(self): - # FIXME: parametrize! - apple_os = ['iOS', 'tvOS', 'watchOS', 'Macos'] - non_apple_os = ['Windows', 'Linux', 'Android'] + @pytest.mark.parametrize("_os, result", + [("Macos", True), ("iOS", True), ("tvOS", True), ("watchOS", True), + ("Linux", False), ("Windows", False), ("Android", False)]) + def test_is_apple_os(self, _os, result): conanfile = ConanFileMock() - for os_ in apple_os: - settings = MockSettings({"os": os_}) - conanfile.settings = settings - self.assertTrue(is_apple_os(conanfile)) - for os_ in non_apple_os: - settings = MockSettings({"os": os_}) - conanfile.settings = settings - self.assertFalse(is_apple_os(conanfile)) + settings = MockSettings({"os": _os}) + conanfile.settings = settings + assert is_apple_os(conanfile) == result def test_to_apple_arch(self): - self.assertEqual(_to_apple_arch('x86'), 'i386') - self.assertEqual(_to_apple_arch('x86_64'), 'x86_64') - self.assertEqual(_to_apple_arch('armv7'), 'armv7') - self.assertEqual(_to_apple_arch('armv7s'), 'armv7s') - self.assertEqual(_to_apple_arch('armv7k'), 'armv7k') - self.assertEqual(_to_apple_arch('armv8'), 'arm64') - self.assertEqual(_to_apple_arch('armv8.3'), 'arm64e') - self.assertEqual(_to_apple_arch('armv8_32'), 'arm64_32') - self.assertIsNone(_to_apple_arch('mips')) - self.assertEqual(_to_apple_arch('mips', default='mips'), 'mips') + assert _to_apple_arch('x86') == 'i386' + assert _to_apple_arch('x86_64') == 'x86_64' + assert _to_apple_arch('armv7') == 'armv7' + assert _to_apple_arch('armv7s') == 'armv7s' + assert _to_apple_arch('armv7k') == 'armv7k' + assert _to_apple_arch('armv8') == 'arm64' + assert _to_apple_arch('armv8.3') == 'arm64e' + assert _to_apple_arch('armv8_32') == 'arm64_32' + assert _to_apple_arch('mips') is None + assert _to_apple_arch('mips', default='mips') == 'mips' diff --git a/test/unittests/util/detect_test.py b/test/unittests/util/detect_test.py index 654a27c75e2..943ed84707c 100644 --- a/test/unittests/util/detect_test.py +++ b/test/unittests/util/detect_test.py @@ -7,7 +7,7 @@ from conan.internal.api.detect.detect_api import _cc_compiler from conan.internal.api.profile.detect import detect_defaults_settings -from conans.model.version import Version +from conan.internal.model.version import Version from conan.test.utils.mocks import RedirectedTestOutput from conan.test.utils.tools import redirect_output from conan.test.utils.env import environment_update diff --git a/test/unittests/util/files/strip_root_extract_test.py b/test/unittests/util/files/strip_root_extract_test.py index cdbdb7b4ac4..3f8746b9925 100644 --- a/test/unittests/util/files/strip_root_extract_test.py +++ b/test/unittests/util/files/strip_root_extract_test.py @@ -5,7 +5,7 @@ from conan.tools.files.files import untargz, unzip from conan.errors import ConanException -from conans.model.manifest import gather_files +from conan.internal.model.manifest import gather_files from conan.test.utils.mocks import ConanFileMock from conan.test.utils.mocks import RedirectedTestOutput from conan.test.utils.test_files import temp_folder diff --git a/test/unittests/util/tools_test.py b/test/unittests/util/tools_test.py index 7581d612859..a7c14476acb 100644 --- a/test/unittests/util/tools_test.py +++ b/test/unittests/util/tools_test.py @@ -6,8 +6,8 @@ import pytest from conan.tools.files import replace_in_file, collect_libs -from conans.model.build_info import CppInfo -from conans.model.layout import Infos +from conan.internal.model.cpp_info import CppInfo +from conan.internal.model.layout import Infos from conan.test.utils.mocks import ConanFileMock, RedirectedTestOutput from conan.test.utils.test_files import temp_folder from conan.test.utils.tools import redirect_output