Skip to content

Commit 88912a1

Browse files
committed
new(core): Creating the core package
1 parent cda4fe5 commit 88912a1

25 files changed

+1482
-0
lines changed

.bumpversion.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[bumpversion]
2+
current_version = 0.0.0
3+
commit = True
4+
5+
[bumpversion:file:ibm_cloud_sdk_core/version.py]
6+
search = __version__ = '{current_version}'
7+
replace = __version__ = '{new_version}'
8+
9+
[bumpversion:file:setup.py]
10+
search = __version__ = '{current_version}'
11+
replace = __version__ = '{new_version}'

.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# IDE OS
2+
.DS_Store
3+
.idea
4+
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# Distribution / packaging
11+
.Python
12+
env/
13+
build/
14+
develop-eggs/
15+
dist/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
47+
.vscode
48+
49+
# virtual env
50+
venv/
51+
# python 3 virtual env
52+
python3/
53+
54+
.env
55+
56+
.sfdx/tools/apex.db
57+
.pytest_cache/

.pylintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# lint Python modules using external checkers.
2+
[MASTER]
3+
ignore=SVN
4+
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
5+

.releaserc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"branch": "master",
3+
"verifyConditions": [],
4+
"prepare": [
5+
{
6+
"path": "@semantic-release/exec",
7+
"cmd": "bumpversion --current-version ${lastRelease.version} --new-version ${nextRelease.version} patch"
8+
}
9+
],
10+
"publish": [
11+
{
12+
"path": "@semantic-release/github",
13+
}
14+
]
15+
}

.travis.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
language: python
2+
python:
3+
- '2.7'
4+
- '3.4'
5+
- '3.5'
6+
- '3.6'
7+
cache: pip
8+
before_install:
9+
- npm install npm@latest -g
10+
install:
11+
- pip install tox-travis
12+
- pip install bumpversion
13+
- npm install @semantic-release/exec
14+
script:
15+
- tox
16+
before_deploy:
17+
- sudo apt-get update
18+
- pip install -r requirements.txt
19+
- pip install -r requirements-dev.txt
20+
- pip install pypandoc
21+
- sudo apt-get install pandoc
22+
- pip install --editable .
23+
deploy:
24+
- provider: script
25+
script: npx semantic-release
26+
skip_cleanup: true
27+
on:
28+
python: '3.5'
29+
branch: master
30+
- provider: pypi
31+
user: ehdsouza
32+
password:
33+
secure: eMssjS1Airz5MrmcEDAnKYnTlMLuzinX8JFsh4TB0A4t7GCes2a/mlvcoazAv2QZMQUKQMC++bAXYGGgXtsSQsfOYnRtojW4pRphxOZrlXlWFgCLGz/eHioamNZVbH+/P/OYjbLy5ZKSzp3M3bZxYqHcmGTq0sBeo5A2Ilkzu5P+D865Jqtn52brwh/xYq4XWeJeQN/BSLwdtPEtZYQXhQupAteNDAo2ON0FVyt0amINrjA0Qw+0k35g36wti+CsKn5fhbaHf6jjN0oRj8J8wPZieXLAUMdxscfBjUXJ8AK8E4H/wPI30IsaMus+1r85ekiDKZC5iukO6uqMARFywjX/eTIDbWxwKImQUgvVa2+gncre7GvZrHIFxhIDDkssH1IfC1fcw3mNY4vCO9df/vHStp3Kvi27GvsYJnfsbXXj6fAhokHtsrnrbpXFET6LghGQx3HgOKrlCQ1EI0Fk92Qw7+g15jwMGlkwUE1qMS+PVOe7dQ4ikxJgw4CVrqU6/zaLFHV8LXFfjv166ZSWcOJHJXGgJ2TPuGiooL60+pWp/UYY00hZVlYX0Vlks6zN0h9zJd16kR3EwDrW0muqFnLC2xTuv5WsCjsOATtsTQzmBNEdCbGdOskgF4+0yPe7ps3kEs3UpAooKtYVh1OOJAUkl4vSMyu4Jg1ASyQWt00=
34+
repository: https://upload.pypi.org/legacy
35+
skip_cleanup: true
36+
on:
37+
python: '3.5'
38+
tags: true

