Clean up imports
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 1m3s
Cargo CI / Lint (pull_request) Successful in 44s

This commit is contained in:
Wojciech Kozlowski 2024-01-22 22:59:14 +01:00
parent 1616cf1a36
commit 410945eef5
31 changed files with 118 additions and 101 deletions

View File

@ -1,10 +1,12 @@
use paste::paste;
use std::path::PathBuf; use std::path::PathBuf;
use paste::paste;
use structopt::{clap::AppSettings, StructOpt}; use structopt::{clap::AppSettings, StructOpt};
use musichoard::{ use musichoard::{
collection::artist::ArtistId,
database::json::{backend::JsonDatabaseFileBackend, JsonDatabase}, database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
ArtistId, MusicHoard, MusicHoardBuilder, NoLibrary, MusicHoard, MusicHoardBuilder, NoLibrary,
}; };
type MH = MusicHoard<NoLibrary, JsonDatabase<JsonDatabaseFileBackend>>; type MH = MusicHoard<NoLibrary, JsonDatabase<JsonDatabaseFileBackend>>;

View File

@ -1,9 +1,11 @@
use core::mem; use std::mem;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::merge::{Merge, MergeSorted}; use crate::core::collection::{
use super::track::Track; merge::{Merge, MergeSorted},
track::Track,
};
/// An album is a collection of tracks that were released together. /// An album is a collection of tracks that were released together.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]

View File

@ -8,9 +8,11 @@ use serde::{Deserialize, Serialize};
use url::Url; use url::Url;
use uuid::Uuid; use uuid::Uuid;
use super::album::Album; use crate::core::collection::{
use super::merge::{Merge, MergeSorted}; album::Album,
use super::Error; merge::{Merge, MergeSorted},
Error,
};
/// An artist. /// An artist.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]

View File

@ -1,3 +1,5 @@
//! The collection module defines the core data types and their relations.
pub mod album; pub mod album;
pub mod artist; pub mod artist;
pub mod track; pub mod track;

View File

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::merge::Merge; use crate::core::collection::merge::Merge;
/// A single track on an album. /// A single track on an album.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]

View File

