jankatins / knitpy

knitpy: Elegant, flexible and fast dynamic report generation with python
https://github.com/jankatins/knitpy
Other
368 stars 29 forks source link

Readme has wrong instruction for functional use #36

Closed nehalecky closed 9 years ago

nehalecky commented 9 years ago

Hi @JanSchulz,

Hope all the issues I'm opening aren't too annoying. ;)

I'm trying to integrate knitpy into a python analytical tool so we can easily generate reports. Trying to call the library from within the application (instead of the command line) using the example pymd doc, I hit an error.

In [1]: import knitpy

In [2]: knitpy.render('knitpy_overview.pymd', out='html')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-29cbdc99edd7> in <module>()
----> 1 knitpy.render('knitpy_overview.pymd', out='html')

AttributeError: 'module' object has no attribute 'render'

Perhaps I am interpreting the instructions in the README incorrectly? Let me know how I can help more in diagnosing the issue. Thanks!

jankatins commented 9 years ago

Fire away with bugs: bugs just mean that knitpy is used :-)

from knitpy import Knitpy
Knitpy().render(....)

-> Bug in readme... -> Maybe add a functional way to use knitpy? Small wrapper which just does the above?

nehalecky commented 9 years ago

Sorry @JanSchulz, busy times!

So, when I try your suggestion, I hit an import error:

n [5]: from knitpy import Knitpy
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-87602d5a0aac> in <module>()
----> 1 from knitpy import Knitpy

ImportError: cannot import name Knitpy

I did a little digging, the knipy.py file contains:

from knitpy.knitpyapp import KnitpyApp

if __name__ == '__main__':
    KnitpyApp.launch_instance()

So, it's not there.... I'll, keep digging :)

nehalecky commented 9 years ago

Grepping for def render(, I got a lead at: https://github.com/JanSchulz/knitpy/blob/master/knitpy/knitpy.py#L692

This method is part of an epic Knitpy class, which I see imported in your test/__init__.py, ala

from knitpy.knitpy import Knitpy

Importing him yields a few ShimWarnings, likely identical the ones we discussed in #33.

In [2]: from knitpy.knitpy import Knitpy
/home/vagrant/miniconda-3.10.1/envs/energiscore-env/lib/python2.7/site-packages/IPython/config.py:13: ShimWarning: The `IPython.config` package has been deprecated. You should import from traitlets.config instead.
  "You should import from traitlets.config instead.", ShimWarning)
/home/vagrant/miniconda-3.10.1/envs/energiscore-env/lib/python2.7/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
  warn("IPython.utils.traitlets has moved to a top-level traitlets package.")
/home/vagrant/miniconda-3.10.1/envs/energiscore-env/lib/python2.7/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)

Calling like above description

In [4]: Knitpy.render('knitpy_overview.pymd')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-8ba938c6d726> in <module>()
----> 1 Knitpy.render('knitpy_overview.pymd')

TypeError: unbound method render() must be called with Knitpy instance as first argument (got str instance instead)

OK, try to call from instance:

In [5]: knitpy_test = Knitpy()

In [6]: knitpy_test.render('./knitpy_overview.pymd')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-51b5252ff961> in <module>()
----> 1 knitpy_test.render('./knitpy_overview.pymd')

/home/vagrant/miniconda-3.10.1/envs/energiscore-env/lib/python2.7/site-packages/knitpy/knitpy.pyc in render(self, filename, output)
    683
    684             # get the temporary md file
--> 685             self.convert(parsed, md_temp)
    686             if final_format.keep_md or self.keep_md:
    687                 mdfilename = basename+"."+final_format.name+".md"

/home/vagrant/miniconda-3.10.1/envs/energiscore-env/lib/python2.7/site-packages/knitpy/knitpy.pyc in convert(self, parsed, output)
    203             if entry[0] == TBLOCK:
    204                 context.mode="block"
--> 205                 self._process_code(entry[1], context=context)
    206             elif entry[0] == TINLINE:
    207                 context.mode="inline"

/home/vagrant/miniconda-3.10.1/envs/energiscore-env/lib/python2.7/site-packages/knitpy/knitpy.pyc in _process_code(self, input, context)
    310             self._run_lines(lines, context)
    311
--> 312         context.execution_finished()
    313
    314

/home/vagrant/miniconda-3.10.1/envs/energiscore-env/lib/python2.7/site-packages/knitpy/knitpy.pyc in execution_finished(self)
    783         for name in self.trait_names():
    784             if name in reset_needed:
--> 785                 self.traits()[name].set_default_value(self)

AttributeError: 'Instance' object has no attribute 'set_default_value'

Don't have any more time tonight, but wanted to ask for any tips? As always, much appreciated. :)

nehalecky commented 9 years ago

Oh, one last thing: even though the error above is the same as #34, with this path I am unfortunately unable to generate the files.

jankatins commented 9 years ago

There is now a PR which should fix all this... #38