def get_template(self, template_file):
        """
        :param str template_file: the template file name that appeared in moban
                                  file. It could be a file name, or a relative
                                  file path with reference to template
                                  directories.
        :return: a jinja2 template

        For example:

        suppose your current working directory is: /User/moban-pro/ and your
        template folder list is: ['./my-template'], and the given template
        file equals to: 'templates/myfile.jj2', they as a group tells the
        template file exists at:
            '/User/moban-pro/my-template/templates/myfile.jj2'
        """
        try:
            template = self.jj2_environment.get_template(template_file)
            return template
        except TemplateNotFound:
            try:
                content = file_system.read_unicode(template_file)
                return self.jj2_environment.from_string(content)
            except fs.errors.ResourceNotFound:
                return self.jj2_environment.from_string(template_file)
Exemplo n.º 2
0
def test_reference_pypi_package(fake_inputs):
    project_name = "project_s"
    fake_inputs.return_value = {
        "full_name": "full_n",
        "email": "email_",
        "github_username": "******",
        "project_name": "project_n",
        "project_slug": "project_s",
        "project_short_description": "project_sd",
        "pypi_username": "******",
        "version": "1.0",
        "use_pytest": "y",
        "use_pypi_deployment_with_travis": "y",
        "add_pyup_badge": "y",
        "command_line_interface": "Click",
        "create_author_file": "y",
        "open_source_license": "MIT license",
    }
    path = "gh:moremoban/cookiecutter-pypackage"
    with patch.object(sys, "argv", ["yh", path]):
        main()

    assert os.path.exists(os.path.join("project_s", ".git"))

    for a_file in find_files("project_s"):
        reference = url_join("tests/fixtures", a_file)
        if ".git" in a_file:
            continue
        if fs.path.basename(a_file) in [
            ".moban.yml",
            "HISTORY.rst",
            ".moban.hashes",
        ]:
            # no way to compare them
            continue
        r = read_unicode(reference)
        a = read_unicode(a_file)
        eq_(r, a, f"{a_file} differs")
        os.unlink(a_file)

    shutil.rmtree(project_name)
Exemplo n.º 3
0
 def _ask_questions(self):
     content = read_unicode(self.project_file)
     first_stage = utils.load_yaml(content)
     utils.color_print(first_stage["introduction"])
     base_path = fs.path.dirname(self.project_file)
     with fs.open_fs(base_path) as the_fs:
         self.template_dir = os.path.join(
             the_fs._root_path,
             first_stage["configuration"]["template_path"],
         )
         self.static_dir = os.path.join(
             the_fs._root_path, first_stage["configuration"]["static_path"])
     self.answers = get_user_inputs(first_stage["questions"])
Exemplo n.º 4
0
def cookiecutter_json_to_yehua_file(path):
    content = read_unicode(url_join(path, "cookiecutter.json"))
    cookie_questions = json.loads(content)

    questions = []
    for key, value in cookie_questions.items():
        if isinstance(value, list):
            complex_question = {"question": f"{key}:"}
            for index, option in enumerate(value, 1):
                complex_question[f"{index}. {option}"] = "N/A"
            questions.append({key: [complex_question]})
        else:
            questions.append({key: f"{key} [{value}]: "})
    project_dir = find_project_name(path)
    dir_list = walk_tree(url_join(path, project_dir))
    better_list = cleanse(dir_list, url_join(path, project_dir))
    layout = find_sub_directories(url_join(path, project_dir))

    git_repo_files = []
    for entry in better_list:
        git_repo_files += list(entry.keys())
    git_repo_files += [".moban.yml", cookiefy(project_dir + ".yml")]
    yehua = {
        "introduction": INTRODUCTION,
        "configuration": {
            "template_path": project_dir,
            "static_path": project_dir,
        },
        "post-moban": {
            "git-repo-files": git_repo_files
        },
        "questions": questions,
        "moban": better_list,
        "layout": layout,
    }
    yaml_content = StringIO()
    dump_yaml(yehua, yaml_content)
    return yaml_content.getvalue()
def test_read_unicode():
    for url, expected in TEST_FILE_CONTENT_SPECS:
        content = file_system.read_unicode(url)
        eq_(content, expected)
Exemplo n.º 6
0
def verify_content_with_fs(file_name, expected):
    content = file_system.read_unicode(file_name)
    assert content == expected
Exemplo n.º 7
0
def verify_content_with_fs(file_name, expected):
    content = file_system.read_unicode(file_name)
    eq_(content, expected)