@ -3,7 +3,7 @@
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use super::IJsonDatabaseBackend; use crate::core::database::json::IJsonDatabaseBackend;
/// JSON database backend that uses a local file for persistent storage. /// JSON database backend that uses a local file for persistent storage.
pub struct JsonDatabaseFileBackend { pub struct JsonDatabaseFileBackend {

View File

@ -1,13 +1,14 @@
//! Module for storing MusicHoard data in a JSON file database. //! Module for storing MusicHoard data in a JSON file database.
pub mod backend;
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;
use crate::Collection; use crate::core::{
collection::Collection,
use super::{IDatabase, LoadError, SaveError}; database::{IDatabase, LoadError, SaveError},
};
pub mod backend;
impl From<serde_json::Error> for LoadError { impl From<serde_json::Error> for LoadError {
fn from(err: serde_json::Error) -> LoadError { fn from(err: serde_json::Error) -> LoadError {
@ -66,7 +67,13 @@ mod tests {
use mockall::predicate; use mockall::predicate;
use crate::{core::testmod::FULL_COLLECTION, Artist, ArtistId, Collection}; use crate::core::{
collection::{
artist::{Artist, ArtistId},
Collection,
},
testmod::FULL_COLLECTION,
};
use super::*; use super::*;
use testmod::DATABASE_JSON; use testmod::DATABASE_JSON;

View File

@ -1,14 +1,14 @@
//! Module for storing MusicHoard data in a database. //! Module for storing MusicHoard data in a database.
#[cfg(feature = "database-json")]
pub mod json;
use std::fmt; use std::fmt;
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;
use crate::Collection; use crate::core::collection::Collection;
#[cfg(feature = "database-json")]
pub mod json;
/// Trait for interacting with the database. /// Trait for interacting with the database.
#[cfg_attr(test, automock)] #[cfg_attr(test, automock)]

View File

@ -8,7 +8,7 @@ use std::{
str, str,
}; };
use super::{Error, IBeetsLibraryExecutor}; use crate::core::library::{beets::IBeetsLibraryExecutor, Error};
const BEET_DEFAULT: &str = "beet"; const BEET_DEFAULT: &str = "beet";

View File

@ -1,14 +1,15 @@
//! Module for interacting with the music library via //! Module for interacting with the music library via
//! [beets](https://beets.readthedocs.io/en/stable/). //! [beets](https://beets.readthedocs.io/en/stable/).
pub mod executor;
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;
use crate::core::collection::track::Format; use crate::core::{
collection::track::Format,
use super::{Error, Field, ILibrary, Item, Query}; library::{Error, Field, ILibrary, Item, Query},
};
pub mod executor;
macro_rules! list_format_separator { macro_rules! list_format_separator {
() => { () => {
@ -176,7 +177,7 @@ mod testmod;
mod tests { mod tests {
use mockall::predicate; use mockall::predicate;
use crate::library::testmod::LIBRARY_ITEMS; use crate::core::library::testmod::LIBRARY_ITEMS;
use super::*; use super::*;
use testmod::LIBRARY_BEETS; use testmod::LIBRARY_BEETS;

View File

@ -1,5 +1,8 @@
//! Module for interacting with the music library. //! Module for interacting with the music library.
#[cfg(feature = "library-beets")]
pub mod beets;
use std::{collections::HashSet, fmt, num::ParseIntError, str::Utf8Error}; use std::{collections::HashSet, fmt, num::ParseIntError, str::Utf8Error};
#[cfg(test)] #[cfg(test)]
@ -7,9 +10,6 @@ use mockall::automock;
use crate::core::collection::track::Format; use crate::core::collection::track::Format;
#[cfg(feature = "library-beets")]
pub mod beets;
/// Trait for interacting with the music library. /// Trait for interacting with the music library.
#[cfg_attr(test, automock)] #[cfg_attr(test, automock)]
pub trait ILibrary { pub trait ILibrary {

View File

@ -1,6 +1,6 @@
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use crate::{library::Item, Format}; use crate::core::{collection::track::Format, library::Item};
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> { pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {
vec![ vec![

View File

@ -1,4 +1,3 @@
// FIXME: visibility?
pub mod collection; pub mod collection;
pub mod database; pub mod database;
pub mod library; pub mod library;

View File

@ -1,12 +1,12 @@
//! The core MusicHoard module. Serves as the main entry-point into the library.
#![allow(clippy::module_inception)] #![allow(clippy::module_inception)]
pub mod musichoard; pub mod musichoard;
pub mod musichoard_builder; pub mod musichoard_builder;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use super::collection; use crate::core::{collection, database, library};
use super::database;
use super::library;
/// Error type for `musichoard`. /// Error type for `musichoard`.
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]

View File

@ -2,15 +2,17 @@ use std::{collections::HashMap, mem};
use paste::paste; use paste::paste;
use super::collection::{ use crate::core::{
album::{Album, AlbumId}, collection::{
artist::{Artist, ArtistId}, album::{Album, AlbumId},
track::{Quality, Track, TrackId}, artist::{Artist, ArtistId},
Collection, Merge, track::{Quality, Track, TrackId},
Collection, Merge,
},
database::IDatabase,
library::{ILibrary, Item, Query},
musichoard::Error,
}; };
use super::database::IDatabase;
use super::library::{ILibrary, Item, Query};
use super::Error;
/// The Music Hoard. It is responsible for pulling information from both the library and the /// The Music Hoard. It is responsible for pulling information from both the library and the
/// database, ensuring its consistent and writing back any changes. /// database, ensuring its consistent and writing back any changes.
@ -334,13 +336,14 @@ impl<LIB, DB: IDatabase> MusicHoard<LIB, DB> {
mod tests { mod tests {
use mockall::predicate; use mockall::predicate;
use super::*; use crate::core::{
collection::artist::{ArtistId, Bandcamp, MusicBrainz, MusicButler, Qobuz},
database::{self, MockIDatabase},
library::{self, testmod::LIBRARY_ITEMS, MockILibrary},
testmod::{FULL_COLLECTION, LIBRARY_COLLECTION},
};
// FIXME: check all crate::* imports - are the tests where they should be? use super::*;
use crate::core::collection::artist::{ArtistId, Bandcamp, MusicBrainz, MusicButler, Qobuz};
use crate::core::testmod::{FULL_COLLECTION, LIBRARY_COLLECTION};
use crate::database::{self, MockIDatabase};
use crate::library::{self, testmod::LIBRARY_ITEMS, MockILibrary};
static MUSICBRAINZ: &str = static MUSICBRAINZ: &str =
"https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8"; "https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8";

View File

@ -1,6 +1,8 @@
use super::database::IDatabase; use crate::core::{
use super::library::ILibrary; database::IDatabase,
use super::musichoard::{MusicHoard, NoDatabase, NoLibrary}; library::ILibrary,
musichoard::musichoard::{MusicHoard, NoDatabase, NoLibrary},
};
/// Builder for [`MusicHoard`]. Its purpose is to make it easier to set various combinations of /// Builder for [`MusicHoard`]. Its purpose is to make it easier to set various combinations of
/// library/database or their absence. /// library/database or their absence.
@ -51,10 +53,9 @@ impl<LIB, DB> MusicHoardBuilder<LIB, DB> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use crate::core::{database::NullDatabase, library::NullLibrary};
use crate::database::NullDatabase; use super::*;
use crate::library::NullLibrary;
#[test] #[test]
fn no_library_no_database() { fn no_library_no_database() {

View File

@ -1,10 +1,10 @@
use once_cell::sync::Lazy;
use crate::core::collection::{ use crate::core::collection::{
album::{Album, AlbumId}, album::{Album, AlbumId},
artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz}, artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz},
track::{Format, Quality, Track, TrackId}, track::{Format, Quality, Track, TrackId},
}; };
use once_cell::sync::Lazy;
use crate::tests::*; use crate::tests::*;
pub static LIBRARY_COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| library_collection!()); pub static LIBRARY_COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| library_collection!());

View File

@ -1,21 +1,11 @@
//! MusicHoard - a music collection manager. //! MusicHoard - a music collection manager.
// FIXME: make private and only provide via re-exports. mod core;
pub mod core;
// FIXME: validate the re-exports. pub use core::collection;
pub use core::database; pub use core::database;
pub use core::library; pub use core::library;
// FIXME: validate the re-exports.
pub use core::collection::{
album::{Album, AlbumId},
artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz},
track::{Format, Quality, Track, TrackId},
Collection,
};
// FIXME: validate the re-exports
pub use core::musichoard::{ pub use core::musichoard::{
musichoard::{MusicHoard, NoDatabase, NoLibrary}, musichoard::{MusicHoard, NoDatabase, NoLibrary},
musichoard_builder::MusicHoardBuilder, musichoard_builder::MusicHoardBuilder,

View File

@ -1,3 +1,5 @@
mod tui;
use std::{ffi::OsString, fs::OpenOptions, io, path::PathBuf}; use std::{ffi::OsString, fs::OpenOptions, io, path::PathBuf};
use ratatui::{backend::CrosstermBackend, Terminal}; use ratatui::{backend::CrosstermBackend, Terminal};
@ -18,7 +20,6 @@ use musichoard::{
MusicHoardBuilder, NoDatabase, NoLibrary, MusicHoardBuilder, NoDatabase, NoLibrary,
}; };
mod tui;
use tui::{event::EventChannel, handler::EventHandler, listener::EventListener, ui::Ui, Tui}; use tui::{event::EventChannel, handler::EventHandler, listener::EventListener, ui::Ui, Tui};
#[derive(StructOpt)] #[derive(StructOpt)]

View File

@ -2,7 +2,7 @@ use crossterm::event::{KeyEvent, MouseEvent};
use std::fmt; use std::fmt;
use std::sync::mpsc; use std::sync::mpsc;
use super::ui::UiError; use crate::tui::ui::UiError;
#[derive(Debug)] #[derive(Debug)]
pub enum EventError { pub enum EventError {
@ -104,7 +104,7 @@ mod tests {
use crate::tui::ui::UiError; use crate::tui::ui::UiError;
use super::{Event, EventChannel, EventError}; use super::*;
#[test] #[test]
fn event_sender() { fn event_sender() {

View File

@ -3,7 +3,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;
use super::{ use crate::tui::{
event::{Event, EventError, EventReceiver}, event::{Event, EventError, EventReceiver},
ui::IUi, ui::IUi,
}; };

View File

@ -1,4 +1,4 @@
use musichoard::{database::IDatabase, library::ILibrary, Collection, MusicHoard}; use musichoard::{collection::Collection, database::IDatabase, library::ILibrary, MusicHoard};
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;

View File

@ -164,20 +164,17 @@ mod testmod;
mod tests { mod tests {
use std::{io, thread}; use std::{io, thread};
use musichoard::Collection;
use ratatui::{backend::TestBackend, Terminal}; use ratatui::{backend::TestBackend, Terminal};
use super::testmod::COLLECTION; use musichoard::collection::Collection;
use super::{ use crate::tui::{
event::EventError, handler::MockIEventHandler, lib::MockIMusicHoard, listener::MockIEventListener, ui::Ui,
handler::MockIEventHandler,
lib::MockIMusicHoard,
listener::MockIEventListener,
ui::{IUi, Ui},
Error, Tui,
}; };
use super::*;
use testmod::COLLECTION;
pub fn terminal() -> Terminal<TestBackend> { pub fn terminal() -> Terminal<TestBackend> {
let backend = TestBackend::new(150, 30); let backend = TestBackend::new(150, 30);
Terminal::new(backend).unwrap() Terminal::new(backend).unwrap()

View File

@ -1,6 +1,7 @@
use musichoard::{ use musichoard::collection::{
Album, AlbumId, Artist, ArtistId, ArtistProperties, Bandcamp, Format, MusicBrainz, MusicButler, album::{Album, AlbumId},
Qobuz, Quality, Track, TrackId, artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz},
track::{Format, Quality, Track, TrackId},
}; };
use once_cell::sync::Lazy; use once_cell::sync::Lazy;

View File

@ -1,6 +1,11 @@
use std::fmt; use std::fmt;
use musichoard::{Album, Artist, Collection, Format, Track}; use musichoard::collection::{
album::Album,
artist::Artist,
track::{Format, Track},
Collection,
};
use ratatui::{ use ratatui::{
backend::Backend, backend::Backend,
layout::{Alignment, Rect}, layout::{Alignment, Rect},
@ -9,7 +14,7 @@ use ratatui::{
Frame, Frame,
}; };
use super::{lib::IMusicHoard, Error}; use crate::tui::{lib::IMusicHoard, Error};
#[derive(Debug)] #[derive(Debug)]
pub enum UiError { pub enum UiError {

View File

@ -1,14 +1,15 @@
use std::{fs, path::PathBuf}; use std::{fs, path::PathBuf};
use once_cell::sync::Lazy;
use tempfile::NamedTempFile;
use musichoard::{ use musichoard::{
collection::artist::Artist,
database::{ database::{
json::{backend::JsonDatabaseFileBackend, JsonDatabase}, json::{backend::JsonDatabaseFileBackend, JsonDatabase},
IDatabase, IDatabase,
}, },
Artist,
}; };
use once_cell::sync::Lazy;
use tempfile::NamedTempFile;
use crate::testlib::COLLECTION; use crate::testlib::COLLECTION;

View File

@ -5,14 +5,14 @@ mod testlib;
use musichoard::MusicHoard; use musichoard::MusicHoard;
use crate::testlib::COLLECTION;
#[cfg(feature = "database-json")] #[cfg(feature = "database-json")]
use musichoard::database::json::{backend::JsonDatabaseFileBackend, JsonDatabase}; use musichoard::database::json::{backend::JsonDatabaseFileBackend, JsonDatabase};
#[cfg(feature = "library-beets")] #[cfg(feature = "library-beets")]
use musichoard::library::beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary}; use musichoard::library::beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary};
use crate::testlib::COLLECTION;
#[test] #[test]
#[cfg(feature = "database-json")] #[cfg(feature = "database-json")]
#[cfg(feature = "library-beets")] #[cfg(feature = "library-beets")]

View File

@ -12,7 +12,7 @@ use musichoard::library::{
Field, ILibrary, Item, Query, Field, ILibrary, Item, Query,
}; };
use super::testmod::LIBRARY_ITEMS; use crate::library::testmod::LIBRARY_ITEMS;
pub static BEETS_TEST_CONFIG_PATH: Lazy<PathBuf> = pub static BEETS_TEST_CONFIG_PATH: Lazy<PathBuf> =
Lazy::new(|| fs::canonicalize("./tests/files/library/config.yml").unwrap()); Lazy::new(|| fs::canonicalize("./tests/files/library/config.yml").unwrap());

View File

@ -1,4 +1,4 @@
mod testmod;
#[cfg(feature = "library-beets")] #[cfg(feature = "library-beets")]
pub mod beets; pub mod beets;
mod testmod;

View File

@ -1,6 +1,6 @@
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use musichoard::{library::Item, Format}; use musichoard::{collection::track::Format, library::Item};
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> { pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {
vec![ vec![

View File

@ -1,9 +1,12 @@
use musichoard::{
Album, AlbumId, Artist, ArtistId, ArtistProperties, Bandcamp, Collection, Format, MusicBrainz,
MusicButler, Qobuz, Quality, Track, TrackId,
};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use musichoard::collection::{
album::{Album, AlbumId},
artist::{Artist, ArtistId, ArtistProperties, Bandcamp, MusicBrainz, MusicButler, Qobuz},
track::{Format, Quality, Track, TrackId},
Collection,
};
pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection { pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
vec![ vec![
Artist { Artist {