[package] factor out `PackageExporter._get_dependencies` (#57335)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57335
Mostly refactoring. The only behavioral change is that I have eliminated
the `orig_source_file` argument to `save_source_string`. I think it
doesn't provide enough marginal value (since if you have the module name
you can get the source file anyway).
Differential Revision: D28114184
Test Plan: Imported from OSS
Reviewed By: VitalyFedyunin
Pulled By: suo
fbshipit-source-id: b5e9eb4250dc84552befeef2dcf9e591b32899ae