Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to specify the output directory #104

Merged
merged 8 commits into from Jun 21, 2017
Merged

Add an option to specify the output directory #104

merged 8 commits into from Jun 21, 2017

Conversation

h4llow3En
Copy link
Contributor

This closes #96.

@h4llow3En h4llow3En changed the title Add an option to specify the output directory WIP: Add an option to specify the output directory Jun 16, 2017
@h4llow3En h4llow3En changed the title WIP: Add an option to specify the output directory Add an option to specify the output directory Jun 16, 2017
let tmp = PathBuf::from(dir);
match tmp.extension() {
Some(_) => {
tt_warning!(status, "file extention in outdir; only the directory will be used");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extention => extension
Maybe also outdir => `-o/--outdir`, so it's clear that outdir means the command line option?

@@ -363,7 +363,7 @@ struct ProcessingSession {
/// This is the virtual "CWD" that our filesystem accesses use. It is the
/// dirname of `primary_input_path`, or an empty path (i.e., corresponding
/// to the CWD if `primary_input_path` is None.
fs_root: PathBuf,
#[allow(unused)] fs_root: PathBuf,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is #[allow(unused)] necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this in because now it is unused. But maybe it will be needed later?
Else there would be a warning while compiling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, I misunderstood, I thought the fs_root below is this one. I think that it is better to remove it. It's easy to add it back if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will do this

}};
if !output_path.exists() { return Err(ErrorKind::Msg(format!("output directory \"{}\" does not exist", output_path.to_string_lossy())).into());}
} else {
output_path = fs_root.clone().to_path_buf()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a double clone? Just clone() seems enough.

Copy link
Contributor Author

@h4llow3En h4llow3En Jun 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just clone() returns a &Path which is mismatched with PathBuf. Even if it should be equal because *PathBuf is a Path

}
None => tmp,
}};
if !output_path.exists() { return Err(ErrorKind::Msg(format!("output directory \"{}\" does not exist", output_path.to_string_lossy())).into());}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_string_lossy => display

@@ -692,9 +714,10 @@ impl ProcessingSession {
continue;
}

let mut real_path = self.fs_root.clone();
let mut real_path = self.output_path.clone();
real_path.push(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be written as

let real_path = self.output_path.join(name);

let tempdir = setup_and_copy_files(&["subdirectory/content/1.tex"]);

let output = run_tectonic(tempdir.path(),
&["--format=plain.fmt.gz", "subdirectory/content/1.tex", "--outdir=subdirectory/non_existant"]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non_existant => non_existent

}};
if !output_path.exists() { return Err(ErrorKind::Msg(format!("output directory \"{}\" does not exist", output_path.display())).into());}
} else {
output_path = fs_root.clone().to_path_buf()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, fs_root is Path. In that case, fs_root.to_path_buf() (or fs_root.to_owned()) should do.

Copy link
Collaborator

@pkgw pkgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me so long to get to this! Thanks, looks good — I just have a few small stylistic requests.

io_builder.filesystem_root(par);
} else {
return Err(ErrorKind::Msg(format!("can't figure out a parent directory for input path \"{}\"",
tex_path.to_string_lossy())).into());
}
}

if let Some(dir) = args.value_of("outdir") {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.

}
None => &tmp,
}};
if !output_path.exists() { return Err(ErrorKind::Msg(format!("output directory \"{}\" does not exist", output_path.display())).into());}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't condense the bodies of if statements to single lines. That is, please put the return statement and closing bracket on their own lines.

.long("outdir")
.short("o")
.value_name("OUTDIR")
.help("The output directory. Default: Same like INPUT."))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format the default description as it appears in the other arguments; something like

The directory in which to place output files. [default: the directory containing INPUT]

@h4llow3En
Copy link
Contributor Author

As you wished, I cleaned up the Code

Copy link
Collaborator

@pkgw pkgw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi — I was looking over this PR again and I noticed a few more things in the handling of the argument that I think should be changed a bit. They're subtle but I think they're important for providing consistent behavior for the user. Can you please make these tweaks too? Thanks for taking the time to work through the process!

io_builder.filesystem_root(par);
} else {
return Err(ErrorKind::Msg(format!("can't figure out a parent directory for input path \"{}\"",
tex_path.to_string_lossy())).into());
}
}

if let Some(dir) = args.value_of("outdir") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use value_of_os to get an OsString from the argument.

if let Some(dir) = args.value_of("outdir") {
output_path = {
let tmp = Path::new(dir);
match tmp.extension() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code should special-case the circumstance where the argument path has an extension. It's not common but sometimes directory names have extensions like files, and in those cases you'll get surprising behavior because the program will alter the path that you pass it.

None => &tmp,
}
};
if !output_path.exists() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, I think here the check should use is_dir, not exists. I think this is closer to what we want and it will handle the case where the user inadvertently passes a filename instead of a directory name to the -o option.

@h4llow3En
Copy link
Contributor Author

I applied you change requests. Could you rerun the one failed test, please?

@pkgw
Copy link
Collaborator

pkgw commented Jun 21, 2017

Transient test failure resolved. Thanks!

@pkgw pkgw merged commit 6761ceb into tectonic-typesetting:master Jun 21, 2017
Mrmaxmeier pushed a commit to Mrmaxmeier/tectonic that referenced this pull request Oct 1, 2019
use objc crate's msg_send! macro to replace placeholders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specify output path
3 participants