Skip to content

Commit 2482c47

Browse files
SG-39809 Bump ruamel.yaml to 0.18.14 (#1049)
* Bump ruamel.yaml to 0.18.14 * Fix import. Remove whitespace from fixture. * Fix linebreak that broke the `yaml_add_eol_comment` * Add instructions for upgrading ruamel.yaml * Control append path to `sys.path`
1 parent eaaadce commit 2482c47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+17466
-9529
lines changed

developer/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ cd tk-core/developer
1515
python upgrade_pyyaml.py
1616
```
1717

18+
## How to upgrade ruamel.yaml
19+
20+
Until version `0.10.10`, the contents of the library was located at `tank_vendor/ruamel_yaml`.
21+
However, starting from `0.18.14`, we had to change it to `tank_vendor/ruamel/yaml`.
22+
23+
Just to confirm, the contents of the PIP package should be placed in `tank_vendor`.
24+
25+
```bash
26+
pip install ruamel.yaml -t path/to/tank_vendor
27+
```
28+
29+
Then, let's remove all undesired directories and files, just leave the `ruamel` directory.
30+
We can automate this task later.
1831

1932
## The requirements.txt file
2033

developer/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
distro==1.4.0
1111
ordereddict==1.1
1212
pyyaml==5.4.1
13-
ruamel_yaml==0.10.10
13+
ruamel_yaml==0.18.14
1414
six==1.13.0

python/tank/platform/environment.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,16 @@ def __init__(self, env_path, pipeline_config, context=None):
833833
self.set_yaml_preserve_mode(True)
834834
super().__init__(env_path, pipeline_config, context)
835835

836+
def _get_ruamel_yaml(self):
837+
vendor_path = os.path.join(os.path.dirname(__file__), "../..", "tank_vendor")
838+
839+
if vendor_path not in sys.path:
840+
sys.path.append(vendor_path)
841+
842+
from tank_vendor.ruamel import yaml as ruamel_yaml
843+
844+
return ruamel_yaml
845+
836846
def __load_writable_yaml(self, path):
837847
"""
838848
Loads yaml data from disk.
@@ -857,9 +867,9 @@ def __load_writable_yaml(self, path):
857867
# which also holds the additional contextual metadata
858868
# required by the parse to maintain the lexical integrity
859869
# of the content.
860-
from tank_vendor import ruamel_yaml
870+
ruamel_yaml = self._get_ruamel_yaml()
861871

862-
yaml_data = ruamel_yaml.load(fh, ruamel_yaml.RoundTripLoader)
872+
yaml_data = ruamel_yaml.YAML(typ="rt").load(fh)
863873
else:
864874
# use pyyaml parser
865875
yaml_data = yaml.load(fh, Loader=yaml.FullLoader)
@@ -930,14 +940,9 @@ def __write_data_file(self, fh, data):
930940
# note that safe_dump is not needed when using the
931941
# roundtrip dumper, it will adopt a 'safe' behaviour
932942
# by default.
933-
from tank_vendor import ruamel_yaml
943+
ruamel_yaml = self._get_ruamel_yaml()
934944

935-
ruamel_yaml.dump(
936-
data,
937-
fh,
938-
default_flow_style=False,
939-
Dumper=ruamel_yaml.RoundTripDumper,
940-
)
945+
ruamel_yaml.YAML(typ="rt").dump(data, fh)
941946
else:
942947
# use pyyaml parser
943948
#

0 commit comments

Comments
 (0)