@@ -40,7 +40,6 @@ def _prepare_result_dir(workspace, tarball_path):
4040
4141
4242def _pack (reponame , repopaths , tarpaths , spec : SpecFile , ** kwargs ):
43- tarballs = {}
4443 for edition in spec .data ['editions' ]:
4544 name = edition .get ('name' )
4645 tarpath = tarpaths [name ] if isinstance (tarpaths , dict ) else tarpaths
@@ -56,12 +55,9 @@ def _pack(reponame, repopaths, tarpaths, spec: SpecFile, **kwargs):
5655 logging .info ("#######\n Edition %s \n #######" , name )
5756 logging .info ("#######\n Packed files list:\n %s\n #######" , "\n " .join (tar .getnames ()))
5857 tar .close ()
58+ stream .seek (0 )
5959 # saving tarball
60- tarballs .update ({name : os .path .join (tarpath , tarname )})
61- with open (tarballs [name ], 'wb' ) as file :
62- stream .seek (0 )
63- file .write (stream .read ())
64- return {'tarballs' : tarballs }
60+ yield os .path .join (tarpath , tarname ), stream
6561
6662
6763def _clean_ws (path ):
@@ -72,44 +68,59 @@ def _clean_ws(path):
7268 remove_tree (path )
7369
7470
75- def build (reponame , repopath , # pylint: disable=W0102, R0913
76- workspace = '/tmp' , tarball_path = None , loglevel = 'ERROR' ,
77- clean_ws = True , master_branches = [ 'master' ], autotest = False ):
71+ def build (reponame = None , repopath = None , workspace = '/tmp' , # pylint: disable=R0913
72+ tarball_path = None , loglevel = 'ERROR' ,
73+ clean_ws = True , master_branches = None , ** args ):
7874 """Moves sources to workspace inside of temporary directory. \
7975 Some operations over sources cant be proceed concurent(for exemple in pytest with xdist \
8076 plugin) that why each thread need is own tmp dir with sources. \
8177 Also when there is complex docker containers launching to process some information there is \
8278 necessery to share same workspace with every used container.
8379 Proceed spec file.
8480 Writes build number to bundle config file.
85- Recursively add files to tarball.
81+ Recursively add files to bytes stream.
82+ Cleanup tmp dirs.
8683
87- :param reponame: arenadata repository name. Used for naming aftifact and tmp dir.
88- :type reponame: str
8984 :param repopath: Where bundle sources are
9085 :type repopath: str
86+ :param reponame: arenadata repository name. Used for naming aftifact and tmp dir.
87+ :type reponame: str
9188 :param workspace: where build operations will be performed, defaults to /tmp.
9289 :type workspace: str, optional
9390 :param tarball_path: where to copy builded bundle, defaults to None.
9491 None means that tarball will be left in temporary directory inside of workspace.
9592 :type tarball_path: str, optional
9693 :param loglevel: lower or equal to INFO will be stdout
9794 :type loglevel: str, optional
98- :return: return a dict. Keys:
99- tarball - path to aftifact
95+ :return: return a dict.
96+ Keys - path and name of tarball to save.
97+ Value - stream of bytes.
10098 :rtype: dict
10199 """
100+ if not master_branches :
101+ master_branches = ['master' ]
102+ if not repopath :
103+ raise ValueError ('path to source should be defined' )
104+ if not reponame :
105+ reponame = os .path .basename (os .path .realpath (repopath ))
106+
102107 logging .basicConfig (stream = sys .stdout , level = getattr (logging , loglevel ))
103108 spec = SpecFile (os .path .join (repopath , 'spec.yaml' ))
104109 spec .normalize_spec ()
110+
105111 ws_tepm_dir , work_dir_paths = _prepare_ws (reponame , workspace , repopath , spec )
106- if autotest :
107- tarpath = _prepare_result_dir (work_dir_paths , tarball_path )
108- else :
109- tarpath = _prepare_result_dir (workspace , tarball_path )
112+
113+ tarpath = _prepare_result_dir (workspace , tarball_path )
110114 spec_processing (spec , work_dir_paths , workspace )
111115
112- out = _pack (reponame , work_dir_paths , tarpath , spec , master_branches = master_branches )
116+ out = dict (
117+ _pack (
118+ reponame ,
119+ work_dir_paths ,
120+ tarpath ,
121+ spec ,
122+ master_branches = master_branches ))
123+
113124 if clean_ws :
114125 _clean_ws (ws_tepm_dir )
115126
0 commit comments