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

Version Logging - Only log on failure #1634

Conversation

christopherwoodall
Copy link
Contributor

No description provided.

christopherwoodall added 2 commits October 4, 2022 16:34
def to_docker_tag(version_str: str) -> str:
"""Convert version string to docker tag"""
return version_str.replace("+", ".")


def get_metadata_version(package: str, version_str: str = "") -> str:
def version_resource() -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unhelpful name. Better might be get_best_version and probably a docstring like
"""returns the first version derived from tag, build, and pip"""

def to_docker_tag(version_str: str) -> str:
"""Convert version string to docker tag"""
return version_str.replace("+", ".")


def get_metadata_version(package: str, version_str: str = "") -> str:
def version_resource() -> str:
checks = [get_tag_version, get_build_version, get_pip_version]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unduly complex, better might be

for check in checks:
    version = check()
    if version:
        log.info(f"read {version} from {check.__name__}")
        return version
    else:
        log.warning(f"could not get version from {check.__name__}

    raise RuntimeError…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the try/except is probably fine, but queuing up the failures is icky.

raise RuntimeError("Unable to determine version number!")


def get_pip_version() -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better might be

def package_version_from_pip(package="armory-testbed"):

)


def get_build_version(version_str: str = "") -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from x import "" is a syntax error

def get_build_version(version_str: str = "") -> str:
"""Retrieve the version from the build hook"""
try:
from armory.__about__ import __version__ as version_str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from armory.__about__ import __version__
return __version__

is clearer

except ModuleNotFoundError:
log.warning("ERROR: Unable to extract version from __about__.py")
return version_str
if Path(project_root / ".git").is_dir():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subtle point here: scm.get_version could well succeed even if .git is not a directory. The failure is that scm failed, the presence of .git is just a proxy indicator of why. If you think this a likely error, you could test for .git presence after scm failure and add a hint to the log.

package_name (str): The name of the package.
pretend_version (str): The version to pretend to be.
update_metadata (bool): Whether to update the metadata.

Example:
$ ARMORY_DEV_MODE=1 ARMORY_PRETEND_VERSION="1.2.3" armory --version
"""
old_version = get_metadata_version(package_name)
old_version = get_pip_version(package_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently get_pip_version takes no arguments. Pylance flagged this for me.

@mwartell
Copy link
Contributor

mwartell commented Oct 5, 2022

Validation checks (kinda hard to pytest missing directories and such). With .git present:

In [2]: version_resource()
Out[2]: '0.15.4.post267+g405df21'

With .git absent:

In [2]: version_resource()
2022-10-05 11:17:25  2s ERROR    armory.utils.version:version_resource:49 failed to get version from get_tag_version: ERROR: Unable to find `.git` directory!
2022-10-05 11:17:25  2s INFO     armory.utils.version:version_resource:46 obtained 0.15.4.post267+g405df21 from get_build_version
Out[2]: '0.15.4.post267+g405df21'

I still need to check shallow clone and developer modes.

@mwartell mwartell mentioned this pull request Oct 5, 2022
@mwartell
Copy link
Contributor

mwartell commented Oct 5, 2022

This has been entirely scooped by #1635. Closing.

@mwartell mwartell closed this Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants