Skip to content

Commit 4f97fc8

Browse files
authored
Merge 639f64f into 30e00a9
2 parents 30e00a9 + 639f64f commit 4f97fc8

4 files changed

Lines changed: 61 additions & 13 deletions

File tree

source/speechDictHandler/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# See the file COPYING for more details.
55

66
import re
7+
from typing import Any
78
import globalVars
89
from logHandler import log
910
import os
@@ -12,6 +13,21 @@
1213
from NVDAState import WritePaths
1314
from . import dictFormatUpgrade
1415

16+
17+
def __getattr__(attrName: str) -> Any:
18+
"""Module level `__getattr__` used to preserve backward compatibility.
19+
"""
20+
import NVDAState
21+
if attrName == "speechDictsPath" and NVDAState._allowDeprecatedAPI():
22+
log.warning(
23+
"speechDictHandler.speechDictsPath is deprecated, "
24+
"instead use NVDAState.WritePaths.speechDictsDir",
25+
stack_info=True
26+
)
27+
return WritePaths.speechDictsDir
28+
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")
29+
30+
1531
dictionaries = {}
1632
dictTypes = ("temp", "voice", "default", "builtin") # ordered by their priority E.G. voice specific speech dictionary is processed before the default
1733

@@ -141,6 +157,5 @@ def loadVoiceDict(synth):
141157
baseName = dictFormatUpgrade.createVoiceDictFileName(synth.name, voice)
142158
else:
143159
baseName=r"{synth}.dic".format(synth=synth.name)
144-
voiceDictsPath = dictFormatUpgrade.voiceDictsPath
145-
fileName= os.path.join(voiceDictsPath, synth.name, baseName)
160+
fileName = os.path.join(WritePaths.voiceDictsDir, synth.name, baseName)
146161
dictionaries["voice"].load(fileName)

source/speechDictHandler/dictFormatUpgrade.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,52 @@
11
# -*- coding: UTF-8 -*-
22
# A part of NonVisual Desktop Access (NVDA)
3-
# Copyright (C) 2017 NV Access Limited
3+
# Copyright (C) 2017-2023 NV Access Limited
44
# This file may be used under the terms of the GNU General Public License, version 2 or later.
55
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
66

77
"""Upgrade speech dict files
88
"""
99

10+
from typing import Any
1011
import globalVars
1112
import os
1213
import api
1314
import glob
1415
from logHandler import log
1516
from NVDAState import WritePaths
1617

17-
voiceDictsPath = WritePaths.voiceDictsDir
18-
voiceDictsBackupPath = WritePaths.voiceDictsBackupDir
18+
19+
def __getattr__(attrName: str) -> Any:
20+
"""Module level `__getattr__` used to preserve backward compatibility.
21+
"""
22+
import NVDAState
23+
if NVDAState._allowDeprecatedAPI():
24+
if attrName == "speechDictsPath":
25+
log.warning(
26+
"speechDictHandler.dictFormatUpgrade.speechDictsPath is deprecated, "
27+
"instead use NVDAState.WritePaths.speechDictsDir",
28+
stack_info=True
29+
)
30+
return WritePaths.speechDictsDir
31+
32+
if attrName == "voiceDictsPath":
33+
log.warning(
34+
"speechDictHandler.dictFormatUpgrade.voiceDictsPath is deprecated, "
35+
"instead use NVDAState.WritePaths.voiceDictsDir",
36+
stack_info=True
37+
)
38+
return WritePaths.voiceDictsDir
39+
40+
if attrName == "voiceDictsBackupPath":
41+
log.warning(
42+
"speechDictHandler.dictFormatUpgrade.voiceDictsBackupPath is deprecated, "
43+
"instead use NVDAState.WritePaths.voiceDictsBackupDir",
44+
stack_info=True
45+
)
46+
return WritePaths.voiceDictsBackupDir
47+
48+
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")
49+
1950

2051
def createVoiceDictFileName(synthName, voiceName):
2152
""" Creates a filename used for the voice dictionary files.
@@ -56,12 +87,12 @@ def _doSynthVoiceDictBackupAndMove(synthName, oldFileNameToNewFileNameList=None)
5687
"""
5788
import shutil
5889

59-
if not os.path.isdir(voiceDictsPath):
60-
os.makedirs(voiceDictsPath)
61-
if not os.path.isdir(voiceDictsBackupPath):
62-
os.makedirs(voiceDictsBackupPath)
90+
if not os.path.isdir(WritePaths.voiceDictsDir):
91+
os.makedirs(WritePaths.voiceDictsDir)
92+
if not os.path.isdir(WritePaths.voiceDictsBackupDir):
93+
os.makedirs(WritePaths.voiceDictsBackupDir)
6394

64-
newDictPath = os.path.join(voiceDictsPath,synthName)
95+
newDictPath = os.path.join(WritePaths.voiceDictsDir, synthName)
6596
needsUpgrade = not os.path.isdir(newDictPath)
6697
if needsUpgrade:
6798
log.info("Upgrading voice dictionaries for %s"%synthName)
@@ -82,7 +113,7 @@ def _doSynthVoiceDictBackupAndMove(synthName, oldFileNameToNewFileNameList=None)
82113
log.debug("processing file: %s" % actualPath)
83114
# files will be copied here before we modify them so as to avoid
84115
# any data loss.
85-
shutil.copy(actualPath, voiceDictsBackupPath)
116+
shutil.copy(actualPath, WritePaths.voiceDictsBackupDir)
86117

87118
actualBasename = os.path.basename(actualPath)
88119
log.debug("basename: %s" % actualBasename)

source/speechDictHandler/speechDictVars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if NVDAState._allowDeprecatedAPI():
1515
log.warning(
1616
"speechDictHandler.speechDictVars.speechDictsPath is deprecated, "
17-
"instead use WritePaths.speechDictsDir",
17+
"instead use NVDAState.WritePaths.speechDictsDir",
1818
stack_info=True
1919
)
2020
speechDictsPath = WritePaths.speechDictsDir

user_docs/en/changes.t2t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ Instead import from ``hwIo.ioThread``. (#14627)
151151
It was introduced in NVDA 2023.1 and was never meant to be part of the public API.
152152
Until removal, it behaves as a no-op, i.e. a context manager yielding nothing. (#14924)
153153
- ``gui.MainFrame.onAddonsManagerCommand`` is deprecated, use ``gui.MainFrame.onAddonStoreCommand`` instead. (#13985)
154-
- ``speechDictHandler.speechDictVars.speechDictsPath`` is deprecated, use ``WritePaths.speechDictsDir`` instead. (#15021)
154+
- ``speechDictHandler.speechDictVars.speechDictsPath`` is deprecated, use ``NVDAState.WritePaths.speechDictsDir`` instead. (#15021)
155+
- Importing ``voiceDictsPath`` and ``voiceDictsBackupPath`` from ``speechDictHandler.dictFormatUpgrade`` is deprecated.
156+
Instead use ``WritePaths.voiceDictsDir`` and ``WritePaths.voiceDictsBackupDir`` from ``NVDAState``. (#15048)
155157
-
156158

157159
= 2023.1 =

0 commit comments

Comments
 (0)