Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitting APIs over multiple files #881

Open
sugizo opened this issue Feb 8, 2021 · 0 comments
Open

Splitting APIs over multiple files #881

sugizo opened this issue Feb 8, 2021 · 0 comments

Comments

@sugizo
Copy link

sugizo commented Feb 8, 2021

something.py

import hug
@hug.get('/')
def say_hi():
    return 'hello from something'

init.py

import hug
from . import something
@hug.get('/')
def say_hi():
    return "Hi from root"
@hug.extend_api('/something')
def something_api():
    return [something]
$ python __init__.py 
Traceback (most recent call last):
  File "__init__.py", line 2, in <module>
    from . import something
ImportError: attempted relative import with no known parent package
$ hug -f __init__.py 
Traceback (most recent call last):
  File "/Users/MacBookPro/miniconda3/envs/python3_test/bin/hug", line 8, in <module>
    sys.exit(development_runner.hug.interface.cli())
  File "/Users/MacBookPro/miniconda3/envs/python3_test/lib/python3.8/site-packages/hug/interface.py", line 650, in __call__
    raise exception
  File "/Users/MacBookPro/miniconda3/envs/python3_test/lib/python3.8/site-packages/hug/interface.py", line 646, in __call__
    result = self.output(self.interface(**pass_to_function), context)
  File "/Users/MacBookPro/miniconda3/envs/python3_test/lib/python3.8/site-packages/hug/interface.py", line 129, in __call__
    return __hug_internal_self._function(*args, **kwargs)
  File "/Users/MacBookPro/miniconda3/envs/python3_test/lib/python3.8/site-packages/hug/development_runner.py", line 65, in hug
    api_module = importlib.machinery.SourceFileLoader(file.split(".")[0], file).load_module()
  File "<frozen importlib._bootstrap_external>", line 462, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 962, in load_module
  File "<frozen importlib._bootstrap_external>", line 787, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "__init__.py", line 2, in <module>
    from . import something
ImportError: attempted relative import with no known parent package

not work on hug-2.6.1
python 3.8

question
how to run hug rest api over multiple files ?

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant