Skip to content

Commit

Permalink
Merge pull request #985 from AFM-SPM/ns-rse/517-remove-old-entry-points
Browse files Browse the repository at this point in the history
refactor(entry_points): Removing legacy entry points
  • Loading branch information
ns-rse authored Oct 30, 2024
2 parents 5d01d43 + 4dd47d8 commit 968124d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 260 deletions.
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies = [
"scikit-image",
"scipy",
"seaborn",
"skan",
"skan~=0.11.0",
"snoop",
"tensorflow",
"tifffile",
Expand Down Expand Up @@ -282,5 +282,3 @@ override_SS05 = [ # override SS05 to allow docstrings starting with these words

[project.scripts]
topostats = "topostats.entry_point:entry_point"
run_topostats = "topostats.entry_point:legacy_run_topostats_entry_point"
toposum = "topostats.entry_point:legacy_toposum_entry_point"
55 changes: 0 additions & 55 deletions tests/test_entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from topostats.entry_point import (
entry_point,
legacy_run_topostats_entry_point,
legacy_toposum_entry_point,
)
from topostats.io import write_config_with_comments
from topostats.plotting import run_toposum
Expand Down Expand Up @@ -135,56 +133,3 @@ def test_entry_point_create_config_file(tmp_path: Path) -> None:
]
)
assert Path(f"{tmp_path}/test_create_config.yaml").is_file()


# Test that the right functions are returned with the right arguments
@pytest.mark.parametrize(
("options", "expected_arg_name", "expected_arg_value"),
[
pytest.param(
[
"-c",
"dummy/config/dir/config.yaml",
],
"config_file",
Path("dummy/config/dir/config.yaml"),
id="Test using -c flag for config file",
),
pytest.param(
[
"--config",
"dummy/config/dir/config.yaml",
],
"config_file",
Path("dummy/config/dir/config.yaml"),
id="Test using --config flag for config file",
),
],
)
def test_legacy_run_topostats_entry_point(options: list, expected_arg_name: str, expected_arg_value: str) -> None:
"""Ensure the arguments are parsed and carried through correctly to legacy entry point."""
returned_args = legacy_run_topostats_entry_point(options, testing=True)
# Convert argparse's Namespace object to dictionary
returned_args_dict = vars(returned_args)

assert returned_args_dict[expected_arg_name] == expected_arg_value


def test_legacy_toposum_entry_point_create_config_file(tmp_path: Path) -> None:
"""Ensure the toposum legacy entry point is able to produce a default config file."""
with pytest.raises(SystemExit):
legacy_toposum_entry_point(
args=["--create-config-file", f"{tmp_path}/test_legacy_toposum_create_config_file.yaml"]
)

assert Path(f"{tmp_path}/test_legacy_toposum_create_config_file.yaml").is_file()


def test_legacy_toposum_entry_point_create_label_file(tmp_path: Path) -> None:
"""Ensure the toposum legacy entry point is able to produce a default label file."""
with pytest.raises(SystemExit):
legacy_toposum_entry_point(
args=["--create-label-file", f"{tmp_path}/test_legacy_toposum_create_label_file.yaml"]
)

assert Path(f"{tmp_path}/test_legacy_toposum_create_label_file.yaml").is_file()
202 changes: 0 additions & 202 deletions topostats/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,205 +372,3 @@ def entry_point(manually_provided_args=None, testing=False) -> None:
args.func(args)

return None


def create_legacy_run_topostats_parser() -> arg.ArgumentParser:
"""
Create a parser reading options for the 'run_topostats' processing entry point.
Returns
-------
arg.ArgumentParser
Arguments to be passed to 'run_topostats'.
"""
parser = arg.ArgumentParser(
description="Process AFM images. Additional arguments over-ride those in the configuration file."
)
parser.add_argument(
"-c",
"--config_file",
dest="config_file",
type=Path,
required=False,
help="Path to a YAML configuration file.",
)
parser.add_argument(
"-s",
"--summary_config",
dest="summary_config",
type=Path,
required=False,
help="Path to a YAML configuration file for summary plots and statistics.",
)
parser.add_argument(
"-b",
"--base_dir",
dest="base_dir",
type=Path,
required=False,
help="Base directory to scan for images.",
)
parser.add_argument(
"-j",
"--cores",
dest="cores",
type=int,
required=False,
help="Number of CPU cores to use when processing.",
)
parser.add_argument(
"-l",
"--log_level",
dest="log_level",
type=str,
required=False,
help="Logging level to use, default is 'info' for verbose output use 'debug'.",
)
parser.add_argument(
"-f",
"--file_ext",
dest="file_ext",
type=str,
required=False,
help="File extension to scan for.",
)
parser.add_argument(
"--channel",
dest="channel",
type=str,
required=False,
help="Channel to extract.",
)
parser.add_argument(
"-o",
"--output_dir",
dest="output_dir",
type=Path,
required=False,
help="Output directory to write results to.",
)
parser.add_argument(
"--save_plots",
dest="save_plots",
type=bool,
required=False,
help="Whether to save plots.",
)
parser.add_argument("-m", "--mask", dest="mask", type=bool, required=False, help="Mask the image.")
parser.add_argument(
"-v",
"--version",
action="version",
version=f"Installed version of TopoStats : {__version__}",
help="Report the current version of TopoStats that is installed.",
)
parser.add_argument(
"-w",
"--warnings",
dest="warnings",
type=bool,
required=False,
help="Whether to ignore warnings.",
)
return parser


def create_legacy_toposum_parser() -> arg.ArgumentParser:
"""
Create a parser reading options for the legacy 'toposum' summarize entry point.
Returns
-------
arg.ArgumentParser
Arguments to be passed to 'toposum'.
"""
parser = arg.ArgumentParser(
description="Summarise and plot histograms, kernel density estimates and scatter plots of TopoStats"
"grain and DNA Tracing statistics."
)
parser.add_argument("-i", "--input_csv", dest="csv_file", required=False, help="Path to CSV file to plot.")
parser.add_argument(
"-c",
"--config_file",
dest="config_file",
type=Path,
required=False,
help="Path to a YAML configuration file.",
)
parser.add_argument(
"-l",
"--var_to_label",
dest="var_to_label",
type=Path,
required=False,
help="Path to a YAML plotting dictionary that maps variable names to labels.",
)
parser.add_argument(
"--create-config-file",
dest="create_config_file",
type=Path,
required=False,
help="Filename to write a sample YAML configuration file to (should end in '.yaml').",
)
parser.add_argument(
"--create-label-file",
dest="create_label_file",
type=Path,
required=False,
help="Filename to write a sample YAML label file to (should end in '.yaml').",
)
return parser


def legacy_run_topostats_entry_point(args=None, testing=False) -> None:
"""
Legacy entry point for the run_topostats processing function.
Parameters
----------
args : None
Arguments.
testing : bool
Whether functions is being tested.
Returns
-------
None
Does not return anything.
"""
parser = create_legacy_run_topostats_parser()
args = parser.parse_args() if args is None else parser.parse_args(args)

if testing:
return args

run_topostats(args=args)

return None


def legacy_toposum_entry_point(args=None, testing=False) -> None:
"""
Legacy entry point for the toposum summarizing function.
Parameters
----------
args : None
Arguments.
testing : bool
Whether functions is being tested.
Returns
-------
None
Does not return anything.
"""
parser = create_legacy_toposum_parser()
args = parser.parse_args() if args is None else parser.parse_args(args)

if testing:
return args

run_toposum(args=args)

return None

0 comments on commit 968124d

Please sign in to comment.