Skip to content

Commit

Permalink
feat: add -dev suffix to the version when installed as dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarolopez committed Jun 11, 2024
1 parent 96f23e8 commit b3139cd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
18 changes: 18 additions & 0 deletions deepaas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,22 @@
# License for the specific language governing permissions and limitations
# under the License.

from contextlib import suppress
import importlib.metadata
from pathlib import Path

__version__ = "2.4.0"


def extract_version() -> str:
"""Returns either the version of the package installed."""
with suppress(FileNotFoundError, StopIteration):
root_dir = Path(__file__).parent.parent
with open(root_dir / "pyproject.toml", encoding="utf-8") as pyproject_toml:
version = (
next(line for line in pyproject_toml if line.startswith("version"))
.split("=")[1]
.strip("'\"\n ")
)
return f"{version}-dev (at {root_dir})"
return importlib.metadata.version(__package__ or __name__.split(".", maxsplit=1)[0])
2 changes: 1 addition & 1 deletion deepaas/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def get_app(
"url": "https://deepaas.readthedocs.org/",
},
basePath=base_path,
version=deepaas.__version__,
version=deepaas.extract_version(),
url="/swagger.json",
swagger_path=doc if enable_doc else None,
prefix=prefix,
Expand Down
2 changes: 1 addition & 1 deletion deepaas/cmd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def main():
log.register_options(CONF)
log.set_defaults(default_log_levels=log.get_default_log_levels())

CONF(sys.argv[1:], project="deepaas", version=deepaas.__version__)
CONF(sys.argv[1:], project="deepaas", version=deepaas.extract_version())

log.setup(CONF, "deepaas-cli")

Expand Down
2 changes: 1 addition & 1 deletion deepaas/cmd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def main():
print(INTRO)
print(BANNER.format(docs, spec, v2))

log.info("Starting DEEPaaS version %s", deepaas.__version__)
log.info("Starting DEEPaaS version %s", deepaas.extract_version())

app = api.get_app(
enable_doc=CONF.doc_endpoint,
Expand Down
2 changes: 1 addition & 1 deletion deepaas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def parse_args(argv, default_config_files=None):
cfg.CONF(
argv[1:],
project="deepaas",
version=deepaas.__version__,
version=deepaas.extract_version(),
default_config_files=default_config_files,
)

Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = deepaas.__version__
release = deepaas.extract_version()
# The short X.Y version.
version = deepaas.__version__

Expand Down

0 comments on commit b3139cd

Please sign in to comment.