Preparing Your Development Environment

Begin Setup

First you need to ensure you have the git and gcc tools available. On Red Hat Enterprise Linux you can do this with the command, as root: yum install git gcc.

Now create your own fork of the insights-core-tutorials project. Do this by going to the insights-core-tutorials Repository on GitHub and clicking on the Fork button.

You will now have an insights-core-tutorials repository under your GitHub user that you can use to checkout the code to your development environment. To check out the code go to the repository page for your fork and copy the link to download the repo.


If you don’t have a GitHub account or you are not interested in checking your modified code into GitHub right now then you can skip the forking step and clone the insights-core-tutorials repo directly using the HTTPS URL with the git clone command below instead of the URL git@github....

Once you have copied this link then go to a terminal in your working directory and use the git command to clone the repository. In this tutorial we will be using work as the directory that will contain the insights-core-tutorials project. If you choose to use a different root directory you will need to substitute work with your chosen root directory when referenced in the tutorial. So for the purposes of this document our working directory is /home/userone/work:

[userone@hostone ~]$ mkdir work
[userone@hostone ~]$ cd work
[userone@hostone work]$ git clone
Cloning into 'insights-core-tutorials'...
remote: Counting objects: 21251, done.
remote: Compressing objects: 100% (88/88), done.
remote: Total 21251 (delta 68), reused 81 (delta 43), pack-reused 21118
Receiving objects: 100% (21251/21251), 5.95 MiB | 2.44 MiB/s, done.
Resolving deltas: 100% (15938/15938), done.

Next you need to run the script to set up your python environment:

[userone@hostone work]$ cd insights-core-tutorials
[userone@hostone insights-core-tutorials]$

If you ran the script to setup you environment you can skip the manual setup instructions and go straight to the Setup Complete.

Manual Setup (Not required if you ran

If you would rather create the development environment mycomponents manually you can follow these steps to create a virtual environment and set it up for development:

[userone@hostone work]$ cd insights-core-tutorials
[userone@hostone insights-core-tutorials]$ python3.6 -m venv .
Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /home/userone/work/insights-core-tutorials/bin/python3.6
Also creating executable in /home/userone/work/insights-core-tutorials/bin/python
Installing setuptools, pip, wheel...done.

New python executable in ./bin/python
Installing Setuptools..................................................done.
Installing Pip....................................................done.

Setup your environment to use the new virtualenv you just created, and upgrade pip to the latest version:

[userone@hostone insights-core-tutorials]$ source ./bin/activate
(env)[userone@hostone insights-core-tutorials]$ pip install --upgrade pip

Now install all of the required packages for insights-core-tutorials development:

(env)[userone@hostone insights-core-tutorials]$ pip install -e .[develop]

Next you will need to create mycomponents directory and directories to develop each of the components (parsers, combiners and rules) in.

The following are the commands to create the mycomponents development environment:

(env)[userone@hostone insights-core-tutorials]$ mkdir ./mycomponents
(env)[userone@hostone insights-core-tutorials]$ cd ./mycomponents
(env)[userone@hostone mycomponents]$ touch
(env)[userone@hostone mycomponents]$ mkdir -p ./parsers/tests
(env)[userone@hostone mycomponents]$ touch ./parsers/
(env)[userone@hostone mycomponents]$ touch ./parsers/tests/
(env)[userone@hostone mycomponents]$ mkdir -p ./combiners/tests
(env)[userone@hostone mycomponents]$ touch ./combiners/
(env)[userone@hostone mycomponents]$ touch ./combiners/tests/
(env)[userone@hostone mycomponents]$ mkdir -p ./rules/tests
(env)[userone@hostone mycomponents]$ touch ./rules/
(env)[userone@hostone mycomponents]$ touch ./rules/tests/
(env)[userone@hostone mycomponents]$ export PYTHONPATH=$PWD:$PYTHONPATH

Once you have completed the setup of the environment by either running the provided script or running the setup steps manually, you will have a complete development environment for rules, parsers, combiners and for your mycomponents development directory.

You can now confirm that everything is setup correctly so far by running the tests, pytest.

If you ran the script the pytests will have been run by the script, you should see the results in console when the script finishes.

This will test the components in the insights_examples directory. Your results should look something like this:

(env)[userone@hostone insights-core-tutorials]$ pytest
====================== test session starts ===========================
platform linux -- Python 3.6.6, pytest-4.0.1, py-1.7.0, pluggy-0.8.0
rootdir: /home/userone/work/insights-core-tutorials, inifile: setup.cfg
plugins: cov-2.6.1
collected 10 items

insights_examples/combiners/tests/ .
insights_examples/parsers/tests/ ...
insights_examples/rules/tests/ ...
insights_examples/rules/tests/ .

=================== 10 passed in 0.30 seconds ========================

Setup Complete

If during this step you see a test failure similar to the following make sure you have unzip installed on your system:

>           raise child_exception
E           CalledProcessError: <CalledProcessError(0, ['unzip', '-q', '-d',
'/tmp/tmplrXhIu', '/tmp/'], [Errno 2] No such file or directory)>

/usr/lib64/python2.7/ CalledProcessError

Your development environment is now ready to begin development and you may move on to the next section. If you had problems with any of these steps then double check that you have completed all of the steps in order and if it still doesn’t work, open a GitHub issue.