Skip to content

Commit

Permalink
Merge pull request #270 from nyx-space/13-support-spk-type-9-lagrange…
Browse files Browse the repository at this point in the history
…-unequal-time-steps

Support SPK Type 9: Lagrange unequal time steps + Support env vars in MetaFile
  • Loading branch information
ChristopherRabotin authored Jun 28, 2024
2 parents afaf489 + d7a2ce3 commit ffd62e6
Show file tree
Hide file tree
Showing 13 changed files with 481 additions and 102 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ jobs:
run: sh dev-env-setup.sh && cd .. # Return to root

- name: Test debug
env:
LAGRANGE_BSP: ${{ secrets.LAGRANGE_BSP }}
run: cargo test --workspace --exclude anise-gui --exclude anise-py

- name: Test release
env:
LAGRANGE_BSP: ${{ secrets.LAGRANGE_BSP }}
run: cargo test --release --workspace --exclude anise-gui --exclude anise-py

lints:
Expand Down Expand Up @@ -85,7 +89,7 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Download data
run: |
wget -O data/de421.bsp http://public-data.nyxspace.com/anise/de421.bsp
Expand Down Expand Up @@ -115,12 +119,17 @@ jobs:

- name: Rust-SPICE hermite validation
run: RUST_BACKTRACE=1 cargo test validate_hermite_type13_ --features spkezr_validation --release --workspace --exclude anise-gui --exclude anise-py -- --nocapture --include-ignored --test-threads 1


- name: Rust-SPICE Lagrange validation
env:
LAGRANGE_BSP: ${{ secrets.LAGRANGE_BSP }}
run: RUST_BACKTRACE=1 cargo test validate_lagrange_type9_with_varying_segment_sizes --features spkezr_validation --release --workspace --exclude anise-gui --exclude anise-py -- --nocapture --include-ignored --test-threads 1

- name: Rust-SPICE PCK validation
run: RUST_BACKTRACE=1 cargo test validate_iau_rotation_to_parent --release --workspace --exclude anise-gui --exclude anise-py -- --nocapture --ignored

- name: Rust-SPICE BPC validation
run: |
run: |
RUST_BACKTRACE=1 cargo test validate_bpc_ --release --workspace --exclude anise-gui --exclude anise-py -- --nocapture --include-ignored --test-threads 1
RUST_BACKTRACE=1 cargo test de440s_translation_verif_venus2emb --release --workspace --exclude anise-gui --exclude anise-py -- --nocapture --include-ignored --test-threads 1
Expand Down Expand Up @@ -148,7 +157,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download data
run: |
wget -O data/de421.bsp http://public-data.nyxspace.com/anise/de421.bsp
Expand All @@ -173,6 +182,9 @@ jobs:
uses: taiki-e/install-action@cargo-llvm-cov

- name: Generate coverage report
env:
LAGRANGE_BSP: ${{ secrets.LAGRANGE_BSP }}
RUSTFLAGS: --cfg __ui_tests
run: |
cd anise # Prevent the workspace flag
cargo llvm-cov clean --workspace
Expand All @@ -183,10 +195,9 @@ jobs:
cargo llvm-cov test --no-report validate_jplde_de440s_no_aberration --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report validate_jplde_de440s_aberration_lt --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report validate_hermite_type13_from_gmat --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report validate_lagrange_type9_with_varying_segment_sizes --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report ut_embed --features embed_ephem
cargo llvm-cov report --lcov > ../lcov.txt
env:
RUSTFLAGS: --cfg __ui_tests
- name: Upload coverage report
uses: codecov/codecov-action@v3
Expand Down Expand Up @@ -217,4 +228,3 @@ jobs:
cd anise # Jump into the package
cargo login $TOKEN
cargo publish
3 changes: 2 additions & 1 deletion anise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ rust-embed = { version = "8.4.0", features = [
"interpolate-folder-path",
"include-exclude",
], optional = true }
regex = {version = "1.10.5" , optional = true}

[dev-dependencies]
rust-spice = "0.7.6"
Expand All @@ -53,7 +54,7 @@ default = ["metaload"]
# Enabling this flag significantly increases compilation times due to Arrow and Polars.
spkezr_validation = []
python = ["pyo3", "pyo3-log"]
metaload = ["url", "reqwest/blocking", "platform-dirs"]
metaload = ["url", "reqwest/blocking", "platform-dirs", "regex"]
embed_ephem = ["rust-embed"]

[[bench]]
Expand Down
40 changes: 39 additions & 1 deletion anise/src/almanac/metaload/metafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

use log::{debug, info};
use platform_dirs::AppDirs;

use regex::Regex;
use serde_derive::{Deserialize, Serialize};
use serde_dhall::StaticType;
use std::env;
use std::fs::{create_dir_all, remove_file, File};
use std::io::Write;
use std::path::Path;
Expand All @@ -32,6 +33,11 @@ use crate::prelude::InputOutputError;

use super::MetaAlmanacError;

/// MetaFile allows downloading a remote file from a URL (http, https only), and interpolation of paths in environment variable using the Dhall syntax `env:MY_ENV_VAR`.
///
/// The data is stored in the user's local temp directory (i.e. `~/.local/share/nyx-space/anise/` on Linux and `AppData/Local/nyx-space/anise/` on Windows).
/// Prior to loading a remote resource, if the local resource exists, its CRC32 will be computed: if it matches the CRC32 of this instance of MetaFile,
/// then the file will not be downloaded a second time.
#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyo3(module = "anise"))]
#[cfg_attr(feature = "python", pyo3(get_all, set_all))]
Expand All @@ -53,6 +59,8 @@ impl MetaFile {
}

pub(crate) fn _process(&mut self) -> Result<(), MetaAlmanacError> {
// First, parse environment variables if any.
self.uri = replace_env_vars(&self.uri);
match Url::parse(&self.uri) {
Err(e) => {
debug!("parsing {} caused {e} -- assuming local path", self.uri);
Expand Down Expand Up @@ -274,6 +282,15 @@ impl MetaFile {
}
}

fn replace_env_vars(input: &str) -> String {
let re = Regex::new(r"env:([A-Z_][A-Z0-9_]*)").unwrap();
re.replace_all(input, |caps: &regex::Captures| {
let var_name = &caps[1];
env::var(var_name).unwrap_or_else(|_| format!("env:{}", var_name))
})
.to_string()
}

#[cfg(test)]
mod ut_metafile {
use super::MetaFile;
Expand Down Expand Up @@ -308,4 +325,25 @@ mod ut_metafile {
assert!(unix_rel_path._process().is_ok());
assert_eq!(unix_rel_path.uri, "../Users/me/meta.dhall".to_string());
}

#[test]
fn test_metafile_regex() {
use std::env;
let mut user_path = MetaFile {
uri: "env:USER/.cargo/env".to_string(),
crc32: None,
};
user_path._process().unwrap();
assert_eq!(user_path.uri, env::var("USER").unwrap() + "/.cargo/env");

let mut unknown_path = MetaFile {
uri: "env:BLAH_BLAH_NO_EXIST/.cargo/env".to_string(),
crc32: None,
};
unknown_path._process().unwrap();
assert_eq!(
unknown_path.uri,
"env:BLAH_BLAH_NO_EXIST/.cargo/env".to_string()
);
}
}
Loading

0 comments on commit ffd62e6

Please sign in to comment.