Skip to content

Commit

Permalink
Make time an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Aug 26, 2024
1 parent 9d5cfa5 commit 3904ef4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ jobs:
run: cargo clippy --features client,camera
- name: Build client+telescope
run: cargo clippy --features client,telescope
- name: Build client+focuser
run: cargo clippy --features client,focuser
- name: Build server+camera
run: cargo clippy --features server,camera
- name: Build server+telescope
run: cargo clippy --features server,telescope
- name: Build server+focuser
run: cargo clippy --features server,focuser
16 changes: 7 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
async-fn-stream = "0.2.2"
async-trait = "0.1.81"
axum = { version = "0.7.5", optional = true }
bytemuck = { version = "1.17.0", features = ["derive", "extern_crate_std"], optional = true }
bytemuck = { version = "1.17.0", features = ["derive", "extern_crate_std"] }
bytes = { version = "1.7.1", optional = true }
custom_debug = "0.6.1"
default-net = "0.22.0"
Expand All @@ -38,7 +38,7 @@ serde_plain = "1.0.2"
serde_repr = "0.1.19"
socket2 = "0.5.7"
thiserror = "1.0.63"
time = { version = "0.3.36", features = ["formatting", "parsing"] }
time = { version = "0.3.36", features = ["formatting", "parsing"], optional = true }
tokio = { version = "1.39.3", features = ["net", "rt", "io-util"] }
tracing = "0.1.40"
tracing-futures = { version = "0.2.5", features = ["futures-03"] }
Expand All @@ -54,11 +54,9 @@ ctor = "0.2.8"
eframe = "0.28.1"
# apparently Cargo doesn't allow `test` to enable `ndarray/rayon` when `ndarray` is an optional dependency
# hence the duplicate dep with rayon feature
ndarray = { version = "0.16.1", features = ["rayon"] }
nokhwa = { version = "0.10.4", features = ["input-native", "output-threaded"] }
parking_lot = { version = "0.12.3", features = ["arc_lock", "send_guard"] }
serial_test = "3.1.1"
time = { version = "0.3.36", features = ["formatting"] }
tracing-subscriber = "0.3.18"
tracing-error = "0.2.0"
color-eyre = "0.6.3"
Expand All @@ -71,7 +69,7 @@ harness = false
[features]
all-devices = ["camera", "covercalibrator", "dome", "filterwheel", "focuser", "observingconditions", "rotator", "safetymonitor", "switch", "telescope"]

camera = ["dep:mediatype", "dep:bytemuck", "dep:ndarray", "dep:serde-ndim"]
camera = ["dep:mediatype", "dep:ndarray", "dep:serde-ndim", "dep:time"]
covercalibrator = []
dome = []
filterwheel = []
Expand All @@ -80,12 +78,12 @@ observingconditions = []
rotator = []
safetymonitor = []
switch = []
telescope = []
telescope = ["dep:time"]

client = ["dep:reqwest", "dep:bytes", "dep:mime", "dep:rand", "dep:once_cell"]
server = ["dep:axum", "dep:sailfish", "tokio/macros"]
client = ["dep:reqwest", "dep:bytes", "dep:mime", "dep:rand", "dep:once_cell", "time/parsing"]
server = ["dep:axum", "dep:sailfish", "tokio/macros", "time/formatting"]

test = ["client", "server", "camera", "tokio/macros", "tokio/rt-multi-thread"]
test = ["client", "server", "camera", "tokio/macros", "tokio/rt-multi-thread", "ndarray/rayon"]

nightly = []

