Пример #1
0
    def load_imports_arguments_test(self):
        file_content = '''
[imports]
OpenCV/bin, * -> ./bin # I need this binaries
OpenCV/lib, * -> ./lib @ root_package=Pkg
OpenCV/data, * -> ./data @ root_package=Pkg, folder=True # Irrelevant
docs, * -> ./docs @ root_package=Pkg, folder=True, ignore_case=True, excludes="a b c" # Other
licenses, * -> ./licenses @ root_package=Pkg, folder=True, ignore_case=True, excludes="a b c", keep_path=False # Other
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Settings(), Profile())
        ret = loader.load_conan_txt(file_path, None)

        ret.copy = Mock()
        ret.imports()
        expected = [
            call(u'*', u'./bin', u'OpenCV/bin', None, False, False, None,
                 True),
            call(u'*', u'./lib', u'OpenCV/lib', u'Pkg', False, False, None,
                 True),
            call(u'*', u'./data', u'OpenCV/data', u'Pkg', True, False, None,
                 True),
            call(u'*', u'./docs', u'docs', u'Pkg', True, True,
                 [u'"a', u'b', u'c"'], True),
            call(u'*', u'./licenses', u'licenses', u'Pkg', True, True,
                 [u'"a', u'b', u'c"'], False)
        ]
        self.assertEqual(ret.copy.call_args_list, expected)
Пример #2
0
    def test_replace_in_file(self):
        file_content = '''
from conans import ConanFile
from conans.tools import download, unzip, replace_in_file
import os

class ConanFileToolsTest(ConanFile):
    name = "test"
    version = "1.9.10"
    settings = []

    def source(self):
        pass

    def build(self):
        replace_in_file("otherfile.txt", "ONE TWO THREE", "FOUR FIVE SIX")

'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "conanfile.py")
        other_file = os.path.join(tmp_dir, "otherfile.txt")
        save(file_path, file_content)
        save(other_file, "ONE TWO THREE")
        loader = ConanFileLoader(None, None, Settings(), OptionsValues.loads(""))
        ret = loader.load_conan(file_path)
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(other_file)
        self.assertEquals(content, "FOUR FIVE SIX")
Пример #3
0
    def package_files(self, reference, path, profile):
        """ Bundle pre-existing binaries
        @param reference: ConanFileReference
        """
        conan_file_path = self._client_cache.conanfile(reference)
        if not os.path.exists(conan_file_path):
            raise ConanException("Package recipe '%s' does not exist" % str(reference))

        current_path = path
        remote_proxy = ConanProxy(self._client_cache, self._user_io, self._remote_manager,
                                  remote_name=None, update=False, check_updates=False,
                                  manifest_manager=None)
        loader = ConanFileLoader(self._runner, self._client_cache.settings, profile)
        conanfile = loader.load_virtual([reference], current_path)
        graph_builder = self._get_graph_builder(loader, False, remote_proxy)
        deps_graph = graph_builder.load(conanfile)

        # this is a bit tricky, but works. The loading of a cache package makes the referenced
        # one, the first of the first level, always existing
        nodes = deps_graph.direct_requires()
        _, conanfile = nodes[0]
        packages_folder = self._client_cache.packages(reference)
        package_folder = os.path.join(packages_folder, conanfile.info.package_id())
        shutil.copytree(path, package_folder)
        save(os.path.join(package_folder, CONANINFO), conanfile.info.dumps())
        # Create the digest for the package
        digest = FileTreeManifest.create(package_folder)
        save(os.path.join(package_folder, CONAN_MANIFEST), str(digest))
