Python How can I get the version number from a .wh

2019-07-17 06:31发布

问题:

Because of some custom logging I would like to get the version number from a wheel file.

I could of course just parse the filename, but my guess is there would be a better way to do this.

回答1:

What I did for now is:

Get the package info and put it into a dict:

def get_package_info():
    info_dict = {}
    with open(os.path.join(glob.glob("./*.egg-info")[0], "PKG-INFO"), "r") as info:
        for i in info:
            i = i.split(":")
            info_dict[i[0].strip()] = i[1].strip()

        return info_dict

Now I can get the Verion from this dictionary.

If someone does have a better approach at this, please let me know.