Skip to content

Latest commit

 

History

History
87 lines (59 loc) · 3.13 KB

new_script.rst

File metadata and controls

87 lines (59 loc) · 3.13 KB

Developing New PypeIt Scripts

All of the PypeIt executable scripts are located in the pypeit/scripts directory, and they all have roughly the same structure:

from pypeit.scripts import scriptbase

class NewScript(scriptbase.ScriptBase):

    @classmethod
    def get_parser(cls, width=None):
        parser = super().get_parser(description='A new PypeIt script', width=width)
        ...

    @staticmethod
    def main(args):
        ...

The important components of the scripts are:

The base class, :class:`~pypeit.scripts.scriptbase.ScriptBase`, provides the common entry point function (:func:`~pypeit.scripts.scriptbase.ScriptBase.entry_point`) used during installation. To ensure that the script is properly installed by `pip`_, you need to add this entry point to the setup.cfg file. All of the PypeIt scripts are listed in the [options.entry_points] group. To add your script, you enter a new line with the following format:

pypeit_new_script = pypeit.scripts.new_script:NewScript.entry_point

Lastly, you should add the import of the script module to the pypeit/scripts/__init__.py file; i.e., add:

from pypeit.scripts import new_script

Note that the script files in the pypeit/scripts directory:

  • Should not be executable (i.e., no xs in their permissions)
  • Should not start with an env statement; i.e., #!/usr/bin/env python
  • Should not end with the if __name__ == '__main__': block

Creating the executables from the raw script files is all handled by `pip`_ installing PypeIt. To ensure the script is installed, from the top-level directory run, e.g.:

pip install -e ".[dev]"

If the new script doesn't appear in your path after running this, you may need to uninstall (pip uninstall pypeit) and reinstall using the command above.