Skip to content

Commit e4b8389

Browse files
committed
Put the filename calc back in _connect. Fixes #916
It was moved to __init__ to avoid recalculating, but the directory could have changed, so we need to wait to do the work. Instead, only do the relpath on systems that need it (Windows Py 2).
1 parent d402b46 commit e4b8389

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

CHANGES.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ want to know what's different in 5.0 since 4.5.x, see :ref:`whatsnew5x`.
2424
Unreleased
2525
----------
2626

27-
Nothing yet.
27+
- A performance improvement in 5.0.2 didn't work for test suites that changed
28+
directory before combining data, causing "Couldn't use data file: no such
29+
table: meta" errors (`issue 916`_). This is now fixed.
30+
31+
.. _issue 916: https://github.com/nedbat/coveragepy/issues/916
2832

2933

3034
.. _changes_502:

coverage/sqldata.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import sys
1717
import zlib
1818

19+
from coverage import env
1920
from coverage.backward import get_thread_id, iitems, to_bytes, to_string
2021
from coverage.debug import NoDebugging, SimpleReprMixin, clipped_repr
2122
from coverage.files import PathAliases
@@ -971,31 +972,34 @@ def __init__(self, filename, debug):
971972
self.filename = filename
972973
self.nest = 0
973974
self.con = None
974-
# SQLite on Windows on py2 won't open a file if the filename argument
975-
# has non-ascii characters in it. Opening a relative file name avoids
976-
# a problem if the current directory has non-ascii.
977-
try:
978-
self.connect_filename = os.path.relpath(self.filename)
979-
except ValueError:
980-
# ValueError can be raised under Windows when os.getcwd() returns a
981-
# folder from a different drive than the drive of self.filename in
982-
# which case we keep the original value of self.filename unchanged,
983-
# hoping that we won't face the non-ascii directory problem.
984-
self.connect_filename = self.filename
985975

986976
def _connect(self):
987977
"""Connect to the db and do universal initialization."""
988978
if self.con is not None:
989979
return
990980

981+
# SQLite on Windows on py2 won't open a file if the filename argument
982+
# has non-ascii characters in it. Opening a relative file name avoids
983+
# a problem if the current directory has non-ascii.
984+
filename = self.filename
985+
if env.WINDOWS and env.PY2:
986+
try:
987+
filename = os.path.relpath(self.filename)
988+
except ValueError:
989+
# ValueError can be raised under Windows when os.getcwd() returns a
990+
# folder from a different drive than the drive of self.filename in
991+
# which case we keep the original value of self.filename unchanged,
992+
# hoping that we won't face the non-ascii directory problem.
993+
pass
994+
991995
# It can happen that Python switches threads while the tracer writes
992996
# data. The second thread will also try to write to the data,
993997
# effectively causing a nested context. However, given the idempotent
994998
# nature of the tracer operations, sharing a connection among threads
995999
# is not a problem.
9961000
if self.debug:
9971001
self.debug.write("Connecting to {!r}".format(self.filename))
998-
self.con = sqlite3.connect(self.connect_filename, check_same_thread=False)
1002+
self.con = sqlite3.connect(filename, check_same_thread=False)
9991003
self.con.create_function('REGEXP', 2, _regexp)
10001004

10011005
# This pragma makes writing faster. It disables rollbacks, but we never need them.

0 commit comments

Comments
 (0)