@@ -958,12 +958,13 @@ def convertDataRole(self, dataRole):
958
958
return conversion
959
959
960
960
def get_imports (self ):
961
- """[summary]
961
+ """
962
+ Gets the Python modules from the current scope's global variables.
962
963
963
964
Yields
964
965
-------
965
- [type]
966
- [description]
966
+ str
967
+ Name of the package that is generated.
967
968
"""
968
969
969
970
for name , val in globals ().items ():
@@ -976,29 +977,36 @@ def get_imports(self):
976
977
yield name
977
978
978
979
def get_pickle_file (self , pPath ):
979
- """[summary]
980
+ """
981
+ Given a file path, retrieve the pickle file(s).
980
982
981
983
Parameters
982
984
----------
983
- pPath : [type]
984
- [description]
985
+ pPath : str
986
+ File location for the input pickle file. Default is the current
987
+ working directory.
985
988
"""
989
+
986
990
fileNames = []
987
991
fileNames .extend (sorted (Path (pPath ).glob ("*.pickle" )))
988
992
989
993
def get_modules_from_pickle_file (self , pickle_file ):
990
- """[summary]
994
+ """
995
+ Reads the pickled byte stream from a file object, serializes the pickled byte
996
+ stream as a bytes object, and inspects the bytes object for all Python modules
997
+ and aggregates them in a set.
991
998
992
999
Parameters
993
1000
----------
994
- pickle_file : [type]
995
- [description]
1001
+ pickle_file : str
1002
+ The file where you stored pickle data.
996
1003
997
1004
Returns
998
1005
-------
999
- [type]
1000
- [description]
1006
+ set
1007
+ A set of modules obtained from the pickle stream.
1001
1008
"""
1009
+
1002
1010
with (open (pickle_file , "rb" )) as openfile :
1003
1011
obj = pickle .load (openfile )
1004
1012
dumps = pickle .dumps (obj )
@@ -1007,12 +1015,13 @@ def get_modules_from_pickle_file(self, pickle_file):
1007
1015
return modules
1008
1016
1009
1017
def createRequirementsJSON (self , jPath = Path .cwd ()):
1010
- """[summary]
1018
+ """
1019
+ Searches the root of the project for all Python modules and writes them to a requirements.json file.
1011
1020
1012
1021
Parameters
1013
1022
----------
1014
- jPath : [type] , optional
1015
- [description] , by default Path.cwd()
1023
+ jPath : str , optional
1024
+ The path to a Python project , by default Path.cwd().
1016
1025
"""
1017
1026
1018
1027
imports = list (set (self .get_imports ()))
@@ -1074,19 +1083,21 @@ def createRequirementsJSON(self, jPath=Path.cwd()):
1074
1083
print (j , file = file )
1075
1084
1076
1085
def get_names (self , stream ):
1077
- """Generates (module, qualname) tuples from a pickle stream
1086
+ """
1087
+ Generates (module, class_name) tuples from a pickle stream. Extracts all class names referenced by GLOBAL and STACK_GLOBAL opcodes.
1078
1088
1079
1089
Credit: https://stackoverflow.com/questions/64850179/inspecting-a-pickle-dump-for-dependencies
1090
+ More information here: https://github.com/python/cpython/blob/main/Lib/pickletools.py
1080
1091
1081
1092
Parameters
1082
1093
----------
1083
- stream : [type]
1084
- [description]
1094
+ stream : bytes or str
1095
+ A file like object or string containing the pickle.
1085
1096
1086
1097
Yields
1087
1098
-------
1088
- [type]
1089
- [description]
1099
+ tuple
1100
+ Generated (module, class_name) tuples.
1090
1101
"""
1091
1102
1092
1103
stack , markstack , memo = [], [], []
0 commit comments