Exemplo n.º 1
0
def run_py(path: str):
    '''
    run a file like `python ?`.
    '''

    py_file = FileInfo(path)
    if not py_file.is_file():
        raise FileNotFoundError(f'{path} is not a file')

    with use_path(py_file.path.dirname):
        return runpy.run_path(py_file.path, run_name='__main__')
Exemplo n.º 2
0
def get_global_funcnames(pyfile: fsoopify.FileInfo) -> list:
    'get a list of global funcnames (use for entry_points.console_scripts).'
    assert pyfile.is_file()

    import ast

    funcnames = []
    mod = ast.parse(pyfile.read_text())
    for stmt in mod.body:
        if isinstance(stmt, ast.FunctionDef):
            funcnames.append(stmt.name)
    return funcnames
Exemplo n.º 3
0
    def parse(cls, path):
        fileinfo = FileInfo(path)
        if not fileinfo.is_file():
            logger.debug('no exists metadata found.')
            return None

        metadata = PackageMetadata()

        fileinfo.load()
        try:
            content = fileinfo.load()
        except SerializeError:
            raise QuickExit(
                '[ERROR] <{}> is not a valid json file. try delete it for continue.'
                .format(path))

        metadata.__dict__.update(content)

        return metadata