Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows path handling #160

Merged
merged 6 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ AllItems.xls
Custom_scripts/
Data_Files/MicroscopyCalibration/Files/
.pytest_cache/
.python-version
8 changes: 6 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ Change Log
----------


3.0.1
=====

* Bug fix: Windows paths were not handled properly for File upload.

3.0.0
=======

`PR 159: Remove Python3.6 support <https://github.com/4dn-dcic/Submit4DN/pull/159>`_

* Drop support for Python3.6

* Add this CHANGELOG and test warning if it's not updated
* Add this CHANGELOG and test warning if it's not updated

* Update dependency to use dcicutils >=4.0

Expand Down Expand Up @@ -212,4 +217,3 @@ Change Log

0.2.2
=====

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Submit4DN"
version = "3.0.0"
version = "3.0.1"
description = "Utility package for submitting data to the 4DN Data Portal"
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_import_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import wranglertools.import_data as imp
import pytest
import pathlib as pp
# test data is in conftest.py


Expand Down Expand Up @@ -1556,3 +1557,15 @@ def test_get_collections(mock_profiles):
colls = imp.get_collections(mock_profiles)
for c in mock_profiles.keys():
assert c.lower() in colls


def test_get_just_filename_posix():
test_path = pp.PurePosixPath('Users', 'username', 'test_dir', 'test_file.fastq.gz')
filename = imp.get_just_filename(test_path)
assert filename == 'test_file.fastq.gz'


def test_get_just_filename_windows():
test_path = pp.PureWindowsPath('c:/', 'Users', 'username', 'test_dir', 'test_file.fastq.gz')
filename = imp.get_just_filename(test_path)
assert filename == 'test_file.fastq.gz'
4 changes: 2 additions & 2 deletions wranglertools/get_field_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def create_common_arg_parser():
help="The keypair identifier from the keyfile. \
Default is --key=default")
parser.add_argument('--keyfile',
default=f"{home}/keypairs.json",
help=f"The keypair file. Default is --keyfile={home}/keypairs.json")
default=home / 'keypairs.json',
help=f"The keypair file. Default is --keyfile={home / 'keypairs.json'}")
parser.add_argument('--debug',
default=False,
action='store_true',
Expand Down
22 changes: 16 additions & 6 deletions wranglertools/import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def build_patch_json(fields, fields2types):


def get_just_filename(path):
return path.split('/')[-1]
return pp.Path(path).name


def check_extra_file_meta(ef_info, seen_formats, existing_formats):
Expand Down Expand Up @@ -1452,15 +1452,25 @@ def upload_file(creds, path): # pragma: no cover
print("Uploading file.")
start = time.time()
try:
subprocess.check_call(['aws', 's3', 'cp', '--only-show-errors', path, creds['upload_url']], env=env)
source = path
target = creds['upload_url']
print("Going to upload {} to {}.".format(source, target))
command = ['aws', 's3', 'cp']
command = command + ['--only-show-errors', source, target]
options = {}
if running_on_windows_native():
options = {"shell": True}
subprocess.check_call(command, env=env, **options)
except subprocess.CalledProcessError as e:
# The aws command returns a non-zero exit code on error.
print("Upload failed with exit code %d" % e.returncode)
sys.exit(e.returncode)
raise RuntimeError("Upload failed with exit code %d" % e.returncode)
else:
end = time.time()
duration = end - start
print("Uploaded in %.2f seconds" % duration)
show("Uploaded in %.2f seconds" % duration)


def running_on_windows_native():
return os.name == 'nt'


# the order to try to upload / update the items
Expand Down