Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd5eb2f4

Browse files
miss-islingtonFFY00iritkatrielhauntsaninja
authored
bpo-40447: accept all path-like objects in compileall.compile_file (GH-19883)
(cherry picked from commit1ecfd1e)Co-authored-by: Filipe Laíns <lains@riseup.net>Signed-off-by: Filipe Laíns <lains@archlinux.org>Signed-off-by: Filipe Laíns <lains@riseup.net>Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
1 parent4b3b642 commitd5eb2f4

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

‎Lib/compileall.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
154154
"in combination with stripdir or prependdir"))
155155

156156
success=True
157-
ifquiet<2andisinstance(fullname,os.PathLike):
158-
fullname=os.fspath(fullname)
157+
fullname=os.fspath(fullname)
158+
stripdir=os.fspath(stripdir)ifstripdirisnotNoneelseNone
159159
name=os.path.basename(fullname)
160160

161161
dfile=None

‎Lib/test/test_compileall.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ def test_compile_file_pathlike_ddir(self):
167167
quiet=2))
168168
self.assertTrue(os.path.isfile(self.bc_path))
169169

170+
deftest_compile_file_pathlike_stripdir(self):
171+
self.assertFalse(os.path.isfile(self.bc_path))
172+
self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path),
173+
stripdir=pathlib.Path('stripdir_path'),
174+
quiet=2))
175+
self.assertTrue(os.path.isfile(self.bc_path))
176+
177+
deftest_compile_file_pathlike_prependdir(self):
178+
self.assertFalse(os.path.isfile(self.bc_path))
179+
self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path),
180+
prependdir=pathlib.Path('prependdir_path'),
181+
quiet=2))
182+
self.assertTrue(os.path.isfile(self.bc_path))
183+
170184
deftest_compile_path(self):
171185
withtest.test_importlib.util.import_state(path=[self.directory]):
172186
self.assertTrue(compileall.compile_path(quiet=2))
@@ -219,6 +233,20 @@ def test_compile_dir_pathlike(self):
219233
self.assertRegex(line,r'Listing ([^WindowsPath|PosixPath].*)')
220234
self.assertTrue(os.path.isfile(self.bc_path))
221235

236+
deftest_compile_dir_pathlike_stripdir(self):
237+
self.assertFalse(os.path.isfile(self.bc_path))
238+
self.assertTrue(compileall.compile_dir(pathlib.Path(self.directory),
239+
stripdir=pathlib.Path('stripdir_path'),
240+
quiet=2))
241+
self.assertTrue(os.path.isfile(self.bc_path))
242+
243+
deftest_compile_dir_pathlike_prependdir(self):
244+
self.assertFalse(os.path.isfile(self.bc_path))
245+
self.assertTrue(compileall.compile_dir(pathlib.Path(self.directory),
246+
prependdir=pathlib.Path('prependdir_path'),
247+
quiet=2))
248+
self.assertTrue(os.path.isfile(self.bc_path))
249+
222250
@skipUnless(_have_multiprocessing,"requires multiprocessing")
223251
@mock.patch('concurrent.futures.ProcessPoolExecutor')
224252
deftest_compile_pool_called(self,pool_mock):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Accept:class:`os.PathLike` (such as:class:`pathlib.Path`) in the ``stripdir`` arguments of
2+
:meth:`compileall.compile_file` and:meth:`compileall.compile_dir`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp