|
16 | 16 | import sys
|
17 | 17 | import zlib
|
18 | 18 |
|
| 19 | +from coverage import env |
19 | 20 | from coverage.backward import get_thread_id, iitems, to_bytes, to_string
|
20 | 21 | from coverage.debug import NoDebugging, SimpleReprMixin, clipped_repr
|
21 | 22 | from coverage.files import PathAliases
|
@@ -971,31 +972,34 @@ def __init__(self, filename, debug):
|
971 | 972 | self.filename = filename
|
972 | 973 | self.nest = 0
|
973 | 974 | 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 |
985 | 975 |
|
986 | 976 | def _connect(self):
|
987 | 977 | """Connect to the db and do universal initialization."""
|
988 | 978 | if self.con is not None:
|
989 | 979 | return
|
990 | 980 |
|
| 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 | + |
991 | 995 | # It can happen that Python switches threads while the tracer writes
|
992 | 996 | # data. The second thread will also try to write to the data,
|
993 | 997 | # effectively causing a nested context. However, given the idempotent
|
994 | 998 | # nature of the tracer operations, sharing a connection among threads
|
995 | 999 | # is not a problem.
|
996 | 1000 | if self.debug:
|
997 | 1001 | 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) |
999 | 1003 | self.con.create_function('REGEXP', 2, _regexp)
|
1000 | 1004 |
|
1001 | 1005 | # This pragma makes writing faster. It disables rollbacks, but we never need them.
|
|
0 commit comments