From 207cf22f966c16315dc2331d5fd97fcde98fa35f Mon Sep 17 00:00:00 2001 From: Bradley Stuart Kirton Date: Sat, 2 Dec 2017 07:55:59 +0200 Subject: [PATCH 1/6] Removed the meta module. The version number can be added to the main package's __init__.py file. --- pybitx/meta.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 pybitx/meta.py diff --git a/pybitx/meta.py b/pybitx/meta.py deleted file mode 100644 index 1ee2704..0000000 --- a/pybitx/meta.py +++ /dev/null @@ -1 +0,0 @@ -version = "0.1.10" From 6260846f7309ae8065ed5e7a1f8b6969495c7fb0 Mon Sep 17 00:00:00 2001 From: Bradley Stuart Kirton Date: Sat, 2 Dec 2017 07:57:35 +0200 Subject: [PATCH 2/6] Added the package __version__ number to the main package __init__.py file. Updated the setup.py file to extract the version number and updated the rest of the project where the __version__ is required to import the __version__ number from the main package. --- pybitx/__init__.py | 6 +++--- pybitx/api.py | 3 +-- setup.py | 22 +++++++++++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pybitx/__init__.py b/pybitx/__init__.py index e0a914a..860bfce 100644 --- a/pybitx/__init__.py +++ b/pybitx/__init__.py @@ -1,4 +1,4 @@ -import meta -from api import BitX +__version__ = "0.1.10" -__version__ = meta.version + +from api import BitX \ No newline at end of file diff --git a/pybitx/api.py b/pybitx/api.py index 7aacd21..b0e516d 100644 --- a/pybitx/api.py +++ b/pybitx/api.py @@ -1,11 +1,10 @@ import requests import logging from concurrent.futures import ThreadPoolExecutor -from meta import version +from pybitx import __version__ import pandas as pd import json -__version__ = version log = logging.getLogger(__name__) diff --git a/setup.py b/setup.py index cef5496..e538103 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,25 @@ +import os +import re + from setuptools import setup, find_packages -import pybitx + + +# Extract the version from the main package __init__ file +PATTERN = '__version__\s+=\s+(?P.*)' +BASE_DIR = os.path.dirname(__file__) + +with open(os.path.join(BASE_DIR, 'pybitx/__init__.py'), 'r') as f: + match = re.search(PATTERN, f.read()) + +if match is None: + raise ValueError("failed to extract package version") + +version = match.groupdict()['version'] + setup( name='pybitx', - version=pybitx.__version__, + version=version, packages=find_packages(exclude=['tests']), description='A BitX API for Python', author='Cayle Sharrock', @@ -17,7 +33,7 @@ ], license='MIT', url='https://github.com/CjS77/pybitx', - download_url='https://github.com/CjS77/pybitx/tarball/%s' % (pybitx.__version__, ), + download_url='https://github.com/CjS77/pybitx/tarball/%s' % (version, ), keywords='BitX Bitcoin exchange API', classifiers=[], test_suite='tests', From 6a1729c4b272d2f826dddba2c95956951e663e2b Mon Sep 17 00:00:00 2001 From: Bradley Stuart Kirton Date: Sat, 2 Dec 2017 07:58:47 +0200 Subject: [PATCH 3/6] Rearranged the imports in the tests file and changed the import api to from pybitx import api. --- tests/test_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 668cf46..5682ede 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,8 +1,9 @@ +import base64 import unittest import requests_mock -import api + +from pybitx import api from pybitx.api import BitX, BitXAPIError -import base64 class TestBitX(unittest.TestCase): From 96bb041d16bb5bd572dfe890f70eafecf0ee7e1a Mon Sep 17 00:00:00 2001 From: Bradley Stuart Kirton Date: Sat, 2 Dec 2017 08:13:14 +0200 Subject: [PATCH 4/6] Moved the test dependencies from tests_require to extras_require. To install all dependencies when developing one can pip install -e .[dev] in the dir containing the setup.py file. --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index e538103..1b71ca1 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,5 @@ keywords='BitX Bitcoin exchange API', classifiers=[], test_suite='tests', - tests_require=[ - 'requests-mock>=0.7.0' - ] + extras_require={'dev': ['requests-mock>=0.7.0']} ) From eab7c4c994c30594ab8061b3c3278ff831f03589 Mon Sep 17 00:00:00 2001 From: Bradley Stuart Kirton Date: Sat, 2 Dec 2017 08:19:02 +0200 Subject: [PATCH 5/6] Updated the installation instructions in the readme file. --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 42567ea..f1483d6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,21 @@ # pybitx -BitX API for python +BitX API for python ([See API documentation](https://www.luno.com/en/api)). # Installation +```bash +pip install pybitx +``` + +#### For Developers +Clone this repo and create a virtual environment +```bash +git clone https://github.com/CjS77/pybitx +cd pybitx +virtualenv -p /usr/bin/python2.7 env +source env/bin/activate +pip install -e .[dev] +python2.7 tests/test_api.py # For good measure +``` # Usage From 2a8327e24720d61f45b9302fd62cf0ba128f7743 Mon Sep 17 00:00:00 2001 From: Bradley Stuart Kirton Date: Sun, 3 Dec 2017 16:40:26 +0200 Subject: [PATCH 6/6] Applied changes for Python 3 compatibility. --- demo.py | 20 ++++++++++++-------- pybitx/__init__.py | 2 +- tests/test_api.py | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/demo.py b/demo.py index 8c9daca..f0d7a3b 100644 --- a/demo.py +++ b/demo.py @@ -1,16 +1,20 @@ -from pybitx.api import BitX +from __future__ import print_function + import os import pprint +from pybitx.api import BitX + + pp = pprint.PrettyPrinter(indent=4, width=80) def format_call(name, results): - print '-'*80 - print '%50s' % (name,) - print '-'*80 + print('-'*80) + print('%50s' % (name,)) + print('-'*80) pp.pprint(results) - print '-'*80 + print('-'*80) def runDemo(): @@ -21,9 +25,9 @@ def runDemo(): user = os.environ['BITX_KEY'] password = os.environ['BITX_SECRET'] else: - print "Note: I couldn't find a BITX_KEY environment variable. This means that none of the API queries\nthat " \ - "require authentication will work. I'll carry on anyway, but make sure your credentials are available " \ - "in the BITX_KEY and BITX_SECRET environment variables and run this demo again" + print("Note: I couldn't find a BITX_KEY environment variable. This means that none of the API queries\nthat " + "require authentication will work. I'll carry on anyway, but make sure your credentials are available " + "in the BITX_KEY and BITX_SECRET environment variables and run this demo again") api = BitX(user, password) kind = 'auth' if auth else 'none' format_call(' Ticker ', api.get_ticker(kind)) diff --git a/pybitx/__init__.py b/pybitx/__init__.py index 860bfce..8945943 100644 --- a/pybitx/__init__.py +++ b/pybitx/__init__.py @@ -1,4 +1,4 @@ __version__ = "0.1.10" -from api import BitX \ No newline at end of file +from pybitx.api import BitX \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py index 5682ede..55a8f9c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -67,8 +67,8 @@ class TestAPICalls(unittest.TestCase): @staticmethod def make_auth_header(auth): s = ':'.join(auth) - k = base64.b64encode(s) - return 'Basic %s' % (k,) + k = base64.b64encode(s.encode('utf-8')) + return 'Basic %s' % (k.decode('utf-8'),) def setUp(self): options = {