Code Duplication    Length = 29-38 lines in 3 locations

src/aiscalator/jupyter/docker_image.py 3 locations

@@ 182-219 (lines=38) @@
179
    return dockerfile
180
181
182
def _include_apt_package(conf: AiscalatorConfig, dockerfile, tmp):
183
    """
184
    Include apt-install packages into the dockerfile
185
186
    Parameters
187
    ----------
188
    conf : AiscalatorConfig
189
        Configuration object for this step
190
    dockerfile : str
191
        path to the dockerfile to modify
192
    tmp : str
193
        path to the temporary dockerfile output
194
195
    Returns
196
    -------
197
        path to the resulting dockerfile
198
    """
199
    if conf.has_step_field("docker_image.apt_package_path"):
200
        content = conf.step_file_path("docker_image.apt_package_path")
201
        value = utils.format_file_content(content, prefix=" ", suffix="\\\n")
202
        if value:
203
            value = ("RUN apt-get update && apt-get install -yqq \\\n" +
204
                     value +
205
                     """    && apt-get purge --auto-remove -yqq $buildDeps \\
206
    && apt-get autoremove -yqq --purge \\
207
    && apt-get clean \\
208
    && rm -rf \\
209
    /var/lib/apt/lists/* \\
210
    /tmp/* \\
211
    /var/tmp/* \\
212
    /usr/share/man \\
213
    /usr/share/doc \\
214
    /usr/share/doc-base
215
""")
216
            utils.copy_replace(dockerfile, tmp,
217
                               pattern="# apt_packages.txt #",
218
                               replace_value=value)
219
            return tmp
220
    return dockerfile
221
222
@@ 149-179 (lines=31) @@
146
    return utils.data_file("../config/docker/" + input_docker_src)
147
148
149
def _include_apt_repo(conf: AiscalatorConfig, dockerfile, tmp):
150
    """
151
    Include add-apt-repository packages into the dockerfile
152
153
    Parameters
154
    ----------
155
    conf : AiscalatorConfig
156
        Configuration object for this step
157
    dockerfile : str
158
        path to the dockerfile to modify
159
    tmp : str
160
        path to the temporary dockerfile output
161
162
    Returns
163
    -------
164
        path to the resulting dockerfile
165
    """
166
    if conf.has_step_field("docker_image.apt_repository_path"):
167
        content = conf.step_file_path("docker_image.apt_repository_path")
168
        value = utils.format_file_content(content, prefix=" ", suffix="\\\n")
169
        if value:
170
            value = ("RUN apt-get update \\\n" +
171
                     " && apt-get install -yqq \\\n" +
172
                     "      software-properties-common \\\n" +
173
                     " && apt-add-repository \\\n" + value +
174
                     " && apt-get update")
175
            utils.copy_replace(dockerfile, tmp,
176
                               pattern="# apt_repository.txt #",
177
                               replace_value=value)
178
            return tmp
179
    return dockerfile
180
181
182
def _include_apt_package(conf: AiscalatorConfig, dockerfile, tmp):
@@ 255-283 (lines=29) @@
252
    return dockerfile
253
254
255
def _include_lab_extensions(conf: AiscalatorConfig, dockerfile, tmp):
256
    """
257
        Include jupyter lab extensions packages into the dockerfile
258
259
        Parameters
260
        ----------
261
        conf : AiscalatorConfig
262
            Configuration object for this step
263
        dockerfile : str
264
            path to the dockerfile to modify
265
        tmp : str
266
            path to the temporary dockerfile output
267
268
        Returns
269
        -------
270
            path to the resulting dockerfile
271
        """
272
    if conf.has_step_field("docker_image.lab_extension_path"):
273
        content = conf.step_file_path("docker_image.lab_extension_path")
274
        prefix = "&& jupyter labextension install "
275
        value = utils.format_file_content(content,
276
                                          prefix=prefix, suffix=" \\\n")
277
        if value:
278
            value = "RUN echo 'Installing Jupyter Extensions' \\\n" + value
279
            utils.copy_replace(dockerfile, tmp,
280
                               pattern="# lab_extensions.txt #",
281
                               replace_value=value)
282
            return tmp
283
    return dockerfile
284
285
286
def _run_build(conf: AiscalatorConfig):