Skip to content

new(core): Creating the core package #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[bumpversion]
current_version = 0.0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure we don't use a 1.x version for the core package until we know it's stable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an initial tag: v0.0.0 and ran semantic locally:

# 0.1.0 (https://github.com/IBM/python-sdk-core/compare/v0.0.0...v0.1.0) (2019-03-13)

### Features

    * core: create a separate core for IBM python SDK (2421459 (https://github.com/IBM/python-sdk-core/commit/2421459))

commit = True

[bumpversion:file:ibm_cloud_sdk_core/version.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'

[bumpversion:file:setup.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# IDE OS
.DS_Store
.idea

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

.vscode

# virtual env
venv/
# python 3 virtual env
python3/

.env

.sfdx/tools/apex.db
.pytest_cache/
5 changes: 5 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# lint Python modules using external checkers.
[MASTER]
ignore=SVN
disable=R0903,R0912,R0913,R0914,R0915,W0141,C0111,C0103,W0603,W0703,R0911,C0301,C0302,R0902,R0904,W0142,W0212,E1101,E1103,R0201,W0201,W0122,W0232,RP0001,RP0003,RP0101,RP0002,RP0401,RP0701,RP0801,F0401,E0611,R0801,I0011,F0401,E0611,E1004,C0111,I0011,I0012,W0704,W0142,W0212,W0232,W0613,W0702,R0201,W0614,R0914,R0912,R0915,R0913,R0904,R0801,C0301,C0411,R0204,W0622,E1121,inconsistent-return-statements,missing-docstring

15 changes: 15 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"branch": "master",
"verifyConditions": [],
"prepare": [
{
"path": "@semantic-release/exec",
"cmd": "bumpversion --current-version ${lastRelease.version} --new-version ${nextRelease.version} patch"
}
],
"publish": [
{
"path": "@semantic-release/github",
}
]
}
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
language: python
python:
- '2.7'
- '3.4'
- '3.5'
- '3.6'
cache: pip
before_install:
- npm install npm@latest -g
install:
- pip install tox-travis
- pip install bumpversion
- npm install @semantic-release/exec
script:
- tox
before_deploy:
- sudo apt-get update
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install pypandoc
- sudo apt-get install pandoc
- pip install --editable .
deploy:
- provider: script
script: npx semantic-release
skip_cleanup: true
on:
python: '3.5'
branch: master
- provider: pypi
user: ehdsouza
password:
secure: eMssjS1Airz5MrmcEDAnKYnTlMLuzinX8JFsh4TB0A4t7GCes2a/mlvcoazAv2QZMQUKQMC++bAXYGGgXtsSQsfOYnRtojW4pRphxOZrlXlWFgCLGz/eHioamNZVbH+/P/OYjbLy5ZKSzp3M3bZxYqHcmGTq0sBeo5A2Ilkzu5P+D865Jqtn52brwh/xYq4XWeJeQN/BSLwdtPEtZYQXhQupAteNDAo2ON0FVyt0amINrjA0Qw+0k35g36wti+CsKn5fhbaHf6jjN0oRj8J8wPZieXLAUMdxscfBjUXJ8AK8E4H/wPI30IsaMus+1r85ekiDKZC5iukO6uqMARFywjX/eTIDbWxwKImQUgvVa2+gncre7GvZrHIFxhIDDkssH1IfC1fcw3mNY4vCO9df/vHStp3Kvi27GvsYJnfsbXXj6fAhokHtsrnrbpXFET6LghGQx3HgOKrlCQ1EI0Fk92Qw7+g15jwMGlkwUE1qMS+PVOe7dQ4ikxJgw4CVrqU6/zaLFHV8LXFfjv166ZSWcOJHJXGgJ2TPuGiooL60+pWp/UYY00hZVlYX0Vlks6zN0h9zJd16kR3EwDrW0muqFnLC2xTuv5WsCjsOATtsTQzmBNEdCbGdOskgF4+0yPe7ps3kEs3UpAooKtYVh1OOJAUkl4vSMyu4Jg1ASyQWt00=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@germanattanasio followed these steps for encrypting key: https://docs.travis-ci.com/user/deployment/pypi/

repository: https://upload.pypi.org/legacy
skip_cleanup: true
on:
python: '3.5'
tags: true
60 changes: 60 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Contributing

## Questions

If you are having difficulties using the APIs or have a question about the IBM Cloud and Services,
please ask a question on [dW Answers][dw] or [Stack Overflow][stackoverflow].

## Issues

If you encounter an issue with the Python SDK, you are welcome to submit a [bug report](https://github.com/IBM/python-sdk-core/issues).
Before that, please search for similar issues. It's possible somebody has encountered this issue already.

## Pull Requests

If you want to contribute to the repository, here's a quick guide:

1. Fork the repository
1. Install `virtualenv` and `tox`
1. Develop and test your code changes with [pytest].
* Respect the original code [style guide][styleguide].
* Only use spaces for indentation.
* Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
* Check for unnecessary whitespace with `git diff --check` before committing.
* Make sure your code supports Python 2.7, 3.4, 3.5 and 3.6. You can use `pyenv` and `tox` for this
1. Make the test pass
1. Commit your changes
* Commits should follow the [Angular commit message guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines). This is because our release tool uses this format for determining release versions and generating changelogs. To make this easier, we recommend using the [Commitizen CLI](https://github.com/commitizen/cz-cli) with the `cz-conventional-changelog` adapter.
1. Push to your fork and submit a pull request to the `dev` branch

## Running the tests

You probably want to set up a [virtualenv].

1. Clone this repository:
```sh
git clone [email protected]:IBM/python-sdk-core.git
```
1. Install the sdk as an editable package using the current source:
```sh
pip install --editable .
```
1. Install the test dependencies with:
```sh
pip install -r requirements-dev.txt
```
1. Run the test cases with:
```sh
py.test test
```

## Additional Resources

* [General GitHub documentation](https://help.github.com/)
* [GitHub pull request documentation](https://help.github.com/send-pull-requests/)

[dw]: https://developer.ibm.com/answers/questions/ask.html
[stackoverflow]: http://stackoverflow.com/questions/ask?tags=ibm
[styleguide]: http://google.github.io/styleguide/pyguide.html
[pytest]: http://pytest.org/latest/
[virtualenv]: http://virtualenv.readthedocs.org/en/latest/index.html
File renamed without changes.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
[![Build Status](https://travis-ci.com/IBM/python-sdk-core.svg?branch=master)](https://travis-ci.com/IBM/python-sdk-core)
[![Latest Stable Version](https://img.shields.io/pypi/v/ibm-cloud-sdk-core.svg)](https://pypi.python.org/pypi/ibm-cloud-sdk-core)

# python-sdk-core
This project contains the core functionality used by Python SDK's generated by the IBM OpenAPI 3 SDK Generator (openapi-sdkgen).
Python code generated by openapi-sdkgen will depend on the function contained in this project.

## Installation

To install, use `pip` or `easy_install`:

```bash
pip install --upgrade ibm-cloud-sdk-core
```

or

```bash
easy_install --upgrade ibm-cloud-sdk-core
```

## Issues

If you encounter an issue with this project, you are welcome to submit a [bug report](https://github.com/IBM/python-sdk-core/issues).
Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.

## Open source @ IBM

Find more open source projects on the [IBM Github Page](http://github.com/IBM)

## License

This library is licensed under Apache 2.0. Full license text is
available in [LICENSE](LICENSE).

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).
19 changes: 19 additions & 0 deletions ibm_cloud_sdk_core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# coding: utf-8
# Copyright 2019 IBM All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .service import Service
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the name service ok or should I move to base_service? @padamstx @germanattanasio

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think base_service it's better

from .detailed_response import DetailedResponse
from .iam_token_manager import IAMTokenManager
from .api_exception import ApiException
48 changes: 48 additions & 0 deletions ibm_cloud_sdk_core/api_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# coding: utf-8

# Copyright 2019 IBM All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class ApiException(Exception):
"""
Custom exception class for errors returned from APIs.

:param int code: The HTTP status code returned.
:param str message: A message describing the error.
:param dict info: A dictionary of additional information about the error.
:param response httpResponse: response
"""
def __init__(self, code, message, info=None, httpResponse=None):
# Call the base class constructor with the parameters it needs
super(ApiException, self).__init__(message)
self.message = message
self.code = code
self.info = info
self.httpResponse = httpResponse
self.transactionId = None
self.globalTransactionId = None
if httpResponse is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get all the headers from the response in a dictionary? maybe they can access that if they use the httpResponse object

self.transactionId = httpResponse.headers.get('X-DP-Watson-Tran-ID')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@padamstx @germanattanasio only Watson specific that I see here is this header. Should I remove it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watson specific code should be in our SDK not the core

self.globalTransactionId = httpResponse.headers.get('X-Global-Transaction-ID')


def __str__(self):
msg = 'Error: ' + str(self.message) + ', Code: ' + str(self.code)
if self.info is not None:
msg += ' , Information: ' + str(self.info)
if self.transactionId is not None:
msg += ' , X-dp-watson-tran-id: ' + str(self.transactionId)
if self.globalTransactionId is not None:
msg += ' , X-global-transaction-id: ' + str(self.globalTransactionId)
return msg
52 changes: 52 additions & 0 deletions ibm_cloud_sdk_core/detailed_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding: utf-8

# Copyright 2019 IBM All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json

class DetailedResponse(object):
"""
Custom class for detailed response returned from APIs.

:param Response response: Either json response or http Response as requested.
:param dict headers: A dict of response headers
:param str status_code: HTTP response code
"""
def __init__(self, response=None, headers=None, status_code=None):
self.result = response
self.headers = headers
self.status_code = status_code

def get_result(self):
return self.result

def get_headers(self):
return self.headers

def get_status_code(self):
return self.status_code

def _to_dict(self):
_dict = {}
if hasattr(self, 'result') and self.result is not None:
_dict['result'] = self.result if isinstance(self.result, dict) else 'HTTP response'
if hasattr(self, 'headers') and self.headers is not None:
_dict['headers'] = self.headers
if hasattr(self, 'status_code') and self.status_code is not None:
_dict['status_code'] = self.status_code
return _dict

def __str__(self):
return json.dumps(self._to_dict(), indent=4, default=lambda o: o.__dict__)
Loading