-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ss/no-multiv
- Loading branch information
Showing
22 changed files
with
4,559 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! Dump standard extensions in serialized form. | ||
use clap::Parser; | ||
use std::{io::Write, path::PathBuf}; | ||
|
||
/// Dump the standard extensions. | ||
#[derive(Parser, Debug)] | ||
#[clap(version = "1.0", long_about = None)] | ||
#[clap(about = "Write standard extensions.")] | ||
#[group(id = "hugr")] | ||
#[non_exhaustive] | ||
pub struct ExtArgs { | ||
/// Output directory | ||
#[arg( | ||
default_value = ".", | ||
short, | ||
long, | ||
value_name = "OUTPUT", | ||
help = "Output directory." | ||
)] | ||
pub outdir: PathBuf, | ||
} | ||
|
||
impl ExtArgs { | ||
/// Write out the standard extensions in serialized form. | ||
/// Qualified names of extensions used to generate directories under the specified output directory. | ||
/// E.g. extension "foo.bar.baz" will be written to "OUTPUT/foo/bar/baz.json". | ||
pub fn run_dump(&self) { | ||
let base_dir = &self.outdir; | ||
|
||
for (name, ext) in hugr_core::std_extensions::std_reg().into_iter() { | ||
let mut path = base_dir.clone(); | ||
for part in name.split('.') { | ||
path.push(part); | ||
} | ||
path.set_extension("json"); | ||
|
||
std::fs::create_dir_all(path.clone().parent().unwrap()).unwrap(); | ||
// file buffer | ||
let mut file = std::fs::File::create(&path).unwrap(); | ||
|
||
serde_json::to_writer_pretty(&mut file, &ext).unwrap(); | ||
|
||
// write newline, for pre-commit end of file check that edits the file to | ||
// add newlines if missing. | ||
file.write_all(b"\n").unwrap(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.