Пример #1
0
    def test_only_user_channel(self):
        tmp = get_reference_fields("user/channel", user_channel_input=True)
        self.assertEqual(tmp, (None, None, "user", "channel", None))

        tmp = get_reference_fields("user", user_channel_input=True)
        self.assertEqual(tmp, (None, None, "user", None, None))

        tmp = get_reference_fields("/channel", user_channel_input=True)
        self.assertEqual(tmp, (None, None, None, "channel", None))

        ref_pattern = ConanFileReference.loads("package/*@user/channel")
        self.assertFalse(check_valid_ref(ref_pattern, strict_mode=False))
Пример #2
0
    def test_fields_complete(self):

        # No matter if we say we allow partial references for "user/channel", if we
        # provide this patterns everything is parsed correctly
        for user_channel_input in [True, False]:
            tmp = get_reference_fields("lib/1.0@user",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, ("lib", "1.0", "user", None, None))

            tmp = get_reference_fields("lib/1.0@/channel",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, ("lib", "1.0", None, "channel", None))

            # FIXME: 2.0 in this case lib is considered the version, weird.
            tmp = get_reference_fields("lib@#rev",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, (None, "lib", None, None, "rev"))

            # FIXME: 2.0 in this case lib is considered the version, weird.
            tmp = get_reference_fields("lib@/channel#rev",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, (None, "lib", None, "channel", "rev"))

            tmp = get_reference_fields("/1.0@user/#rev",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, (None, "1.0", "user", None, "rev"))

            tmp = get_reference_fields("/@/#",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, (None, None, None, None, None))

            tmp = get_reference_fields("lib/1.0@/",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, ("lib", "1.0", None, None, None))

            tmp = get_reference_fields("lib/1.0@",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, ("lib", "1.0", None, None, None))

            tmp = get_reference_fields("lib/@",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, ("lib", None, None, None, None))

            tmp = get_reference_fields("/@",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, (None, None, None, None, None))

            tmp = get_reference_fields("@",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, (None, None, None, None, None))

            tmp = get_reference_fields("lib/1.0@user/channel#rev",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, ("lib", "1.0", "user", "channel", "rev"))

            # FIXME: 2.0 in this case lib is considered the version, weird.
            tmp = get_reference_fields("lib@user/channel",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, (None, "lib", "user", "channel", None))

            tmp = get_reference_fields("/@/#",
                                       user_channel_input=user_channel_input)
            self.assertEqual(tmp, (None, None, None, None, None))
