Skip to content

Commit

Permalink
[Poetry] (#114)
Browse files Browse the repository at this point in the history
* commit

* install poetry

* config

* fix tag filter

* Updated config.yml

* config

* config

* config

* config

* config

* -v config

* -v config

* -v config

* --no-ansi

* --no-interaction

* Print Python and Poetry versions

* Updated config.yml

* poetry install --no-root

* orb

* args: --no-root

* del packages = [{include = "demisto_py"}]

* del packages = [{include = "demisto_py"}]

* revert no root

* update poetry

* python -m

* poetry install --no-interaction --no-ansi -no-root

* test pypi

* test pypi

* ${PYPI_TEST_TOKEN}

* Updated config.yml

* BUILD

* - checkout

* --build --no-ansi

* --no-interaction

* BUILD

* *poetry_build

* poetry_build

* echo

* debug    poetry config --list

* debug    poetry config --list

* debug    poetry config --list

* config

* config

* del files

* attach_workspace

* del files

* del files

* del files

* changelog

* version = "3.3.0"

* replace from 3.10 to 3.11.4

* demo publish

* revert docker version added verify requires

* Updated config.yml

* include

* revert include

* revert include

* re

* code

* sudo

* revert gen code

* ubuntu docker

* machine

* del commands

* Apache-2.0

* checkout

* only: sk_change_to_-poetry

* version 3.1.1

* 'Apache Software License'

* Apache-2.0

* "3.3.1beta1"

* test tag

* test tag

* tag 2

* tag 2

* update MD

* cr fix, update changelog

* CHANGELOG

* added docker parameter

* del test-requirements file

* edit swagger codegen ignore

* update comment

* update comment

* fix link

* update poetry

* Update CHANGELOG.md

Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com>

* Update README.md

Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com>

* update version

---------

Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com>
  • Loading branch information
shmuel44 and dorschw authored Sep 26, 2023
1 parent 42f5bf8 commit 26cd534
Show file tree
Hide file tree
Showing 12 changed files with 624 additions and 158 deletions.
130 changes: 100 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,112 @@
### =============================================================
### This configuration file is used by CircleCI build server
### https://circleci.com/docs/config-sample
### https://circleci.com/docs/sample-config
### =============================================================
version: 2
version: 2.1

parameters:
docker_image_for_publishing:
# python 3.10 is the latest supported version
description: "Docker image to use for the build"
type: string
default: cimg/python:3.10

references:
install_poetry: &install_poetry
- run:
name: Install Poetry
command: |
# in old images we need to remove existing poetry
rm -rf $HOME/.poetry/bin/poetry
sudo curl -sSL https://install.python-poetry.org | python3 -
poetry --version
install_project_dependencies: &install_project_dependencies
- run:
name: Install Project Dependencies
command: |
poetry install --no-interaction --no-ansi --no-root
poetry_build: &poetry_build
- run:
name: Build Package
command: |
poetry build
jobs:
# using tox
toxify:
machine:
run-unit-tests:
parameters:
pythonversion:
type: string
docker:
- image: cimg/python:<< parameters.pythonversion >>
steps:
- checkout
- <<: *install_poetry
- <<: *install_project_dependencies
- run:
name: Run Unit Tests
command: |
mkdir test-results
poetry run python -m pytest --junitxml=test-results/junit.xml -v tests
- store_test_results:
path: test-results
verify:
machine:
image: ubuntu-2004:202201-02
steps:
- checkout
- run:
name: Verify
command: |
./verify.sh
publish-to-test-pypi:
docker:
- image: << pipeline.parameters.docker_image_for_publishing >>
steps:
- checkout
- <<: *poetry_build
- run:
name: Publish Package To Test PyPI
command: |
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry publish -u __token__ -p ${PYPI_TEST_TOKEN} -r testpypi

steps:
- checkout
- run:
name: Setup Python
command: |
pyenv versions
pyenv install 3.9.10
pyenv install 3.8.12
pyenv global 3.10.2 3.9.10 3.8.12
- run:
name: tox build
command: |
pip install tox
tox -q
- run:
name: verify
command: |
./verify.sh
- run:
name: deploy
command: |
./deploy.sh
publish-to-pypi:
docker:
- image: << pipeline.parameters.docker_image_for_publishing >>
steps:
- checkout
- <<: *poetry_build
- run:
name: Publish Package To PyPI
command: |
poetry publish -u __token__ -p ${PYPI_TOKEN}
workflows:
version: 2
build_and_release:
jobs:
- toxify:
- run-unit-tests:
matrix:
parameters:
pythonversion: ["3.8", "3.9", "3.10"]
name: run-unit-tests-<< matrix.pythonversion >>
- verify
- publish-to-test-pypi:
requires:
- run-unit-tests
- verify
filters:
branches:
only: master
- publish-to-pypi:
requires:
- run-unit-tests
- verify
filters:
tags:
only: /^v\d+\.\d+\.\d+$/
only: /^v\d+\.\d+\.\d+$/ # only run on tags [e.g. v0.0.0]
branches:
ignore: /.*/

7 changes: 3 additions & 4 deletions .swagger-codegen-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#!docs/README.md

.gitignore
tox.ini
test-requirements.txt
setup.py
requirements.txt
poetry.lock
pyproject.toml

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
[PyPI History][1]
[1]: https://pypi.org/project/demisto-py/#history

## Unreleased

* Changed package management from pip to Poetry for better dependency handling and packaging.

## 3.2.12
* Fixed an issue where download command would fail when trying to convert bytes types to string.

Expand Down
64 changes: 36 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Demisto Client for Python

[![PyPI version](https://badge.fury.io/py/demisto-py.svg)](https://badge.fury.io/py/demisto-py)
[![CircleCI](https://circleci.com/gh/demisto/demisto-py/tree/master.svg?style=svg)](https://circleci.com/gh/demisto/demisto-py/tree/master)

# Demisto Client for Python

A Python library for the Demisto API.

Expand Down Expand Up @@ -97,10 +98,14 @@ except ApiException as e:

Additional examples available in the [docs](docs/README.md) and under the [examples folder](examples/).

---

## API Documentation

API Documentation based upon the Demisto Server Swagger API is available [here](docs/README.md)

---

## Troubleshooting

### API Key
Expand Down Expand Up @@ -132,6 +137,8 @@ Content-Type: text/plain; charset=utf-8
{"demistoVersion":"5.5.0", ...}
```

---

## Contributing

Contributions are welcome and appreciated. To contribute follow the instructions below and submit a PR.
Expand All @@ -142,47 +149,42 @@ When you open a new pull request, a bot will evaluate whether you have signed th

If the `license/cla` status check remains on *Pending*, even though all contributors have accepted the CLA, you can recheck the CLA status by visiting the following link (replace **[PRID]** with the ID of your PR): <https://cla-assistant.io/check/demisto/demisto-py?pullRequest=[PRID>] .

---

## Dev Environment Setup

We recommend installing both development environments. We use [tox](https://github.com/tox-dev/tox) for managing environments and running unit tests.
We will now setup a quick virtualenv in which we will install the `demisto-py` 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.

Install `tox`:
1. Make sure you have python3 installed.

```bash
pip install tox
```
2. Make sure you have [Poetry](https://python-poetry.org/) installed.

List configured environments:
3. run `poetry install`

```bash
tox -l
```
4. For further reading about Poetry, you can refer to [Poetry documentation](https://python-poetry.org/).

Then setup dev virtual envs for python 3 (will also install all necessary requirements):
You have now setup the your `demisto-py` dev environment!

```bash
tox --devenv py310
```
To activate it simply run: `poetry shell`.

Switch to python 3 env by running:
To deactivate the virtual environment and return simply run: `exit`.

```bash
. py310/bin/activate
```
---

## Running Unit Tests
## Running unit-tests using Pytest

We use pytest to run unit tests. Inside a virtual env you can run unit test using:
We use [pytest](https://github.com/pytest-dev/pytest) to run unit tests.

```bash
python -m pytest -v
Simply use `poetry` to run your tests on a relevant folder. For example:
```
poetry run python -m pytest tests
```

Additionally, our build uses tox to run on multiple envs. To use tox to run on all supported environments (py38, py39, py310), run:
To run with a specific python version (see the [demisto-py PyPi page](https://pypi.org/project/demisto-py/) for the current supported versions), use [poetry environments](https://python-poetry.org/docs/managing-environments/) to switch to a different env with a different python version.

---

```bash
tox -q
```

## Code Generation

Expand All @@ -199,10 +201,13 @@ To generate the code run (requires bash, sed and docker):
./gen-code.sh
```

---

## Publishing a Release (demisto devs)

After merging to `master`, a test deployment will be pushed to: <https://test.pypi.org/project/demisto-py/> .
You can test the test package by following the pip install instructions. For example:
You can test the test package by following the pip install instructions.
For example:

```bash
pip install -i https://test.pypi.org/simple/ demisto-py
Expand All @@ -211,7 +216,9 @@ pip install -i https://test.pypi.org/simple/ demisto-py
Steps to publish a production release:

* Make sure [CHANGELOG.md](CHANGELOG.md) is up to date.
* Create and push a tag with the release version using git. For example:
* Update the version number in the `pyproject.toml` file to the new version.
* Create and push a tag with the release version using git.
For example:

```bash
git tag v2.0.19
Expand All @@ -223,6 +230,7 @@ Steps to publish a production release:

Congratulations! The release is now public.

---
## License

Apache 2.0 - See [LICENSE](LICENSE) for more information.
21 changes: 0 additions & 21 deletions deploy.sh

This file was deleted.

Loading

0 comments on commit 26cd534

Please sign in to comment.