Пример #4
0
    def test_replace_in_file(self):
        file_content = '''
from conans import ConanFile
from conans.tools import download, unzip, replace_in_file
import os

class ConanFileToolsTest(ConanFile):
    name = "test"
    version = "1.9.10"
    settings = []

    def source(self):
        pass

    def build(self):
        replace_in_file("otherfile.txt", "ONE TWO THREE", "FOUR FIVE SIX")

'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "conanfile.py")
        other_file = os.path.join(tmp_dir, "otherfile.txt")
        save(file_path, file_content)
        save(other_file, "ONE TWO THREE")
        loader = ConanFileLoader(None, Settings(), None,
                                 OptionsValues.loads(""), Scopes(), None, None)
        ret = loader.load_conan(file_path, None)
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(other_file)
        self.assertEquals(content, "FOUR FIVE SIX")
Пример #5
0
    def test_package_settings(self):
        # CREATE A CONANFILE TO LOAD
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    name = "MyPackage"
    version = "1.0"
    settings = "os"
"""
        save(conanfile_path, conanfile)

        # Apply windows for MyPackage
        profile = Profile()
        profile.processed_settings = Settings({"os": ["Windows", "Linux"]})
        profile.package_settings = {"MyPackage": OrderedDict([("os", "Windows")])}
        loader = ConanFileLoader(None, TestBufferConanOutput(), ConanPythonRequire(None, None))

        recipe = loader.load_consumer(conanfile_path,
                                      test_processed_profile(profile))
        self.assertEqual(recipe.settings.os, "Windows")

        # Apply Linux for MyPackage
        profile.package_settings = {"MyPackage": OrderedDict([("os", "Linux")])}
        recipe = loader.load_consumer(conanfile_path,
                                      test_processed_profile(profile))
        self.assertEqual(recipe.settings.os, "Linux")

        # If the package name is different from the conanfile one, it wont apply
        profile.package_settings = {"OtherPACKAGE": OrderedDict([("os", "Linux")])}
        recipe = loader.load_consumer(conanfile_path,
                                      test_processed_profile(profile))
        self.assertIsNone(recipe.settings.os.value)
Пример #6
0
    def setUp(self):
        settings = Settings()
        self.profile = Profile()
        self.profile.processed_settings = settings

        output = TestBufferConanOutput()
        self.loader = ConanFileLoader(None, output,
                                      ConanPythonRequire(None, None))
Пример #7
0
 def setUp(self):
     settings = Settings()
     self.profile = Profile()
     self.profile._settings = settings
     self.profile._user_options = None
     self.profile._env_values = None
     self.conanfile_txt_path = os.path.join(temp_folder(), "conanfile.txt")
     output = TestBufferConanOutput()
     self.loader = ConanFileLoader(None, output, None)
Пример #8
0
 def test_layout_not_predefined(self):
     txt = textwrap.dedent("""
                 [layout]
                 missing
             """)
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "conanfile.txt")
     save(file_path, txt)
     with pytest.raises(ConanException) as exc:
         loader = ConanFileLoader(None, Mock(), None)
         loader.load_conanfile_txt(file_path, create_profile())
     assert "Unknown predefined layout 'missing'" in str(exc.value)
Пример #9
0
    def _build_and_check(self, tmp_dir, file_path, text_file, msg):
        loader = ConanFileLoader(None, Settings(), Profile())
        ret = loader.load_conan(file_path, None)
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEquals(content, msg)
Пример #10
0
 def setUp(self):
     settings = Settings()
     self.profile = Profile()
     self.profile._settings = settings
     self.profile._user_options = None
     self.profile._env_values = None
     self.profile._dev_reference = None
     self.profile._package_settings = None
     self.conanfile_path = os.path.join(temp_folder(), "conanfile.py")
     output = TestBufferConanOutput()
     self.loader = ConanFileLoader(None, output,
                                   ConanPythonRequire(None, None))
Пример #11
0
    def _build_and_check(self, tmp_dir, file_path, text_file, msg):
        loader = ConanFileLoader(None, None, ConanPythonRequire(None, None))
        ret = loader.load_conanfile(file_path, None, ProcessedProfile())
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEquals(content, msg)
Пример #12
0
    def _build_and_check(self, tmp_dir, file_path, text_file, msg):
        loader = ConanFileLoader(None, TestBufferConanOutput(), ConanPythonRequire(None, None))
        ret = loader.load_consumer(file_path, test_profile())
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEqual(content, msg)
Пример #13
0
    def _build_and_check(self, tmp_dir, file_path, text_file, msg):
        loader = ConanFileLoader(None, Settings(), None,
                                 OptionsValues.loads(""), Scopes(), None)
        ret = loader.load_conan(file_path, None)
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEquals(content, msg)
Пример #14
0
 def test_load_options_error(self):
     conanfile_txt = textwrap.dedent("""
         [options]
         myoption: myvalue
     """)
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "file.txt")
     save(file_path, conanfile_txt)
     loader = ConanFileLoader(None, Mock(), None)
     with six.assertRaisesRegex(self, ConanException,
                                r"Error while parsing \[options\] in conanfile\n"
                                "Options should be specified as 'pkg:option=value'"):
         loader.load_conanfile_txt(file_path, create_profile())
Пример #15
0
 def test_layout_multiple(self):
     txt = textwrap.dedent("""
                 [layout]
                 cmake_layout
                 vs_layout
             """)
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "conanfile.txt")
     save(file_path, txt)
     with pytest.raises(ConanException) as exc:
         loader = ConanFileLoader(None, Mock(), None)
         loader.load_conanfile_txt(file_path, create_profile())
     assert "Only one layout can be declared in the [layout] section of the conanfile.txt" \
            in str(exc.value)
Пример #16
0
    def requires_init_test(self):
        loader = ConanFileLoader(None, Settings(), Profile())
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    def requirements(self):
        self.requires("MyPkg/0.1@user/channel")
"""
        for requires in ("''", "[]", "()", "None"):
            save(conanfile_path, conanfile.format(requires))
            result = loader.load_conan(conanfile_path, output=None, consumer=True)
            result.requirements()
            self.assertEqual("MyPkg/0.1@user/channel", str(result.requires))
Пример #17
0
    def test_requires_init(self):
        loader = ConanFileLoader(None, Mock(), ConanPythonRequire(None, None))
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    def requirements(self):
        self.requires("MyPkg/0.1@user/channel")
"""
        for requires in ("''", "[]", "()", "None"):
            save(conanfile_path, conanfile.format(requires))
            result = loader.load_consumer(conanfile_path, profile_host=create_profile())
            result.requirements()
            self.assertEqual("MyPkg/0.1@user/channel", str(result.requires))
Пример #18
0
 def download_packages(self, reference, package_ids):
     assert(isinstance(package_ids, list))
     remote, _ = self._get_remote(reference)
     export_path = self._client_cache.export(reference)
     self._remote_manager.get_recipe(reference, export_path, remote)
     conanfile_path = self._client_cache.conanfile(reference)
     loader = ConanFileLoader(None, None, None, None, None, None, None)
     conanfile = loader.load_class(conanfile_path)
     short_paths = conanfile.short_paths
     self._registry.set_ref(reference, remote)
     output = ScopedOutput(str(reference), self._out)
     for package_id in package_ids:
         package_reference = PackageReference(reference, package_id)
         package_folder = self._client_cache.package(package_reference, short_paths=short_paths)
         self._retrieve_remote_package(package_reference, package_folder, output, remote)
Пример #19
0
 def download_packages(self, reference, package_ids):
     assert(isinstance(package_ids, list))
     remote, _ = self._get_remote(reference)
     export_path = self._client_cache.export(reference)
     self._remote_manager.get_recipe(reference, export_path, remote)
     conanfile_path = self._client_cache.conanfile(reference)
     loader = ConanFileLoader(None, None, None, None, None, None)
     conanfile = loader.load_class(conanfile_path)
     short_paths = conanfile.short_paths
     self._registry.set_ref(reference, remote)
     output = ScopedOutput(str(reference), self._out)
     for package_id in package_ids:
         package_ref = PackageReference(reference, package_id)
         package_folder = self._client_cache.package(package_ref, short_paths=short_paths)
         self._retrieve_remote_package(package_ref, package_folder, output, remote)
Пример #20
0
    def requires_init_test(self):
        loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), Scopes(),
                                 None, None)
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    def requirements(self):
        self.requires("MyPkg/0.1@user/channel")
"""
        for requires in ("''", "[]", "()", "None"):
            save(conanfile_path, conanfile.format(requires))
            result = loader.load_conan(conanfile_path, output=None, consumer=True)
            result.requirements()
            self.assertEqual("MyPkg/0.1@user/channel", str(result.requires))
Пример #21
0
    def _loader(self, current_path=None, user_settings_values=None, package_settings=None,
                user_options_values=None, scopes=None, env_values=None, use_conaninfo=True):

        # The disk settings definition, already including the default disk values
        settings = self._client_cache.settings

        conaninfo_scopes = Scopes()
        user_options = OptionsValues(user_options_values)
        mixed_env_values = EnvValues()
        mixed_env_values.update(env_values)

        if current_path:
            conan_info_path = os.path.join(current_path, CONANINFO)
            if use_conaninfo and os.path.exists(conan_info_path):
                existing_info = ConanInfo.load_file(conan_info_path)
                settings.values = existing_info.full_settings
                options = existing_info.full_options  # Take existing options from conaninfo.txt
                options.update(user_options)
                user_options = options
                conaninfo_scopes = existing_info.scope
                # Update with info (prioritize user input)
                mixed_env_values.update(existing_info.env_values)

        if user_settings_values:
            aux_values = Values.from_list(user_settings_values)
            settings.values = aux_values

        if scopes:
            conaninfo_scopes.update_scope(scopes)

        self._current_scopes = conaninfo_scopes
        return ConanFileLoader(self._runner, settings, package_settings=package_settings,
                               options=user_options, scopes=conaninfo_scopes,
                               env_values=mixed_env_values)
Пример #22
0
class ParseSCMFromConanDataTestCase(unittest.TestCase):
    loader = ConanFileLoader(runner=None,
                             output=TestBufferConanOutput(),
                             python_requires=ConanPythonRequire(None, None))

    def test_parse_data(self):
        conanfile = textwrap.dedent("""
            import os
            from conans import ConanFile

            class Recipe(ConanFile):
                scm = {"type": "git", "url": "auto", "revision": "auto"}
        """)
        conan_data = {
            'something_else': {},
            '.conan': {
                'scm': {
                    'type': 'git',
                    'url': 'http://myrepo.com',
                    'shallow': False,
                    'revision': 'abcdefghijk'
                }
            }
        }
        test_folder = tempfile.mkdtemp()
        save_files(
            test_folder, {
                'conanfile.py': conanfile,
                DATA_YML: yaml.safe_dump(conan_data, default_flow_style=False)
            })

        conanfile_path = os.path.join(test_folder, 'conanfile.py')
        conanfile, _ = self.loader.load_basic_module(
            conanfile_path=conanfile_path)
        self.assertDictEqual(conanfile.scm, conan_data['.conan']['scm'])
Пример #23
0
class LoadConanfileTest(unittest.TestCase):
    def setUp(self):
        settings = Settings()
        self.profile = Profile()
        self.profile._settings = settings
        self.profile._user_options = None
        self.profile._env_values = None
        self.profile._dev_reference = None
        self.profile._package_settings = None
        self.conanfile_path = os.path.join(temp_folder(), "conanfile.py")
        output = TestBufferConanOutput()
        self.loader = ConanFileLoader(None, output,
                                      ConanPythonRequire(None, None))

    def env_test(self):
        env_values = EnvValues()
        env_values.add("PREPEND_PATH", ["hello", "bye"])
        env_values.add("VAR", ["var_value"])
        self.profile._env_values = env_values
        save(
            self.conanfile_path,
            textwrap.dedent("""
                from conans import ConanFile

                class TestConan(ConanFile):
                    name = "hello"
                    version = "1.0"
             """))
        ref = ConanFileReference("hello", "1.0", "user", "channel")
        conanfile = self.loader.load_conanfile(self.conanfile_path,
                                               self.profile, ref)
        self.assertEqual(conanfile.env, {
            "PREPEND_PATH": ["hello", "bye"],
            "VAR": ["var_value"]
        })
Пример #24
0
    def _loader(self,
                current_path=None,
                user_settings_values=None,
                user_options_values=None):
        # The disk settings definition, already including the default disk values
        settings = self._paths.settings
        options = OptionsValues()

        if current_path:
            conan_info_path = os.path.join(current_path, CONANINFO)
            if os.path.exists(conan_info_path):
                existing_info = ConanInfo.load_file(conan_info_path)
                settings.values = existing_info.full_settings
                options = existing_info.full_options  # Take existing options from conaninfo.txt

        if user_settings_values:
            aux_values = Values.from_list(user_settings_values)
            settings.values = aux_values

        if user_options_values is not None:  # Install will pass an empty list []
            # Install OVERWRITES options, existing options in CONANINFO are not taken
            # into account, just those from CONANFILE + user command line
            options = OptionsValues.from_list(user_options_values)

        return ConanFileLoader(self._runner, settings, options=options)
Пример #25
0
    def _loader(self, conan_info_path=None, profile=None):
        # The disk settings definition, already including the default disk values
        settings = self._client_cache.settings
        mixed_profile = Profile()
        if profile is None:
            if conan_info_path and os.path.exists(conan_info_path):
                existing_info = ConanInfo.load_file(conan_info_path)
                settings.values = existing_info.full_settings
                mixed_profile.options = existing_info.full_options
                mixed_profile.scopes = existing_info.scope
                mixed_profile.env_values = existing_info.env_values
        else:
            mixed_profile.env_values.update(profile.env_values)
            settings.values = profile.settings_values
            if profile.scopes:
                mixed_profile.scopes.update_scope(profile.scopes)
            mixed_profile.options.update(profile.options)
            for pkg, pkg_settings in profile.package_settings.items():
                mixed_profile.package_settings[pkg].update(pkg_settings)

        self._current_scopes = mixed_profile.scopes
        return ConanFileLoader(
            self._runner,
            settings=settings,
            package_settings=mixed_profile.package_settings_values,
            options=mixed_profile.options,
            scopes=mixed_profile.scopes,
            env_values=mixed_profile.env_values)
Пример #26
0
    def package_files(self, reference, package_folder, profile, force):
        """ Bundle pre-existing binaries
        @param reference: ConanFileReference
        """
        conan_file_path = self._client_cache.conanfile(reference)
        if not os.path.exists(conan_file_path):
            raise ConanException("Package recipe '%s' does not exist" %
                                 str(reference))

        current_path = package_folder
        remote_proxy = ConanProxy(self._client_cache,
                                  self._user_io,
                                  self._remote_manager,
                                  remote_name=None,
                                  update=False,
                                  check_updates=False,
                                  manifest_manager=None)

        loader = ConanFileLoader(self._runner, self._client_cache.settings,
                                 self._profile_with_defaults(profile))
        conanfile = loader.load_virtual([reference], current_path)
        graph_builder = self._get_graph_builder(loader, False, remote_proxy)
        deps_graph = graph_builder.load(conanfile)

        # this is a bit tricky, but works. The loading of a cache package makes the referenced
        # one, the first of the first level, always existing
        nodes = deps_graph.direct_requires()
        _, conanfile = nodes[0]
        packages_folder = self._client_cache.packages(reference)
        pkg_id = conanfile.info.package_id()
        self._user_io.out.info("Packaging to %s" % pkg_id)
        dest_package_folder = os.path.join(packages_folder, pkg_id)
        if os.path.exists(dest_package_folder):
            if force:
                shutil.rmtree(dest_package_folder)
            else:
                raise ConanException(
                    "Package already exists. Please use --force, -f to overwrite it"
                )
        shutil.copytree(package_folder, dest_package_folder, symlinks=True)
        recipe_hash = self._client_cache.load_manifest(reference).summary_hash
        conanfile.info.recipe_hash = recipe_hash
        save(os.path.join(dest_package_folder, CONANINFO),
             conanfile.info.dumps())
        # Create the digest for the package
        digest = FileTreeManifest.create(dest_package_folder)
        save(os.path.join(dest_package_folder, CONAN_MANIFEST), str(digest))
Пример #27
0
    def __init__(self, client_cache, user_io, runner, remote_manager, interactive=True):
        assert isinstance(user_io, UserIO)
        assert isinstance(client_cache, ClientCache)
        self._client_cache = client_cache
        self._user_io = user_io
        self._runner = runner
        self._remote_manager = remote_manager
        self._registry = RemoteRegistry(self._client_cache.registry, self._user_io.out)
        if not interactive:
            self._user_io.disable_input()

        self._proxy = ConanProxy(client_cache, self._user_io.out, remote_manager, registry=self._registry)
        resolver = RangeResolver(self._user_io.out, client_cache, self._proxy)
        python_requires = ConanPythonRequire(self._proxy, resolver)
        self._loader = ConanFileLoader(self._runner, self._user_io.out, python_requires)
        self._graph_manager = GraphManager(self._user_io.out, self._client_cache, self._registry,
                                           self._remote_manager, self._loader, self._proxy, resolver)
Пример #28
0
def edit_conandata(conanfile_path, version, new_base_url):
    conan_data = ConanFileLoader._load_data(conanfile_path)
    url = conan_data["sources"][version]["url"]
    olds_parts = urllib.parse.urlparse(url)
    new_parts = urllib.parse.urlparse(new_base_url)
    new_parts = new_parts._replace(path=new_parts.path + olds_parts.path)
    new_url = new_parts.geturl()
    conan_data["sources"][version]["url"] = new_url
    return conan_data
Пример #29
0
 def _get_deps_graph(self, reference, profile, filename, current_path,
                     remote_proxy):
     loader = ConanFileLoader(self._runner, self._client_cache.settings,
                              self._profile_with_defaults(profile))
     conanfile = self._get_conanfile_object(loader, reference, filename,
                                            current_path)
     graph_builder = self._get_graph_builder(loader, False, remote_proxy)
     deps_graph = graph_builder.load(conanfile)
     return deps_graph, graph_builder, conanfile
Пример #30
0
    def inherit_short_paths_test(self):
        loader = ConanFileLoader(None, Settings(), Profile())
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from base_recipe import BasePackage
class Pkg(BasePackage):
    pass
"""
        base_recipe = """from conans import ConanFile
class BasePackage(ConanFile):
    short_paths = True
"""
        save(conanfile_path, conanfile)
        save(os.path.join(tmp_dir, "base_recipe.py"), base_recipe)
        conan_file = load_conanfile_class(conanfile_path)
        self.assertEqual(conan_file.short_paths, True)

        result = loader.load_conan(conanfile_path, output=None, consumer=True)
        self.assertEqual(result.short_paths, True)
Пример #31
0
    def test_inherit_short_paths(self):
        loader = ConanFileLoader(None, Mock(), ConanPythonRequire(None, None))
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from base_recipe import BasePackage
class Pkg(BasePackage):
    pass
"""
        base_recipe = """from conans import ConanFile
class BasePackage(ConanFile):
    short_paths = True
"""
        save(conanfile_path, conanfile)
        save(os.path.join(tmp_dir, "base_recipe.py"), base_recipe)
        conan_file = loader.load_basic(conanfile_path)
        self.assertEqual(conan_file.short_paths, True)

        result = loader.load_consumer(conanfile_path, profile_host=create_profile())
        self.assertEqual(result.short_paths, True)
Пример #32
0
    def test_patch_from_file(self):
        file_content = '''
