Skip to content

Commit

Permalink
Merge branch 'alpha' of github.com:Wandalen/wTools into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed Mar 22, 2024
2 parents 933a0aa + 42b24a1 commit aa7cf24
Show file tree
Hide file tree
Showing 22 changed files with 972 additions and 361 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,17 @@ default-features = true
## test experimental

[workspace.dependencies.test_experimental_a]
version = "~0.3.0"
version = "~0.5.0"
path = "module/test/a"
default-features = true

[workspace.dependencies.test_experimental_b]
version = "~0.2.0"
version = "~0.3.0"
path = "module/test/b"
default-features = true

[workspace.dependencies.test_experimental_c]
version = "~0.2.0"
version = "~0.3.0"
path = "module/test/c"
default-features = true

Expand Down
38 changes: 38 additions & 0 deletions module/move/wca/src/ca/grammar/types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
pub( crate ) mod private
{
use crate::*;
use std::fmt::
{
Display,
Formatter
};
use wtools;
use wtools::{ error::Result, err };
use wtools::Itertools;

/// Available types that can be converted to a `Value`
///
Expand Down Expand Up @@ -87,6 +93,38 @@ pub( crate ) mod private
List( Vec< Value > ),
}

impl Display for Value
{
fn fmt( &self, f : &mut Formatter< '_ >) -> std::fmt::Result
{
match self
{
Value::String( s ) =>
{
write!( f , "{s}" )?;
}
Value::Number( n ) =>
{
write!( f, "{n}" )?;
}
Value::Path( p ) =>
{
write!( f, "{}", p.display() )?;
}
Value::Bool( b ) =>
{
write!( f, "{b}" )?;
}
Value::List( list ) =>
{
let list = list.iter().map( | element | element.to_string() ).join( "," ); // qqq : don't hardcode ", " find way to get original separator
write!( f, "{list}" )?;
}
}
Ok( () )
}
}

macro_rules! value_into_impl
{
( $( $value_kind : path => $( $kind : ty => $cast : expr ),+ );+ ) =>
Expand Down
24 changes: 24 additions & 0 deletions module/move/wca/tests/inc/commands_aggregator/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,29 @@ tests_impls!

a_id!( (), executor.command( dictionary, grammar_command ).unwrap() );
}

// qqq : make the following test work
// fn subject_with_spaces()
// {
// let query = "SELECT title, links, MIN( published ) FROM Frames";
// let ca = CommandsAggregator::former()
// .grammar(
// [
// wca::Command::former()
// .hint( "hint" )
// .long_hint( "long_hint" )
// .phrase( "query.execute" )
// .subject( "SQL query", Type::String, false )
// .form(),
// ])
// .executor(
// [
// ( "query.execute".to_owned(), Routine::new( move |( args, _ )| { assert_eq!( query, args.get_owned::< &str >( 0 ).unwrap() ); Ok( () ) } ) ),
// ])
// .build();

// a_id!( (), ca.perform( vec![ ".query.execute".to_string(), query.into() ] ).unwrap() );
// }
}

//
Expand All @@ -257,4 +280,5 @@ tests_index!
string_subject_with_colon,
no_prop_subject_with_colon,
optional_prop_subject_with_colon,
// subject_with_spaces,
}
51 changes: 51 additions & 0 deletions module/move/wca/tests/inc/parser/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,56 @@ tests_impls!
);
}

// qqq : the parser must be able to accept a list of arguments(std::env::args())
// fn with_spaces_in_value()
// {
// let parser = Parser::former().form();

// a_id!
// (
// ParsedCommand
// {
// name : "command".into(),
// subjects : vec![ "value with spaces".into() ],
// properties : HashMap::new(),
// },
// parser.command( vec![ ".command".to_string(), "value with spaces".into() ] ).unwrap()
// );

// a_id!
// (
// ParsedCommand
// {
// name : "command".into(),
// subjects : vec![],
// properties : HashMap::from_iter([ ( "prop".into(), "value with spaces".into() ) ]),
// },
// parser.command( vec![ ".command".to_string(), "prop:value with spaces".into() ] ).unwrap()
// );

// a_id!
// (
// ParsedCommand
// {
// name : "command".into(),
// subjects : vec![],
// properties : HashMap::from_iter([ ( "prop".into(), "value with spaces".into() ) ]),
// },
// parser.command( vec![ ".command".to_string(), "prop:".into(), "value with spaces".into() ] ).unwrap()
// );

