2
2
3
3
import os
4
4
import shutil
5
+ import tempfile
5
6
from typing import (
6
7
Any ,
7
8
Dict ,
16
17
cast ,
17
18
)
18
19
19
- import fs .base
20
- import fs .tempfs
21
20
from attrs import define , field
22
21
from fontTools .ufoLib import UFOFileStructure , UFOReader , UFOWriter
23
22
48
47
_setstate_attrs ,
49
48
)
50
49
from ufoLib2 .serde import serde
51
- from ufoLib2 .typing import HasIdentifier , PathLike , T
50
+ from ufoLib2 .typing import PATH_TYPES , HasIdentifier , PathLike , T
52
51
53
52
54
53
def _convert_LayerSet (value : LayerSet | Iterable [Layer ]) -> LayerSet :
@@ -532,7 +531,7 @@ def write(self, writer: UFOWriter, saveAs: bool | None = None) -> None:
532
531
533
532
def save (
534
533
self ,
535
- path : PathLike | fs . base . FS | None = None ,
534
+ path : PathLike | None = None ,
536
535
formatVersion : int = 3 ,
537
536
structure : UFOFileStructure | None = None ,
538
537
overwrite : bool = False ,
@@ -541,9 +540,8 @@ def save(
541
540
"""Saves the font to ``path``.
542
541
543
542
Args:
544
- path: The target path. If it is None, the path from the last save (except
545
- when that was a ``fs.base.FS``) or when the font was first opened will
546
- be used.
543
+ path: The target path. If it is None, the path from the last save or when
544
+ the font was first opened will be used.
547
545
formatVersion: The version to save the UFO as. Only version 3 is supported
548
546
currently.
549
547
structure (fontTools.ufoLib.UFOFileStructure): How to store the UFO.
@@ -567,8 +565,8 @@ def save(
567
565
structure = self ._fileStructure
568
566
569
567
# Normalize path unless we're given a fs.base.FS, which we pass to UFOWriter.
570
- if path is not None and not isinstance (path , fs . base . FS ):
571
- path = os .path .normpath (os .fspath (path ))
568
+ if path is not None and isinstance (path , PATH_TYPES ):
569
+ path = os .fsdecode ( os . path .normpath (os .fspath (path ) ))
572
570
573
571
overwritePath = tmp = None
574
572
@@ -577,8 +575,8 @@ def save(
577
575
if isinstance (path , str ) and os .path .exists (path ):
578
576
if overwrite :
579
577
overwritePath = path
580
- tmp = fs . tempfs . TempFS ()
581
- path = tmp . getsyspath ( os .path .basename (path ))
578
+ tmp = tempfile . TemporaryDirectory ()
579
+ path = os . path . join ( tmp . name , os .path .basename (path ))
582
580
else :
583
581
import errno
584
582
@@ -608,12 +606,12 @@ def save(
608
606
finally :
609
607
# clean up the temporary directory
610
608
if tmp is not None :
611
- tmp .close ()
609
+ tmp .cleanup ()
612
610
613
611
# Only remember path if it isn't a fs.base.FS because not all FS objects are
614
612
# OsFS with a corresponding filesystem path. E.g. think about MemoryFS.
615
613
# If you want, you can call getsyspath("") method of OsFS object and set that to
616
614
# self._path. But you then have to catch the fs.errors.NoSysPath and skip if
617
615
# the FS object does not implement a filesystem path.
618
- if not isinstance (path , fs . base . FS ):
616
+ if isinstance (path , str ):
619
617
self ._path = path
0 commit comments