scripts/pythondistdeps: Do anything only when called as a main script

Note that the code is completely unchanged except for the indentation
under the new if __name__ == "__main__":

Note that this change is necessary, but not sufficient to use the
RpmVersion class.
The init of the RpmVersion class will fail when called from an outside
script, because the `parse_version()` function is lazily imported from
the code outside the class.  However, adding the import of
parse_version() to RpmVersion class is not done right now, because while
we would import it from `pkg_resources`, other scripts might want to
rely instead of the lightweight `packaging` module for the import. Thus
I'm leaving this conondrum to be addressed in the future.
This commit is contained in:
Tomas Orsava 2020-04-20 16:37:29 +02:00
parent 1523def34e
commit d48f3500d8

View File

@ -143,6 +143,10 @@ def normalize_name(name):
return re.sub(r'[-_.]+', '-', name).lower()
if __name__ == "__main__":
"""To allow this script to be importable (and its classes/functions
reused), actions are performed only when run as a main script."""
parser = argparse.ArgumentParser(prog=argv[0])
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-P', '--provides', action='store_true', help='Print Provides')
@ -166,7 +170,6 @@ parser.add_argument('-l', '--legacy', action='store_true', help='Print legacy py
parser.add_argument('files', nargs=argparse.REMAINDER)
args = parser.parse_args()
py_abi = args.requires
py_deps = {}