// a_id!
// (
// ParsedCommand
// {
// name : "command".into(),
// subjects : vec![],
// properties : HashMap::from_iter([ ( "prop".into(), "value with spaces".into() ) ]),
// },
// parser.command( vec![ ".command".to_string(), "prop".into(), ":".into(), "value with spaces".into() ] ).unwrap()
// );
// }

fn not_only_alphanumeric_symbols()
{
let parser = Parser::former().form();
Expand Down Expand Up @@ -387,6 +437,7 @@ tests_index!
{
basic,
with_spaces,
// with_spaces_in_value,
not_only_alphanumeric_symbols,
same_command_and_prop_delimeter,
path_in_subject,
Expand Down
103 changes: 26 additions & 77 deletions module/move/willbe/src/action/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod private
pub workspace_root_dir : Option< AbsolutePath >,
/// Represents a collection of packages that are roots of the trees.
pub wanted_to_publish : Vec< CrateDir >,
pub plan : Option< package::PublishPlan >,
/// Represents a collection of packages and their associated publishing reports.
pub packages : Vec<( AbsolutePath, package::PublishReport )>
}
Expand All @@ -30,62 +31,19 @@ mod private
{
if self.packages.is_empty()
{
f.write_fmt( format_args!( "Nothing to publish" ) )?;
write!( f, "Nothing to publish" )?;
return Ok( () );
}
write!( f, "Tree(-s):\n" )?;
let name_bump_report = self
.packages
.iter()
.filter_map( |( _, r )| r.bump.as_ref() )
.map( | b | &b.base )
.filter_map( | b | b.name.as_ref().and_then( | name | b.old_version.as_ref().and_then( | old | b.new_version.as_ref().map( | new | ( name, ( old, new ) ) ) ) ) )
.collect::< HashMap< _, _ > >();
for wanted in &self.wanted_to_publish
if let Some( plan ) = &self.plan
{
let list = action::list
(
action::list::ListOptions::former()
.path_to_manifest( wanted.clone() )
.format( action::list::ListFormat::Tree )
.dependency_sources([ action::list::DependencySource::Local ])
.dependency_categories([ action::list::DependencyCategory::Primary ])
.form()
)
.map_err( |( _, _e )| std::fmt::Error )?;
let action::list::ListReport::Tree( list ) = list else { unreachable!() };

fn callback( name_bump_report : &HashMap< &String, ( &String, &String) >, mut r : action::list::ListNodeReport ) -> action::list::ListNodeReport
{
if let Some(( old, new )) = name_bump_report.get( &r.name )
{
r.version = Some( format!( "({old} -> {new})" ) );
}
r.normal_dependencies = r.normal_dependencies.into_iter().map( | r | callback( name_bump_report, r ) ).collect();
r.dev_dependencies = r.dev_dependencies.into_iter().map( | r | callback( name_bump_report, r ) ).collect();
r.build_dependencies = r.build_dependencies.into_iter().map( | r | callback( name_bump_report, r ) ).collect();

r
}
let list = list.into_iter().map( | r | callback( &name_bump_report, r ) ).collect();
write!( f, "Tree{} :\n", if self.wanted_to_publish.len() > 1 { "s" } else { "" } )?;
plan.display_as_tree( f, &self.wanted_to_publish )?;

let list = action::list::ListReport::Tree( list );
write!( f, "{}\n", list )?;
}
writeln!( f, "The following packages are pending for publication :" )?;
for ( idx, package ) in self.packages.iter().map( |( _, p )| p ).enumerate()
{
if let Some( bump ) = &package.bump
{
match ( &bump.base.name, &bump.base.old_version, &bump.base.new_version )
{
( Some( name ), Some( old ), Some( new ) ) => writeln!( f, "[{idx}] {name} ({old} -> {new})" )?,
_ => {}
}
}
writeln!( f, "The following packages are pending for publication :" )?;
plan.display_as_list( f )?;
}

write!( f, "\nActions :\n" )?;
writeln!( f, "\nActions :" )?;
for ( path, report ) in &self.packages
{
let report = report.to_string().replace("\n", "\n ");
Expand All @@ -98,7 +56,7 @@ mod private
{
path.as_ref()
};
f.write_fmt( format_args!( "Publishing crate by `{}` path\n {report}\n", path.display() ) )?;
write!( f, "Publishing crate by `{}` path\n {report}", path.display() )?;
}

Ok( () )
Expand Down Expand Up @@ -135,14 +93,12 @@ mod private

Workspace::with_crate_dir( dir ).err_with( || report.clone() )?
};
report.workspace_root_dir = Some
(
metadata
.workspace_root()
.err_with( || report.clone() )?
.try_into()
.err_with( || report.clone() )?
);
let workspace_root_dir : AbsolutePath = metadata
.workspace_root()
.err_with( || report.clone() )?
.try_into()
.err_with( || report.clone() )?;
report.workspace_root_dir = Some( workspace_root_dir.clone() );
let packages = metadata.load().err_with( || report.clone() )?.packages().err_with( || report.clone() )?;
let packages_to_publish : Vec< _ > = packages
.iter()
Expand Down Expand Up @@ -184,26 +140,19 @@ mod private
let subgraph = graph::remove_not_required_to_publish( &package_map, &tmp, &packages_to_publish, dir.clone() );
let subgraph = subgraph.map( | _, n | n, | _, e | e );

let queue = graph::toposort( subgraph ).unwrap().into_iter().map( | n | package_map.get( &n ).unwrap() ).collect::< Vec< _ > >();
let queue = graph::toposort( subgraph ).unwrap().into_iter().map( | n | package_map.get( &n ).unwrap() ).cloned().collect::< Vec< _ > >();

for package in queue
let plan = package::PublishPlan::former()
.workspace_dir( CrateDir::try_from( workspace_root_dir ).unwrap() )
.option_base_temp_dir( dir.clone() )
.dry( dry )
.packages( queue )
.form();
report.plan = Some( plan.clone() );
for package_report in package::perform_packages_publish( plan ).err_with( || report.clone() )?
{
let args = package::PublishSingleOptions::former()
.package( package )
.force( true )
.option_base_temp_dir( &dir )
.dry( dry )
.form();
let current_report = package::publish_single( args )
.map_err
(
| ( current_report, e ) |
{
report.packages.push(( package.crate_dir().absolute_path(), current_report.clone() ));
( report.clone(), e.context( "Publish list of packages" ) )
}
)?;
report.packages.push(( package.crate_dir().absolute_path(), current_report ));
let path : &std::path::Path = package_report.get_info.as_ref().unwrap().current_path.as_ref();
report.packages.push(( AbsolutePath::try_from( path ).unwrap(), package_report ));
}

if temp
Expand Down
28 changes: 26 additions & 2 deletions module/move/willbe/src/action/publish_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ mod private
use wtools::error::for_app::Result;
use diff::{ DiffReport, crate_diff };

/// Options for `publish_diff` command
#[ derive( Debug, former::Former ) ]
pub struct PublishDiffOptions
{
path : PathBuf,
keep_archive : Option< PathBuf >,
}

/// Return the differences between a local and remote package versions.
#[ cfg_attr( feature = "tracing", tracing::instrument ) ]
pub fn publish_diff( path : PathBuf ) -> Result< DiffReport >
pub fn publish_diff( o : PublishDiffOptions ) -> Result< DiffReport >
{
let path = AbsolutePath::try_from( path )?;
let path = AbsolutePath::try_from( o.path )?;
let dir = CrateDir::try_from( path )?;

let package = package::Package::try_from( dir.clone() )?;
Expand All @@ -25,6 +33,21 @@ mod private
let l = CrateArchive::read( packed_crate::local_path( name, version, dir )? )?;
let r = CrateArchive::download_crates_io( name, version ).unwrap();

if let Some( out_path ) = o.keep_archive
{
_ = std::fs::create_dir_all( &out_path );
for path in r.list()
{
let local_path = out_path.join( path );
let folder = local_path.parent().unwrap();
_ = std::fs::create_dir_all( folder );

let content = r.content_bytes( path ).unwrap();

std::fs::write( local_path, content )?;
}
}

Ok( crate_diff( &l, &r ) )
}
}
Expand All @@ -33,6 +56,7 @@ mod private

crate::mod_interface!
{
orphan use PublishDiffOptions;
/// Publishes the difference between the local and published versions of a package.
orphan use publish_diff;
}
5 changes: 5 additions & 0 deletions module/move/willbe/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ pub( crate ) mod private
.kind( Type::Path )
.optional( true )
.end()
.property( "keep_archive" )
.hint( "Save remote package version to the specified path" )
.kind( Type::Path )
.optional( true )
.end()
.routine( command::publish_diff )
.end()

Expand Down
Loading

0 comments on commit aa7cf24

Please sign in to comment.