Called by `handle_argv()` to handle `install` command..
(self, record_path=None, root=None)
| 1076 | |
| 1077 | |
| 1078 | def install(self, record_path=None, root=None): |
| 1079 | ''' |
| 1080 | Called by `handle_argv()` to handle `install` command.. |
| 1081 | ''' |
| 1082 | log2( f'{record_path=} {root=}') |
| 1083 | |
| 1084 | # Do a build and get list of files to install. |
| 1085 | # |
| 1086 | items = list() |
| 1087 | if self.fn_build: |
| 1088 | items = self._call_fn_build( dict()) |
| 1089 | |
| 1090 | root2 = install_dir(root) |
| 1091 | log2( f'{root2=}') |
| 1092 | |
| 1093 | log1( f'Installing into: {root2!r}') |
| 1094 | dist_info_dir = self._dist_info_dir() |
| 1095 | |
| 1096 | if not record_path: |
| 1097 | record_path = f'{root2}/{dist_info_dir}/RECORD' |
| 1098 | record = _Record() |
| 1099 | |
| 1100 | def add_file(from_, to_abs, to_rel): |
| 1101 | os.makedirs( os.path.dirname( to_abs), exist_ok=True) |
| 1102 | if isinstance(from_, bytes): |
| 1103 | log2(f'Copying content into {to_abs}.') |
| 1104 | with open(to_abs, 'wb') as f: |
| 1105 | f.write(from_) |
| 1106 | record.add_content(from_, to_rel) |
| 1107 | else: |
| 1108 | log0(f'{from_=}') |
| 1109 | log2(f'Copying from {os.path.relpath(from_, self.root)} to {to_abs}') |
| 1110 | shutil.copy2( from_, to_abs) |
| 1111 | record.add_file(from_, to_rel) |
| 1112 | |
| 1113 | def add_str(content, to_abs, to_rel): |
| 1114 | log2( f'Writing to: {to_abs}') |
| 1115 | os.makedirs( os.path.dirname( to_abs), exist_ok=True) |
| 1116 | with open( to_abs, 'w') as f: |
| 1117 | f.write( content) |
| 1118 | record.add_content(content, to_rel) |
| 1119 | |
| 1120 | for item in items: |
| 1121 | from_, (to_abs, to_rel) = self._fromto(item) |
| 1122 | log0(f'{from_=} {to_abs=} {to_rel=}') |
| 1123 | to_abs2 = f'{root2}/{to_rel}' |
| 1124 | add_file( from_, to_abs2, to_rel) |
| 1125 | |
| 1126 | add_str( self._metainfo(), f'{root2}/{dist_info_dir}/METADATA', f'{dist_info_dir}/METADATA') |
| 1127 | |
| 1128 | if self.license: |
| 1129 | add_str( self.license, f'{root2}/{dist_info_dir}/COPYING', f'{dist_info_dir}/COPYING') |
| 1130 | |
| 1131 | entry_points_text = self._entry_points_text() |
| 1132 | if entry_points_text: |
| 1133 | add_str( |
| 1134 | entry_points_text, |
| 1135 | f'{root2}/{dist_info_dir}/entry_points.txt', |
no test coverage detected