import __version__ instead of open file __init__
This commit is contained in:
parent
6c45754710
commit
fed6b57bbe
|
@ -1,4 +1,3 @@
|
|||
import re
|
||||
import flask
|
||||
import json
|
||||
import requests
|
||||
|
@ -10,6 +9,7 @@ from flask import make_response, g
|
|||
from teal.resource import Resource, View
|
||||
|
||||
from ereuse_devicehub.resources.inventory.model import Inventory
|
||||
from ereuse_devicehub import __version__
|
||||
|
||||
|
||||
def get_tag_version(app):
|
||||
|
@ -31,10 +31,9 @@ def get_tag_version(app):
|
|||
class VersionView(View):
|
||||
def get(self, *args, **kwargs):
|
||||
"""Get version of DeviceHub and ereuse-tag."""
|
||||
with open("ereuse_devicehub/__init__.py", encoding="utf8") as f:
|
||||
dh_version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)
|
||||
|
||||
tag_version = get_tag_version(self.resource_def.app)
|
||||
versions = {'devicehub': dh_version, "ereuse_tag": "0.0.0"}
|
||||
versions = {'devicehub': __version__, "ereuse_tag": "0.0.0"}
|
||||
versions.update(tag_version)
|
||||
return json.dumps(versions)
|
||||
|
||||
|
@ -58,7 +57,7 @@ class VersionDef(Resource):
|
|||
super().__init__(app, import_name, static_folder, static_url_path, template_folder,
|
||||
url_prefix, subdomain, url_defaults, root_path, cli_commands)
|
||||
|
||||
d = {'devicehub': '0.0.0'}
|
||||
d = {'devicehub': __version__, "ereuse_tag": "0.0.0"}
|
||||
get = {'GET'}
|
||||
|
||||
version_view = VersionView.as_view('VersionView', definition=self)
|
||||
|
|
7
setup.py
7
setup.py
|
@ -1,10 +1,7 @@
|
|||
import re
|
||||
|
||||
from pathlib import Path
|
||||
from setuptools import find_packages, setup
|
||||
from ereuse_devicehub import __version__
|
||||
|
||||
with open("ereuse_devicehub/__init__.py", encoding="utf8") as f:
|
||||
version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)
|
||||
|
||||
test_requires = [
|
||||
'pytest',
|
||||
|
@ -13,7 +10,7 @@ test_requires = [
|
|||
|
||||
setup(
|
||||
name='ereuse-devicehub',
|
||||
version=version,
|
||||
version=__version__,
|
||||
url='https://github.com/ereuse/devicehub-teal',
|
||||
project_urls={
|
||||
'Documentation': 'http://devicehub.ereuse.org',
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import datetime
|
||||
import re
|
||||
import pytest
|
||||
|
||||
from uuid import UUID
|
||||
|
@ -13,6 +12,7 @@ from sqlalchemy.util import OrderedSet
|
|||
from teal.db import ResourceNotFound
|
||||
from teal.enums import Layouts
|
||||
|
||||
from ereuse_devicehub import __version__
|
||||
from ereuse_devicehub.client import Client, UserClient
|
||||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.devicehub import Devicehub
|
||||
|
@ -123,9 +123,8 @@ def test_get_version(app: Devicehub, client: Client):
|
|||
"""Checks GETting versions of services."""
|
||||
|
||||
content, res = client.get("/versions/", None)
|
||||
with open("ereuse_devicehub/__init__.py", encoding="utf8") as f:
|
||||
dh_version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)
|
||||
version = {'devicehub': dh_version, 'ereuse_tag': '0.0.0'}
|
||||
|
||||
version = {'devicehub': __version__, 'ereuse_tag': '0.0.0'}
|
||||
assert res.status_code == 200
|
||||
assert content == version
|
||||
|
||||
|
|
Reference in New Issue