From b72c4272d723a9f8f93b9d979eab086a94b2252b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristram=20Gr=C3=A4bener?= Date: Tue, 31 Dec 2024 15:03:40 +0100 Subject: [PATCH] editoast: extract osm_to_railjson in separate binary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tristram Gräbener --- editoast/Cargo.lock | 2 +- editoast/Cargo.toml | 2 +- editoast/osm_to_railjson/Cargo.toml | 1 + editoast/osm_to_railjson/README.md | 2 +- editoast/osm_to_railjson/src/main.rs | 17 +++++++++++++++++ editoast/src/client/mod.rs | 11 ----------- editoast/src/main.rs | 3 --- 7 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 editoast/osm_to_railjson/src/main.rs diff --git a/editoast/Cargo.lock b/editoast/Cargo.lock index 104c1b8a85e..74e7cc953c6 100644 --- a/editoast/Cargo.lock +++ b/editoast/Cargo.lock @@ -1324,7 +1324,6 @@ dependencies = [ "opentelemetry-semantic-conventions", "opentelemetry_sdk", "ordered-float", - "osm_to_railjson", "paste", "pathfinding", "postgis_diesel", @@ -3066,6 +3065,7 @@ dependencies = [ name = "osm_to_railjson" version = "0.1.0" dependencies = [ + "clap", "editoast_schemas", "geo-types", "geos", diff --git a/editoast/Cargo.toml b/editoast/Cargo.toml index 4ed1763b464..20ec23d1f0b 100644 --- a/editoast/Cargo.toml +++ b/editoast/Cargo.toml @@ -26,6 +26,7 @@ license = "LGPL-3.0" [workspace.dependencies] chrono = { version = "0.4.39", default-features = false, features = ["serde"] } +clap = { version = "4.5.23", features = ["derive", "env"] } derivative = "2.2.0" diesel = { version = "2.2", default-features = false, features = [ "32-column-tables", @@ -158,7 +159,6 @@ opentelemetry-otlp = { version = "0.27.0", default-features = false, features = opentelemetry-semantic-conventions.workspace = true opentelemetry_sdk.workspace = true ordered-float = { version = "4.6.0", features = ["serde"] } -osm_to_railjson = { path = "./osm_to_railjson" } paste.workspace = true pathfinding = "4.13.0" postgis_diesel.workspace = true diff --git a/editoast/osm_to_railjson/Cargo.toml b/editoast/osm_to_railjson/Cargo.toml index 3689efa53da..90bf95c6398 100644 --- a/editoast/osm_to_railjson/Cargo.toml +++ b/editoast/osm_to_railjson/Cargo.toml @@ -5,6 +5,7 @@ version.workspace = true edition.workspace = true [dependencies] +clap.workspace = true editoast_schemas.workspace = true geo-types = "0.7.14" geos.workspace = true diff --git a/editoast/osm_to_railjson/README.md b/editoast/osm_to_railjson/README.md index b36e2159e29..a78a9394cca 100644 --- a/editoast/osm_to_railjson/README.md +++ b/editoast/osm_to_railjson/README.md @@ -9,7 +9,7 @@ Example for Germany: 2. Launch conversion (release build of editoast and conversion can be long): ```sh cd ../../editoast - cargo run --release -- osm-to-railjson + cargo run --release -p osm_to_railjson -- ``` 3. Load railjson (also possible through [a script](../../scripts/load-railjson-infra.sh) or OSRD's web interface): ```sh diff --git a/editoast/osm_to_railjson/src/main.rs b/editoast/osm_to_railjson/src/main.rs new file mode 100644 index 00000000000..cfe275fb034 --- /dev/null +++ b/editoast/osm_to_railjson/src/main.rs @@ -0,0 +1,17 @@ +use clap::Parser; +use std::path::PathBuf; + +#[derive(Parser)] +#[command(about, long_about = "Extracts a railjson from OpenStreetMap data")] +pub struct OsmToRailjsonArgs { + /// Input file in the OSM PBF format + pub osm_pbf_in: PathBuf, + /// Output file in Railjson format + pub railjson_out: PathBuf, +} + +fn main() { + let args = OsmToRailjsonArgs::parse(); + osm_to_railjson::osm_to_railjson(args.osm_pbf_in, args.railjson_out) + .expect("Could not convert osm to railjson"); +} diff --git a/editoast/src/client/mod.rs b/editoast/src/client/mod.rs index 6c91a73d705..243815f20f8 100644 --- a/editoast/src/client/mod.rs +++ b/editoast/src/client/mod.rs @@ -16,7 +16,6 @@ mod valkey_config; use std::env; use std::path::PathBuf; -use clap::Args; use clap::Parser; use clap::Subcommand; use clap::ValueEnum; @@ -77,7 +76,6 @@ pub enum Commands { ElectricalProfiles(electrical_profiles_commands::ElectricalProfilesCommands), ImportRollingStock(ImportRollingStockArgs), ImportTowedRollingStock(ImportRollingStockArgs), - OsmToRailjson(OsmToRailjsonArgs), #[command(about, long_about = "Prints the OpenApi of the service")] Openapi, #[command(subcommand, about, long_about = "Search engine related commands")] @@ -102,15 +100,6 @@ pub enum Commands { Healthcheck(CoreArgs), } -#[derive(Args, Debug)] -#[command(about, long_about = "Extracts a railjson from OpenStreetMap data")] -pub struct OsmToRailjsonArgs { - /// Input file in the OSM PBF format - pub osm_pbf_in: PathBuf, - /// Output file in Railjson format - pub railjson_out: PathBuf, -} - /// Prints the OpenApi to stdout pub fn print_openapi() { let openapi = OpenApiRoot::build_openapi(); diff --git a/editoast/src/main.rs b/editoast/src/main.rs index 754c6999d67..9348119020a 100644 --- a/editoast/src/main.rs +++ b/editoast/src/main.rs @@ -138,9 +138,6 @@ async fn run() -> Result<(), Box> { Commands::ImportTowedRollingStock(args) => { import_towed_rolling_stock(args, db_pool.into()).await } - Commands::OsmToRailjson(args) => { - osm_to_railjson::osm_to_railjson(args.osm_pbf_in, args.railjson_out) - } Commands::Openapi => { print_openapi(); Ok(())