Fuyukai / Kyoukai

[OLD] A fully async web framework for Python3.5+ using asyncio
https://mirai.veriny.tf
MIT License
298 stars 14 forks source link

Doc issue with Asphalt usage #28

Closed smlbiobot closed 7 years ago

smlbiobot commented 7 years ago

Hi—

Same issue with this page: https://mirai.veriny.tf/en/latest/core/asphalt.html#

I can’t actually figure out what is wrong. I put this in my code as what the page asked me to:

from asphalt.core import ContainerComponent, Context
from kyoukai import Kyoukai
from kyoukai import KyoukaiComponent

app = Kyoukai("api")

class AppContainer(ContainerComponent):
    async def start(self, ctx: Context):
        self.add_component(
            'kyoukai', KyoukaiComponent, ip="127.0.0.1", port=4444, app=app)
        await super().start(ctx)

But just get a bunch of error messages and I don’t know how to fix / what is wrong:

[409]:$ asphalt run config.yml
INFO:asphalt.core.runner:Running in development mode
Traceback (most recent call last):
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/asphalt/core/utils.py", line 32, in resolve_reference
    obj = import_module(modulename)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'application'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/sml/Virtualenvs/crweb/bin/asphalt", line 11, in <module>
    sys.exit(main())
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/asphalt/core/command.py", line 34, in run
    run_application(**config)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/asphalt/core/runner.py", line 101, in run_application
    component = component_types.create_object(**component)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/asphalt/core/utils.py", line 162, in create_object
    plugin_class = self.resolve(type)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/asphalt/core/utils.py", line 136, in resolve
    return resolve_reference(obj)
  File "/Users/sml/Virtualenvs/crweb/lib/python3.6/site-packages/asphalt/core/utils.py", line 35, in resolve_reference
    'error resolving reference {}: could not import module'.format(ref)) from e
LookupError: error resolving reference application.container:AppContainer: could not import module

As an addendum, this is currently the structure of my project folder:

[413]:$ tree
.
├── README.md
├── application
│   ├── __pycache__
│   │   └── container.cpython-36.pyc
│   └── container.py
├── config.yml
├── static
└── templates
    └── index.html
smlbiobot commented 7 years ago

Ok I have solved the error, after reading the Asphalt doc, it seems that I have to run this instead:

PYTHONPATH=. asphalt run config.yaml

Reference: Asphalt documentation on how to run config if it’s not in site-packages

Fuyukai commented 7 years ago

...I had that exact answer written in the box, but I must've closed the tab without commenting. Sorry about that.