nice error for missing __init__.py

7 views
Skip to first unread message

zsol...@gmail.com

unread,
Nov 27, 2022, 5:50:33 AM11/27/22
to pylons-discuss
Upon upgrading to 2.0 I just removed my empty __init__.py files or at least I tried to (hoping I won't need them any more).

Eventually I realised I had to put some of them back as config.scan() broke without them.

My recommendation is that if possible, can you make a better error message for this? Because I basically got a 73 line long stack trace, which contained absolutely no information about what is the problem. I mean, just as a nice to have, for other users who happen run into this very long stacktrace.

2022-11-27 11:44:39,679 ERROR [waitress] Exception while serving /
Traceback (most recent call last):
  File "python3.10/site-packages/waitress/channel.py", line 428, in service
    task.service()
  File "python3.10/site-packages/waitress/task.py", line 168, in service
    self.execute()
  File "python3.10/site-packages/waitress/task.py", line 434, in execute
    app_iter = self.channel.server.application(environ, start_response)
  File "python3.10/site-packages/pyramid/router.py", line 270, in __call__
    response = self.execution_policy(environ, self)
  File "python3.10/site-packages/pyramid/router.py", line 276, in default_execution_policy
    return router.invoke_request(request)
  File "python3.10/site-packages/pyramid/router.py", line 245, in invoke_request
    response = handle_request(request)
  File "python3.10/site-packages/pyramid_tm/__init__.py", line 178, in tm_tween
    raise exc from None
  File "python3.10/site-packages/pyramid_tm/__init__.py", line 145, in tm_tween
    response = handler(request)
  File "python3.10/site-packages/pyramid/tweens.py", line 43, in excview_tween
    response = _error_handler(request, exc)
  File "python3.10/site-packages/pyramid/tweens.py", line 17, in _error_handler
    reraise(*exc_info)
  File "python3.10/site-packages/pyramid/util.py", line 733, in reraise
    raise value
  File "python3.10/site-packages/pyramid/tweens.py", line 41, in excview_tween
    response = handler(request)
  File "python3.10/site-packages/pyramid/router.py", line 143, in handle_request
    response = _call_view(
  File "python3.10/site-packages/pyramid/view.py", line 674, in _call_view
    response = view_callable(context, request)
  File "python3.10/site-packages/pyramid/viewderivers.py", line 512, in csrf_view
    return view(context, request)
  File "md_server/view_derivers.py", line 30, in wrapper_view
    response = view(context, request)
  File "md_server/view_derivers.py", line 43, in wrapper_view
    response = view(context, request)
  File "md_server/view_derivers.py", line 65, in wrapper_view
    response = view(context, request)
  File "md_server/view_derivers.py", line 142, in wrapper_view
    response = view(context, request)
  File "python3.10/site-packages/pyramid/viewderivers.py", line 450, in rendered_view
    response = view_renderer.render_view(
  File "python3.10/site-packages/pyramid/renderers.py", line 443, in render_view
    return self.render_to_response(response, system, request=request)
  File "python3.10/site-packages/pyramid/renderers.py", line 466, in render_to_response
    result = self.render(value, system_values, request=request)
  File "python3.10/site-packages/pyramid/renderers.py", line 462, in render
    result = renderer(value, system_values)
  File "python3.10/site-packages/pyramid_jinja2/__init__.py", line 260, in __call__
    template = self.template_loader()
  File "python3.10/site-packages/pyramid_jinja2/__init__.py", line 275, in template_loader
    return self.environment.get_template(name_with_package)
  File "python3.10/site-packages/jinja2/environment.py", line 1010, in get_template
    return self._load_template(name, globals)
  File "python3.10/site-packages/jinja2/environment.py", line 969, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
  File "python3.10/site-packages/jinja2/loaders.py", line 126, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "python3.10/site-packages/pyramid_jinja2/__init__.py", line 197, in get_source
    src = self._get_absolute_source(template)
  File "python3.10/site-packages/pyramid_jinja2/__init__.py", line 137, in _get_absolute_source
    filename = abspath_from_asset_spec(template)
  File "python3.10/site-packages/pyramid/asset.py", line 43, in abspath_from_asset_spec
    return pkg_resources.resource_filename(pname, filename)
  File "python3.10/site-packages/pkg_resources/__init__.py", line 1154, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "python3.10/site-packages/pkg_resources/__init__.py", line 361, in get_provider
    return _find_adapter(_provider_factories, loader)(module)
  File "python3.10/site-packages/pkg_resources/__init__.py", line 1403, in __init__
    self.module_path = os.path.dirname(getattr(module, '__file__', ''))
  File "/Users/user/.pyenv/versions/3.10.8/lib/python3.10/posixpath.py", line 152, in dirname
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Zsolt


Bert JW Regeer

unread,
Nov 27, 2022, 2:13:41 PM11/27/22
to pylons-...@googlegroups.com
The stack trace you just posted is related to Jinja2 and attempts to use pkg_resources (in fact it is failing inside pkg_resources) not config.scan()…

As for the venusian issue (and related pkg_resources issues) of not being able to scan folders without __init__.py see https://github.com/Pylons/venusian/issues/68

Bert
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/9341de88-f1dd-4d0e-8cf4-13f98a649875n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages