Skip to content

Commit

Permalink
Python2 compatibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinclert committed Mar 17, 2020
1 parent fe01107 commit bb2acc7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion hepdata_validator/schema_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,18 @@ def save_locally(self, schema_name, schema_spec, overwrite=False):
"""

file_path = os.path.join(self.saved_schema_path, schema_name)
file_folder = os.path.dirname(file_path)

# Skip download if the file exist
if os.path.isfile(file_path) and not overwrite:
return

os.makedirs(os.path.dirname(file_path), exist_ok=True)
# This is compatible both with Python2 and Python3
try:
os.makedirs(file_folder)
except OSError:
if not os.path.isdir(file_folder):
raise

with open(file_path, 'w') as f:
f.write(schema_spec)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'pytest-cov>=1.8.0',
'pytest-pep8>=1.0.6',
'coverage>=3.7.1',
'mock>=2.0.0',
]

extras_require = {
Expand Down
2 changes: 1 addition & 1 deletion testsuite/test_schema_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from hepdata_validator.schema_downloader import HTTPSchemaDownloader
from requests.exceptions import HTTPError
from unittest.mock import patch
from mock import patch


####################################################
Expand Down

0 comments on commit bb2acc7

Please sign in to comment.