Created
January 2, 2020 15:52
-
-
Save Jerakin/56d7faab185c2fa22b63227f6848ba36 to your computer and use it in GitHub Desktop.
a naive way to check for a license file within a python package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkg_resources | |
def get_pkg_license(pkgname): | |
pkgs = pkg_resources.require(pkgname) | |
pkg = pkgs[0] | |
try: | |
lines = pkg.get_metadata_lines('METADATA') | |
except: | |
lines = pkg.get_metadata_lines('PKG-INFO') | |
for line in lines: | |
if line.startswith('License'): | |
(k, v) = line.split(': ', 1) | |
if v != 'UNKNOWN': | |
return v | |
elif line.startswith('Classifier: License'): | |
a = line.split(':: ') | |
return a[-1] | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment