Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional version import #42

Merged
merged 1 commit into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dbtmetabase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
from .metabase import MetabaseClient
from .parsers.dbt_folder import DbtFolderReader
from .parsers.dbt_manifest import DbtManifestReader
from .utils import get_version

from typing import Iterable, List, Union

from ._version import version as __version__
__version__ = get_version()


def export(
Expand Down Expand Up @@ -122,6 +123,11 @@ def main(args: List = None):
parser = argparse.ArgumentParser(
description="Model synchronization from dbt to Metabase."
)
parser.add_argument(
"--version",
action="version",
version=f"%(prog)s {__version__}",
)
parser.add_argument("command", choices=["export"], help="command to execute")

# dbt arguments
Expand Down
24 changes: 24 additions & 0 deletions dbtmetabase/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import logging
import importlib.metadata


def get_version() -> str:
"""Checks _version.py or build metadata for package version.

Returns:
str: Version string.
"""

try:
from ._version import version

return version
except ModuleNotFoundError:
logging.debug("No _version.py found")

try:
return importlib.metadata.version("dbt-metabase")
except importlib.metadata.PackageNotFoundError:
logging.warning("No version found in metadata")

return "0.0.0-UNKONWN"