-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[stdlib] implement mkdtemp #2742
Conversation
Part of the implementation for #2018 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thanks for pushing this forward! This is shaping up nicely, I would just like to see some tests for gettempdir
before we bring it in.
ef2b4c0
to
7a645ad
Compare
) | ||
|
||
# test gettempdir falls back to TMP | ||
with _TempEnvForTest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that this test is going to fail in the internal CI, similar to what happens here:
mojo/stdlib/test/os/test_mkdir_and_rmdir.mojo
Lines 84 to 94 in 011bf40
mkdir(my_dir_path, 0o111) | |
# TODO: This test is failing on Graviton internally in CI, revisit. | |
# with assert_raises(contains="Permission denied"): | |
# var file = open(file_name, "w") | |
# file.close() | |
# if exists(file_name): | |
# remove(file_name) | |
if exists(my_dir_path): | |
rmdir(my_dir_path) |
@laszlokindrat I added some tests for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks! This looks great to me, I just have a few more requests for change, nothing major.
constrained[not sys.os_is_windows(), "windows not supported yet"]() | ||
|
||
var dirlist = List[String]() | ||
var possible_env_vars = List("TMPDIR", "TEMP", "TMP") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be an alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing this to be an alias causes an issue at runtime:
+ mojo /home/temo/repos/mojo/stdlib/test/tempfile/test_tempfile.mojo
<unknown>:0: error: failed to legalize operation 'kgen.param.constant' that was explicitly marked illegal
<unknown>:0: note: see current operation: %2 = "kgen.param.constant"() {value = #interp.store_to_mem<#kgen.struct<#interp.memref<[(memory_blob_bc35f10c536d6691ed3bb9bfa830df1b0bc51395ed96fff37be4aab479df5484, heap, []), (memory_blob_79210cf7423b267ddb5a7bc898de233a883230728f74e5fced11b22adb5eb763, stack, [(0, 0, 0)]), (memory_blob_9c18dd61ff20f539c03848a0ac560e46cc48cc8629755a8236a7c3b7ce7f2026, stack, []), (memory_blob_0e63b401645577494c63bffad4c5e392342e2b004bfd3283a98daf47d391b60d, stack, []), (memory_blob_2bc6fefda0788d1117810a96ee52f69e7ba6c9e594aa2c39c37435a0ff3bcb51, stack, []), (static_string_14f8defe8295f90f25152e66dd3608c11b5b242e9f917c5c31bcabb7c16dd1b7, const_global, []), (static_string_e810509f0bd1009a376d10738b852aa41d0f7edcfe8210f45e95bd7027a9b056, const_global, []), (static_string_b6801ff93b1ce1c9aa784dc10cd72a98d154d8edeb17ea9b1d48d460119c54cf, const_global, []), (memory_blob_bbebd66f64306b5de8c1e7a61f72f2f9b60099f333e5fbe9ab634e6a1e7b7de8, persistent, [(0, 2, 0), (8, 3, 0), (16, 4, 0)])], 0, 0>, 3, 3> : !kgen.struct<(pointer<none>, index, index) memoryOnly>> : !kgen.pointer<struct<(pointer<none>, index, index) memoryOnly>>} : () -> !kgen.pointer<struct<(pointer<none>, index, index) memoryOnly>>
mojo: error: Failed to materialize symbols: { (exec, { KGEN_EE_JIT_GlobalDestructor, main, KGEN_EE_JIT_GlobalConstructor }) } (from the layer: failed to lower module to LLVM IR for archive compilation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the same regression that broke @gabrieldemarmiesse work on SSO from yesterday.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laszlokindrat want me to just revert rather than waiting since I think we have two distinct breakages out in the wild in flight now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, @JoeLoser will try to fix this regression by reverting. @artemiogr97 I will just add a TODO here to improve this.
assert_false(exists(dir_name), "Failed to delete temporary directory") | ||
|
||
|
||
struct _TempEnvForTest: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Followup idea: we could potentially move this to the os
module, or at least to test utils. I always found temporary environment settings useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made _TempEnvForTest
more generic (using dict instead of hard-coded values), I can move it to test_utils
if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks! Let's keep it as is for now; once it lands, you can circle back to it if you want to, it would be highly appreciated! :)
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
Signed-off-by: Artemio Garza Reyna <artemiogr97@gmail.com>
fn __init__( | ||
inout self, | ||
vars_to_set: Dict[String, String], | ||
clean_up_function: fn () raises -> None, | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking: This is fine for now, since it's just a local testing utility. If we move this to os
or testing
, we should add an overload that takes variadic keyword arguments. We should also consider, whether clean_up_function
should be a parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, thank you so much for working on this! It might take a bit on my end to land this, but I hope it will make it in the next nightly.
!sync |
I added an empty |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
Landed in fd697f0! Thank you for your contribution 🎉 |
[External] [stdlib] Implement `tempfile.{mkdtemp,gettempdir}` A new `tempfile` module is added with these two functions. Currently limited to MacOS and Linux. ORIGINAL_AUTHOR=artemiogr97 <57588855+artemiogr97@users.noreply.github.com> PUBLIC_PR_LINK=#2742 --------- Co-authored-by: artemiogr97 <57588855+artemiogr97@users.noreply.github.com> Closes #2742 MODULAR_ORIG_COMMIT_REV_ID: 943428af5d911d2f82d723f54b4029480d68ec5c
No description provided.