Ejemplo n.º 1
0
def cmd_doc(ctx: ProjectContext, args: argparse.Namespace) -> int:
    """Generate local project documentation."""
    if not _verify_executable_exists(ctx, 'sphinx-build'):
        return 1

    if args.doxygen:
        if not _verify_executable_exists(ctx, 'doxygen'):
            return 1

        doxygen_args: List[str] = [ctx.path_for_program('doxygen'),
                                   os.path.join(ctx.calendon_home(), 'Doxyfile')]
        doxygen_exit_code: int = run_program(doxygen_args, cwd=(ctx.calendon_home()))
        if doxygen_exit_code != 0:
            return doxygen_exit_code

    source_dir: str = os.path.join(ctx.sphinx_dir(), 'source')
    build_dir: str = 'build'
    sphinx_args: List[str] = [ctx.path_for_program('sphinx-build'),
                              '-M', 'html', source_dir, build_dir]
    sphinx_exit_code: int = run_program(sphinx_args, cwd=ctx.sphinx_dir())
    if sphinx_exit_code != 0:
        return sphinx_exit_code

    if args.no_open:
        return sphinx_exit_code

    index: str = os.path.join(ctx.sphinx_dir(), 'build', 'html', 'index.html')
    return mp.open_file(index)
Ejemplo n.º 2
0
def cmd_pysetup(ctx: ProjectContext, args: argparse.Namespace) -> int:
    """Creates a virtual environment for helper module installs."""
    if not _verify_executable_exists(ctx, 'python3'):
        return 1

    if os.path.isfile(ctx.venv_dir()):
        print(f'Cannot create venv, {ctx.venv_dir()} is a file.')
        return 1

    if os.path.isdir(ctx.venv_dir()) and args.clean:
        shutil.rmtree(ctx.venv_dir())

    if not os.path.isdir(ctx.venv_dir()):
        venv_args = [(ctx.path_for_program('python3')), '-m', 'venv', ctx.venv_dir()]
        venv_setup = run_program(venv_args, cwd=ctx.calendon_home())
        if venv_setup != 0:
            print(f'Could not create virtual environment at {ctx.venv_dir()}')
            return venv_setup
        ctx.register_program('localpython3', os.path.join(ctx.venv_bin_dir(),
                                                          mp.root_to_executable('python')),
                             override=True)

    pip_upgrade_result = run_program(
        [(ctx.path_for_program('localpython3')), '-m', 'pip', 'install',
         '--upgrade', 'pip', 'setuptools', 'wheel'], cwd=ctx.calendon_home())
    if pip_upgrade_result != 0:
        print('Could not upgrade pip.')

    requirements_file = os.path.join(ctx.py_dir(), 'requirements.txt')
    if os.path.isfile(requirements_file):
        pip_install_args = [ctx.path_for_program('localpython3'), '-m', 'pip', 'install', '-r', requirements_file]
    else:
        required_dev_packages = ['mypy', 'pylint', 'pydocstyle', 'pycodestyle', 'bandit', 'colorama']
        required_dev_packages.extend(['sphinx', 'sphinx_rtd_theme', 'breathe'])
        pip_install_args = [ctx.path_for_program('localpython3'), '-m', 'pip', 'install']
        pip_install_args.extend(required_dev_packages)

    sphinx_build_path: str = os.path.join(ctx.venv_bin_dir(), mp.root_to_executable('sphinx-build'))
    ctx.register_program('sphinx-build', sphinx_build_path, override=True)
    return run_program(pip_install_args, cwd=ctx.calendon_home())
Ejemplo n.º 3
0
def write_demo_template(ctx: ProjectContext, name: str, dry_run: bool) -> bool:
    realname: str = sanitize_for_file_name(name)
    demo_src_dir: str = os.path.join(ctx.calendon_home(), 'src', 'demos')
    demo_source_file: str = os.path.join(demo_src_dir, realname + '.c')
    if os.path.exists(demo_source_file):
        print(f'Demo source file already exists: {demo_source_file}')
        return False

    if dry_run:
        print(f'Would have written demo to {demo_source_file}')
        return True

    with open(demo_source_file, 'w') as file:
        file.write(f'''#include <calendon/cn.h>
#include <calendon/log.h>

CnLogHandle LogSysSample;

CN_GAME_API bool Game_Init(void)
{{
    cnLog_RegisterSystem(&LogSysSample, "{realname}", CnLogVerbosityTrace);
    CN_TRACE(LogSysSample, "{realname} loaded");
    return true;
}}

CN_GAME_API void Game_Draw(void)
{{
}}

CN_GAME_API void Game_Tick(uint64_t dt)
{{
    CN_UNUSED(dt);
}}

CN_GAME_API void Game_Shutdown(void)
{{
}}
''')
    return True