-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat(python): add head/tail under string namespace #10339
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
474cd28
Add head/tail under string namespace
mcrumiller 741d61e
Fix docstring
mcrumiller acf6b9e
Add head/tail on rust side & update docstring
mcrumiller 125eba2
Add head/tail to docs list
mcrumiller 1924999
Clean up i64/u64 conversion
mcrumiller 36adb83
Initial add of negative n
mcrumiller b8cb454
Try to implement negative n for str_head
mcrumiller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import os | ||
import re | ||
import sys | ||
import time | ||
from pathlib import Path | ||
|
||
|
||
def launch_debugging() -> None: | ||
""" | ||
Debug Rust files via Python. | ||
|
||
Determine the pID for the current debugging session, attach the Rust LLDB launcher, | ||
and execute the originally-requested script. | ||
""" | ||
if len(sys.argv) == 1: | ||
raise RuntimeError( | ||
"launch.py is not meant to be executed directly; please use the `Python: " | ||
"Debug Rust` debugging configuration to run a python script that uses the " | ||
"polars library." | ||
) | ||
|
||
# get the current process ID | ||
pID = os.getpid() | ||
|
||
# print to the console to allow the "Rust LLDB" routine to pick up on the signal | ||
launch_file = Path(__file__).parents[2] / ".vscode/launch.json" | ||
if not launch_file.exists(): | ||
raise RuntimeError(f"Cannot locate {launch_file}") | ||
with launch_file.open("r") as f: | ||
launch_info = f.read() | ||
|
||
# overwrite the pid found in launch.config with the pid for the current process | ||
# match initial the "Rust LLDB" definition with the pid immediately after | ||
pattern = re.compile('("Rust LLDB",\\s*"pid":\\s*")\\d+(")') | ||
found = pattern.search(launch_info) | ||
if not found: | ||
raise RuntimeError( | ||
"Cannot locate pid definition in launch.json for Rust LLDB configuration. " | ||
"Please follow the instructions in CONTRIBUTING.md for creating the " | ||
"launch configuration." | ||
) | ||
|
||
launch_info_with_new_pid = pattern.sub(rf"\g<1>{pID}\g<2>", launch_info) | ||
with launch_file.open("w") as f: | ||
f.write(launch_info_with_new_pid) | ||
|
||
# print pID to the debug console. This auto-triggers the Rust LLDB configurations. | ||
print(f"pID = {pID}") | ||
|
||
# give the LLDB time to connect. We may have to play with this setting. | ||
time.sleep(1) | ||
|
||
# run the originally requested file | ||
# update sys.argv so that when exec() is called, it's populated with the requested | ||
# script name in sys.argv[0], and the remaining args after | ||
sys.argv.pop(0) | ||
with Path(sys.argv[0]).open() as fh: | ||
script_contents = fh.read() | ||
|
||
# path to the script to be executed | ||
fh = Path(sys.argv[0]) | ||
exec(compile(script_contents, fh, mode="exec"), {"__name__": "__main__"}) | ||
|
||
|
||
if __name__ == "__main__": | ||
launch_debugging() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 also added this note to both the str and expr docstrings for
slice
.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 wanted to be explicit in the definition as per @orlp 's comment here, but I wonder if we should remove the "non-surrogate" part, since not many people will recognize what that means.
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.
Without it it's technically not correct. You can also call it a Unicode Scalar Value like the Rust docs if you prefer.