Skip to content

Commit

Permalink
Merge pull request #378 from VIDA-NYU/pathlib
Browse files Browse the repository at this point in the history
Get rid of rpaths, use pathlib
  • Loading branch information
remram44 committed Jul 8, 2021
2 parents 13b97d8 + a173e6b commit 5bae4d7
Show file tree
Hide file tree
Showing 38 changed files with 448 additions and 354 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ jobs:
os: [ubuntu-latest]
mode: [tests]
python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
include:
- os: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,4 @@


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/3/': None,
'http://rpaths.remram.fr/en/latest/': None}
intersphinx_mapping = {'https://docs.python.org/3/': None}
56 changes: 29 additions & 27 deletions reprounzip-docker/reprounzip_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import json
import logging
import os
from pathlib import Path, PurePosixPath
import re
from rpaths import Path, PosixPath
import shutil
import socket
import subprocess
import sys
import tarfile
import tempfile

from reprozip_core.common import load_config, record_usage, RPZPack
from reprounzip import signals
Expand Down Expand Up @@ -120,7 +121,7 @@ def docker_setup(args):
try:
docker_setup_build(args)
except BaseException:
Path(args.target[0]).rmtree(ignore_errors=True)
shutil.rmtree(args.target[0], ignore_errors=True)
raise


Expand Down Expand Up @@ -242,13 +243,14 @@ def docker_setup_create(args):
data_files = rpz_pack.data_filenames()
listoffiles = list(chain(other_files, missing_files))
for f in listoffiles:
if f.path.unicodename in ('resolv.conf', 'hosts') and (
f.path.lies_under('/etc') or
f.path.lies_under('/run') or
f.path.lies_under('/var')):
if f.path.name in ('resolv.conf', 'hosts') and (
PurePosixPath('/etc') in f.path.parents or
PurePosixPath('/run') in f.path.parents or
PurePosixPath('/var') in f.path.parents
):
continue
path = PosixPath('/')
for c in rpz_pack.remove_data_prefix(f.path).components:
path = PurePosixPath('/')
for c in rpz_pack.remove_data_prefix(f.path).parts:
path = path / c
if path in paths:
continue
Expand All @@ -261,7 +263,7 @@ def docker_setup_create(args):
rpz_pack.close()
with (target / 'files.list').open('wb') as filelist:
for p in pathlist:
filelist.write(join_root(PosixPath(''), p).path)
filelist.write(bytes(join_root(PurePosixPath(''), p)))
filelist.write(b'\0')

if args.use_buildkit:
Expand Down Expand Up @@ -386,7 +388,7 @@ def docker_setup_create(args):

signals.post_setup(target=target, pack=pack)
except Exception:
target.rmtree(ignore_errors=True)
shutil.rmtree(target, ignore_errors=True)
raise


Expand Down Expand Up @@ -414,7 +416,7 @@ def docker_setup_build(args):
env = dict(os.environ, DOCKER_BUILDKIT='1')
retcode = subprocess.call(args.docker_cmd.split() + ['build', '-t'] +
args.docker_option + [image, '.'],
cwd=target.path,
cwd=target,
env=env)
except OSError:
logger.critical("docker executable not found")
Expand Down Expand Up @@ -721,31 +723,31 @@ def prepare_upload(self, files):
file=sys.stderr)
sys.exit(1)

self.build_directory = Path.tempdir(prefix='reprozip_build_')
self.build_directory = Path(tempfile.mkdtemp(prefix='reprozip_build_'))
self.docker_copy = []

def upload_file(self, local_path, input_path):
stem, ext = local_path.stem, local_path.ext
stem, ext = local_path.stem, local_path.suffix
name = local_path.name
nb = 0
while (self.build_directory / name).exists():
nb += 1
name = stem + ('_%d' % nb).encode('ascii') + ext
name = Path(name)
local_path.copyfile(self.build_directory / name)
shutil.copyfile(local_path, self.build_directory / name)
logger.info("Copied file %s to %s", local_path, name)
self.docker_copy.append((name, input_path))

def finalize(self):
if not self.docker_copy:
self.build_directory.rmtree()
shutil.rmtree(self.build_directory)
return

from_image = self.unpacked_info['current_image']

