From f8848916b92acfd926566e026689f089e03ee087 Mon Sep 17 00:00:00 2001 From: mikibonacci Date: Tue, 5 Dec 2023 15:43:11 +0000 Subject: [PATCH 1/2] providing a subsection in developer guide docs, about automatic code installation --- docs/source/development/plugin.rst | 80 +++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/docs/source/development/plugin.rst b/docs/source/development/plugin.rst index 3dbd12692..df3f4349a 100644 --- a/docs/source/development/plugin.rst +++ b/docs/source/development/plugin.rst @@ -354,7 +354,83 @@ Here is the example of the built-in `pdos` plugins with codes `dos.x` and `projw } For the moment, the app does not support set up the newly added codes automatically. -Thus, the user needs to set up the codes manually. +Thus, the user needs to set up the codes manually. However, the developer can provide console +scripts to make user life easier. Please read to following section for some instructions on how +to do it. + + +Setting up console scripts for automatic code installation +---------------------------------------------------------- +It is possible to provide console scripts in order to make new code installation almost automatic, +with only running an instruction from the command line. +Console scripts can be defined in the `pyproject.toml`: + +.. code-block:: + + [project.scripts] + phonopy_install = "phonopy_install:install_phonopy" + +When the user, after the package installation, will execute the command + +.. code-block:: console + + phonopy_install + +this will invoke the function `install_phonopy`, contained in the phonopy_install.py file in the +root directory of the package. + +or in the `setup.cfg` file (if you prefer): + +.. code-block:: + + [options.entry_points] + console_scripts= + install_muon_codes = aiidalab_qe_muon.scripts.post_install:InstallCodes + +this will invoke the function `InstallCodes`, contained in the post_install.py file in the +{root-directory-of-the-package}/aiidalab_qe_muon/scripts/ directory. + +These examples are taken respectively from `aiidalab-qe-vibroscopy`_ and `aiidalab-qe-muon`_. +The actual function to install the code should be something similar: + +.. code-block:: python + + from aiida.common.exceptions import NotExistent + import subprocess + from aiida.orm import load_code + from aiida import load_profile + + def install_phonopy(): + load_profile() + try: + load_code("phonopy@localhost") + except NotExistent: + # Construct the command as a list of arguments + command = [ + "verdi", + "code", + "create", + "core.code.installed", + "--non-interactive", + "--label", + "phonopy", + "--default-calc-job-plugin", + "phonopy.phonopy", + "--computer", + "localhost", + "--filepath-executable", + "/opt/conda/bin/phonopy", + ] + + # Use subprocess.run to run the command + subprocess.run(command, check=True) + else: + raise Warning("Code phonopy@localhost already installed!") + + + # Called when the script is run directly + if __name__ == "__main__": + install_phonopy() Further Reading ================================ @@ -362,3 +438,5 @@ QuantumESPRESSO app comes with several built-in plugins, which can be found in t You can also use them as a start point to create your own plugins. .. _aiidalab-qe-plugin-demos: https://github.com/aiidalab/aiidalab-qe-plugin-demos +.. _aiidalab-qe-vibroscopy: https://github.com/mikibonacci/aiidalab-qe-vibroscopy +.. _aiidalab-qe-muon: https://github.com/mikibonacci/aiidalab-qe-muon \ No newline at end of file From 1d571ae6395b4eadf682592de33085531b834c4f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:44:38 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/development/plugin.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/source/development/plugin.rst b/docs/source/development/plugin.rst index df3f4349a..d06c51cca 100644 --- a/docs/source/development/plugin.rst +++ b/docs/source/development/plugin.rst @@ -354,19 +354,19 @@ Here is the example of the built-in `pdos` plugins with codes `dos.x` and `projw } For the moment, the app does not support set up the newly added codes automatically. -Thus, the user needs to set up the codes manually. However, the developer can provide console -scripts to make user life easier. Please read to following section for some instructions on how +Thus, the user needs to set up the codes manually. However, the developer can provide console +scripts to make user life easier. Please read to following section for some instructions on how to do it. Setting up console scripts for automatic code installation ---------------------------------------------------------- -It is possible to provide console scripts in order to make new code installation almost automatic, -with only running an instruction from the command line. +It is possible to provide console scripts in order to make new code installation almost automatic, +with only running an instruction from the command line. Console scripts can be defined in the `pyproject.toml`: .. code-block:: - + [project.scripts] phonopy_install = "phonopy_install:install_phonopy" @@ -376,7 +376,7 @@ When the user, after the package installation, will execute the command phonopy_install -this will invoke the function `install_phonopy`, contained in the phonopy_install.py file in the +this will invoke the function `install_phonopy`, contained in the phonopy_install.py file in the root directory of the package. or in the `setup.cfg` file (if you prefer): @@ -387,7 +387,7 @@ or in the `setup.cfg` file (if you prefer): console_scripts= install_muon_codes = aiidalab_qe_muon.scripts.post_install:InstallCodes -this will invoke the function `InstallCodes`, contained in the post_install.py file in the +this will invoke the function `InstallCodes`, contained in the post_install.py file in the {root-directory-of-the-package}/aiidalab_qe_muon/scripts/ directory. These examples are taken respectively from `aiidalab-qe-vibroscopy`_ and `aiidalab-qe-muon`_. @@ -439,4 +439,4 @@ You can also use them as a start point to create your own plugins. .. _aiidalab-qe-plugin-demos: https://github.com/aiidalab/aiidalab-qe-plugin-demos .. _aiidalab-qe-vibroscopy: https://github.com/mikibonacci/aiidalab-qe-vibroscopy -.. _aiidalab-qe-muon: https://github.com/mikibonacci/aiidalab-qe-muon \ No newline at end of file +.. _aiidalab-qe-muon: https://github.com/mikibonacci/aiidalab-qe-muon