Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pins/databricks/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def _upload_files(path):
if is_file:
rel_path = abs_path.relative_to(orig_path)
db_path = PurePath(rpath).joinpath(rel_path)
file = open(abs_path, "rb")
w.files.upload(str(db_path), BytesIO(file.read()), overwrite=True)
with open(abs_path, "rb") as f:
w.files.upload(str(db_path), BytesIO(f.read()), overwrite=True)
else:
_upload_files(abs_path)

Expand Down
8 changes: 4 additions & 4 deletions pins/tests/test_rsconnect_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ def test_rsconnect_api_get_content_bundle_archive(rsc_short):

tmp_file.file.close()

tar = tarfile.open(tmp_file.name, "r:gz")
tar.extractall(path=tmp_dst)
tar.close()
with tarfile.open(tmp_file.name, "r:gz") as tar:
tar.extractall(path=tmp_dst)

# run checks inside context handler for easier de-bugging ----
p_src = Path(tmp_src)
Expand Down Expand Up @@ -421,7 +420,8 @@ def test_rsconnect_fs_get_data(fs_short):
fs_short.get(f"susan/test-content/{bund1['id']}/index.html", tmp.name)

# TODO: make more robust
assert "yo" in open(tmp.name).read()
with open(tmp.name) as f:
assert "yo" in f.read()


# fs.put ----
Expand Down
6 changes: 5 additions & 1 deletion pins/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def from_files(
) -> Version:
hashes = []
for f in files:
hash_ = cls.hash_file(open(f, "rb") if isinstance(f, (str, Path)) else f)
if isinstance(f, (str, Path)):
with open(f, "rb") as f:
hash_ = cls.hash_file(f)
else:
hash_ = cls.hash_file(f)
hashes.append(hash_)

if created is None:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ select = [
"UP", # Upgrade to latest supported Python syntax
"W", # Style
"A", # Don't shadow built-ins
"SIM115", # Use context managers for file opens
]
ignore = [
"E501", # Line too long
Expand Down
3 changes: 2 additions & 1 deletion script/setup-rsconnect/dump_api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ def get_api_key(user, password, email):
"derek": get_api_key("derek", "derek", "[email protected]"),
}

json.dump(api_keys, open(OUT_FILE, "w"))
with open(OUT_FILE, "w") as f:
json.dump(api_keys, f)
Loading