with self.build_directory.open('w', 'Dockerfile',
encoding='utf-8',
newline='\n') as dockerfile:
with (self.build_directory / 'Dockerfile').open(
'w', encoding='utf-8', newline='\n',
) as dockerfile:
dockerfile.write('FROM %s\n\n' % from_image.decode('ascii'))
for src, target in self.docker_copy:
# FIXME : spaces in filenames will probably break Docker
Expand All @@ -761,7 +763,7 @@ def finalize(self):
tar = tarfile.open(str(self.target / 'data.tgz'), 'r:*')
try:
info = tar.getmember(str(
join_root(PosixPath(b'DATA'), target)
join_root(PurePosixPath('DATA'), target)
))
uid, gid = info.uid, info.gid
except KeyError:
Expand All @@ -784,7 +786,7 @@ def finalize(self):
image = make_unique_name(b'reprounzip_image_')
retcode = subprocess.call(self.docker_cmd +
['build', '-t', image, '.'],
cwd=self.build_directory.path)
cwd=self.build_directory)
if retcode != 0:
logger.critical("docker build failed with code %d", retcode)
sys.exit(1)
Expand All @@ -801,7 +803,7 @@ def finalize(self):
self.unpacked_info['current_image'] = image
write_dict(self.target, self.unpacked_info)

self.build_directory.rmtree()
shutil.rmtree(self.build_directory)


@target_must_exist
Expand Down Expand Up @@ -839,18 +841,18 @@ def prepare_download(self, files):
def download(self, remote_path, local_path):
# Docker copies to a file in the specified directory, cannot just take
# a file name (#4272)
tmpdir = Path.tempdir(prefix='reprozip_docker_output_')
tmpdir = Path(tempfile.mkdtemp(prefix='reprozip_docker_output_'))
try:
ret = subprocess.call(self.docker_cmd +
['cp',
self.container + b':' + remote_path.path,
tmpdir.path])
self.container + b':' + bytes(remote_path),
tmpdir])
if ret != 0:
logger.critical("Can't get output file: %s", remote_path)
return False
(tmpdir / remote_path.name).copyfile(local_path)
shutil.copyfile(tmpdir / remote_path.name, local_path)
finally:
tmpdir.rmtree()
shutil.rmtree(tmpdir)
return True

def finalize(self):
Expand Down Expand Up @@ -914,7 +916,7 @@ def docker_destroy_dir(args):

logger.info("Removing directory %s...", target)
signals.pre_destroy(target=target)
target.rmtree()
shutil.rmtree(target)
signals.post_destroy(target=target)


Expand Down
3 changes: 1 addition & 2 deletions reprounzip-docker/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
'reprounzip.unpackers': [
'docker = reprounzip_docker:setup']},
install_requires=[
'reprounzip>=2.0.0,<3.0.0',
'rpaths>=0.8'],
'reprounzip>=2.0.0,<3.0.0'],
description="Allows the ReproZip unpacker to create Docker containers",
author="Remi Rampin, Fernando Chirigati, Dennis Shasha, Juliana Freire",
author_email='dev@reprozip.org',
Expand Down
2 changes: 1 addition & 1 deletion reprounzip-qt/reprounzip_qt/gui/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _file_changed(self):
self.b_download.setEnabled(True)
self.b_reset.setEnabled(False)
self.f_name.setText(file_status.name)
self.f_path.setText(file_status.path)
self.f_path.setText(str(file_status))
self.f_status.setEnabled(False)
if file_status.assigned is None:
self.f_status.setText("(original)")
Expand Down
2 changes: 1 addition & 1 deletion reprounzip-qt/reprounzip_qt/reprounzip_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import itertools
import logging
import os
from rpaths import Path
from pathlib import Path
import pickle
import subprocess
import sys
Expand Down
2 changes: 1 addition & 1 deletion reprounzip-qt/reprounzip_qt/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
version='%s %s' % ('reprounzip-qt', version),
unique_user_id=True,
env_var='REPROZIP_USAGE_STATS',
ssl_verify=_certificate_file.path
ssl_verify=_certificate_file
)


Expand Down

0 comments on commit 5bae4d7

Please sign in to comment.