Skip to content

Commit da750d4

Browse files
brtieusmlindauer
authored andcommitted
Add documentation to methods.
1 parent 578a88e commit da750d4

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/sasctl/pzmm/write_json_files.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -958,12 +958,13 @@ def convertDataRole(self, dataRole):
958958
return conversion
959959

960960
def get_imports(self):
961-
"""[summary]
961+
"""
962+
Gets the Python modules from the current scope's global variables.
962963
963964
Yields
964965
-------
965-
[type]
966-
[description]
966+
str
967+
Name of the package that is generated.
967968
"""
968969

969970
for name, val in globals().items():
@@ -976,29 +977,36 @@ def get_imports(self):
976977
yield name
977978

978979
def get_pickle_file(self, pPath):
979-
"""[summary]
980+
"""
981+
Given a file path, retrieve the pickle file(s).
980982
981983
Parameters
982984
----------
983-
pPath : [type]
984-
[description]
985+
pPath : str
986+
File location for the input pickle file. Default is the current
987+
working directory.
985988
"""
989+
986990
fileNames = []
987991
fileNames.extend(sorted(Path(pPath).glob("*.pickle")))
988992

989993
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.
991998
992999
Parameters
9931000
----------
994-
pickle_file : [type]
995-
[description]
1001+
pickle_file : str
1002+
The file where you stored pickle data.
9961003
9971004
Returns
9981005
-------
999-
[type]
1000-
[description]
1006+
set
1007+
A set of modules obtained from the pickle stream.
10011008
"""
1009+
10021010
with (open(pickle_file, "rb")) as openfile:
10031011
obj = pickle.load(openfile)
10041012
dumps = pickle.dumps(obj)
@@ -1007,12 +1015,13 @@ def get_modules_from_pickle_file(self, pickle_file):
10071015
return modules
10081016

10091017
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.
10111020
10121021
Parameters
10131022
----------
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().
10161025
"""
10171026

10181027
imports = list(set(self.get_imports()))
@@ -1074,19 +1083,21 @@ def createRequirementsJSON(self, jPath=Path.cwd()):
10741083
print(j, file=file)
10751084

10761085
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.
10781088
10791089
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
10801091
10811092
Parameters
10821093
----------
1083-
stream : [type]
1084-
[description]
1094+
stream : bytes or str
1095+
A file like object or string containing the pickle.
10851096
10861097
Yields
10871098
-------
1088-
[type]
1089-
[description]
1099+
tuple
1100+
Generated (module, class_name) tuples.
10901101
"""
10911102

10921103
stack, markstack, memo = [], [], []

0 commit comments

Comments
 (0)