Conversation
|
Changes unknown |
rust/agama-locale-data/src/lib.rs
Outdated
|
|
||
| #[derive(Debug, Deserialize)] | ||
| pub struct Keyboards { | ||
| pub keyboard: Vec<Keyboard> |
There was a problem hiding this comment.
np: If you do not plan to add anything else, you could use the newtype pattern idiom.
imobachgs
left a comment
There was a problem hiding this comment.
I don't know whether we need to split the code into so many modules, but it looks fine, as I do not have enough experience. I would do reduce the amount of repeated code too.
And thanks for writing those unit tests 💯
| pub mod ranked; | ||
|
|
||
| pub fn get_keyboards() -> keyboard::Keyboards { | ||
| const FILE_PATH: &str = "/usr/share/langtable/data/keyboards.xml.gz"; |
There was a problem hiding this comment.
I would put all the constants outside of the functions so it is easier to adjust the names. Although I would expect Rust not define the const on every single call.
rust/agama-dbus-server/src/main.rs
Outdated
| self.keyboard_id = keyboard.to_string(); | ||
| } | ||
|
|
||
| fn list_timezones(&self, locale: &str) -> Vec<(String, String)> { |
There was a problem hiding this comment.
A bad input makes a thread panic and then the service is running in an unusable state. We should send error replies instead
$ ./target/debug/agama-dbus-server &
$ busctl --user call org.opensuse.Agama.Locale1 /org/opensuse/Agama/Locale1 org.opensuse.Agama.Locale1 ListTimezones s idontknow
thread 'zbus::Connection executor' panicked at 'Wrong language {language}', agama-locale-data/src/localization.rs:12:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Call failed: Connection timed outuse a file_reader helper
|
@jreidinger I have pushed code that enables error reporting via the D-Bus methods Funnily, it does not help with the error that I originally encountered: ListTimezones("nosuchlanguage") because that one is pretty deep down the call stack and I want to think about the general API there first. |
rust/agama-locale-data/src/lib.rs
Outdated
| #[test] | ||
| fn test_get_languages() { | ||
| let result = get_languages().unwrap(); | ||
| assert_eq!(result.language.len(), 356); |
There was a problem hiding this comment.
Guess what, on my system this fails because the actual result is 354 🤣
There was a problem hiding this comment.
interesting why you have different data from langtable.
There was a problem hiding this comment.
I think I took an old python3-langtable-0.0.51 and symlinked the directory. But the result is valid even for proper packaging: upstream will add some data and this will break our brittle tests.
considering langtable, de-emphasizing systemd but not throwing it away just yet because systemd:locale != langtable:(territory+language) well yes but the `+` is a nontrivial operation
|
CI Failures:
|
this only helps for local testing, not for CI
TODO: move this test to integration tests where we can install the python-langtable-data dependency
Its child services would fail anyway when they could not reach Locale
…ks it that's why we would see the login screen in Playwright tests and that needs the frontend built and installed first
|
@jreidinger I made CI green again, yay :) |
imobachgs
left a comment
There was a problem hiding this comment.
The approach looks good. I have some comments, especially about the internal APIs. Nothing to block this PR, though.
rust/agama-dbus-server/src/locale.rs
Outdated
| let (loc_language, loc_territory) = agama_locale_data::parse_locale(locale.as_str())?; | ||
| let languages = agama_locale_data::get_languages()?; | ||
| let territories = agama_locale_data::get_territories()?; | ||
| let language = languages |
There was a problem hiding this comment.
I like that get_languages and get_territories return their structs (territory::Territory and languages::Languages). But it would be even better if those structs implemented an API to find a language or a territory instead of iterating here. You would not even need to know that the languages::Languages has a language field.
Not to mention that this code would be much shorter.
There was a problem hiding this comment.
Agreed, I think it makes sense. I just want to have something working quickly and then abstract usable parts to those structs. Parts that are really used.
|
|
||
| #[dbus_interface(property)] | ||
| fn locales(&self) -> Vec<String> { | ||
| return self.locales.to_owned(); |
There was a problem hiding this comment.
I would say it is more idiomatic to omit the return (and the semicolon).
rust/agama-dbus-server/src/locale.rs
Outdated
|
|
||
| #[dbus_interface(property)] | ||
| fn supported_locales(&self) -> Vec<String> { | ||
| return self.supported_locales.to_owned(); |
There was a problem hiding this comment.
| return self.supported_locales.to_owned(); | |
| self.supported_locales.to_owned() |
Co-authored-by: Imobach González Sosa <igonzalezsosa@suse.com>
and other doc fixes thanks to Imo's review
or else the daemon WILL disconnect you!! ;-)
thanks to Imo and https://www.deepl.com/write Also link to the cargo_audit PR CI skip, docs only
by running `cargo test` in integration_tests job where we do have the langtable dependency With that, integration_tests has swallowed the entire cli_build job.
This makes python-langtable-data available if you only set up the backend I hope I got the split right
Problem
Language dbus backend is quite limited in functionality and still eating and lot of memory.
Solution
try to write language component in rust to compare it.
The D-Bus interface
org.opensuse.Agama.Language1is replaced byorg.opensuse.Agama.Locale1, described in doc/locale_api.mdTwo new crates in the
rust/directory:python-langtable-data.rpmwhich is just the XML part without the Python code