File tree 3 files changed +17
-17
lines changed
3 files changed +17
-17
lines changed Original file line number Diff line number Diff line change @@ -735,27 +735,12 @@ def absolute(self):
735
735
# Treat the root directory as the current working directory.
736
736
return self .with_segments ('/' , * self ._raw_paths )
737
737
738
- @classmethod
739
- def cwd (cls ):
740
- """Return a new path pointing to the current working directory."""
741
- # We call 'absolute()' rather than using 'os.getcwd()' directly to
742
- # enable users to replace the implementation of 'absolute()' in a
743
- # subclass and benefit from the new behaviour here. This works because
744
- # os.path.abspath('.') == os.getcwd().
745
- return cls ().absolute ()
746
-
747
738
def expanduser (self ):
748
739
""" Return a new path with expanded ~ and ~user constructs
749
740
(as returned by os.path.expanduser)
750
741
"""
751
742
raise UnsupportedOperation (self ._unsupported_msg ('expanduser()' ))
752
743
753
- @classmethod
754
- def home (cls ):
755
- """Return a new path pointing to expanduser('~').
756
- """
757
- return cls ("~" ).expanduser ()
758
-
759
744
def readlink (self ):
760
745
"""
761
746
Return the path to which the symbolic link points.
Original file line number Diff line number Diff line change @@ -726,6 +726,14 @@ def absolute(self):
726
726
tail .extend (self ._tail )
727
727
return self ._from_parsed_parts (drive , root , tail )
728
728
729
+ @classmethod
730
+ def cwd (cls ):
731
+ """Return a new path pointing to the current working directory."""
732
+ cwd = os .getcwd ()
733
+ path = cls (cwd )
734
+ path ._str = cwd # getcwd() returns a normalized path
735
+ return path
736
+
729
737
def resolve (self , strict = False ):
730
738
"""
731
739
Make the path absolute, resolving all symlinks on the way and also
@@ -907,6 +915,15 @@ def expanduser(self):
907
915
908
916
return self
909
917
918
+ @classmethod
919
+ def home (cls ):
920
+ """Return a new path pointing to expanduser('~').
921
+ """
922
+ homedir = os .path .expanduser ("~" )
923
+ if homedir == "~" :
924
+ raise RuntimeError ("Could not determine home directory." )
925
+ return cls (homedir )
926
+
910
927
@classmethod
911
928
def from_uri (cls , uri ):
912
929
"""Return a new path from the given 'file' URI."""
Original file line number Diff line number Diff line change @@ -1371,9 +1371,7 @@ def test_unsupported_operation(self):
1371
1371
self .assertRaises (e , p .rglob , '*' )
1372
1372
self .assertRaises (e , lambda : list (p .walk ()))
1373
1373
self .assertRaises (e , p .absolute )
1374
- self .assertRaises (e , P .cwd )
1375
1374
self .assertRaises (e , p .expanduser )
1376
- self .assertRaises (e , p .home )
1377
1375
self .assertRaises (e , p .readlink )
1378
1376
self .assertRaises (e , p .symlink_to , 'foo' )
1379
1377
self .assertRaises (e , p .hardlink_to , 'foo' )
You can’t perform that action at this time.
0 commit comments