clean up a few small things (#2002)

This commit is contained in:
Anthony Sottile 2020-11-01 01:31:16 -08:00 committed by GitHub
parent d89f97683e
commit 3ae716faf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 12 deletions

View file

@ -24,7 +24,7 @@ class AppDataAction(Action):
@staticmethod
def _check_folder(folder):
folder = os.path.abspath(folder)
if not os.path.exists(folder):
if not os.path.isdir(folder):
try:
os.makedirs(folder)
logging.debug("created app data folder %s", folder)

View file

@ -154,10 +154,7 @@ class JSONStoreDisk(ContentStore):
def write(self, content):
folder = self.file.parent
try:
folder.mkdir(parents=True, exist_ok=True)
except OSError:
pass
folder.mkdir(parents=True, exist_ok=True)
self.file.write_text(ensure_text(json.dumps(content, sort_keys=True, indent=2)))
logging.debug("wrote {} at %s".format(self.msg), *self.msg_args)

View file

@ -14,7 +14,7 @@ from virtualenv.util.path import Path
class _CountedFileLock(FileLock):
def __init__(self, lock_file):
parent = os.path.dirname(lock_file)
if not os.path.exists(parent):
if not os.path.isdir(parent):
try:
os.makedirs(parent)
except OSError:
@ -32,7 +32,7 @@ class _CountedFileLock(FileLock):
def release(self, force=False):
with self.thread_safe:
if self.count == 1:
super(_CountedFileLock, self).release()
super(_CountedFileLock, self).release(force=force)
self.count = max(self.count - 1, 0)

View file

@ -56,7 +56,7 @@ def copy(src, dest):
def copytree(src, dest):
for root, _, files in os.walk(src):
dest_dir = os.path.join(dest, os.path.relpath(root, src))
if not os.path.exists(dest_dir):
if not os.path.isdir(dest_dir):
os.makedirs(dest_dir)
for name in files:
src_f = os.path.join(root, name)

View file

@ -2,7 +2,7 @@ from __future__ import absolute_import, unicode_literals
import os
import sys
from stat import S_IREAD, S_IRGRP, S_IROTH, S_IWUSR
from stat import S_IRGRP, S_IROTH, S_IRUSR, S_IXUSR
from threading import Thread
import pytest
@ -110,17 +110,18 @@ def test_seed_link_via_app_data(tmp_path, coverage_env, current_fastest, copies)
@pytest.fixture()
def read_only_app_data(temp_app_data):
temp_app_data.mkdir()
orig_mode = os.stat(str(temp_app_data)).st_mode
try:
os.chmod(str(temp_app_data), S_IREAD | S_IRGRP | S_IROTH)
os.chmod(str(temp_app_data), S_IRUSR | S_IXUSR | S_IRGRP | S_IROTH)
yield temp_app_data
finally:
os.chmod(str(temp_app_data), S_IWUSR | S_IREAD)
os.chmod(str(temp_app_data), orig_mode)
@pytest.mark.skipif(sys.platform == "win32", reason="Windows only applies R/O to files")
def test_base_bootstrap_link_via_app_data_not_writable(tmp_path, current_fastest, read_only_app_data, monkeypatch):
dest = tmp_path / "venv"
result = cli_run(["--seeder", "app-data", "--creator", current_fastest, "--reset-app-data", "-vv", str(dest)])
result = cli_run(["--seeder", "app-data", "--creator", current_fastest, "-vv", str(dest)])
assert result