-
Notifications
You must be signed in to change notification settings - Fork 29
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
Changes from all commits
88912a1
2421459
c3de2e1
2982424
3e0ae7e
b8c123a
0866521
975b907
65e17d0
416dd82
49ed7eb
d631acc
e1df393
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[bumpversion] | ||
current_version = 0.0.0 | ||
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}' |
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/ |
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 | ||
|
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", | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
language: python | ||
matrix: | ||
include: | ||
- python: 2.7 | ||
- python: 3.4 | ||
- python: 3.5 | ||
- python: 3.6 | ||
- python: 3.7 | ||
dist: xenial | ||
sudo: true | ||
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: eqNea0s1XHWbluBZiRRShfhx1NeGdcGC05IB+fNf1M6FC3klwjxFOhdToYNPr2RhpKTDFt2DZHqZt9fHHN18/aAmMPIc4Nbe7FBtZAEfNe6VH9shWGJFm1fOhjzz8x/BD1dn0wj7XmJon0jT13RS5VxlIxgxOAAceK0mGuM9hi0vnb0e10CBZ4Gk3h8Ns7Zke4WBsjpSdalAzJmfH5Zl/ZbXZj4UDI0ZT6Noc4CbB0buVdRVg8ph1S0n7I5TCKg34ERbm5GShNv/y6K4fTXh72pLIOZZlzXk/IfHPHWx/MZ/BqjjYHZY7disSldRsvW/PqR2tpKY3U7xZgupOzjbIuDzcrERfXA4gy+t9htZOMSXfG5P5LVKIYU5lMI9FOZcKHoyIrOBwKdqFiLbja+X6/95jyjDWb/ukp4BUatD6ju75v+YutOkyPCmBQmadzXDMLSyLcHAAuaWtIV1ZPufaZRr0LJbgAHPa+LBGvSWZ4JvfwguLKt2dgvYF3ZxImM528tcXjPFLej75Md21xsks1rsTbWZO/Cut8BTjj/mn/B9c2sSdPNUZRdVhTpb3tcnwpkis9tqdnzRqxoNftmfEAPWkDx8Z6U9lWEm4f4frSwkLKmyAA5FtLPW6TSwV4N7p8v6VnEO2JHAtWBxPOc/zjd9O49H3Wk3QPZwPoLSHOw= | ||
repository: https://upload.pypi.org/legacy | ||
skip_cleanup: true | ||
on: | ||
python: '3.5' | ||
tags: true |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,39 @@ | ||
[](https://travis-ci.com/IBM/python-sdk-core) | ||
[](https://codecov.io/gh/IBM/python-sdk-core) | ||
[](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). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 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 .base_service import BaseService | ||
from .detailed_response import DetailedResponse | ||
from .iam_token_manager import IAMTokenManager | ||
from .api_exception import ApiException | ||
from .utils import datetime_to_string, string_to_datetime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean that a generated .py file no longer needs to explicitly import these functions as long as it imports the "ibm_cloud_sdk_core" module? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import would look something like: or if you want to import the entire module
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# 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 http_response: response | ||
""" | ||
def __init__(self, code, message=None, info=None, http_response=None): | ||
# Call the base class constructor with the parameters it needs | ||
super(ApiException, self).__init__(message) | ||
self.message = message | ||
self.code = code | ||
self.http_response = http_response | ||
self.global_transaction_id = None | ||
if http_response is not None: | ||
self.global_transaction_id = http_response.headers.get('X-Global-Transaction-ID') | ||
self.message = self.message if self.message else self._get_error_message(http_response) | ||
|
||
def __str__(self): | ||
msg = 'Error: ' + str(self.message) + ', Code: ' + str(self.code) | ||
if self.global_transaction_id is not None: | ||
msg += ' , X-global-transaction-id: ' + str(self.global_transaction_id) | ||
return msg | ||
|
||
def _get_error_message(self, response): | ||
""" | ||
Gets the error message from a JSON response. | ||
:return: the error message | ||
:rtype: string | ||
""" | ||
error_message = 'Unknown error' | ||
try: | ||
error_json = response.json() | ||
if 'errors' in error_json: | ||
if isinstance(error_json['errors'], list): | ||
err = error_json['errors'][0] | ||
error_message = err.get('message') | ||
elif 'error' in error_json: | ||
error_message = error_json['error'] | ||
elif 'message' in error_json: | ||
error_message = error_json['message'] | ||
return error_message | ||
except: | ||
return response.text or error_message |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: