-
Notifications
You must be signed in to change notification settings - Fork 12
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
Include comments in config files generated with --create-config-file #588
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c8f7ad8
Copy default_config.yaml using shutil instead of loading and saving w…
SylviaWhittle b7a4cc6
Move config string saving into io.py and standardise documentation ou…
SylviaWhittle f678918
PR feedback, thanks @ns-rse
SylviaWhittle 78c6e18
Add tests for added functions in io.py
SylviaWhittle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,21 @@ | |
from multiprocessing import Pool | ||
from pprint import pformat | ||
import sys | ||
from pathlib import Path | ||
import yaml | ||
|
||
import pandas as pd | ||
from tqdm import tqdm | ||
|
||
from topostats import __version__ | ||
from topostats.io import find_files, read_yaml, save_folder_grainstats, write_yaml, LoadScans | ||
from topostats.io import ( | ||
find_files, | ||
read_yaml, | ||
save_folder_grainstats, | ||
write_yaml, | ||
write_config_with_comments, | ||
LoadScans, | ||
) | ||
from topostats.logs.logs import LOGGER_NAME | ||
from topostats.plotting import toposum | ||
from topostats.processing import check_run_steps, completion_message, process_scan | ||
|
@@ -142,11 +150,12 @@ def main(args=None): | |
# Parse command line options, load config (or default) and update with command line options | ||
parser = create_parser() | ||
args = parser.parse_args() if args is None else parser.parse_args(args) | ||
if args.config_file is not None: | ||
config = read_yaml(args.config_file) | ||
if args.config_file is None: | ||
default_config = pkg_resources.open_text(__package__, "default_config.yaml").read() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, very neat trick of shifting the |
||
config = yaml.safe_load(default_config) | ||
else: | ||
default_config = pkg_resources.open_text(__package__, "default_config.yaml") | ||
config = yaml.safe_load(default_config.read()) | ||
config = read_yaml(args.config_file) | ||
|
||
config = update_config(config, args) | ||
|
||
# Set logging level | ||
|
@@ -162,19 +171,10 @@ def main(args=None): | |
validate_config(config, schema=DEFAULT_CONFIG_SCHEMA, config_type="YAML configuration file") | ||
|
||
# Write sample configuration if asked to do so and exit | ||
if args.create_config_file and args.config_file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
raise ValueError("--create-config-file and --config cannot be used together.") | ||
if args.create_config_file: | ||
write_yaml( | ||
config, | ||
output_dir="./", | ||
config_file=args.create_config_file, | ||
header_message="Sample configuration file auto-generated", | ||
) | ||
LOGGER.info(f"A sample configuration has been written to : ./{args.create_config_file}") | ||
LOGGER.info( | ||
"Please refer to the documentation on how to use the configuration file : \n\n" | ||
"https://afm-spm.github.io/TopoStats/usage.html#configuring-topostats\n" | ||
"https://afm-spm.github.io/TopoStats/configuration.html" | ||
) | ||
write_config_with_comments(config=default_config, output_dir=Path.cwd(), filename=args.create_config_file) | ||
sys.exit() | ||
|
||
# Create base output directory | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to have this eventuality caught 👍