Objectives

In this Exercise you will learn how to:

  • setup starter package with IOT fucntions

Prerequisites

Before you begin:
This Exercise requires that you have:

  1. Install Python 3.11.x in your environment.
  2. Install Git.
  3. Install pip3 package manager for Python.
  4. Install an editor such as Pycharm Community Edition

Setup Starter Package

  1. Clone the HelloWorld starter package .
  2. Open a terminal window.
  3. Make a new project folder for the starter package. For example, mkdir custom_function.
  4. Change to the project directory. For example, cd custom_function.
  5. Clone the starter package. Enter:
    git clone --branch starter_package https://github.com/ibm-watson-iot/functions.git
  6. Verify that you cloned the starter package to the custom_function directory.
  7. Change to the functions directory in the starter package. Enter: cd functions
  8. Open the setup.py file. The setup.py file defines the package name and the list of packages that are required for the project.
  9. Set the name parameter to custom{your_initials}. Replace the {your_initials} variable with your initials or with another unique value.
  10. In the ibm-watson-iot/functions repository, verify that the iotfunction package is the correct version. For example, for Maximo Monitor 9.1, the package must be from the 9.1.X GitHub branch. Do not replace the x in the version with another value. The following text is an example setup.py file. The name parameter is set to customId and the 9.1.X branch is used.
    
            #!/usr/bin/env python 
            from setuptools import setup, find_packages
            setup(name='customld', version='0.0.1', packages=find_packages(),
            install_requires=['iotfunctions@git+https://github.com/ibm-watson-iot/functions.git@9.1.x'])
            

Setup Pycharm

  1. Install the PyCharm community edition
  2. Open PyCharm and select Open to browse to your cloned directory.
  3. Next, create a Python virtual environment (venv) inside the custome_function folder by running the following command:

  4. 
            python3 -m venv venv-cust
            cd venv-cust/bin source activate
         
    1. Set up a virtual environment:
    2. Go to PyCharm > Preferences > Project > Python Interpreter
    3. Click the settings icon and select Add
    4. Set your venv folder location
    5. Set the base interpreter to your Python 3.11.x directory
  5. Run the following command to install the iotfunctions package into your Python environment. Ensure that you use the correct branch name for your version
    
                pip3 install git+https://github.com/ibm-watson-iot/functions.git@9.1.x --upgrade
         

Note

Always use the IoT Functions version that matches your Maximo Monitor version to avoid pipeline issues.

Attention

If you're using a Mac Machine, you might encounter compatibility issues with the ibm_db package. Here's how to resolve them:
Open the requirements.txt file
Change ibm_db==3.2.3 to ibm_db==3.2.5
Save the file
pip3 install -r requirements.txt


Congratulations you have successfully setup the starter package.