Comments (5)
@Dreamsorcerer names like app.py
or main.py
is very common and can conflicting between lib and application. It's have sense if package can be use as lib or as application.
from aiohttp-devtools.
I think that's a bit of an unusual case, but if you can write a test to reproduce that, then it seems like a reasonable change.
from aiohttp-devtools.
Here are the simple steps to reproduce
Folder Structure
libs
- l1
- `__init__.py`
- app.py
app.py
app.py
from aiohttp import web
import sys
sys.path.insert(0, 'libs/l1')
class Main:
def __init__(self):
self.app = web.Application()
self.app.router.add_get('/', self.handle_request)
async def handle_request(self, request):
return web.Response(text="testing", content_type='text/html')
def create_app():
page = Main()
return page.app
libs/l1/app.py
print("I am app")
Test
adev runserver app.py --port=8080 --aux-port=8086 --verbose --no-livereload
[15:52:30] Root path not specified, using current working directory
[15:52:30] app_path is a file, returning it directly
[15:52:30] config loaded:
Config:
py_file: PosixPath('*********/test_devtools/app.py')
static_path: None
static_url: '/static/'
livereload: False
shutdown_by_url: False
path_prefix: '/_devtools'
app_factory_name: None
host: 'localhost'
main_port: 8080
aux_port: 8086
[15:52:30] successfully loaded "app" from "*********/test_devtools"
[15:52:30] found default attribute "create_app" in module "<module 'app' from '*********/test_devtools/app.py'>"
[15:52:30] Starting aux server at http://localhost:8086 ◆
[15:52:30] Starting dev server at http://localhost:8080 ●
======== Running on http://0.0.0.0:8086 ========
(Press CTRL+C to quit)
I am app
[15:52:30] successfully loaded "app" from "*********/test_devtools"
Process Process-1:
Traceback (most recent call last):
File "*********/test_devtools/venv/lib/python3.11/site-packages/aiohttp_devtools/runserver/config.py", line 160, in import_app_factory
attr = getattr(module, self.app_factory_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'app' has no attribute 'create_app'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
self.run()
File "/usr/lib/python3.11/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "*********/test_devtools/venv/lib/python3.11/site-packages/aiohttp_devtools/runserver/serve.py", line 168, in serve_main_app
app_factory = config.import_app_factory()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "*********/test_devtools/venv/lib/python3.11/site-packages/aiohttp_devtools/runserver/config.py", line 162, in import_app_factory
raise AdevConfigError("Module '{}' does not define a '{}' attribute/class".format(
aiohttp_devtools.exceptions.AiohttpDevConfigError: Module 'app.py' does not define a 'create_app' attribute/class
from aiohttp-devtools.
Here are the simple steps to reproduce
I meant a test, in a PR.
from aiohttp-devtools.
Here is the reproducable test, seems its happening only with process.. so can't mock process in this test.
# test_runserver_main.py
from multiprocessing import set_start_method
from aiohttp_devtools.runserver.watch import AppTask
@forked
def test_start_runserver_with_multi_app_modules(tmpworkdir, event_loop, capfd):
mktree(tmpworkdir, {
'app.py': f"""\
from aiohttp import web
import sys
sys.path.insert(0, '{tmpworkdir}/libs/l1')
async def hello(request):
return web.Response(text='<h1>hello world</h1>', content_type='text/html')
async def create_app():
a = web.Application()
a.router.add_get('/', hello)
return a
""",
"libs": {
"l1": {
"__init__.py": "",
"app.py": "print('wrong_import')"
}
}
})
set_start_method('spawn')
config = Config(app_path="app.py", root_path=tmpworkdir, main_port=0, app_factory_name="create_app")
config.import_app_factory()
app_task = AppTask(config)
app_task._start_dev_server()
app_task._process.join(2)
captured = capfd.readouterr()
assert captured.out == "wrong_import\n"
Here is the working test..
from aiohttp-devtools.
Related Issues (20)
- [feature-request] Adding additional parameters HOT 2
- Reload on additional file changes HOT 2
- No graceful shutdown when CTRL-C HOT 3
- Auto reload get triggered by Emacs tmp files HOT 2
- Incorrect behavior if __name__ == '__main__': sys.exit(main()) HOT 2
- Remove/enable --boxed
- As of 3.10, the *loop* parameter was removed from Event HOT 2
- Not working with python 3.10 version HOT 2
- v1.0 broken (missing JS)
- How do I use aiohttp-devtools with the PyCharm debugger? HOT 2
- runserver doesn't respect host setting HOT 3
- async_generator object has no attribute lock HOT 3
- logging / log format HOT 5
- Looking to wrong server to find static files. HOT 2
- Cleanup context is not always run HOT 7
- Cleanup context is not run on reload on Windows HOT 17
- Host setting not respected HOT 2
- Tests leave python processes and an open port behind
- Let's put `aiohttp-devtools` under the `aio-libs` org on PyPI HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp-devtools.