fix uninstalled package tests under tox
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 88bcf78 · Browse files · 3 files·+15 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+15 added−7 removed
- tests:+0 added−3 removed
- other:+15 added−4 removed
Provenance
- Commit
3ba37d2- Tree
f71b48d- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
88bcf78
3 files changed+15 added−7 removed
modified:src/flask/scaffold.py+14 added-4 removed
1 import importlib.util2 import os3+import pathlib4 import pkgutil5 import sys6 import typing as t7 from collections import defaultdict772 unmodified lines780 f" import hooks."781 )782 783 784+def _path_is_relative_to(path: pathlib.PurePath, base: str) -> bool:785+ # Path.is_relative_to doesn't exist until Python 3.9786+ try:787+ path.relative_to(base)788+ return True789+ except ValueError:790+ return False791+792+793 def _find_package_path(import_name):794 """Find the path that contains the package or module."""795 root_mod_name, _, _ = import_name.partition(".")796 14 unmodified lines811 if root_spec.origin in {"namespace", None}:812 package_spec = importlib.util.find_spec(import_name)813 if package_spec is not None and package_spec.submodule_search_locations:814 # Pick the path in the namespace that contains the submodule.805- package_path = os.path.commonpath(806- package_spec.submodule_search_locations815+ package_path = pathlib.Path(816+ os.path.commonpath(package_spec.submodule_search_locations)817 )818 search_locations = (819 location820 for location in root_spec.submodule_search_locations811- if package_path.startswith(location)821+ if _path_is_relative_to(package_path, location)822 )823 else:824 # Pick the first path.825 search_locations = iter(root_spec.submodule_search_locations)48 unmodified lines874 package_path = _find_package_path(import_name)875 py_prefix = os.path.abspath(sys.prefix)876 877 # installed to the system868- if package_path.startswith(py_prefix):878+ if _path_is_relative_to(pathlib.PurePath(package_path), py_prefix):879 return py_prefix, package_path880 881 site_parent, site_folder = os.path.split(package_path)882 17 unmodified linesmodified:tests/test_instance_config.py-3 removed
13 unmodified lines14 app = flask.Flask(__name__, instance_path=str(modules_tmpdir))15 assert app.instance_path == str(modules_tmpdir)16 17 18-@pytest.mark.xfail(reason="weird interaction with tox")18 def test_main_module_paths(modules_tmpdir, purge_module):19 app = modules_tmpdir.join("main_app.py")20 app.write('import flask\n\napp = flask.Flask("__main__")')21 purge_module("main_app")3 unmodified lines25 here = os.path.abspath(os.getcwd())26 assert app.instance_path == os.path.join(here, "instance")27 28 30-@pytest.mark.xfail(reason="weird interaction with tox")29 def test_uninstalled_module_paths(modules_tmpdir, purge_module):30 app = modules_tmpdir.join("config_module_app.py").write(31 "import os\n"32 "import flask\n"6 unmodified lines39 40 assert app.instance_path == str(modules_tmpdir.join("instance"))41 42 45-@pytest.mark.xfail(reason="weird interaction with tox")43 def test_uninstalled_package_paths(modules_tmpdir, purge_module):44 app = modules_tmpdir.mkdir("config_package_app")45 init = app.join("__init__.py")46 init.write(91 unmodified linesmodified:tox.ini+1 added
7 unmodified lines8 docs9 skip_missing_interpreters = true10 11 [testenv]12+envtmpdir = {toxworkdir}/tmp/{envname}13 deps =14 -r requirements/tests.txt15 min: -r requirements/tests-pallets-min.txt16 dev: -r requirements/tests-pallets-dev.txt18 unmodified lines