Пример #3
0
def cmd_new(ref,
            header=False,
            pure_c=False,
            test=False,
            exports_sources=False,
            bare=False,
            visual_versions=None,
            linux_gcc_versions=None,
            linux_clang_versions=None,
            osx_clang_versions=None,
            shared=None,
            upload_url=None,
            gitignore=None,
            gitlab_gcc_versions=None,
            gitlab_clang_versions=None,
            circleci_gcc_versions=None,
            circleci_clang_versions=None,
            circleci_osx_versions=None,
            template=None,
            cache=None,
            defines=None):
    try:
        name, version, user, channel, revision = get_reference_fields(
            ref, user_channel_input=False)
        # convert "package_name" -> "PackageName"
        package_name = re.sub(r"(?:^|[\W_])(\w)", lambda x: x.group(1).upper(),
                              name)
    except ValueError:
        raise ConanException("Bad parameter, please use full package name,"
                             "e.g.: MyLib/1.2.3@user/testing")

    # Validate it is a valid reference
    ConanFileReference(name, version, user, channel)

    if header and exports_sources:
        raise ConanException("'header' and 'sources' are incompatible options")
    if pure_c and header:
        raise ConanException("'pure_c' is incompatible with 'header'")
    if pure_c and not exports_sources:
        raise ConanException("'pure_c' requires the use of --source")
    if bare and (header or exports_sources):
        raise ConanException(
            "'bare' is incompatible with 'header' and 'sources'")
    if template and (header or exports_sources or bare or pure_c):
        raise ConanException("'template' is incompatible with 'header', "
                             "'sources', 'pure-c' and 'bare'")

    defines = defines or dict()

    if header:
        files = {
            "conanfile.py":
            conanfile_header.format(name=name,
                                    version=version,
                                    package_name=package_name)
        }
    elif exports_sources:
        if not pure_c:
            files = {
                "conanfile.py":
                conanfile_sources.format(name=name,
                                         version=version,
                                         package_name=package_name,
                                         configure=""),
                "src/{}.cpp".format(name):
                hello_cpp.format(name=name, version=version),
                "src/{}.h".format(name):
                hello_h.format(name=name, version=version),
                "src/CMakeLists.txt":
                cmake.format(name=name, version=version)
            }
        else:
            config = ("\n    def configure(self):\n"
                      "        del self.settings.compiler.libcxx\n"
                      "        del self.settings.compiler.cppstd\n")
            files = {
                "conanfile.py":
                conanfile_sources.format(name=name,
                                         version=version,
                                         package_name=package_name,
                                         configure=config),
                "src/{}.c".format(name):
                hello_c.format(name=name, version=version),
                "src/{}.h".format(name):
                hello_h.format(name=name, version=version),
                "src/CMakeLists.txt":
                cmake_pure_c.format(name=name, version=version)
            }
    elif bare:
        files = {
            "conanfile.py":
            conanfile_bare.format(name=name,
                                  version=version,
                                  package_name=package_name)
        }
    elif template:
        is_file_template = os.path.basename(template).endswith('.py')
        if is_file_template:
            if not os.path.isabs(template):
                # FIXME: Conan 2.0. The old path should be removed
                old_path = os.path.join(cache.cache_folder, "templates",
                                        template)
                new_path = os.path.join(cache.cache_folder, "templates",
                                        "command/new", template)
                template = new_path if os.path.isfile(new_path) else old_path
            if not os.path.isfile(template):
                raise ConanException("Template doesn't exist: %s" % template)
            replaced = _render_template(load(template),
                                        name=name,
                                        version=version,
                                        package_name=package_name,
                                        defines=defines)
            files = {"conanfile.py": replaced}
        elif template == "v2_cmake":
            from conans.assets.templates.new_v2_cmake import get_files
            files = get_files(name, version, package_name)
        else:
            if not os.path.isabs(template):
                template = os.path.join(cache.cache_folder, "templates",
                                        "command/new", template)
            if not os.path.isdir(template):
                raise ConanException(
                    "Template doesn't exist: {}".format(template))
            template = os.path.normpath(template)
            files = _get_files_from_template_dir(template_dir=template,
                                                 name=name,
                                                 version=version,
                                                 package_name=package_name,
                                                 defines=defines)
    else:
        files = {
            "conanfile.py":
            conanfile.format(name=name,
                             version=version,
                             package_name=package_name)
        }

    if test:
        files["test_package/conanfile.py"] = test_conanfile.format(
            name=name,
            version=version,
            user=user,
            channel=channel,
            package_name=package_name)
        if pure_c:
            files["test_package/example.c"] = test_main.format(name=name)
            files["test_package/CMakeLists.txt"] = test_cmake_pure_c
        else:
            include_name = name if exports_sources else "hello"
            files["test_package/example.cpp"] = test_main.format(
                name=include_name)
            files["test_package/CMakeLists.txt"] = test_cmake

    if gitignore:
        files[".gitignore"] = gitignore_template

    files.update(
        ci_get_files(name, version, user, channel, visual_versions,
                     linux_gcc_versions, linux_clang_versions,
                     osx_clang_versions, shared, upload_url,
                     gitlab_gcc_versions, gitlab_clang_versions,
                     circleci_gcc_versions, circleci_clang_versions,
                     circleci_osx_versions))
    return files