Expand Down
16 changes: 7 additions & 9 deletions src/api/autogen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ interface EnumType extends RegisteredTypeBase {

interface DateType extends RegisteredTypeBase {
kind: 'Date';
trailingZ: boolean;
formatName: string;
}

interface DeviceMethod {
Expand Down Expand Up @@ -325,7 +325,8 @@ function handleType(
name,
doc: getDoc(schema),
kind: 'Date',
trailingZ: schema.format === 'date-time'
formatName:
schema.format === 'date-time' ? 'DATE_TIME_OFFSET' : 'DATE_TIME'
}));
return rusty('std::time::SystemTime', `${formatter}`);
}
Expand Down Expand Up @@ -668,7 +669,6 @@ use macro_rules_attribute::apply;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use time::format_description::well_known::Iso8601;
pub use server_info::*;
Expand Down Expand Up @@ -745,7 +745,7 @@ ${stringifyIter(types, ({ features, type }) => {
`;
}
case 'Date': {
let format = `Iso8601::DATE_TIME${type.trailingZ ? '_OFFSET' : ''}`;
let format = `&time::format_description::well_known::Iso8601::${type.formatName}`;
return `
${stringifyDoc(type.doc)}
Expand Down Expand Up @@ -775,7 +775,7 @@ ${stringifyIter(types, ({ features, type }) => {
fn serialize<S: serde::Serializer>(value: &time::OffsetDateTime, serializer: S) -> Result<S::Ok, S::Error> {
value
.to_offset(time::UtcOffset::UTC)
.format(&${format})
.format(${format})
.map_err(serde::ser::Error::custom)?
.serialize(serializer)
}
Expand All @@ -791,10 +791,8 @@ ${stringifyIter(types, ({ features, type }) => {
}
fn visit_str<E: serde::de::Error>(self, value: &str) -> Result<Self::Value, E> {
match time::PrimitiveDateTime::parse(value, &${format}) {
Ok(time) => Ok(time.assume_utc()),
Err(err) => Err(serde::de::Error::custom(err)),
}
time::OffsetDateTime::parse(value, ${format})
.map_err(serde::de::Error::custom)
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use macro_rules_attribute::apply;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use time::format_description::well_known::Iso8601;

pub use server_info::*;

Expand Down Expand Up @@ -133,7 +132,7 @@ impl LastExposureStartTime {
) -> Result<S::Ok, S::Error> {
value
.to_offset(time::UtcOffset::UTC)
.format(&Iso8601::DATE_TIME)
.format(&time::format_description::well_known::Iso8601::DATE_TIME)
.map_err(serde::ser::Error::custom)?
.serialize(serializer)
}
Expand All @@ -151,10 +150,11 @@ impl LastExposureStartTime {
}

fn visit_str<E: serde::de::Error>(self, value: &str) -> Result<Self::Value, E> {
match time::PrimitiveDateTime::parse(value, &Iso8601::DATE_TIME) {
Ok(time) => Ok(time.assume_utc()),
Err(err) => Err(serde::de::Error::custom(err)),
}
time::OffsetDateTime::parse(
value,
&time::format_description::well_known::Iso8601::DATE_TIME,
)
.map_err(serde::de::Error::custom)
}
}

Expand Down Expand Up @@ -478,7 +478,7 @@ impl TelescopeUtcdate {
) -> Result<S::Ok, S::Error> {
value
.to_offset(time::UtcOffset::UTC)
.format(&Iso8601::DATE_TIME_OFFSET)
.format(&time::format_description::well_known::Iso8601::DATE_TIME_OFFSET)
.map_err(serde::ser::Error::custom)?
.serialize(serializer)
}
Expand All @@ -496,10 +496,11 @@ impl TelescopeUtcdate {
}

fn visit_str<E: serde::de::Error>(self, value: &str) -> Result<Self::Value, E> {
match time::PrimitiveDateTime::parse(value, &Iso8601::DATE_TIME_OFFSET) {
Ok(time) => Ok(time.assume_utc()),
Err(err) => Err(serde::de::Error::custom(err)),
}
time::OffsetDateTime::parse(
value,
&time::format_description::well_known::Iso8601::DATE_TIME_OFFSET,
)
.map_err(serde::de::Error::custom)
}
}

Expand Down

0 comments on commit 3904ef4

Please sign in to comment.