Skip to content

Commit

Permalink
Dev setup - script setup (#769)
Browse files Browse the repository at this point in the history
* Development script

* Fix suffix

* Fix zsh comment

* better handling

* better handling

* updating documentation

* typo fix

* workon not working solution

* addinbg step 4

* final adjustments

* fixing CHANGELOG.md

* checking working dir

* checking working dir

* reverting config changes

* checking for init

* checking for init

* trying to run update from Test

* reverting config.yml changes

* reverting config.yml changes

* reverting config.yml changes

Co-authored-by: rsagi <[email protected]>
  • Loading branch information
GalRabin and roysagi authored Oct 22, 2020
1 parent d203aeb commit e00caa9
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog
* No longer require setting `DEMISTO_README_VALIDATION` env var to enable README mdx validation. Validation will now run automatically if all necessary node modules are available.
* Fixed a bug in the **validate** command where the `--skip-pack-dependencies` flag did not work.
* Fixed an issue in the **validate** command where the `--skip-pack-dependencies` would not skip id-set creation.
* Fixed an issue in the **validate** command where validation would fail if supplied an integration with an empty `commands` key.
* Fixed an issue in the **validate** command where validation would fail due to a required version bump for packs which are not versioned.
* Will use env var `DEMISTO_VERIFY_SSL` to determine if to use a secure connection for commands interacting with the Server when `--insecure` is not passed. If working with a local Server without a trusted certificate, you can set env var `DEMISTO_VERIFY_SSL=no` to avoid using `--insecure` on each command.
Expand Down
36 changes: 15 additions & 21 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We build `demisto-sdk` to support python 3.7 and 3.8.
## Getting started

1. [Clone demisto-sdk repository](#1-Clone-demisto-sdk-repository)
2. [Install demisto-sdk as editable versions](#2-Install-demisto-sdk-as-editable-version)
2. [Install demisto sdk dev environment](#2-Install-demisto-sdk-dev-environment)
3. [Pre-commit hooks setup](#3-Pre-commit-hooks-setup)
4. [DemistoContentPython Libary](#4-DemistoContentPython-Libary)
5. [Develop new command](#5-Develop-new-command)
Expand All @@ -26,34 +26,28 @@ git clone https://github.com/demisto/demisto-sdk.git

---

### 2. Install demisto sdk as editable version
1. If you are using virtualenv for this process you can skip this step, uninstall current installed version of
`demisto-sdk`:
### 2. Install demisto sdk dev environment

```shell
pip3 uninstall demisto-sdk
```
We will now setup a quick virtualenv in which we will install the `demisto-sdk` version you are currently working on.
This will be used as your testing environment, you do not need to update it again or re-run in any way.

2. Inside root directory of `demisto-sdk` repository - Install PyPi package as [editable package](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs):
1. Make sure you have python3 installed.

```shell
pip3 install -e .
```
2. Add executable permissions to our setup script by running `chmod a+x ~/dev/demisto/demisto-sdk/demisto-sdk-development.sh`.

3. Validate that `demisto-sdk` installed path is correct by
3. Run the script: `~/dev/demisto/demisto-sdk/demisto-sdk-development.sh`.
* You might need to setup your SHELL env variable by running `export SHELL=/bin/zsh` or `export SHELL=/bin/bash`.

```shell
pip3 show demisto-sdk | grep Location
```
4. Restart your terminal.

You have now setup the your `demisto-sdk-dev` env!

should be `demisto-sdk` repository in your local enviorment.
To activate it simply run: `workon demisto-sdk-dev`
* Check that the demisto-sdk installed is your local version by running `demisto-sdk -v` - you will should see something similar to `demisto-sdk 1.X.X.dev`.
If not, while your current working directory is the `demisto-sdk` root repo by runnning `cd ~/dev/demisto/demisto-sdk` and then run `pip3 install -e .`.

4. Install dev-requirements:

```shell
pip3 install -r <repo>/requirements-dev.txt
```
To deactivate the virtual environment and return simply run: `deactivate`.
* Note that your local `demisto-sdk` version should remain unchanged.

---

Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ Supported commands:

---

### How to run commands in your development environment
In the Demisto-SDK repository while on the git branch you want to activate and run this command to use python 3.7:
```
source .tox/py37/bin/activate
```
or this command to use python 3.8:

For detailed command usage press [here](demisto_sdk/commands/upload/README.md)
### How to setup development environment?

Follow the guide found [here](CONTRIBUTION.md#2-install-demisto-sdk-dev-environment) to setup your `demisto-sdk-dev` virtual environment.
The development environment is connected to the branch you are currently using in the SDK repository.

Simply activate it by running `workon demisto-sdk-dev`.
The virtual environment can be deactivated at all times by running `deactivate`.

---

Expand Down
83 changes: 83 additions & 0 deletions demisto-sdk-development.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/zsh

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
VIRTUALENV_NAME="demisto-sdk-dev"

# Get current working dir
SDK_WORKDIR=`pwd`

# Arguments handling
if [[ $1 == "-h" ]]; then
printf "This script creates environment for developing demisto-sdk, The following steps are done:
1. Installing virtualenv-wrapper.
2. Create virtualenv \"${VIRTUALENV_NAME}\".
3. Installing in virtualenv demisto-sdk as editable version.
Notes:
1. This script requires python3 installed.
2. For more information please see the Contribution guide.
\n"
exit 0
fi

# Validate mandatoy executables for execution
executables_exists=0
for executable in pyenv python3 git
do
if ! command -v $executable &> /dev/null
then
printf "${RED}$executable isn't installed, Please install $executable before using this script!${NC}\n"
executables_exists=1
fi
done

if [[ executables_exists -eq 1 ]]; then
exit 1
fi

# Validate Pyenv configure correctly
if [[ "*/.pyenv/*" = $(which python3) ]]; then
printf "${RED}Python3 executable source isn't managed by pyenv, Please verify global var PATH configuration${NC}\n"
exit 1
fi

# Install pyenv-vritualenvwrapper
printf "Installing pyenv-vritualenvwrapper\n"
rm -rf $(pyenv root)/plugins/pyenv-virtualenvwrapper
command git clone https://github.com/pyenv/pyenv-virtualenvwrapper.git $(pyenv root)/plugins/pyenv-virtualenvwrapper

if [ $? -eq 0 ]; then
printf "pyenv-virtualenvwrapper installed ${GREEN}succefully${NC}\n"
else
printf "${RED}pyenv-virtualenvwrapper can't installed using brew$\nAdditional error details:\n${output}${NC}"
exit 1
fi

# Init PATH variables
if [[ $SHELL == *"bin/zsh"* ]]; then
source ~/.zshrc
elif [[ $SHELL == *"bin/bash"* ]]; then
source ~/.bash_profile
else
printf "${RED}Currnltly only bash/zsh is supported as base shell.\n${output}${NC}"
printf "${RED}Run 'export SHELL=/bin/zsh' or 'export SHELL=/bin/bash' and rerun the script.\n${output}${NC}"
exit 1
fi

# Initializing pyenv-vritualenvwrapper
printf "Initiallizing pyenv-vritualenvwrapper\n"
pyenv virtualenvwrapper
echo pyenv virtualenvwrapper >> ~/.zshrc
echo pyenv virtualenvwrapper >> ~/.bash_profile

# Creating development enviorment
rmvirtualenv ${VIRTUALENV_NAME}
mkvirtualenv ${VIRTUALENV_NAME}

pip3 install -e ${SDK_WORKDIR}

# Summary log
printf "\n\nDemisto-sdk virtual env setup finished succefully:\n 1. Restart your terminal.\n 2. In order to activate enviorment ${GREEN}workon ${VIRTUALENV_NAME}${NC}\n 3. Inorder to deactivate enviorment ${RED}deactivate${NC}\n"
exit 0

0 comments on commit e00caa9

Please sign in to comment.