from conans import ConanFile
from conans.tools import patch
import os

class ConanFileToolsTest(ConanFile):
    name = "test"
    version = "1.9.10"
    settings = []

    def source(self):
        pass

    def build(self):
        patch(patch_file="file.patch")

'''
        patch_content = '''--- text.txt\t2016-01-25 17:57:11.452848309 +0100
+++ text_new.txt\t2016-01-25 17:57:28.839869950 +0100
@@ -1 +1 @@
-ONE TWO THREE
+ONE TWO FOUR'''

        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "conanfile.py")
        text_file = os.path.join(tmp_dir, "text.txt")
        patch_file = os.path.join(tmp_dir, "file.patch")
        save(file_path, file_content)
        save(text_file, "ONE TWO THREE")
        save(patch_file, patch_content)
        loader = ConanFileLoader(None, Settings(), None,
                                 OptionsValues.loads(""), Scopes(), None, None)
        ret = loader.load_conan(file_path, None)
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEquals(content, "ONE TWO FOUR")
Пример #33
0
    def inherit_short_paths_test(self):
        loader = ConanFileLoader(None, Settings(), Profile())
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from base_recipe import BasePackage
class Pkg(BasePackage):
    pass
"""
        base_recipe = """from conans import ConanFile
class BasePackage(ConanFile):
    short_paths = True
"""
        save(conanfile_path, conanfile)
        save(os.path.join(tmp_dir, "base_recipe.py"), base_recipe)
        conan_file = load_conanfile_class(conanfile_path)
        self.assertEqual(conan_file.short_paths, True)

        result = loader.load_conan(conanfile_path, output=None, consumer=True)
        self.assertEqual(result.short_paths, True)
Пример #34
0
    def test_patch_from_file(self):
        file_content = '''
