Skip to content

Commit

Permalink
feat: format DatabaseConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Jul 18, 2023
1 parent 5540a67 commit 4fb8f1b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile_linter
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt update \
&& add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main' \
&& apt install -y clang-tidy-17

RUN pip install conan==2.0.2
RUN pip install conan==2.0.8

COPY conanfile.py conanprofile.docker ./
RUN mv conanprofile.docker conanprofile
Expand Down
17 changes: 17 additions & 0 deletions include/silo/config/database_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,21 @@ struct [[maybe_unused]] fmt::formatter<silo::config::DatabaseSchema> : fmt::form
) -> decltype(ctx.out());
};

template <>
struct [[maybe_unused]] fmt::formatter<silo::config::DatabaseMetadata>
: fmt::formatter<std::string> {
[[maybe_unused]] static auto format(
const silo::config::DatabaseMetadata& database_metadata,
format_context& ctx
) -> decltype(ctx.out());
};

template <>
struct [[maybe_unused]] fmt::formatter<silo::config::ValueType> : fmt::formatter<std::string> {
[[maybe_unused]] static auto format(
const silo::config::ValueType& value_type,
format_context& ctx
) -> decltype(ctx.out());
};

#endif // SILO_INCLUDE_SILO_CONFIG_DATABASECONFIG_H_
42 changes: 38 additions & 4 deletions src/silo/config/database_config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "silo/config/database_config.h"

#include <fmt/format.h>
#include <algorithm>
#include <iterator>
#include <stdexcept>
Expand Down Expand Up @@ -75,7 +76,7 @@ std::optional<DatabaseMetadata> DatabaseConfig::getMetadata(const std::string& n
) -> decltype(ctx.out()) {
return format_to(
ctx.out(),
"DatabaseConfig[default_nucleotide_sequence: {}, schema: {}",
"{{ default_nucleotide_sequence: '{}', schema: {} }}",
database_config.default_nucleotide_sequence,
database_config.schema
);
Expand All @@ -87,9 +88,42 @@ std::optional<DatabaseMetadata> DatabaseConfig::getMetadata(const std::string& n
) -> decltype(ctx.out()) {
return format_to(
ctx.out(),
"DatabaseSchema[instance_name: {}, primary_key: {}, partition_by: {}]",
"{{ instance_name: '{}', primary_key: '{}', partition_by: '{}', metadata: [{}] }}",
database_schema.instance_name,
database_schema.primary_key,
database_schema.partition_by
database_schema.partition_by,
fmt::join(database_schema.metadata, ",")
);
}
}

[[maybe_unused]] auto fmt::formatter<silo::config::DatabaseMetadata>::format(
const silo::config::DatabaseMetadata& database_metadata,
fmt::format_context& ctx
) -> decltype(ctx.out()) {
return format_to(
ctx.out(),
"{{ name: '{}', type: '{}', generate_index: {} }}",
database_metadata.name,
database_metadata.type,
database_metadata.generate_index
);
}

[[maybe_unused]] auto fmt::formatter<silo::config::ValueType>::format(
const silo::config::ValueType& value_type,
fmt::format_context& ctx
) -> decltype(ctx.out()) {
switch (value_type) {
case silo::config::ValueType::STRING:
return format_to(ctx.out(), "string");
case silo::config::ValueType::DATE:
return format_to(ctx.out(), "date");
case silo::config::ValueType::PANGOLINEAGE:
return format_to(ctx.out(), "pango_lineage");
case silo::config::ValueType::INT:
return format_to(ctx.out(), "int");
case silo::config::ValueType::FLOAT:
return format_to(ctx.out(), "float");
}
return format_to(ctx.out(), "unknown");
}
5 changes: 5 additions & 0 deletions src/silo/config/database_config_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <vector>

#include <spdlog/spdlog.h>
#include <yaml-cpp/yaml.h>

#include "silo/config/database_config.h"
Expand All @@ -19,6 +20,9 @@ struct convert<silo::config::DatabaseConfig> {
} else {
config.default_nucleotide_sequence = "main";
}

SPDLOG_TRACE("Resulting database config: {}", config);

return true;
}
};
Expand Down Expand Up @@ -64,6 +68,7 @@ struct convert<silo::config::DatabaseMetadata> {

namespace silo::config {
DatabaseConfig DatabaseConfigReader::readConfig(const std::filesystem::path& config_path) const {
SPDLOG_INFO("Reading database config from {}", config_path.string());
return YAML::LoadFile(config_path.string()).as<DatabaseConfig>();
}
} // namespace silo::config
2 changes: 0 additions & 2 deletions src/silo/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ void Database::preprocessing(
const config::DatabaseConfig& database_config_
) {
database_config = database_config_;
SPDLOG_DEBUG("preprocessing - using database config: {}", database_config);
SPDLOG_DEBUG("preprocessing - using preprocessing config: {}", preprocessing_config);

SPDLOG_INFO("preprocessing - validate metadata file against config");
preprocessing::MetadataValidator().validateMedataFile(
Expand Down

0 comments on commit 4fb8f1b

Please sign in to comment.