diff --git a/docs/cli.rst b/docs/cli.rst index f743099a..c157e841 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -7,7 +7,7 @@ see all available options, run: .. code:: bash - python -m platypus --help + platypus --help Solve ----- @@ -16,14 +16,14 @@ Solve executes the given algorithm on a problem, saving the final approximation .. code:: bash - python -m platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 --output NSGAII_DTLZ2.set + platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 --output NSGAII_DTLZ2.set Additional arguments can be provided, such as setting the ``population_size`` as demonstrated below. Note that only arguments with primitive types are supported. .. code:: bash - python -m platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 population_size=250 + platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 population_size=250 :: @@ -39,7 +39,7 @@ the hypervolume using a reference set for normalization: .. code:: bash - python -m platypus hypervolume --reference_set ./examples/DTLZ2.2D.pf NSGAII_DTLZ2.set + platypus hypervolume --reference_set ./examples/DTLZ2.2D.pf NSGAII_DTLZ2.set which outputs: @@ -54,8 +54,8 @@ The results can be filtered to remove any dominated, infeasible, or duplicate so .. code:: bash - python -m platypus filter --output NSGAII_DTLZ2_unique.set --feasible --unique NSGAII_DTLZ2.set - python -m platypus filter --output NSGAII_DTLZ2_epsilons.set --epsilons 0.01,0.01 NSGAII_DTLZ2.set + platypus filter --output NSGAII_DTLZ2_unique.set --feasible --unique NSGAII_DTLZ2.set + platypus filter --output NSGAII_DTLZ2_epsilons.set --epsilons 0.01,0.01 NSGAII_DTLZ2.set Normalization ------------- @@ -67,8 +67,8 @@ the normalized solutions: .. code:: bash - python -m platypus normalize --output NSGAII_DTLZ2_normalized.set --reference_set ./examples/DTLZ2.2D.pf NSGAII_DTLZ2.set - python -m platypus normalize --output NSGAII_DTLZ2_normalized.set --minimum 0.0,0.0 --maximum 1.0,1.0 NSGAII_DTLZ2.set + platypus normalize --output NSGAII_DTLZ2_normalized.set --reference_set ./examples/DTLZ2.2D.pf NSGAII_DTLZ2.set + platypus normalize --output NSGAII_DTLZ2_normalized.set --minimum 0.0,0.0 --maximum 1.0,1.0 NSGAII_DTLZ2.set Plotting -------- @@ -77,8 +77,8 @@ For 2 and 3 objectives, we can also generate a plot, either interactive or savin .. code:: bash - python -m platypus plot NSGAII_DTLZ2.set - python -m platypus plot --output NSGAII_DTLZ2.png NSGAII_DTLZ2.set + platypus plot NSGAII_DTLZ2.set + platypus plot --output NSGAII_DTLZ2.png NSGAII_DTLZ2.set Combining or Chaining Commands ------------------------------ @@ -89,6 +89,6 @@ as demonstrated below: .. code:: bash - python -m platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 | \ - python -m platypus filter --epsilons 0.01,0.01 | \ - python -m platypus plot + platypus solve --algorithm NSGAII --problem DTLZ2 --nfe 10000 | \ + platypus filter --epsilons 0.01,0.01 | \ + platypus plot diff --git a/platypus/__main__.py b/platypus/__main__.py index ef9ceea0..9eb7e8d2 100644 --- a/platypus/__main__.py +++ b/platypus/__main__.py @@ -32,10 +32,13 @@ type_cast) -def main(input): +def main(input=None): """The main entry point for the Platypus CLI.""" LOGGER = logging.getLogger("Platypus") + if input is None: + input = sys.argv[1:] + def load_set(file): """Loads input file from stdin or file.""" if file is None: @@ -264,4 +267,4 @@ def debug_inputs(args): plt.show() if __name__ == "__main__": - main(sys.argv[1:]) + main() diff --git a/pyproject.toml b/pyproject.toml index 530b8775..591695aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,9 @@ test = ["pytest", "mock", "flake8", "flake8-pyproject", "numpy", "matplotlib", " docs = ["sphinx", "sphinx-rtd-theme"] full = ["mpi4py", "Platypus-Opt[test]", "Platypus-Opt[docs]"] +[project.scripts] +platypus = "platypus.__main__:main" + [tool.setuptools.dynamic] version = {attr = "platypus.__version__"}