from conans import ConanFile
from conans.tools import patch
import os

class ConanFileToolsTest(ConanFile):
    name = "test"
    version = "1.9.10"
    settings = []

    def source(self):
        pass

    def build(self):
        patch(patch_file="file.patch")

'''
        patch_content = '''--- text.txt\t2016-01-25 17:57:11.452848309 +0100
+++ text_new.txt\t2016-01-25 17:57:28.839869950 +0100
@@ -1 +1 @@
-ONE TWO THREE
+ONE TWO FOUR'''

        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "conanfile.py")
        text_file = os.path.join(tmp_dir, "text.txt")
        patch_file = os.path.join(tmp_dir, "file.patch")
        save(file_path, file_content)
        save(text_file, "ONE TWO THREE")
        save(patch_file, patch_content)
        loader = ConanFileLoader(None, Settings(), OptionsValues.loads(""), Scopes())
        ret = loader.load_conan(file_path, None)
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEquals(content, "ONE TWO FOUR")
Пример #35
0
    def load_imports_arguments_test(self):
        file_content = '''
[imports]
OpenCV/bin, * -> ./bin # I need this binaries
OpenCV/lib, * -> ./lib @ root_package=Pkg
OpenCV/data, * -> ./data @ root_package=Pkg, folder=True # Irrelevant
docs, * -> ./docs @ root_package=Pkg, folder=True, ignore_case=True, excludes="a b c" # Other
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Settings(), Profile())
        ret = loader.load_conan_txt(file_path, None)

        ret.copy = Mock()
        ret.imports()
        expected = [call(u'*', u'./bin', u'OpenCV/bin', None, False, False, None),
                    call(u'*', u'./lib', u'OpenCV/lib', u'Pkg', False, False, None),
                    call(u'*', u'./data', u'OpenCV/data', u'Pkg', True, False, None),
                    call(u'*', u'./docs', u'docs', u'Pkg', True, True, [u'"a', u'b', u'c"'])]
        self.assertEqual(ret.copy.call_args_list, expected)
