Skip to content

Commit

Permalink
Rename ImageSpec to ImageRef.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfachan committed Dec 6, 2024
1 parent 6217bee commit 0f99e28
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions crates/maelstrom-client-base/src/items.proto
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ enum ImageUse {
IMAGE_USE_WORKING_DIRECTORY = 2;
}

message ImageSpec {
message ImageRef {
string name = 1;
repeated ImageUse use = 2;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ message JobTty {

message ContainerParent {
oneof parent {
ImageSpec image = 1;
ImageRef image = 1;
ContainerRef container = 2;
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/maelstrom-client-base/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ where
}

#[derive(Clone, Debug, Eq, Hash, IntoProtoBuf, Ord, PartialEq, PartialOrd, TryFromProtoBuf)]
#[proto(proto_buf_type = "proto::ImageSpec")]
pub struct ImageSpec {
#[proto(proto_buf_type = "proto::ImageRef")]
pub struct ImageRef {
pub name: String,
pub r#use: EnumSet<ImageUse>,
}
Expand All @@ -67,15 +67,15 @@ pub struct ContainerRef {
enum_type = "proto::container_parent::Parent"
)]
pub enum ContainerParent {
Image(ImageSpec),
Image(ImageRef),
Container(ContainerRef),
}

#[macro_export]
macro_rules! image_container_parent {
(@expand [] -> [$name:expr, $layers:literal, $environment:literal, $working_directory:literal]) => {
$crate::spec::ContainerParent::Image(
$crate::spec::ImageSpec {
$crate::spec::ImageRef {
name: $name.into(),
r#use: {
let mut r#use = EnumSet::new();
Expand Down
4 changes: 2 additions & 2 deletions crates/maelstrom-client-process/src/preparer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use maelstrom_base::{
NonEmpty, Sha256Digest, Timeout, UserId, Utf8PathBuf,
};
use maelstrom_client_base::spec::{
ContainerParent, ContainerSpec, ConvertedImage, EnvironmentSpec, ImageSpec, ImageUse,
ContainerParent, ContainerSpec, ConvertedImage, EnvironmentSpec, ImageRef, ImageUse,
JobSpec as ClientJobSpec, LayerSpec,
};
use maelstrom_util::ext::OptionExt as _;
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<DepsT: Deps> Preparer<DepsT> {
let (pending_image, get_image) = {
match container.parent {
None | Some(ContainerParent::Container(_)) => (None, None),
Some(ContainerParent::Image(ImageSpec { name, r#use })) => {
Some(ContainerParent::Image(ImageRef { name, r#use })) => {
if r#use.is_empty() {
(None, None)
} else {
Expand Down
12 changes: 6 additions & 6 deletions crates/maelstrom-pytest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use maelstrom_base::{
};
use maelstrom_client::{
job_spec,
spec::{ImageSpec, LayerSpec, PrefixOptions},
spec::{ImageRef, LayerSpec, PrefixOptions},
AcceptInvalidRemoteContainerTlsCerts, CacheDir, Client, ClientBgProcess,
ContainerImageDepotDir, ContainerParent, ProjectDir, StateDir,
};
Expand Down Expand Up @@ -169,13 +169,13 @@ struct PytestTestCollector<'client> {
build_dir: RootBuf<BuildDir>,
cache_dir: RootBuf<CacheDir>,
client: &'client Client,
test_layers: Mutex<HashMap<ImageSpec, LayerSpec>>,
test_layers: Mutex<HashMap<ImageRef, LayerSpec>>,
}

impl PytestTestCollector<'_> {
fn get_pip_packages(
&self,
image_spec: ImageSpec,
image_spec: ImageRef,
ref_: &DockerReference,
ui: &UiSender,
) -> Result<Utf8PathBuf> {
Expand Down Expand Up @@ -308,7 +308,7 @@ impl PytestTestCollector<'_> {
Ok(upper.try_into()?)
}

fn build_test_layer(&self, image: ImageSpec, ui: &UiSender) -> Result<Option<LayerSpec>> {
fn build_test_layer(&self, image: ImageRef, ui: &UiSender) -> Result<Option<LayerSpec>> {
let image_name: ImageName = image.name.parse()?;
let ImageName::Docker(ref_) = image_name else {
return Ok(None);
Expand Down Expand Up @@ -336,7 +336,7 @@ pub(crate) struct PytestTestArtifact {
ignored_tests: Vec<String>,
package: PytestPackageId,
pytest_options: PytestConfigValues,
test_layers: HashMap<ImageSpec, LayerSpec>,
test_layers: HashMap<ImageRef, LayerSpec>,
}

#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
Expand Down Expand Up @@ -468,7 +468,7 @@ impl CollectTests for PytestTestCollector<'_> {
Ok((handle, stream))
}

fn build_test_layers(&self, images: Vec<ImageSpec>, ui: &UiSender) -> Result<()> {
fn build_test_layers(&self, images: Vec<ImageRef>, ui: &UiSender) -> Result<()> {
let mut test_layers = self.test_layers.lock().unwrap();
for image in images {
if let Entry::Vacant(e) = test_layers.entry(image.clone()) {
Expand Down
4 changes: 2 additions & 2 deletions crates/maelstrom-pytest/src/pytest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
};
use anyhow::{anyhow, bail, Result};
use maelstrom_client::{
spec::{ImageSpec, LayerSpec},
spec::{ImageRef, LayerSpec},
ProjectDir,
};
use maelstrom_test_runner::WaitStatus;
Expand Down Expand Up @@ -123,7 +123,7 @@ pub fn pytest_collect_tests(
pytest_options: &PytestConfigValues,
project_dir: &Root<ProjectDir>,
build_dir: &Root<BuildDir>,
test_layers: HashMap<ImageSpec, LayerSpec>,
test_layers: HashMap<ImageRef, LayerSpec>,
) -> Result<(WaitHandle, TestArtifactStream)> {
compile_python(project_dir.as_ref())?;

Expand Down
4 changes: 2 additions & 2 deletions crates/maelstrom-run/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use maelstrom_base::{
UserId, Utf8PathBuf,
};
use maelstrom_client::spec::{
incompatible, ContainerParent, ContainerSpec, EnvironmentSpec, Image, ImageSpec, ImageUse,
incompatible, ContainerParent, ContainerSpec, EnvironmentSpec, Image, ImageRef, ImageUse,
IntoEnvironment, JobSpec, LayerSpec, PossiblyImage,
};
use serde::de::Error as _;
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Job {
}
};
let parent = self.image.map(|image| {
ContainerParent::Image(ImageSpec {
ContainerParent::Image(ImageRef {
name: image,
r#use: image_use,
})
Expand Down
4 changes: 2 additions & 2 deletions crates/maelstrom-test-runner/src/deps.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{metadata::TestMetadata, ui};
use anyhow::Result;
use maelstrom_base::Utf8PathBuf;
use maelstrom_client::spec::{ImageSpec, LayerSpec};
use maelstrom_client::spec::{ImageRef, LayerSpec};
use maelstrom_util::{process::ExitCode, template::TemplateVars};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -246,7 +246,7 @@ pub trait CollectTests {
fn get_packages(&self, ui: &ui::UiSender) -> Result<Vec<Self::Package>>;

/// Build any test layers that might want to be used later. This function is allowed to block.
fn build_test_layers(&self, _images: Vec<ImageSpec>, _ui: &ui::UiSender) -> Result<()> {
fn build_test_layers(&self, _images: Vec<ImageRef>, _ui: &ui::UiSender) -> Result<()> {
Ok(())
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/maelstrom-test-runner/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use container::TestContainer;
use directive::TestDirective;
use maelstrom_base::{EnumSet, GroupId, JobMount, JobNetwork, Timeout, UserId, Utf8PathBuf};
use maelstrom_client::{
spec::{ContainerParent, EnvironmentSpec, ImageSpec, ImageUse, LayerSpec, PossiblyImage},
spec::{ContainerParent, EnvironmentSpec, ImageRef, ImageUse, LayerSpec, PossiblyImage},
ProjectDir,
};
use maelstrom_util::{fs::Fs, root::Root, template::TemplateVars};
Expand Down Expand Up @@ -110,7 +110,7 @@ impl TestMetadataContainer {

if container.image.is_some() {
self.parent = container.image.as_ref().map(|image| {
ContainerParent::Image(ImageSpec {
ContainerParent::Image(ImageRef {
name: image.into(),
r#use: image_use,
})
Expand Down Expand Up @@ -206,11 +206,11 @@ where
.try_fold(TestMetadata::default(), |m, d| m.try_fold(d))
}

pub fn get_all_images(&self) -> Vec<ImageSpec> {
pub fn get_all_images(&self) -> Vec<ImageRef> {
self.directives
.iter()
.filter_map(|directive| {
directive.container.image.as_ref().map(|name| ImageSpec {
directive.container.image.as_ref().map(|name| ImageRef {
name: name.into(),
r#use: {
let mut image_use = EnumSet::new();
Expand Down
2 changes: 1 addition & 1 deletion py/maelstrom_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Duration,
EnvironmentSpec,
GlobLayer,
ImageSpec,
ImageRef,
ImageUse,
JobDevice,
JobMount,
Expand Down
2 changes: 1 addition & 1 deletion py/maelstrom_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional, Union, Protocol, Sequence
from .items_pb2 import (
GlobLayer,
ImageSpec,
ImageRef,
JobMount,
JobSpec,
PathsLayer,
Expand Down
4 changes: 2 additions & 2 deletions py/run_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import os
import sys

from maelstrom_client import Client, ImageSpec, ContainerSpec, ContainerRef, JobSpec, ImageUse, ContainerParent
from maelstrom_client import Client, ImageRef, ContainerSpec, ContainerRef, JobSpec, ImageUse, ContainerParent

def main():
prog=sys.argv[1]
arguments=sys.argv[2:]

client = Client(slots=4)

image = ImageSpec(name="docker://alpine", use=[ImageUse.IMAGE_USE_LAYERS])
image = ImageRef(name="docker://alpine", use=[ImageUse.IMAGE_USE_LAYERS])
container = ContainerSpec(working_directory="/", parent=ContainerParent(image=image))
spec = JobSpec(
container=container,
Expand Down

0 comments on commit 0f99e28

Please sign in to comment.