-
Notifications
You must be signed in to change notification settings - Fork 28
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
[tech] simpler gtfs reading api #780
Conversation
closes #739 hide the `Configuration` needed to read GTFS to have easier hello world and an api closer to the ntfs module. Also add a `gtfs::read` method that detect if the GTFS is a zip or not (like `ntfs::read`). now the canonimal way to read a gtfs is: ```rust let model = transit_model::gtfs::read("path to a zip or directory")?; ``` For better control there is also: ```rust let model = transit_model::gtfs::read_from_path("path to a directory")?; ``` ```rust let model = transit_model::gtfs::read_from_zip("path to a zip")?; ``` or even a `gtfs::from_read` method that takes a reader (cf doc). When a configuration is need a `Reader` struct is needed ```rust let conf = gtfs::Configuration { read_as_line: true, ..Default::default() }; let model = transit_model::gtfs::Reader::new(conf).from(input_dir)?; ```
damn clippy doesn't like |
I feel the I feel we have several choices (feel free to add more if I missed some): 1 keep it this wayignore clippy warning 2 use parse in struct as proposed2a and don't change free functionsthis way we are coherent with reader.parse_zip_read()
reader.parse_zip_path()
reader.parse_dir_path()
reader.parse()
// and
transit_model::gtfs::read()
transit_model::gtfs::from_zip()
transit_model::gtfs::from_path()
transit_model::gtfs::from_zip_read() 2b and change free functionsAnd should we change the reader.parse_zip_read()
reader.parse_zip_path()
reader.parse_dir_path()
reader.parse()
// and
transit_model::gtfs::parse()
transit_model::gtfs::parse_zip_path()
transit_model::gtfs::parse_dir_path()
transit_model::gtfs::parse_zip_read() ConclusionI'd vote for 1. or 2a. since they are easy to implement and I feel the api is nice, but I'm open to suggestion |
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.
Nice refactorization. For your question, I'd vote 2a too. One is a builder pattern and the other are free functions so I feel they can be named differently. Note that I see one weird thing: we have reader.parse_zip_read()
but we have transit_model::gtfs::from_read()
. Should we have transit_model::gtfs::from_zip_read()
?
// let resp = reqwest::blocking::get(url)?; // or async call | ||
// let data = std::io::Cursor::new(resp.bytes()?.to_vec()); | ||
// let model = transit_model::gtfs::from_read(data, &url, configuration)?; | ||
/// ```ignore |
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.
Why do we need to ignore it? Because reqwest
is not part of the dependency-tree? Why didn't it fail before?
For this specific documentation example, we might be able to find another example that doesn't require to bring a big dependency?
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.
yes reqwest is not a dependency, it cannot be build.
Before the was only 2 /
so it was not build at all 😅
Do you have an example in mind? It's true that it's a shame not to build all examples, but I think it can be nice to have a real use case here.
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.
Opened a PR targeting this branch to explore activation of doc test: #782
Let you take only what's fine out of it.
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.
Bringing reqwest
will considerably increase the build time as it pull an important number of transitive dependencies. This is one of the reason reqwest
was removed from transit_model
in the first place. So even if what you propose does work, I'm not sure we want to go that way.
Also, it does bring a dependency to the network inside the tests, I'm not entirely sure if it's risky or not but usually, a test that does not depend on the outside is more reliable.
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.
OK, locally I didn't hit the reqwest
build time (but it looks like CI doesn't have it so easy).
Added to network and to the files that would move, it's a pain indeed.
Should we add only the transit_model:: for Errors? (and the complete output line for ntfs doc-test)?
ok for Is it ok for you if I also change the |
311652d
to
b363c4d
Compare
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.
Why parse_from_zip_reader()
? I thought parse_zip_reader()
was fine and a bit less a mouthful.
isn't or we can remove all the |
I'd be OK to remove |
ok, last call I hope 😅 I only changed the Reader functions: reader.parse(..)
reader.parse_zip(..)
reader.parse_dir(..)
reader.parse_zip_reader(.., ...) |
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.
Fine refactor, did not review all thoroughly but 👍 from me.
// let resp = reqwest::blocking::get(url)?; // or async call | ||
// let data = std::io::Cursor::new(resp.bytes()?.to_vec()); | ||
// let model = transit_model::gtfs::from_read(data, &url, configuration)?; | ||
/// ```ignore |
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.
Opened a PR targeting this branch to explore activation of doc test: #782
Let you take only what's fine out of it.
Co-authored-by: Pierre-Etienne Bougué <pierre-etienne.bougue@kisio.com>
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.
Fine for me, pick what you want (if anything) from my PR and close it 👍
closes #739 and preparation adding a bit of docs.
Hide the
Configuration
needed to read GTFS to have easier hello world and an api closer to the ntfs module.Also add a
gtfs::read
method that detect if the GTFS is a zip or not (likentfs::read
).now the canonimal way to read a gtfs is:
For better control there is also:
or even a
gtfs::from_read
method that takes a reader (cf doc).When a configuration is needed, a
Reader
struct needs to be instanciatedNote: I did not use
parse_from_*
like it was discussed previously because I think this naming is more consistent with the NTFS.