Skip to content
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

Fix a few regex inefficiencies #1326

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rye-devtools/src/rye_devtools/find_uv_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class UvDownloads:
"pc-windows-msvc": ("windows", None),
}

RE = re.compile(r"uv-(?P<arch>[^\-]+)-(?P<plat_env>.+)(\.tar\.gz|\.zip)$")
RE = re.compile(r"uv-(?P<arch>[^-]+)-(?P<plat_env>.+)(\.tar\.gz|\.zip)$")

def __init__(self, client: httpx.Client) -> None:
self.client = client
Expand Down
2 changes: 1 addition & 1 deletion rye/src/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ while to_resolve:
print(json.dumps(result))
"#;
static SUCCESSFULLY_DOWNLOADED_RE: Lazy<Regex> =
Lazy::new(|| Regex::new("(?m)^Successfully downloaded (.*?)$").unwrap());
Lazy::new(|| Regex::new("(?m)^Successfully downloaded (.*)").unwrap());

#[derive(Eq, PartialEq)]
pub struct ToolInfo {
Expand Down
6 changes: 3 additions & 3 deletions rye/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::uv::{UvBuilder, UvPackageUpgrade};

static FILE_EDITABLE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^-e (file://.*?)\s*$").unwrap());
static DEP_COMMENT_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^ # (?:(via)|(?:via (.*?))|(?: (.*?)))$").unwrap());
Lazy::new(|| Regex::new(r"^ # (?:via$|via (.*)| (.*))").unwrap());
static REQUIREMENTS_HEADER: &str = r#"# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
Expand All @@ -41,7 +41,7 @@ static REQUIREMENTS_HEADER: &str = r#"# generated by rye

"#;
static PARAM_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^# (pre|features|all-features|with-sources|universal):\s*(.*?)$").unwrap()
Regex::new(r"^# (pre|features|all-features|with-sources|universal):\s*(.*)").unwrap()
});

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -569,7 +569,7 @@ fn finalize_lockfile(
continue;
}
} else if let Some(m) = DEP_COMMENT_RE.captures(line) {
if let Some(dep) = m.get(2).or_else(|| m.get(3)).map(|x| x.as_str()) {
if let Some(dep) = m.get(1).or_else(|| m.get(2)).map(|x| x.as_str()) {
if !dep.starts_with("-r ") {
// we cannot tell today based on the output where this comes from. This
// can show up because it's a root dependency, because it's a dev dependency
Expand Down
2 changes: 1 addition & 1 deletion rye/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn get_default_author_with_fallback(dir: &PathBuf) -> Option<(String, String
.arg("config")
.arg("--get-regexp")
.current_dir(dir)
.arg("^user.(name|email)$")
.arg(r"^user\.(name|email)$")
.stdout(Stdio::piped())
.output()
{
Expand Down
4 changes: 4 additions & 0 deletions rye/tests/.test-list.rs.pending-snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"run_id":"1725330156-141805000","line":18,"new":{"module_name":"test_list","snapshot_name":"basic_list","metadata":{"source":"rye/tests/test-list.rs","assertion_line":18,"info":{"program":"rye","args":["list"],"env":{"__RYE_UV_EXCLUDE_NEWER":"2023-11-18T12:00:00Z","RYE_HOME":"/Users/crmarsh/workspace/rye/target/debug/rye-test-dir/home","UV_CACHE_DIR":"/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.rye-tests---5aZXcS/uv-cache"}}},"snapshot":"success: true\nexit_code: 0\n----- stdout -----\n\n----- stderr -----\n"},"old":{"module_name":"test_list","metadata":{},"snapshot":"success: true\nexit_code: 0\n----- stdout -----\njinja2==3.1.2\nmarkupsafe==2.1.3\n-e file:[TEMP_PATH]/project\n\n----- stderr -----"}}
{"run_id":"1725330156-141805000","line":47,"new":null,"old":null}
{"run_id":"1725330197-789961000","line":47,"new":null,"old":null}
{"run_id":"1725330197-789961000","line":18,"new":null,"old":null}
6 changes: 3 additions & 3 deletions rye/tests/test_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ fn test_version() {
let _guard = space.lock_rye_home();

let mut settings = Settings::clone_current();
settings.add_filter(r"(?m)^(rye )\d+\.\d+\.\d+?$", "$1[VERSION]");
settings.add_filter(r"(?m)^(commit: ).*?$", "$1[COMMIT]");
settings.add_filter(r"(?m)^(platform: ).*?$", "$1[PLATFORM]");
settings.add_filter(r"(?m)^(rye )\d+\.\d+\.\d+$", "$1[VERSION]");
settings.add_filter(r"(?m)^(commit: ).*", "$1[COMMIT]");
settings.add_filter(r"(?m)^(platform: ).*", "$1[PLATFORM]");
let _guard = settings.bind_to_scope();

rye_cmd_snapshot!(space.rye_cmd().arg("--version"), @r###"
Expand Down
Loading