Skip to content

Commit

Permalink
fix(#51): another crack at improving the build system migration forma…
Browse files Browse the repository at this point in the history
…ts from python, ive chosen not to check for the actual path format yet as that will come in a later update
  • Loading branch information
stvnksslr committed Jan 26, 2025
1 parent 74f53e2 commit 7433702
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 29 deletions.
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "README.md"
keywords = ["python", "uv"]

[dependencies]
clap = "4.5.23"
clap = "4.5.27"
dirs = "6.0.0"
log = "0.4.22"
env_logger = "0.11.6"
Expand All @@ -23,9 +23,9 @@ self_update = { version = "0.42.0", features = [
serde = { version = "1.0.216", features = ["derive"] }
toml = "0.8.19"
which = "7.0.1"
semver = "1.0.24"
semver = "1.0.25"
toml_edit = "0.22.22"
serde_json = "1.0.134"
serde_json = "1.0.137"

[dev-dependencies]
tempfile = "3.14.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This project is not associated with astral or the uv project in anyway

## What is it?

UV Migrator is simple cli tool designed to seamlessly transition Python projects from various dependency management systems to the UV package manager.
UV Migrator is simple cli tool designed to seamlessly transition Python projects from various dependency management systems to the UV package manager.
It handles the complexities of migration while preserving your project's dependencies and any existing configs. This project currently supports migrating
applications that consume packages, stay tuned for support for migrating packages themselves.

Expand Down Expand Up @@ -39,7 +39,7 @@ Package Formats

## Coming Soon

Project formats
Project formats
🔄 anaconda projects

## Usage
Expand Down
85 changes: 81 additions & 4 deletions src/utils/build_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ pub fn update_build_system(doc: &mut DocumentMut, project_dir: &Path) -> Result<
.and_then(|packages| packages.as_array())
.is_some_and(|packages| {
packages.iter().any(|pkg| {
pkg.as_inline_table()
.and_then(|t| t.get("include"))
.and_then(|i| i.as_str())
== Some("src")
if let Some(table) = pkg.as_inline_table() {
(table.get("from").and_then(|f| f.as_str()) == Some("src"))
|| (table.get("include").and_then(|i| i.as_str()).is_some()
&& table.get("from").and_then(|f| f.as_str()) == Some("src"))
} else {
false
}
})
});

Expand Down Expand Up @@ -106,6 +109,80 @@ mod tests {
name = "test-project"
version = "0.1.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
"#;

let new_content = r#"
[project]
name = "test-project"
version = "0.1.0"
"#;

let (_temp_dir, mut doc, project_dir) = setup_test_environment(old_content, new_content);

let result = update_build_system(&mut doc, &project_dir).unwrap();
assert!(result);

let build_system = doc.get("build-system").unwrap();
let requires = build_system.get("requires").unwrap().as_array().unwrap();
let first_req = requires.get(0).unwrap().as_str().unwrap();
assert_eq!(first_req, "hatchling");

let backend = build_system.get("build-backend").unwrap().as_str().unwrap();
assert_eq!(backend, "hatchling.build");
}

#[test]
fn test_poetry_to_hatchling_with_just_from_src_package_config() {
let old_content = r#"
[tool.poetry]
name = "test-project"
version = "0.1.0"
[tool.poetry.packages]
packages = [
{ from = "src" },
]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
"#;

let new_content = r#"
[project]
name = "test-project"
version = "0.1.0"
"#;

let (_temp_dir, mut doc, project_dir) = setup_test_environment(old_content, new_content);

let result = update_build_system(&mut doc, &project_dir).unwrap();
assert!(result);

let build_system = doc.get("build-system").unwrap();
let requires = build_system.get("requires").unwrap().as_array().unwrap();
let first_req = requires.get(0).unwrap().as_str().unwrap();
assert_eq!(first_req, "hatchling");

let backend = build_system.get("build-backend").unwrap().as_str().unwrap();
assert_eq!(backend, "hatchling.build");
}

#[test]
fn test_poetry_to_hatchling_with_include_and_from_src_package_config() {
let old_content = r#"
[tool.poetry]
name = "test-project"
version = "0.1.0"
[tool.poetry.packages]
packages = [
{ include = "my_package", from = "src" },
]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down

0 comments on commit 7433702

Please sign in to comment.