Skip to content

Commit 5c6cd29

Browse files
authored
Enable --sqlite-cache by default (#21041)
1 parent 87576c6 commit 5c6cd29

File tree

12 files changed

+33
-11
lines changed

12 files changed

+33
-11
lines changed

docs/source/command_line.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,10 @@ beyond what incremental mode can offer, try running mypy in
10191019
writing to the cache, use ``--cache-dir=/dev/null`` (UNIX)
10201020
or ``--cache-dir=nul`` (Windows).
10211021

1022-
.. option:: --sqlite-cache
1022+
.. option:: --no-sqlite-cache
10231023

1024-
Use an `SQLite`_ database to store the cache.
1024+
Avoid using `SQLite`_ database to store the cache, instead write cache data
1025+
out to individual files.
10251026

10261027
.. option:: --cache-fine-grained
10271028

docs/source/config_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ These options may only be set in the global section (``[mypy]``).
979979
.. confval:: sqlite_cache
980980

981981
:type: boolean
982-
:default: False
982+
:default: True
983983

984984
Use an `SQLite`_ database to store the cache.
985985

mypy/build.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,6 @@ def build_inner(
456456
# Validate error codes after plugins are loaded.
457457
options.process_error_codes(error_callback=build_error)
458458

459-
# Add catch-all .gitignore to cache dir if we created it
460-
cache_dir_existed = os.path.isdir(options.cache_dir)
461-
462459
# Construct a build manager object to hold state during the build.
463460
#
464461
# Ignore current directory prefix in error messages.
@@ -510,7 +507,7 @@ def build_inner(
510507
if reports is not None:
511508
# Finish the HTML or XML reports even if CompileError was raised.
512509
reports.finish()
513-
if not cache_dir_existed and os.path.isdir(options.cache_dir):
510+
if os.path.isdir(options.cache_dir):
514511
add_catch_all_gitignore(options.cache_dir)
515512
exclude_from_backups(options.cache_dir)
516513
if os.path.isdir(options.cache_dir):

mypy/metastore.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def commit(self) -> None:
6868
@abstractmethod
6969
def list_all(self) -> Iterable[str]: ...
7070

71+
@abstractmethod
72+
def close(self) -> None:
73+
"""Release any resources held by the backing store."""
74+
7175

7276
def random_string() -> str:
7377
return binascii.hexlify(os.urandom(8)).decode("ascii")
@@ -136,6 +140,9 @@ def list_all(self) -> Iterable[str]:
136140
for file in files:
137141
yield os.path.normpath(os_path_join(dir, file))
138142

143+
def close(self) -> None:
144+
pass
145+
139146

140147
SCHEMA = """
141148
CREATE TABLE IF NOT EXISTS files2 (
@@ -224,3 +231,12 @@ def list_all(self) -> Iterable[str]:
224231
if self.db:
225232
for row in self.db.execute("SELECT path FROM files2"):
226233
yield row[0]
234+
235+
def close(self) -> None:
236+
if self.db:
237+
db = self.db
238+
self.db = None
239+
db.close()
240+
241+
def __del__(self) -> None:
242+
self.close()

mypy/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def __init__(self) -> None:
299299
# Caching and incremental checking options
300300
self.incremental = True
301301
self.cache_dir = defaults.CACHE_DIR
302-
self.sqlite_cache = False
302+
self.sqlite_cache = True
303303
self.fixed_format_cache = True
304304
self.debug_cache = False
305305
self.skip_version_check = False

mypy/test/test_ref_info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
2323
options.use_builtins_fixtures = True
2424
options.show_traceback = True
2525
options.export_ref_info = True # This is the flag we are testing
26+
options.sqlite_cache = False
2627

2728
src = "\n".join(testcase.input)
2829
result = build.build(

mypy/test/testcheck.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def run_case_once(
258258
assert_module_equivalence(
259259
"stale" + suffix, expected_stale, res.manager.stale_modules
260260
)
261+
res.manager.metastore.close()
261262

262263
if testcase.output_files:
263264
check_test_output_files(testcase, incremental_step, strip_prefix="tmp/")

mypy/test/testexportjson.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
3131
options.show_traceback = True
3232
options.allow_empty_bodies = True
3333
options.fixed_format_cache = True
34+
options.sqlite_cache = False
3435
fnam = os.path.join(self.base_path, "main.py")
3536
with open(fnam, "w") as f:
3637
f.write(src)

mypyc/codegen/emitmodule.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,15 @@ def parse_and_typecheck(
198198
alt_lib_path: str | None = None,
199199
) -> BuildResult:
200200
assert options.strict_optional, "strict_optional must be turned on"
201+
mypyc_plugin = MypycPlugin(options, compiler_options, groups)
201202
result = build(
202203
sources=sources,
203204
options=options,
204205
alt_lib_path=alt_lib_path,
205206
fscache=fscache,
206-
extra_plugins=[MypycPlugin(options, compiler_options, groups)],
207+
extra_plugins=[mypyc_plugin],
207208
)
209+
mypyc_plugin.metastore.close()
208210
if result.errors:
209211
raise CompileError(result.errors)
210212
return result

mypyc/test/test_run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
294294
for line in e.messages:
295295
print(fix_native_line_number(line, testcase.file, testcase.line))
296296
assert False, "Compile error"
297+
finally:
298+
result.manager.metastore.close()
297299

298300
# Check that serialization works on this IR. (Only on the first
299301
# step because the returned ir only includes updated code.)

0 commit comments

Comments
 (0)