Skip to content

Commit 5f5ccd9

Browse files
authored
Merge pull request #1 from IBM/init
new(core): Creating the core package
2 parents cda4fe5 + e1df393 commit 5f5ccd9

27 files changed

+1673
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
language: python
2+
matrix:
3+
include:
4+
- python: 2.7
5+
- python: 3.4
6+
- python: 3.5
7+
- python: 3.6
8+
- python: 3.7
9+
dist: xenial
10+
sudo: true
11+
cache: pip
12+
before_install:
13+
- npm install npm@latest -g
14+
install:
15+
- pip install tox-travis
16+
- pip install bumpversion
17+
- npm install @semantic-release/exec
18+
script:
19+
- tox
20+
before_deploy:
21+
- sudo apt-get update
22+
- pip install -r requirements.txt
23+
- pip install -r requirements-dev.txt
24+
- pip install pypandoc
25+
- sudo apt-get install pandoc
26+
- pip install --editable .
27+
deploy:
28+
- provider: script
29+
script: npx semantic-release
30+
skip_cleanup: true
31+
on:
32+
python: '3.5'
33+
branch: master
34+
- provider: pypi
35+
user: ehdsouza
36+
password:
37+
secure: eqNea0s1XHWbluBZiRRShfhx1NeGdcGC05IB+fNf1M6FC3klwjxFOhdToYNPr2RhpKTDFt2DZHqZt9fHHN18/aAmMPIc4Nbe7FBtZAEfNe6VH9shWGJFm1fOhjzz8x/BD1dn0wj7XmJon0jT13RS5VxlIxgxOAAceK0mGuM9hi0vnb0e10CBZ4Gk3h8Ns7Zke4WBsjpSdalAzJmfH5Zl/ZbXZj4UDI0ZT6Noc4CbB0buVdRVg8ph1S0n7I5TCKg34ERbm5GShNv/y6K4fTXh72pLIOZZlzXk/IfHPHWx/MZ/BqjjYHZY7disSldRsvW/PqR2tpKY3U7xZgupOzjbIuDzcrERfXA4gy+t9htZOMSXfG5P5LVKIYU5lMI9FOZcKHoyIrOBwKdqFiLbja+X6/95jyjDWb/ukp4BUatD6ju75v+YutOkyPCmBQmadzXDMLSyLcHAAuaWtIV1ZPufaZRr0LJbgAHPa+LBGvSWZ4JvfwguLKt2dgvYF3ZxImM528tcXjPFLej75Md21xsks1rsTbWZO/Cut8BTjj/mn/B9c2sSdPNUZRdVhTpb3tcnwpkis9tqdnzRqxoNftmfEAPWkDx8Z6U9lWEm4f4frSwkLKmyAA5FtLPW6TSwV4N7p8v6VnEO2JHAtWBxPOc/zjd9O49H3Wk3QPZwPoLSHOw=
38+
repository: https://upload.pypi.org/legacy
39+
skip_cleanup: true
40+
on:
41+
python: '3.5'
42+
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 [email protected]:IBM/python-sdk-core.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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
[![Build Status](https://travis-ci.com/IBM/python-sdk-core.svg?branch=master)](https://travis-ci.com/IBM/python-sdk-core)
2+
[![codecov](https://codecov.io/gh/python-sdk-core/branch/master/graph/badge.svg)](https://codecov.io/gh/IBM/python-sdk-core)
3+
[![Latest Stable Version](https://img.shields.io/pypi/v/ibm-cloud-sdk-core.svg)](https://pypi.python.org/pypi/ibm-cloud-sdk-core)
4+
15
# python-sdk-core
26
This project contains the core functionality used by Python SDK's generated by the IBM OpenAPI 3 SDK Generator (openapi-sdkgen).
37
Python code generated by openapi-sdkgen will depend on the function contained in this project.
8+
9+
## Installation
10+
11+
To install, use `pip` or `easy_install`:
12+
13+
```bash
14+
pip install --upgrade ibm-cloud-sdk-core
15+
```
16+
17+
or
18+
19+
```bash
20+
easy_install --upgrade ibm-cloud-sdk-core
21+
```
22+
23+
## Issues
24+
25+
If you encounter an issue with this project, you are welcome to submit a [bug report](https://github.com/IBM/python-sdk-core/issues).
26+
Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.
27+
28+
## Open source @ IBM
29+
30+
Find more open source projects on the [IBM Github Page](http://github.com/IBM)
31+
32+
## License
33+
34+
This library is licensed under Apache 2.0. Full license text is
35+
available in [LICENSE](LICENSE).
36+
37+
## Contributing
38+
39+
See [CONTRIBUTING.md](CONTRIBUTING.md).

ibm_cloud_sdk_core/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 .base_service import BaseService
17+
from .detailed_response import DetailedResponse
18+
from .iam_token_manager import IAMTokenManager
19+
from .api_exception import ApiException
20+
from .utils import datetime_to_string, string_to_datetime

ibm_cloud_sdk_core/api_exception.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 http_response: response
25+
"""
26+
def __init__(self, code, message=None, info=None, http_response=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.http_response = http_response
32+
self.global_transaction_id = None
33+
if http_response is not None:
34+
self.global_transaction_id = http_response.headers.get('X-Global-Transaction-ID')
35+
self.message = self.message if self.message else self._get_error_message(http_response)
36+
37+
def __str__(self):
38+
msg = 'Error: ' + str(self.message) + ', Code: ' + str(self.code)
39+
if self.global_transaction_id is not None:
40+
msg += ' , X-global-transaction-id: ' + str(self.global_transaction_id)
41+
return msg
42+
43+
def _get_error_message(self, response):
44+
"""
45+
Gets the error message from a JSON response.
46+
:return: the error message
47+
:rtype: string
48+
"""
49+
error_message = 'Unknown error'
50+
try:
51+
error_json = response.json()
52+
if 'errors' in error_json:
53+
if isinstance(error_json['errors'], list):
54+
err = error_json['errors'][0]
55+
error_message = err.get('message')
56+
elif 'error' in error_json:
57+
error_message = error_json['error']
58+
elif 'message' in error_json:
59+
error_message = error_json['message']
60+
return error_message
61+
except:
62+
return response.text or error_message

0 commit comments

Comments
 (0)