-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[LIT] replace lit.util.mkdir with pathlib.Path.mkdir
#163948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2efd128
665e97f
c9fc27d
10db692
a37027e
cdf8adc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import math | ||
| import numbers | ||
| import os | ||
| import pathlib | ||
| import platform | ||
| import re | ||
| import signal | ||
|
|
@@ -131,48 +132,17 @@ def abs_path_preserve_drive(path): | |
| # Since Python 3.8, os.path.realpath resolves sustitute drives, | ||
| # so we should not use it. In Python 3.7, os.path.realpath | ||
| # was implemented as os.path.abspath. | ||
| if isinstance(path, pathlib.Path): | ||
| return path.absolute() | ||
| return os.path.abspath(path) | ||
| else: | ||
| # On UNIX, the current directory always has symbolic links resolved, | ||
| # so any program accepting relative paths cannot preserve symbolic | ||
| # links in paths and we should always use os.path.realpath. | ||
| if isinstance(path, pathlib.Path): | ||
| return path.resolve() | ||
| return os.path.realpath(path) | ||
|
|
||
| def mkdir(path): | ||
| try: | ||
| if platform.system() == "Windows": | ||
| from ctypes import windll | ||
| from ctypes import GetLastError, WinError | ||
|
|
||
| path = os.path.abspath(path) | ||
| # Make sure that the path uses backslashes here, in case | ||
| # python would have happened to use forward slashes, as the | ||
| # NT path format only supports backslashes. | ||
| path = path.replace("/", "\\") | ||
| NTPath = to_unicode(r"\\?\%s" % path) | ||
| if not windll.kernel32.CreateDirectoryW(NTPath, None): | ||
| raise WinError(GetLastError()) | ||
| else: | ||
| os.mkdir(path) | ||
| except OSError: | ||
| e = sys.exc_info()[1] | ||
| # ignore EEXIST, which may occur during a race condition | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, all EEXIST errors were ignored. |
||
| if e.errno != errno.EEXIST: | ||
| raise | ||
|
|
||
|
|
||
| def mkdir_p(path): | ||
| """mkdir_p(path) - Make the "path" directory, if it does not exist; this | ||
| will also make directories for any missing parent directories.""" | ||
| if not path or os.path.exists(path): | ||
| return | ||
|
|
||
| parent = os.path.dirname(path) | ||
| if parent != path: | ||
| mkdir_p(parent) | ||
|
|
||
| mkdir(path) | ||
|
|
||
|
|
||
| def listdir_files(dirname, suffixes=None, exclude_filenames=None, prefixes=None): | ||
| """Yields files in a directory. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| ## Tests glob pattern handling in the mkdir command. | ||
|
|
||
| ## This mkdir should fail because the `example_file*.input`s are regular files. | ||
| # RUN: not mkdir %S/example_file*.input | ||
|
|
||
| ## This mkdir should succeed (so RUN should fail) because the `example_dir*.input`s that already exist are directories. | ||
| # RUN: not mkdir %S/example_dir*.input |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| ## Tests glob pattern handling in echo command. | ||
|
|
||
| # RUN: not %{lit} -a -v %{inputs}/shtest-glob \ | ||
| # RUN: | FileCheck -dump-input=fail -match-full-lines %s | ||
| # | ||
| # RUN: | FileCheck -dump-input=fail -match-full-lines --implicit-check-not=Error: %s | ||
| # END. | ||
|
|
||
| # CHECK: UNRESOLVED: shtest-glob :: glob-echo.txt ({{[^)]*}}) | ||
| # CHECK: TypeError: string argument expected, got 'GlobItem' | ||
|
|
||
| # CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}}) | ||
| # CHECK: # error: command failed with exit status: 1 | ||
| # CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}}) | ||
| # CHECK: # | Error: 'mkdir' command failed, {{.*}}example_file1.input' | ||
| # CHECK-NEXT: # | Error: 'mkdir' command failed, {{.*}}example_file2.input' | ||
| # CHECK: # error: command failed with exit status: 1 |
Uh oh!
There was an error while loading. Please reload this page.