noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.73k stars 507 forks source link

Template directory is wrong when the program is run from setuptools' entrypoint #187

Open edouardklein opened 8 years ago

edouardklein commented 8 years ago

Here is a minimal working example: file frmwe/init.py:

from flask import Flask
from flask_restplus import Resource, Api
APP = Flask(__name__)
api = Api(APP)

@api.route('/toto')
class Graph(Resource):
    "toto"
    def get(self):
        "toto toto"
        return "toto"

def bug():
    APP.run(debug=True)

if __name__ == "__main__":
    bug()

file setup.py:

from setuptools import setup

setup(name='frmwe',
      packages=['frmwe'],
      version='0.1',
      author='toto',
      author_email='toto@titi.tata',
      description='A minimal working example of a bug',
      keywords="bug",
      license='WTFPL',
      entry_points={
          'console_scripts': ['frmwe=frmwe:bug']
      },
      long_description='''No long description''')

When I run the file directly, i.e. by running python3 frmwe/__init__.py, everything runs as it should. When I install the program sudo python3 setup.py install, a wrapper is created by setuptools in my $PATH, and when I call this program (frmwe), I get the following error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python3.4/dist-packages/flask_restplus/api.py", line 537, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.4/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.4/dist-packages/flask_restplus/api.py", line 537, in error_router
    return original_handler(e)
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.4/dist-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.4/dist-packages/flask_restplus/api.py", line 359, in render_doc
    return apidoc.ui_for(self)
  File "/usr/local/lib/python3.4/dist-packages/flask_restplus/apidoc.py", line 41, in ui_for
    specs_url=api.specs_url)
  File "/usr/local/lib/python3.4/dist-packages/flask/templating.py", line 127, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 851, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 812, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/local/lib/python3.4/dist-packages/jinja2/environment.py", line 774, in _load_template
    cache_key = self.loader.get_source(self, name)[1]
  File "/usr/local/lib/python3.4/dist-packages/flask/templating.py", line 60, in get_source
    return loader.get_source(environment, local_name)
  File "/usr/local/lib/python3.4/dist-packages/jinja2/loaders.py", line 171, in get_source
    f = open_if_exists(filename)
  File "/usr/local/lib/python3.4/dist-packages/jinja2/utils.py", line 151, in open_if_exists
    return open(filename, mode)
NotADirectoryError: [Errno 20] Not a directory: '/usr/local/lib/python3.4/dist-packages/frmwe-0.1-py3.4.egg/frmwe/templates/swagger-ui.html'

We are trying to pinpoint the line where the template directory is erroneously set. We will report here if we find it.

davidism commented 7 years ago

egg is not really a supported format in Python / Jinja anymore. Actually install the package, don't just put the egg in site-packages. Generate the package as an sdist or bdist_wheel. Use pip to install packages, not setup.py directly.