CONTRIBUTING.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Contributing
2+
3+
## Questions
4+
5+
If you are having difficulties using the APIs or have a question about the IBM Cloud and Services,
6+
please ask a question on [dW Answers][dw] or [Stack Overflow][stackoverflow].
7+
8+
## Issues
9+
10+
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).
11+
Before that, please search for similar issues. It's possible somebody has encountered this issue already.
12+
13+
## Pull Requests
14+
15+
If you want to contribute to the repository, here's a quick guide:
16+
17+
1. Fork the repository
18+
1. Install `virtualenv` and `tox`
19+
1. Develop and test your code changes with [pytest].
20+
* Respect the original code [style guide][styleguide].
21+
* Only use spaces for indentation.
22+
* 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.
23+
* Check for unnecessary whitespace with `git diff --check` before committing.
24+
* Make sure your code supports Python 2.7, 3.4, 3.5 and 3.6. You can use `pyenv` and `tox` for this
25+
1. Make the test pass
26+
1. Commit your changes
27+
* 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.
28+
1. Push to your fork and submit a pull request to the `dev` branch
29+
30+
## Running the tests
31+
32+
You probably want to set up a [virtualenv].
33+
34+
1. Clone this repository:
35+
```sh
36+
git clone https://github.com/watson-developer-cloud/python-sdk.git
37+
```
38+
1. Install the sdk as an editable package using the current source:
39+
```sh
40+
pip install --editable .
41+
```
42+
1. Install the test dependencies with:
43+
```sh
44+
pip install -r requirements-dev.txt
45+
```
46+
1. Run the test cases with:
47+
```sh
48+
py.test test
49+
```
50+
51+
## Additional Resources
52+
53+
* [General GitHub documentation](https://help.github.com/)
54+
* [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
55+
56+
[dw]: https://developer.ibm.com/answers/questions/ask.html
57+
[stackoverflow]: http://stackoverflow.com/questions/ask?tags=ibm
58+
[styleguide]: http://google.github.io/styleguide/pyguide.html
59+
[pytest]: http://pytest.org/latest/
60+
[virtualenv]: http://virtualenv.readthedocs.org/en/latest/index.html
File renamed without changes.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
11
# python-sdk-core
22
This project contains the core functionality used by Python SDK's generated by the IBM OpenAPI 3 SDK Generator (openapi-sdkgen).
33
Python code generated by openapi-sdkgen will depend on the function contained in this project.
4+
5+
## Installation
6+
7+
To install, use `pip` or `easy_install`:
8+
9+
```bash
10+
pip install --upgrade ibm-cloud-sdk-core
11+
```
12+
13+
or
14+
15+
```bash
16+
easy_install --upgrade ibm-cloud-sdk-core
17+
```
18+
19+
## Issues
20+
21+
If you encounter an issue with this project, you are welcome to submit a [bug report](https://github.com/IBM/python-sdk-core/issues).
22+
Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.
23+
24+
## Open source @ IBM
25+
26+
Find more open source projects on the [IBM Github Page](http://github.com/IBM)
27+
28+
## License
29+
30+
This library is licensed under Apache 2.0. Full license text is
31+
available in [LICENSE](LICENSE).
32+
33+
## Contributing
34+
35+
See [CONTRIBUTING.md](CONTRIBUTING.md).

ibm_cloud_sdk_core/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# coding: utf-8
2+
# Copyright 2019 IBM All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from .service import Service
17+
from .detailed_response import DetailedResponse
18+
from .iam_token_manager import IAMTokenManager
19+
from .api_exception import ApiException

ibm_cloud_sdk_core/api_exception.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# coding: utf-8
2+
3+
# Copyright 2019 IBM All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
class ApiException(Exception):
18+
"""
19+
Custom exception class for errors returned from APIs.
20+
21+
:param int code: The HTTP status code returned.
22+
:param str message: A message describing the error.
23+
:param dict info: A dictionary of additional information about the error.
24+
:param response httpResponse: response
25+
"""
26+
def __init__(self, code, message, info=None, httpResponse=None):
27+
# Call the base class constructor with the parameters it needs
28+
super(ApiException, self).__init__(message)
29+
self.message = message
30+
self.code = code
31+
self.info = info
32+
self.httpResponse = httpResponse
33+
self.transactionId = None
34+
self.globalTransactionId = None
35+
if httpResponse is not None:
36+
self.transactionId = httpResponse.headers.get('X-DP-Watson-Tran-ID')
37+
self.globalTransactionId = httpResponse.headers.get('X-Global-Transaction-ID')
38+
39+
40+
def __str__(self):
41+
msg = 'Error: ' + str(self.message) + ', Code: ' + str(self.code)
42+
if self.info is not None:
43+
msg += ' , Information: ' + str(self.info)
44+
if self.transactionId is not None:
45+
msg += ' , X-dp-watson-tran-id: ' + str(self.transactionId)
46+
if self.globalTransactionId is not None:
47+
msg += ' , X-global-transaction-id: ' + str(self.globalTransactionId)
48+
return msg
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# coding: utf-8
2+
3+
# Copyright 2019 IBM All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import json
18+
19+
class DetailedResponse(object):
20+
"""
21+
Custom class for detailed response returned from APIs.
22+
23+
:param Response response: Either json response or http Response as requested.
24+
:param dict headers: A dict of response headers
25+
:param str status_code: HTTP response code
26+
"""
27+
def __init__(self, response=None, headers=None, status_code=None):
28+
self.result = response
29+
self.headers = headers
30+
self.status_code = status_code
31+
32+
def get_result(self):
33+
return self.result
34+
35+
def get_headers(self):
36+
return self.headers
37+
38+
def get_status_code(self):
39+
return self.status_code
40+
41+
def _to_dict(self):
42+
_dict = {}
43+
if hasattr(self, 'result') and self.result is not None:
44+
_dict['result'] = self.result if isinstance(self.result, dict) else 'HTTP response'
45+
if hasattr(self, 'headers') and self.headers is not None:
46+
_dict['headers'] = self.headers
47+
if hasattr(self, 'status_code') and self.status_code is not None:
48+
_dict['status_code'] = self.status_code
49+
return _dict
50+
51+
def __str__(self):
52+
return json.dumps(self._to_dict(), indent=4, default=lambda o: o.__dict__)

0 commit comments

Comments
 (0)