Skip to content

Commit

Permalink
Read version from config instead of using import
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Apr 10, 2019
1 parent 21dfaf0 commit 4580dfc
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 31 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ venv

examples/settings.py
examples/ubuntu_dialogs*
sentence_tokenizer.pickle
.env
.out

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include LICENSE
include README.md
include requirements.txt
include setup.cfg

global-exclude __pycache__
global-exclude *.py[co]
Expand Down
4 changes: 0 additions & 4 deletions chatterbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
"""
from .chatterbot import ChatBot

__version__ = '1.0.5'
__author__ = 'Gunther Cox'
__email__ = '[email protected]'
__url__ = 'https://github.com/gunthercox/ChatterBot'

__all__ = (
'ChatBot',
Expand Down
14 changes: 11 additions & 3 deletions chatterbot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import importlib
import configparser
import sys
import os


def get_chatterbot_version():
chatterbot = importlib.import_module('chatterbot')
return chatterbot.__version__
config = configparser.ConfigParser()

current_directory = os.path.dirname(os.path.abspath(__file__))
parent_directory = os.path.abspath(os.path.join(current_directory, os.pardir))
config_file_path = os.path.join(parent_directory, 'setup.cfg')

config.read(config_file_path)

return config['chatterbot']['version']


if __name__ == '__main__':
Expand Down
31 changes: 19 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import sys
import os
import sys
import configparser
from datetime import datetime
import sphinx_rtd_theme


# Insert the project root dir as the first element in the PYTHONPATH.
# This lets us ensure that the source package is imported, and that its version is used.
config = configparser.ConfigParser()

current_directory = os.path.dirname(os.path.abspath(__file__))
parent_directory = os.path.abspath(os.path.join(current_directory, os.pardir))
sys.path.insert(0, parent_directory)
config_file_path = os.path.join(parent_directory, 'setup.cfg')

config.read(config_file_path)

import chatterbot # NOQA
# Insert the project root dir as the first element in the PYTHONPATH.
# This lets us ensure that the source package is imported, and used to generate the documentation.
sys.path.insert(0, parent_directory)

# -- General configuration ------------------------------------------------

# Sphinx extension modules
extensions = [
Expand Down Expand Up @@ -41,14 +45,17 @@

# General information about the project
project = 'ChatterBot'
copyright = '{}, {}'.format(datetime.now().year, chatterbot.__author__)
author = chatterbot.__author__

# The short X.Y version
version = chatterbot.__version__
author = config['chatterbot']['author']
copyright = '{}, {}'.format(
datetime.now().year,
author
)

# The full version, including alpha/beta/rc tags
release = chatterbot.__version__
release = config['chatterbot']['version']

# The short X.Y version
version = config['chatterbot']['version'].rsplit('.', 1)[0]

language = 'en'

Expand Down
8 changes: 7 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ cover-min-percentage = 40
# H306: imports not in alphabetical order (time, os)
ignore = H306
max_line_length = 175
exclude = .eggs, .git, .tox, build,
exclude = .eggs, .git, .tox, build,

[chatterbot]
version = 1.0.5
author = Gunther Cox
email = [email protected]
url = https://github.com/gunthercox/ChatterBot
22 changes: 14 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"""
ChatterBot setup file.
"""
import os
import sys
import platform
import configparser
from setuptools import setup


Expand All @@ -15,13 +17,17 @@
)
)

# Dynamically retrieve the version information from the chatterbot module
CHATTERBOT = __import__('chatterbot')
VERSION = CHATTERBOT.__version__
AUTHOR = CHATTERBOT.__author__
AUTHOR_EMAIL = CHATTERBOT.__email__
URL = CHATTERBOT.__url__
DESCRIPTION = CHATTERBOT.__doc__
config = configparser.ConfigParser()

current_directory = os.path.dirname(os.path.abspath(__file__))
config_file_path = os.path.join(current_directory, 'setup.cfg')

config.read(config_file_path)

VERSION = config['chatterbot']['version']
AUTHOR = config['chatterbot']['author']
AUTHOR_EMAIL = config['chatterbot']['email']
URL = config['chatterbot']['url']

with open('README.md') as f:
LONG_DESCRIPTION = f.read()
Expand All @@ -45,7 +51,7 @@
project_urls={
'Documentation': 'https://chatterbot.readthedocs.io',
},
description=DESCRIPTION,
description='ChatterBot is a machine learning, conversational dialog engine.',
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',
author=AUTHOR,
Expand Down
6 changes: 4 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from unittest import TestCase
from chatterbot import __version__
from chatterbot import __main__ as main


Expand All @@ -10,4 +9,7 @@ class CommandLineInterfaceTests(TestCase):

def test_get_chatterbot_version(self):
version = main.get_chatterbot_version()
self.assertEqual(version, __version__)
version_parts = version.split('.')
self.assertEqual(len(version_parts), 3)
self.assertTrue(version_parts[0].isdigit())
self.assertTrue(version_parts[1].isdigit())

0 comments on commit 4580dfc

Please sign in to comment.