Пример #36
0
 def get_loader(self, profile, local=False):
     """ When local=True it means that the state is being recovered from installed files
     conaninfo.txt, conanbuildinfo.txt, and only local methods as build() are being executed.
     Thus, it is necessary to restore settings from that info, as configure() is not called,
     being necessary to remove those settings that doesn't have a value
     """
     cache_settings = self._client_cache.settings.copy()
     cache_settings.values = profile.settings_values
     self._settings_preprocessor.preprocess(cache_settings)
     if local:
         cache_settings.remove_undefined()
     return ConanFileLoader(self._runner, cache_settings, profile)
Пример #37
0
    def test_package_settings(self):
        # CREATE A CONANFILE TO LOAD
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    name = "MyPackage"
    version = "1.0"
    settings = "os"
"""
        save(conanfile_path, conanfile)

        # Apply windows for MyPackage
        profile = Profile()
        profile.package_settings = {"MyPackage": OrderedDict([("os", "Windows")])}
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertEquals(recipe.settings.os, "Windows")

        # Apply Linux for MyPackage
        profile.package_settings = {"MyPackage": OrderedDict([("os", "Linux")])}
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertEquals(recipe.settings.os, "Linux")

        # If the package name is different from the conanfile one, it wont apply
        profile.package_settings = {"OtherPACKAGE": OrderedDict([("os", "Linux")])}
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertIsNone(recipe.settings.os.value)
Пример #38
0
    def package_files(self, reference, package_folder, profile, force):
        """ Bundle pre-existing binaries
        @param reference: ConanFileReference
        """
        conan_file_path = self._client_cache.conanfile(reference)
        if not os.path.exists(conan_file_path):
            raise ConanException("Package recipe '%s' does not exist" % str(reference))

        current_path = package_folder
        remote_proxy = ConanProxy(self._client_cache, self._user_io, self._remote_manager,
                                  remote_name=None, update=False, check_updates=False,
                                  manifest_manager=None)
        loader = ConanFileLoader(self._runner, self._client_cache.settings, profile)
        conanfile = loader.load_virtual([reference], current_path)
        graph_builder = self._get_graph_builder(loader, False, remote_proxy)
        deps_graph = graph_builder.load(conanfile)

        # this is a bit tricky, but works. The loading of a cache package makes the referenced
        # one, the first of the first level, always existing
        nodes = deps_graph.direct_requires()
        _, conanfile = nodes[0]
        packages_folder = self._client_cache.packages(reference)
        pkg_id = conanfile.info.package_id()
        self._user_io.out.info("Packaging to %s" % pkg_id)
        dest_package_folder = os.path.join(packages_folder, pkg_id)
        if os.path.exists(dest_package_folder):
            if force:
                shutil.rmtree(dest_package_folder)
            else:
                raise ConanException("Package already exists. "
                                     "Please use --force, -f to overwrite it")
        shutil.copytree(package_folder, dest_package_folder)
        recipe_hash = self._client_cache.load_manifest(reference).summary_hash
        conanfile.info.recipe_hash = recipe_hash
        save(os.path.join(dest_package_folder, CONANINFO), conanfile.info.dumps())
        # Create the digest for the package
        digest = FileTreeManifest.create(dest_package_folder)
        save(os.path.join(dest_package_folder, CONAN_MANIFEST), str(digest))
Пример #39
0
 def _get_app(self):
     self.remote_manager = MockRemoteManager()
     cache = self.cache
     self.resolver = RangeResolver(self.cache, self.remote_manager)
     proxy = ConanProxy(cache, self.output, self.remote_manager)
     self.loader = ConanFileLoader(None, self.output, ConanPythonRequire(None, None))
     binaries = GraphBinariesAnalyzer(cache, self.output, self.remote_manager)
     self.manager = GraphManager(self.output, cache, self.remote_manager, self.loader, proxy,
                                 self.resolver, binaries)
     hook_manager = Mock()
     app_type = namedtuple("ConanApp", "cache out remote_manager hook_manager graph_manager"
                           " binaries_analyzer")
     app = app_type(self.cache, self.output, self.remote_manager, hook_manager, self.manager,
                    binaries)
     return app
Пример #40
0
    def complete_test(self):
        """ basic installation of a new conans
        """
        client = TestClient()
        client.init_dynamic_vars()
        files = hello_source_files()

        conan_ref = ConanFileReference.loads("Hello/1.2.1/frodo/stable")
        reg_folder = client.paths.export(conan_ref)

        client.save(files, path=reg_folder)
        client.save({CONANFILE: myconan1,
                     CONANINFO: "//empty",
                     "include/no_copy/lib0.h":                     "NO copy",
                     "include/math/lib1.h":                        "copy",
                     "include/math/lib2.h":                        "copy",
                     "include/physics/lib.hpp":                    "copy",
                     "my_lib/debug/libd.a":                        "copy",
                     "my_data/readme.txt":                         "copy",
                     "my_data/readme.md":                          "NO copy",
                     "contrib/math/math.h":                        "copy",
                     "contrib/physics/gravity.h":                  "copy",
                     "contrib/contrib.h":                          "copy",
                     "include/opencv/opencv.hpp":                  "copy",
                     "include/opencv2/opencv2.hpp":                "copy",
                     "modules/simu/src/simu.cpp":                  "NO copy",
                     "modules/simu/include/opencv2/simu/simu.hpp": "copy",
                     "modules/3D/doc/readme.md":                   "NO copy",
                     "modules/3D/include/opencv2/3D/3D.hpp":       "copy",
                     "modules/dev/src/dev.cpp":                    "NO copy",
                     "modules/dev/include/opencv2/dev/dev.hpp":    "copy",
                     "modules/opencv_mod.hpp":                     "copy"}, path=reg_folder)

        conanfile_path = os.path.join(reg_folder, CONANFILE)
        package_ref = PackageReference(conan_ref, "myfakeid")
        build_folder = client.paths.build(package_ref)
        package_folder = client.paths.package(package_ref)

        shutil.copytree(reg_folder, build_folder)

        loader = ConanFileLoader(None, Settings(), OptionsValues.loads(""))
        conanfile = loader.load_conan(conanfile_path, None)
        output = ScopedOutput("", TestBufferConanOutput())
        create_package(conanfile, build_folder, package_folder, output)

        # test build folder
        self.assertTrue(os.path.exists(build_folder))
        self.assertTrue(os.path.exists(os.path.join(package_folder, CONANINFO)))

        # test pack folder
        self.assertTrue(os.path.exists(package_folder))

        def exist(rel_path):
            return os.path.exists(os.path.join(package_folder, rel_path))

        # Expected files
        self.assertTrue(exist("include/lib1.h"))
        self.assertTrue(exist("include/lib2.h"))
        self.assertTrue(exist("include/physics/lib.hpp"))
        self.assertTrue(exist("include/contrib/math/math.h"))
        self.assertTrue(exist("include/contrib/physics/gravity.h"))
        self.assertTrue(exist("include/contrib/contrib.h"))
        self.assertTrue(exist("include/opencv/opencv.hpp"))
        self.assertTrue(exist("include/opencv2/opencv2.hpp"))
        self.assertTrue(exist("include/opencv2/simu/simu.hpp"))
        self.assertTrue(exist("include/opencv2/3D/3D.hpp"))
        self.assertTrue(exist("include/opencv2/dev/dev.hpp"))
        self.assertTrue(exist("lib/my_lib/libd.a"))
        self.assertTrue(exist("res/shares/readme.txt"))

        # Not expected files
        self.assertFalse(exist("include/opencv2/opencv_mod.hpp"))
        self.assertFalse(exist("include/opencv2/simu.hpp"))
        self.assertFalse(exist("include/opencv2/3D.hpp"))
        self.assertFalse(exist("include/opencv2/dev.hpp"))
        self.assertFalse(exist("include/modules/simu/src/simu.cpp"))
        self.assertFalse(exist("include/modules/3D/doc/readme.md"))
        self.assertFalse(exist("include/modules/dev/src/dev.cpp"))
        self.assertFalse(exist("include/opencv2/opencv_mod.hpp"))
        self.assertFalse(exist("include/include/no_copy/lib0.h"))
        self.assertFalse(exist("res/my_data/readme.md"))
Пример #41
0
    def load_conan_txt_test(self):
        file_content = '''[requires]
OpenCV/2.4.10@phil/stable
OpenCV2/2.4.10@phil/stable
[generators]
one
two
[imports]
OpenCV/bin, * -> ./bin # I need this binaries
OpenCV/lib, * -> ./lib
[options]
OpenCV:use_python=True
OpenCV:other_option=False
OpenCV2:use_python2=1
OpenCV2:other_option=Cosa
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), Scopes(),
                                 None, None)
        ret = loader.load_conan_txt(file_path, None)
        options1 = OptionsValues.loads("""OpenCV:use_python=True
