From 4397783acf216513ae1e8ab1095a7043f997cf0b Mon Sep 17 00:00:00 2001 From: Yuki Igarashi Date: Sat, 27 Jun 2020 20:47:35 +0900 Subject: [PATCH 1/6] Use absolute path when checking source duplication error --- mypy/build.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index c94ca94a3d702..ac0c1b9d30e5b 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2758,7 +2758,7 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, # Note: Running this each time could be slow in the daemon. If it's a problem, we # can do more work to maintain this incrementally. - seen_files = {st.path: st for st in graph.values() if st.path} + seen_files = {os.path.abspath(st.path): st for st in graph.values() if st.path} # Collect dependencies. We go breadth-first. # More nodes might get added to new as we go, but that's fine. @@ -2805,16 +2805,18 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, if dep in st.dependencies_set: st.suppress_dependency(dep) else: - if newst.path in seen_files: - manager.errors.report( - -1, 0, - "Source file found twice under different module names: '{}' and '{}'". - format(seen_files[newst.path].id, newst.id), - blocker=True) - manager.errors.raise_error() - if newst.path: - seen_files[newst.path] = newst + newst_path = os.path.abspath(newst.path) + + if newst_path in seen_files: + manager.errors.report( + -1, 0, + "Source file found twice under different module names: " + "'{}' and '{}'".format(seen_files[newst_path].id, newst.id), + blocker=True) + manager.errors.raise_error() + + seen_files[newst_path] = newst assert newst.id not in graph, newst.id graph[newst.id] = newst From ad54c7f55f5061c4dc6ce1a3a4156f7118ea3c94 Mon Sep 17 00:00:00 2001 From: Yuki Igarashi Date: Sat, 4 Jul 2020 16:03:40 +0900 Subject: [PATCH 2/6] Query both relative and absolute path in module duplication check --- mypy/build.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index ac0c1b9d30e5b..d9905cab99bce 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2758,7 +2758,7 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, # Note: Running this each time could be slow in the daemon. If it's a problem, we # can do more work to maintain this incrementally. - seen_files = {os.path.abspath(st.path): st for st in graph.values() if st.path} + seen_files = {st.path: st for st in graph.values() if st.path} # Collect dependencies. We go breadth-first. # More nodes might get added to new as we go, but that's fine. @@ -2806,17 +2806,26 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, st.suppress_dependency(dep) else: if newst.path: - newst_path = os.path.abspath(newst.path) + newst_path = newst.path + seen_state = seen_files.get(newst_path) - if newst_path in seen_files: + if seen_state is None: + if os.path.isabs(newst_path): + newst_path = os.path.relpath(newst_path) + else: + newst_path = os.path.abspath(newst_path) + + seen_state = seen_files.get(newst_path) + + if seen_state is not None: manager.errors.report( -1, 0, "Source file found twice under different module names: " - "'{}' and '{}'".format(seen_files[newst_path].id, newst.id), + "'{}' and '{}'".format(seen_state.id, newst.id), blocker=True) manager.errors.raise_error() - seen_files[newst_path] = newst + seen_files[newst.path] = newst assert newst.id not in graph, newst.id graph[newst.id] = newst From 7b2795b0049bc7a029ffe52781f632816e43016f Mon Sep 17 00:00:00 2001 From: Yuki Igarashi Date: Sat, 4 Jul 2020 17:02:35 +0900 Subject: [PATCH 3/6] Handle failure case when converting abspath to relpath --- mypy/build.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index d9905cab99bce..60adfa12b0df9 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2811,11 +2811,16 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, if seen_state is None: if os.path.isabs(newst_path): - newst_path = os.path.relpath(newst_path) + try: + newst_path = os.path.relpath(newst_path) + except ValueError: + # Ignore when newst_path does not start with os.curdir + pass + else: + seen_state = seen_files.get(newst_path) else: newst_path = os.path.abspath(newst_path) - - seen_state = seen_files.get(newst_path) + seen_state = seen_files.get(newst_path) if seen_state is not None: manager.errors.report( From 749c3dfd7ccda59bb76cfe4d5f80a66c08707de2 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Sat, 17 Oct 2020 22:15:16 -0700 Subject: [PATCH 4/6] Revert "Handle failure case when converting abspath to relpath" This reverts commit 7b2795b0049bc7a029ffe52781f632816e43016f. --- mypy/build.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index 60adfa12b0df9..d9905cab99bce 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2811,16 +2811,11 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, if seen_state is None: if os.path.isabs(newst_path): - try: - newst_path = os.path.relpath(newst_path) - except ValueError: - # Ignore when newst_path does not start with os.curdir - pass - else: - seen_state = seen_files.get(newst_path) + newst_path = os.path.relpath(newst_path) else: newst_path = os.path.abspath(newst_path) - seen_state = seen_files.get(newst_path) + + seen_state = seen_files.get(newst_path) if seen_state is not None: manager.errors.report( From c47300b8a8183066f4fb87f04405487e750b95f9 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Sat, 17 Oct 2020 22:15:25 -0700 Subject: [PATCH 5/6] Revert "Query both relative and absolute path in module duplication check" This reverts commit ad54c7f55f5061c4dc6ce1a3a4156f7118ea3c94. --- mypy/build.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index d9905cab99bce..ac0c1b9d30e5b 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2758,7 +2758,7 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, # Note: Running this each time could be slow in the daemon. If it's a problem, we # can do more work to maintain this incrementally. - seen_files = {st.path: st for st in graph.values() if st.path} + seen_files = {os.path.abspath(st.path): st for st in graph.values() if st.path} # Collect dependencies. We go breadth-first. # More nodes might get added to new as we go, but that's fine. @@ -2806,26 +2806,17 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, st.suppress_dependency(dep) else: if newst.path: - newst_path = newst.path - seen_state = seen_files.get(newst_path) + newst_path = os.path.abspath(newst.path) - if seen_state is None: - if os.path.isabs(newst_path): - newst_path = os.path.relpath(newst_path) - else: - newst_path = os.path.abspath(newst_path) - - seen_state = seen_files.get(newst_path) - - if seen_state is not None: + if newst_path in seen_files: manager.errors.report( -1, 0, "Source file found twice under different module names: " - "'{}' and '{}'".format(seen_state.id, newst.id), + "'{}' and '{}'".format(seen_files[newst_path].id, newst.id), blocker=True) manager.errors.raise_error() - seen_files[newst.path] = newst + seen_files[newst_path] = newst assert newst.id not in graph, newst.id graph[newst.id] = newst From b511aeac9402e39411d40662d4e77bc693057d73 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Sat, 17 Oct 2020 22:24:58 -0700 Subject: [PATCH 6/6] Compute abspath once --- mypy/build.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mypy/build.py b/mypy/build.py index ac0c1b9d30e5b..367adb7d5e8b0 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -1699,6 +1699,7 @@ class State: order = None # type: int # Order in which modules were encountered id = None # type: str # Fully qualified module name path = None # type: Optional[str] # Path to module source + abspath = None # type: Optional[str] # Absolute path to module source xpath = None # type: str # Path or '' source = None # type: Optional[str] # Module source code source_hash = None # type: Optional[str] # Hash calculated based on the source code @@ -1800,6 +1801,8 @@ def __init__(self, if follow_imports == 'silent': self.ignore_all = True self.path = path + if path: + self.abspath = os.path.abspath(path) self.xpath = path or '' if path and source is None and self.manager.fscache.isdir(path): source = '' @@ -2758,7 +2761,7 @@ def load_graph(sources: List[BuildSource], manager: BuildManager, # Note: Running this each time could be slow in the daemon. If it's a problem, we # can do more work to maintain this incrementally. - seen_files = {os.path.abspath(st.path): st for st in graph.values() if st.path} + seen_files = {st.abspath: st for st in graph.values() if st.path} # Collect dependencies. We go breadth-first. # More nodes might get added to new as we go, but that's fine.