In [1]:
import ast
import os

In [2]:
from conda_skeletor.setup_parser import SetupScraper

In [3]:
setup_py = os.path.join(os.path.expanduser('~/dev/conda/conda-skeletor/setup.py'))

In [4]:
with open(setup_py, 'r') as f:
    code = f.read()
tree = ast.parse(code)

In [5]:
scraper = SetupScraper()
scraper.visit(tree)


name = name, value = {'s': 'conda_skeletor', 'col_offset': 9, 'lineno': 5}
name = version, value = {'ctx': <_ast.Load object at 0x7f5b138009e8>, 'id': 'VERSION', 'col_offset': 12, 'lineno': 6}
name = author, value = {'s': 'Eric Dill', 'col_offset': 11, 'lineno': 7}
name = author_email, value = {'s': 'thedizzle@gmail.com', 'col_offset': 17, 'lineno': 8}
name = description, value = {'s': 'Automagically generate conda recipes from your source', 'col_offset': 16, 'lineno': 9}
name = url, value = {'s': 'http://github.com/ericdill/conda-skeletor', 'col_offset': 8, 'lineno': 10}
name = platforms, value = {'s': 'Cross platform (Linux, Mac OSX, Windows)', 'col_offset': 14, 'lineno': 11}
name = license, value = {'s': 'GPLv3', 'col_offset': 12, 'lineno': 12}
name = packages, value = {'args': [], 'keywords': [], 'kwargs': None, 'lineno': 14, 'col_offset': 13, 'func': <_ast.Attribute object at 0x7f5b09e54c50>, 'starargs': None}
name = package_data, value = {'values': [<_ast.List object at 0x7f5b09e54d68>], 'keys': [<_ast.Str object at 0x7f5b09e54d30>], 'col_offset': 17, 'lineno': 16}
name = include_package_data, value = {'value': True, 'col_offset': 25, 'lineno': 17}
name = install_requires, value = {'ctx': <_ast.Load object at 0x7f5b138009e8>, 'elts': [<_ast.Str object at 0x7f5b09e54eb8>], 'col_offset': 21, 'lineno': 19}
name = entry_points, value = {'values': [<_ast.List object at 0x7f5b09e54f98>], 'keys': [<_ast.Str object at 0x7f5b09e54f60>], 'col_offset': 17, 'lineno': 21}

In [6]:
scraper.setup_info


Out[6]:
[]

In [7]:
scraper.setup_node


Out[7]:
<_ast.Call at 0x7fb05f7c92e8>

In [8]:
vars(scraper.setup_node)


Out[8]:
{'args': [],
 'col_offset': 0,
 'func': <_ast.Name at 0x7fb05f7c9860>,
 'keywords': [<_ast.keyword at 0x7fb05f7c9898>,
  <_ast.keyword at 0x7fb05f7c9908>,
  <_ast.keyword at 0x7fb05f7c9978>,
  <_ast.keyword at 0x7fb05f7c99e8>,
  <_ast.keyword at 0x7fb05f7c9a58>,
  <_ast.keyword at 0x7fb05f7c9ac8>,
  <_ast.keyword at 0x7fb05f7c9b38>,
  <_ast.keyword at 0x7fb05f7c9ba8>,
  <_ast.keyword at 0x7fb05f7c9c18>,
  <_ast.keyword at 0x7fb05f7c9cf8>,
  <_ast.keyword at 0x7fb05f7c9e10>,
  <_ast.keyword at 0x7fb05f7c9e80>,
  <_ast.keyword at 0x7fb05f7c9f28>],
 'kwargs': None,
 'lineno': 4,
 'starargs': None}

In [22]:
setup_func = """
def setup(*args, **kwargs):
    print('args\\n----')
    for arg in args:
        print(arg)
    print("\\nkwargs\\n------")
    for kwarg in kwargs:
        print(kwargs)
    
    return args, kwargs
"""
setup_call= """

setup('cat', 'dog', frank='person')
"""

In [23]:
setup_func += setup_call

In [24]:
setup_func


Out[24]:
'\ndef setup(*args, **kwargs):\n    print(\'args\\n----\')\n    for arg in args:\n        print(arg)\n    print("\\nkwargs\\n------")\n    for kwarg in kwargs:\n        print(kwargs)\n    \n    return args, kwargs\n\n\nsetup(\'cat\', \'dog\', frank=\'person\')\n'

In [25]:
tree = ast.parse(setup_func, '<ast>')

In [26]:
compiled = compile(tree, 'setup.pyc', 'exec')

In [27]:
exec(compiled)


args
----
cat
dog

kwargs
------
{'frank': 'person'}

In [9]:
compiled.


Out[9]:
'setup.py'

In [6]:
ls


build.sh            meta.yaml                   test_regex.ipynb
conda-skeletor.yml  rewrite-setup-dot-py.ipynb  Untitled.ipynb

In [14]:
import setup


---------------------------------------------------------------------------
VersioneerBadRootError                    Traceback (most recent call last)
<ipython-input-14-614b2480e525> in <module>()
----> 1 import setup

/home/edill/dev/python/scikit-xray/setup.py in <module>()
     17 setup(
     18     name='scikit-xray',
---> 19     version=versioneer.get_version(),
     20     cmdclass=versioneer.get_cmdclass(),
     21     author='Brookhaven National Lab',

/home/edill/dev/python/scikit-xray/versioneer.py in get_version()
   1403 
   1404 def get_version():
-> 1405     return get_versions()["version"]
   1406 
   1407 

/home/edill/dev/python/scikit-xray/versioneer.py in get_versions(verbose)
   1336         del sys.modules["versioneer"]
   1337 
-> 1338     root = get_root()
   1339     cfg = get_config_from_root(root)
   1340 

/home/edill/dev/python/scikit-xray/versioneer.py in get_root()
    374                "or in a way that lets it use sys.argv[0] to find the root "
    375                "(like 'python path/to/setup.py COMMAND').")
--> 376         raise VersioneerBadRootError(err)
    377     try:
    378         # Certain runtime workflows (setup.py install/develop in a setuptools

VersioneerBadRootError: Versioneer was unable to run the project root directory. Versioneer requires setup.py to be executed from its immediate directory (like 'python setup.py COMMAND'), or in a way that lets it use sys.argv[0] to find the root (like 'python path/to/setup.py COMMAND').

In [ ]:
exec(compiled)

In [ ]:
tree = ast.parse("print('hello world')")

In [ ]:
ast.k