Skip to content

Commit

Permalink
Merge pull request #101 from TheFriendlyCoder/version_fix
Browse files Browse the repository at this point in the history
fixed version number file
  • Loading branch information
TheFriendlyCoder committed Jun 23, 2019
2 parents 2f8afaa + b12a722 commit 5603198
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
18 changes: 13 additions & 5 deletions docs/conf.py
Expand Up @@ -13,18 +13,26 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import ast
# import os
# import sys
# sys.path.insert(0, os.path.abspath(os.path.join('..', 'src')))
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
_base_path = os.path.abspath(os.path.dirname(__file__))
_src_dir = os.path.abspath(os.path.join(_base_path, '..', 'src'))
sys.path.insert(0, _src_dir)

# -- Project information -----------------------------------------------------

copyright = '2019, Kevin S. Phillips'
author = 'Kevin S. Phillips'
_proj_props = ast.literal_eval(open('../project.prop').read())
with open("../src/" + _proj_props["NAME"] + "/version.prop") as prop_file:
_proj_props["VERSION"] = ast.literal_eval(prop_file.read())
_proj_dir = os.path.join(_src_dir, _proj_props["NAME"])
with open(os.path.join(_proj_dir, "version.py")) as prop_file:
_data = ast.parse(prop_file.read())
_proj_props["VERSION"] = _data.body[0].value.s

project = _proj_props["NAME"]
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
1 change: 1 addition & 0 deletions docs/friendlyshell.rst
Expand Up @@ -12,6 +12,7 @@ Submodules
friendlyshell.command_complete_mixin
friendlyshell.command_parsers
friendlyshell.shell_help_mixin
friendlyshell.version

Module contents
---------------
Expand Down
25 changes: 17 additions & 8 deletions setup.py
Expand Up @@ -78,21 +78,30 @@ def _verify_src_version(version):

def _src_version(project):
"""Parses the version number from the source project
:param str project: the name of the project to get the version for
:returns: the version for the specified project
:rtype: :class:`str`
"""
ver_path = os.path.join(os.getcwd(), 'src', project, 'version.prop')
root_dir = os.path.dirname(__file__)
ver_path = os.path.join(root_dir, 'src', project, 'version.py')
assert os.path.exists(ver_path)

with open(ver_path) as prop_file:
data = prop_file.read()
retval = ast.literal_eval(data)

assert retval is not None
assert _verify_src_version(retval)
return retval
data = ast.parse(prop_file.read())

# The version.py file is expected to contain only a single statement
# of the form:
# __version__ = "1.2.3"
assert len(data.body) == 1
statement = data.body[0]
assert isinstance(statement, ast.Assign)
assert len(statement.targets) == 1
assert statement.targets[0].id == "__version__"
assert isinstance(statement.value, ast.Str)

# If we get here we know the one statement in the version module has
# a string value with the version number in it, so we just return it here
return statement.value.s


def get_version_number(project):
Expand Down
9 changes: 1 addition & 8 deletions src/friendlyshell/__init__.py
@@ -1,12 +1,5 @@
"""Package initialization..."""
import logging
import os
import ast

_CUR_FILE = os.path.realpath(__file__)
_CUR_PATH = os.path.split(_CUR_FILE)[0]
with open(os.path.join(_CUR_PATH, 'version.prop')) as prop_file:
_PROPS = prop_file.read()
__version__ = ast.literal_eval(_PROPS)
from .version import __version__

logging.getLogger(__name__).addHandler(logging.NullHandler())
6 changes: 0 additions & 6 deletions src/friendlyshell/version.prop

This file was deleted.

2 changes: 2 additions & 0 deletions src/friendlyshell/version.py
@@ -0,0 +1,2 @@
# pylint: disable=missing-docstring
__version__ = "1.0.8"

0 comments on commit 5603198

Please sign in to comment.