Skip to content
Myr

ignore colon with slash when split app_import_path

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Flask currently supports importing app through a combination of module path and app variable name, such as '/usr/app.py:my_app'. When the module path contains a colon, it will conflict with this import way and a `flask.cli.NoAppException` will be raised. A file path on a Windows system may contain a colon followed by a slash. So we solved this problem on Windows by ignoring the colon followed by a slash when we split app_import_path. Fix issue #2961.

authored by garenchan · committed by garenchan · parent 363205b · Browse files · 2 files+17 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−4 removed

  • tests:+16 added−3 removed
  • other:+1 added−1 removed

2 files+17 added−4 removed

modified:flask/cli.py+1 added-1 removed
367 unmodified lines
368 if self.create_app is not None:369 app = call_factory(self, self.create_app)370 else:371 if self.app_import_path:372 path, name = (self.app_import_path.split(':', 1) + [None])[:2]372 path, name = (re.split(r':(?![\\/])', self.app_import_path, 1) + [None])[:2]373 import_name = prepare_import(path)374 app = locate_app(self, import_name, name)375 else:376 for path in ('wsgi.py', 'app.py'):
527 unmodified lines
modified:tests/test_cli.py+16 added-3 removed
259 unmodified lines
260261def test_scriptinfo(test_apps, monkeypatch):262 """Test of ScriptInfo."""263 obj = ScriptInfo(app_import_path="cliapp.app:testapp")264 assert obj.load_app().name == "testapp"265 assert obj.load_app().name == "testapp"264 app = obj.load_app()265 assert app.name == "testapp"266 assert obj.load_app() is app267268 # import app with module's absolute path269 cli_app_path = os.path.abspath(os.path.join(270 os.path.dirname(__file__), 'test_apps', 'cliapp', 'app.py'))271 obj = ScriptInfo(app_import_path=cli_app_path)272 app = obj.load_app()273 assert app.name == 'testapp'274 assert obj.load_app() is app275 obj = ScriptInfo(app_import_path=cli_app_path + ':testapp')276 app = obj.load_app()277 assert app.name == 'testapp'278 assert obj.load_app() is app279280 def create_app(info):281 return Flask("createapp")282283 obj = ScriptInfo(create_app=create_app)284 app = obj.load_app()285 assert app.name == "createapp"273 assert obj.load_app() == app286 assert obj.load_app() is app287288 obj = ScriptInfo()289 pytest.raises(NoAppException, obj.load_app)290
286 unmodified lines