From 193f2ed6c7c19d2a0b27dc3b24ff15628b281d82 Mon Sep 17 00:00:00 2001 From: "zhu.boxiang" Date: Mon, 30 May 2022 14:42:53 +0800 Subject: [PATCH] refactor: Use pbr to get package version 1. use pbr to get package version 2. update the dependencies' version Change-Id: If221a54a2eecbca76c212838fddef272bfd48484 --- requirements.txt | 4 ++-- skyline_apiserver/__init__.py | 15 ------------- skyline_apiserver/core/security.py | 4 ++-- skyline_apiserver/tests/api/v1/test_login.py | 4 ++-- skyline_apiserver/tests/utils/utils.py | 4 ++-- skyline_apiserver/version.py | 23 ++++++++++++++++++++ test-requirements.txt | 2 +- 7 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 skyline_apiserver/version.py diff --git a/requirements.txt b/requirements.txt index c8eb48a..d4ff1bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,9 +13,9 @@ aiomysql<=0.1.1 # MIT aiosqlite<=0.17.0 # MIT loguru<=0.5.3 # MIT PyYAML>=5.4.1,<=6.0 # MIT -immutables>=0.16,<=0.17 # Apache-2.0 +immutables>=0.16 # Apache-2.0 alembic>=1.7.5,<=1.7.7 # MIT -httpx>=0.16.1,<=0.22.0 # BSD License (3 clause) +httpx>=0.16.1 # BSD License (3 clause) SQLAlchemy>=1.3.24,<=1.4.36 # MIT PyMySQL>=0.9.3,<=1.0.2 # MIT dnspython>=2.1.0,<=2.2.1 # ISC diff --git a/skyline_apiserver/__init__.py b/skyline_apiserver/__init__.py index 0b747ca..e69de29 100644 --- a/skyline_apiserver/__init__.py +++ b/skyline_apiserver/__init__.py @@ -1,15 +0,0 @@ -# Copyright 2021 99cloud -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -__version__ = "0.1.0" diff --git a/skyline_apiserver/core/security.py b/skyline_apiserver/core/security.py index 3b20bcc..fd56f66 100644 --- a/skyline_apiserver/core/security.py +++ b/skyline_apiserver/core/security.py @@ -20,7 +20,7 @@ import uuid from fastapi import HTTPException, status from jose import jwt -from skyline_apiserver import __version__, schemas +from skyline_apiserver import schemas, version from skyline_apiserver.client import utils from skyline_apiserver.client.utils import get_system_session from skyline_apiserver.config import CONF @@ -71,5 +71,5 @@ async def generate_profile( base_domains=CONF.openstack.base_domains, exp=exp or int(time.time()) + CONF.default.access_token_expire, uuid=uuid_value or uuid.uuid4().hex, - version=__version__, + version=version.version_string(), ) diff --git a/skyline_apiserver/tests/api/v1/test_login.py b/skyline_apiserver/tests/api/v1/test_login.py index a107183..108f39b 100644 --- a/skyline_apiserver/tests/api/v1/test_login.py +++ b/skyline_apiserver/tests/api/v1/test_login.py @@ -18,7 +18,7 @@ import time import pytest from httpx import AsyncClient -from skyline_apiserver import __version__, main +from skyline_apiserver import main, version from skyline_apiserver.config import CONF from skyline_apiserver.db import api as db_api, setup as db_setup from skyline_apiserver.tests.utils import utils @@ -60,7 +60,7 @@ async def test_get_profile_ok(client: AsyncClient, login_jwt: str) -> None: assert "projects" in result assert "base_roles" in result assert "base_domains" in result - assert result["version"] == __version__ + assert result["version"] == version.version_string() assert len(CONF.openstack.base_domains) == len(result["base_domains"]) diff --git a/skyline_apiserver/tests/utils/utils.py b/skyline_apiserver/tests/utils/utils.py index a43bbde..78084fc 100644 --- a/skyline_apiserver/tests/utils/utils.py +++ b/skyline_apiserver/tests/utils/utils.py @@ -17,7 +17,7 @@ import uuid from httpx import AsyncClient -from skyline_apiserver import __version__, config, main, schemas +from skyline_apiserver import config, main, schemas, version def get_session_profile() -> schemas.Profile: @@ -62,7 +62,7 @@ def get_session_profile() -> schemas.Profile: "4c017648d2e34d1a8e732b98e3232af9": {"name": "alt_demo", "domain_id": "default"}, "e88226c062094881b7a1f01517b945b4": {"name": "admin", "domain_id": "default"}, }, - version=__version__, + version=version.version_string(), ) return profile diff --git a/skyline_apiserver/version.py b/skyline_apiserver/version.py new file mode 100644 index 0000000..b1766b7 --- /dev/null +++ b/skyline_apiserver/version.py @@ -0,0 +1,23 @@ +# Copyright 2022 99cloud +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from pbr import version as pbr_version + +SKYLINE_APISERVER_VENDOR = "OpenStack Foundation" +SKYLINE_APISERVER_PRODUCT = "OpenStack Skyline APIServer" +SKYLINE_APISERVER_PACKAGE = None # OS distro package version suffix + +loaded = False +version_info = pbr_version.VersionInfo("skyline-apiserver") +version_string = version_info.version_string diff --git a/test-requirements.txt b/test-requirements.txt index 1f541df..384ed8a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -8,7 +8,7 @@ Sphinx<=4.5.0 # BSD isort<=5.9.3 # MIT black<=22.3.0 # MIT flake8<=3.9.2 # MIT -mypy>=0.910,<=0.950 # MIT +mypy>=0.910 # MIT pytest>=6.2.5,<=7.1.2 # MIT pytest-xdist>=2.4.0,<=2.5.0 # MIT pytest-asyncio<=0.15.1 # Apache-2.0