Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with "production" code #59

Open
mateusoliveira43 opened this issue Sep 4, 2022 · 1 comment
Open

Issue with "production" code #59

mateusoliveira43 opened this issue Sep 4, 2022 · 1 comment
Assignees

Comments

@mateusoliveira43
Copy link
Owner

What is the issue?
There is no command to transform the written code with CLY?! in a single file that can later be executed with

curl path/to/file/in/github | python -

What do you suggest?
Implement this feature.

@mateusoliveira43 mateusoliveira43 self-assigned this Sep 4, 2022
@mateusoliveira43
Copy link
Owner Author

first ideas

import ast
from collections import namedtuple

Import = namedtuple("Import", ["module", "name", "alias"])


def get_imports(path):
    imports = []
    with open(path) as fh:
       root = ast.parse(fh.read(), path)

    for node in ast.walk(root):
        if isinstance(node, ast.Import):
            module = []
        elif isinstance(node, ast.ImportFrom):
            if node.module:
                module = node.module.split('.')
            else:
                module = []
            for _ in range(node.level):
                module.insert(0, ".")
        else:
            continue

        for n in node.names:
            imports.append(Import(module, n.name.split('.'), n.asname))

    return imports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant