hermes.commands.init.base
=========================

.. py:module:: hermes.commands.init.base


Attributes
----------

.. autoapisummary::

   hermes.commands.init.base.TUTORIAL_URL
   hermes.commands.init.base.REPOSITORY_URL
   hermes.commands.init.base.DepositOptions


Classes
-------

.. autoapisummary::

   hermes.commands.init.base.GitHoster
   hermes.commands.init.base.DepositId
   hermes.commands.init.base.DepositPlatform
   hermes.commands.init.base.HermesInitFolderInfo
   hermes.commands.init.base._HermesInitSettings
   hermes.commands.init.base.HermesInitCommand


Functions
---------

.. autoapisummary::

   hermes.commands.init.base.scout_current_folder
   hermes.commands.init.base.get_git_hoster_from_url
   hermes.commands.init.base.download_file_from_url
   hermes.commands.init.base.string_in_file
   hermes.commands.init.base.get_builtin_plugins
   hermes.commands.init.base.get_handler_by_name


Module Contents
---------------

.. py:data:: TUTORIAL_URL
   :value: 'https://hermes.software-metadata.pub/en/latest/tutorials/automated-publication-with-ci.html'


.. py:data:: REPOSITORY_URL
   :value: 'https://github.com/softwarepub/hermes'


.. py:class:: GitHoster(*args, **kwds)

   Bases: :py:obj:`enum.Enum`


   Create a collection of name/value pairs.

   Example enumeration:

   >>> class Color(Enum):
   ...     RED = 1
   ...     BLUE = 2
   ...     GREEN = 3

   Access them by:

   - attribute access:

     >>> Color.RED
     <Color.RED: 1>

   - value lookup:

     >>> Color(1)
     <Color.RED: 1>

   - name lookup:

     >>> Color['RED']
     <Color.RED: 1>

   Enumerations can be iterated over, and know how many members they have:

   >>> len(Color)
   3

   >>> list(Color)
   [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

   Methods can be added to enumerations, and members can have their own
   attributes -- see the documentation for details.


   .. py:attribute:: Empty


   .. py:attribute:: GitHub


   .. py:attribute:: GitLab


.. py:class:: DepositId(*args, **kwds)

   Bases: :py:obj:`enum.Enum`


   Enum as additional identifier for DepositPlatforms so we have something persistent to code with.


   .. py:attribute:: Empty


   .. py:attribute:: Zenodo


   .. py:attribute:: ZenodoSandbox


   .. py:attribute:: Rodare


   .. py:attribute:: RodareTest


.. py:class:: DepositPlatform(name: str = '', url: str = '', plugin_name: str = '', deposit_id: DepositId = DepositId.Empty)

   This dataclass contains all relevant data to set up hermes for a given platform.


   .. py:attribute:: name
      :type:  str
      :value: ''



   .. py:attribute:: url
      :type:  str
      :value: ''


      Base url of the deposit platform


   .. py:attribute:: plugin_name
      :type:  str
      :value: ''


      Internal name of our related hermes deposit plugin


   .. py:attribute:: id
      :type:  DepositId

      Non changing enum-based ID to keep the consistency


   .. py:attribute:: internal_name
      :type:  str
      :value: 'Empty'



   .. py:attribute:: token
      :type:  str
      :value: ''


      This is the access token which will get filled in connect_deposit_platform


   .. py:attribute:: token_name
      :type:  str

      This is the internal name in uppercase, with underscores and ending with _TOKEN.
      This is used as name for the secret variable on the GitHoster.


.. py:data:: DepositOptions
   :type:  list[DepositPlatform]

.. py:class:: HermesInitFolderInfo

   Contains information about the current state of the target project directory.


   .. py:attribute:: absolute_path
      :type:  str
      :value: ''



   .. py:attribute:: has_git_folder
      :type:  bool
      :value: False



   .. py:attribute:: has_hermes_toml
      :type:  bool
      :value: False



   .. py:attribute:: has_gitignore
      :type:  bool
      :value: False



   .. py:attribute:: has_citation_cff
      :type:  bool
      :value: False



   .. py:attribute:: has_readme
      :type:  bool
      :value: False



   .. py:attribute:: current_dir
      :type:  str
      :value: ''



   .. py:attribute:: dir_list
      :type:  list[str]
      :value: []



   .. py:attribute:: dir_folders
      :type:  list[str]
      :value: []



.. py:function:: scout_current_folder() -> HermesInitFolderInfo

   This method looks at the current directory and collects all init relevant data.
   This method is not meant to contain any user interactions.
   @return: HermesInitFolderInfo object containing the gathered knowledge


.. py:function:: get_git_hoster_from_url(url: str) -> GitHoster

   Returns the matching GitHoster value to the given url. Returns GitHoster.Empty if none is found.


.. py:function:: download_file_from_url(url, filepath, append: bool = False) -> None

.. py:function:: string_in_file(file_path, search_string: str) -> bool

.. py:function:: get_builtin_plugins(plugin_commands: list[str]) -> dict[str, hermes.commands.base.HermesPlugin]

   Returns a list of installed HermesPlugins based on a list of related command names.
   This is currently not used (we use the marketplace code instead) but maybe later.


.. py:function:: get_handler_by_name(name: str) -> logging.Handler | None

   Own implementation of logging.getHandlerByName so that we don't require Python 3.12


.. py:class:: _HermesInitSettings(/, **data: Any)

   Bases: :py:obj:`pydantic.BaseModel`


   Configuration of the ``init`` command.


.. py:class:: HermesInitCommand(parser: argparse.ArgumentParser)

   Bases: :py:obj:`hermes.commands.base.HermesCommand`


   Install HERMES onto a project.


   .. py:attribute:: command_name
      :value: 'init'



   .. py:attribute:: settings_class


   .. py:attribute:: folder_info
      :type:  HermesInitFolderInfo


   .. py:attribute:: hermes_was_already_installed
      :type:  bool
      :value: False



   .. py:attribute:: warn_on_old_version
      :type:  bool
      :value: True



   .. py:attribute:: new_created_paths
      :type:  list[pathlib.Path]
      :value: []



   .. py:attribute:: tokens
      :type:  dict


   .. py:attribute:: setup_method
      :type:  str
      :value: ''



   .. py:attribute:: deposit_platform
      :type:  DepositPlatform


   .. py:attribute:: git_branch
      :type:  str
      :value: ''



   .. py:attribute:: git_remote
      :type:  str
      :value: ''



   .. py:attribute:: git_remote_url
      :value: ''



   .. py:attribute:: git_hoster
      :type:  GitHoster


   .. py:attribute:: template_base_url
      :type:  str
      :value: 'https://raw.githubusercontent.com'



   .. py:attribute:: template_branch
      :type:  str
      :value: 'main'



   .. py:attribute:: template_repo
      :type:  str
      :value: 'softwarepub/ci-templates'



   .. py:attribute:: template_folder
      :type:  str
      :value: 'init-templates'



   .. py:attribute:: ci_parameters
      :type:  dict


   .. py:attribute:: hermes_toml_data


   .. py:attribute:: plugin_relevant_commands
      :value: ['harvest', 'deposit']



   .. py:attribute:: builtin_plugins
      :type:  dict[str, hermes.commands.base.HermesPlugin]


   .. py:attribute:: selected_plugins
      :type:  list[hermes.commands.marketplace.PluginInfo]
      :value: []



   .. py:method:: init_command_parser(command_parser: argparse.ArgumentParser) -> None

      Initialize the command line arguments available for this specific HERMES sub-commands.

      You should override this method to add your custom arguments to the command line parser of
      the respective sub-command.

      :param command_parser: The command line sub-parser responsible for the HERMES sub-command.



   .. py:method:: load_settings(args: argparse.Namespace)

      Load settings from the configuration file (passed in from command line).



   .. py:method:: refresh_folder_info() -> None

      Checks the contents of the current directory and saves relevant info in self.folder_info



   .. py:method:: setup_file_logging() -> None


   .. py:method:: __call__(args: argparse.Namespace) -> None

      Execute the HERMES sub-command.

      :param args: The namespace that was returned by the command line parser when reading the arguments.



   .. py:method:: check_hermes_version() -> None

      Fetches the current Pypi Hermes version. Gives a warning if the current version is not up to date.



   .. py:method:: test_initialization() -> None

      Test if init is possible and wanted. If not: sys.exit()



   .. py:method:: create_hermes_toml() -> None

      Creates the hermes.toml file based on a self.hermes_toml_data



   .. py:method:: create_citation_cff() -> None

      If there is no CITATION.cff, the user gets the opportunity to create one online.



   .. py:method:: update_gitignore() -> None

      Creates .gitignore if there is none and adds '.hermes' to it



   .. py:method:: get_template_url(filename: str) -> str

      Returns the full template url with a given filename.



   .. py:method:: create_ci_template() -> None

      Downloads and configures the ci workflow files using templates from the chosen template branch.



   .. py:method:: configure_ci_template(ci_file_path) -> None

      Replaces all {%parameter%} in a ci file with values from ci_parameters dict



   .. py:method:: create_zenodo_token() -> None

      Makes the user create a zenodo token and saves it in self.deposit_platform.token.



   .. py:method:: create_rodare_token()


   .. py:method:: configure_git_project() -> None

      Adds the token to the git secrets & changes action workflow settings.



   .. py:method:: configure_github() -> None


   .. py:method:: configure_gitlab() -> None


   .. py:method:: choose_deposit_platform() -> None

      User chooses his desired deposit platform.



   .. py:method:: integrate_deposit_platform() -> None

      Makes changes to the toml data or something else based on the chosen deposit platform.



   .. py:method:: choose_setup_method() -> None

      User chooses his desired setup method: Either preferring automatic (if available) or manual.



   .. py:method:: connect_deposit_platform() -> None

      Acquires the access token of the chosen deposit platform.



   .. py:method:: choose_plugins() -> None

      User chooses the plugins he wants to use.



   .. py:method:: integrate_plugins() -> None

      Plugin installation is added to the ci-parameters.
      Also for now we use this method to do custom plugin installation steps.



   .. py:method:: no_git_setup(start_question: str = '') -> None

      Makes the init for a gitless project (basically just creating hermes.toml)



   .. py:method:: choose_push_trigger() -> None

      User chooses the branch / tag that should be used to trigger the whole hermes pipeline.



   .. py:method:: set_push_trigger_to_branch(branch: str) -> None

      Sets the CI parameters, so that the pipeline gets triggered when the branch gets pushed.



   .. py:method:: set_push_trigger_to_tag(tag_pattern: str = '') -> None

      Sets the CI parameters, so that the pipeline gets triggered when a tag that matches the pattern gets pushed.



   .. py:method:: choose_deposit_files() -> None

      User chooses the files that should be included in the deposition.



   .. py:method:: mark_as_new_path(path: pathlib.Path, avoid_existing: bool = True) -> None

      This method should be called directly BEFORE creating a new file in the given Path.
      This way we can look if something already exists there to decide later-on if we want to delete it on abort.



   .. py:method:: clean_up_files(aborted: bool) -> None

      This gets called when init is finished (successfully or aborted).
      It cleans up unwanted files (like .hermes folder) and everything new when aborted.



