Skip to content

Commit b1030a4

Browse files
authored
Fixes problems with new poetry release (#40)
* Fixes problems with new poetry release * Fixes problems with new poetry release * Fixes problems with new poetry release
1 parent 2fe8d1c commit b1030a4

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

pytest_mypy_plugins/collect.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@
1818

1919

2020
class File:
21-
def __init__(self, path: str, content: str):
21+
def __init__(self, path: str, content: str) -> None:
2222
self.path = path
2323
self.content = content
2424

2525

2626
def parse_test_files(test_files: List[Dict[str, Any]]) -> List[File]:
2727
files: List[File] = []
2828
for test_file in test_files:
29-
path = test_file.get("path")
30-
if not path:
31-
path = "main.py"
32-
29+
path = test_file.get("path", "main.py")
3330
file = File(path=path, content=test_file.get("content", ""))
3431
files.append(file)
3532
return files

pytest_mypy_plugins/item.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,29 @@ def typecheck_in_new_subprocess(
172172
import distutils.spawn
173173

174174
mypy_executable = distutils.spawn.find_executable("mypy")
175-
assert mypy_executable is not None
175+
assert mypy_executable is not None, "mypy executable is not found"
176176

177177
# add current directory to path
178-
self.environment_variables["PYTHONPATH"] = str(execution_path)
178+
self.environment_variables["PYTHONPATH"] = ":".join(
179+
[
180+
os.environ.get("PYTHONPATH", ""),
181+
str(execution_path),
182+
]
183+
)
184+
185+
# adding proper MYPYPATH variable
186+
mypy_path_parts = []
187+
existing_mypy_path = os.environ.get("MYPYPATH", "")
188+
if existing_mypy_path:
189+
mypy_path_parts.append(existing_mypy_path)
190+
if self.base_ini_fpath:
191+
mypy_path_parts.append(os.path.dirname(self.base_ini_fpath))
192+
self.environment_variables["MYPYPATH"] = ":".join(mypy_path_parts)
193+
179194
# Windows requires this to be set, otherwise the interpreter crashes
180195
if "SYSTEMROOT" in os.environ:
181196
self.environment_variables["SYSTEMROOT"] = os.environ["SYSTEMROOT"]
197+
182198
completed = subprocess.run(
183199
[mypy_executable, *mypy_cmd_options],
184200
stdout=subprocess.PIPE,

pytest_mypy_plugins/utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def _add_aligned_message(s1: str, s2: str, error_message: str) -> str:
117117
maxw = 72 # Maximum number of characters shown
118118

119119
error_message += "Alignment of first line difference:\n"
120-
# sys.stderr.write('Alignment of first line difference:\n')
121120

122121
trunc = False
123122
while s1[:30] == s2[:30]:
@@ -136,23 +135,18 @@ def _add_aligned_message(s1: str, s2: str, error_message: str) -> str:
136135

137136
# Write a chunk of both lines, aligned.
138137
error_message += " E: {}{}\n".format(s1[:maxw], extra)
139-
# sys.stderr.write(' E: {}{}\n'.format(s1[:maxw], extra))
140138
error_message += " A: {}{}\n".format(s2[:maxw], extra)
141-
# sys.stderr.write(' A: {}{}\n'.format(s2[:maxw], extra))
142139
# Write an indicator character under the different columns.
143140
error_message += " "
144141
# sys.stderr.write(' ')
145142
for j in range(min(maxw, max(len(s1), len(s2)))):
146143
if s1[j : j + 1] != s2[j : j + 1]:
147144
error_message += "^"
148-
# sys.stderr.write('^') # Difference
149145
break
150146
else:
151147
error_message += " "
152-
# sys.stderr.write(' ') # Equal
153148
error_message += "\n"
154149
return error_message
155-
# sys.stderr.write('\n')
156150

157151

158152
def remove_empty_lines(lines: List[str]) -> List[str]:

0 commit comments

Comments
 (0)