OpenCV:other_option=False
OpenCV2:use_python2=1
OpenCV2:other_option=Cosa""")
        requirements = Requirements()
        requirements.add("OpenCV/2.4.10@phil/stable")
        requirements.add("OpenCV2/2.4.10@phil/stable")

        self.assertEquals(ret.requires, requirements)
        self.assertEquals(ret.generators, ["one", "two"])
        self.assertEquals(ret.options.values.dumps(), options1.dumps())

        ret.copy = Mock()
        ret.imports()

        self.assertTrue(ret.copy.call_args_list, [('*', './bin', 'OpenCV/bin'),
                                                  ('*', './lib', 'OpenCV/lib')])

        # Now something that fails
        file_content = '''[requires]
OpenCV/2.4.104phil/stable <- use_python:True, other_option:False
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), 
                                 Scopes(), None, None)
        with self.assertRaisesRegexp(ConanException, "Wrong package recipe reference(.*)"):
            loader.load_conan_txt(file_path, None)

        file_content = '''[requires]
OpenCV/2.4.10@phil/stable <- use_python:True, other_option:False
[imports]
OpenCV/bin/* - ./bin
'''
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "file.txt")
        save(file_path, file_content)
        loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), 
                                 Scopes(), None, None)
        with self.assertRaisesRegexp(ConanException, "is too long. Valid names must contain"):
            loader.load_conan_txt(file_path, None)