Skip to content

Commit c9dabff

Browse files
committed
PICARD-2213: Support for YAML export packages is mandatory again
1 parent 969799b commit c9dabff

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

INSTALL.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Required:
1111
* [Python 3.6 or newer](http://python.org/download)
1212
* [PyQt 5.10 or newer](http://www.riverbankcomputing.co.uk/software/pyqt/download)
1313
* [Mutagen 1.37 or newer](https://mutagen.readthedocs.io/)
14+
* [PyYAML 5.1 or newer](https://pyyaml.org/)
1415
* [python-dateutil](https://dateutil.readthedocs.io/en/stable/)
1516
* gettext:
1617
* [Windows](https://mlocati.github.io/articles/gettext-iconv-windows.html)

picard/script/__init__.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import json
4545
import uuid
4646

47+
import yaml
48+
4749
from picard.config import get_config
4850
from picard.const import (
4951
DEFAULT_FILE_NAMING_FORMAT,
@@ -71,14 +73,6 @@
7173
)
7274

7375

74-
try:
75-
import yaml
76-
supports_script_package = True
77-
except ImportError:
78-
yaml = None
79-
supports_script_package = False
80-
81-
8276
class ScriptFunctionDocError(Exception):
8377
pass
8478

@@ -139,16 +133,15 @@ def __init__(self, *args):
139133
super().__init__(*args)
140134

141135

142-
class ScriptLiteral(str):
136+
class MultilineLiteral(str):
143137
@staticmethod
144138
def yaml_presenter(dumper, data):
145139
if data:
146140
data = data.rstrip() + '\n'
147141
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
148142

149143

150-
if yaml:
151-
yaml.add_representer(ScriptLiteral, ScriptLiteral.yaml_presenter)
144+
yaml.add_representer(MultilineLiteral, MultilineLiteral.yaml_presenter)
152145

153146

154147
class PicardScript():
@@ -214,7 +207,7 @@ def script(self):
214207

215208
@script.setter
216209
def script(self, value):
217-
self._script = ScriptLiteral(value)
210+
self._script = MultilineLiteral(value)
218211

219212
@staticmethod
220213
def make_last_updated():
@@ -393,6 +386,14 @@ def __init__(
393386
self.license = license
394387
self.version = version
395388

389+
@property
390+
def description(self):
391+
return self._description
392+
393+
@description.setter
394+
def description(self, value):
395+
self._description = MultilineLiteral(value)
396+
396397

397398
def get_file_naming_script_presets():
398399
"""Generator of preset example file naming script objects.

picard/ui/scripteditor.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
ScriptImportError,
4747
ScriptParser,
4848
get_file_naming_script_presets,
49-
supports_script_package,
5049
)
5150
from picard.util import (
5251
icontheme,
@@ -872,7 +871,7 @@ def import_script(self):
872871
if not file_content.strip():
873872
self.output_file_error(FILE_ERROR_IMPORT, filename, _('The file was empty'))
874873
return
875-
if supports_script_package and file_type == self.FILE_TYPE_PACKAGE:
874+
if file_type == self.FILE_TYPE_PACKAGE:
876875
try:
877876
script_item = FileNamingScript().create_from_yaml(file_content)
878877
except ScriptImportError as error:
@@ -907,7 +906,7 @@ def export_script(self):
907906
if ext and str(name).endswith('.' + ext):
908907
filename = name
909908
log.debug('Exporting naming script file: %s' % filename)
910-
if supports_script_package and file_type == self.FILE_TYPE_PACKAGE:
909+
if file_type == self.FILE_TYPE_PACKAGE:
911910
script_text = script_item.to_yaml()
912911
try:
913912
with open(filename, 'w', encoding='utf8') as o_file:
@@ -925,12 +924,11 @@ def export_script(self):
925924
dialog.exec_()
926925

927926
def _get_dialog_filetypes(self):
928-
file_types = []
929-
if supports_script_package:
930-
file_types.append(self.FILE_TYPE_PACKAGE)
931-
file_types.append(self.FILE_TYPE_SCRIPT)
932-
file_types.append(self.FILE_TYPE_ALL)
933-
return ";;".join(file_types)
927+
return ";;".join((
928+
self.FILE_TYPE_PACKAGE,
929+
self.FILE_TYPE_SCRIPT,
930+
self.FILE_TYPE_ALL,
931+
))
934932

935933
def reset_script(self):
936934
"""Reset the script to the last saved value.

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pyobjc-core~=6.2; sys_platform == 'darwin'
77
pyobjc-framework-Cocoa~=6.2; sys_platform == 'darwin'
88
PyQt5~=5.10
99
pywin32; sys_platform == 'win32'
10-
pyyaml>=5.1
10+
pyyaml~=5.1

0 commit comments

Comments
 (0)