Skip to content

Commit

Permalink
release/0.7.0: Move version parsing from class Porter to module sklea…
Browse files Browse the repository at this point in the history
…rn_porter
  • Loading branch information
nok committed Dec 9, 2018
1 parent 345540e commit 1daa4b3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion recipes/run.deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rm -rf ./build/*
rm -rf ./dist/*

# Read package version:
VERSION=`python -c "from sklearn_porter.Porter import Porter; print(Porter.__version__);"`
VERSION=`python -c "from sklearn_porter import __version__ as ver; print(ver);"`

# Define the deployment platform:
target=https://test.pypi.org/legacy/
Expand Down
8 changes: 0 additions & 8 deletions sklearn_porter/Porter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@

class Porter(object):

# Version:
local_dir = os.path.dirname(__file__)
version_file = os.path.join(local_dir, '__version__.txt')
version = open(version_file).readlines().pop()
if isinstance(version, bytes):
version = version.decode('utf-8')
__version__ = str(version).strip()

def __init__(self, estimator, language='java', method='predict', **kwargs):
# pylint: disable=unused-argument
"""
Expand Down
17 changes: 17 additions & 0 deletions sklearn_porter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# -*- coding: utf-8 -*-

import os
import os.path

from sklearn_porter.Porter import Porter


def _read_version():
"""Read the module version from __version__.txt"""
source_dir = os.path.abspath(os.path.dirname(__file__))
version_file = os.path.join(source_dir, '__version__.txt')
version = open(version_file, 'r').readlines().pop()
if isinstance(version, bytes):
version = version.decode('utf-8')
version = str(version).strip()
return version


__version__ = _read_version()
5 changes: 3 additions & 2 deletions sklearn_porter/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from sklearn.externals import joblib

from sklearn_porter import __version__ as porter_version
from sklearn_porter.Porter import Porter
from sklearn_porter.language import *

Expand All @@ -28,7 +29,7 @@
[--class_name CLASS_NAME] [--method_name METHOD_NAME]
[--export] [--checksum] [--data] [--pipe]
[--c] [--java] [--js] [--go] [--php] [--ruby]
[--help] [--version]'''.format(Porter.__version__)
[--help] [--version]'''.format(porter_version)


def parse_args(args):
Expand Down Expand Up @@ -98,7 +99,7 @@ def parse_args(args):
# Extra arguments:
extras = parser.add_argument_group('Extra arguments')
extras.add_argument('--version', '-v', action='version',
version='sklearn-porter v{}'.format(Porter.__version__))
version='sklearn-porter v{}'.format(porter_version))

# Show help by default:
if len(sys.argv) == 1:
Expand Down

0 comments on commit 1daa4b3

Please sign in to comment.