Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
85dcaa74
P
pip
项目概览
镜像
/
Python_Packaging_Authority
/
pip
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pip
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
85dcaa74
编写于
9月 19, 2019
作者:
C
Chris Hunt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unconditionally create TempDirectory.path
上级
dd627311
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
16 addition
and
38 deletion
+16
-38
src/pip/_internal/build_env.py
src/pip/_internal/build_env.py
+0
-1
src/pip/_internal/cache.py
src/pip/_internal/cache.py
+0
-1
src/pip/_internal/commands/install.py
src/pip/_internal/commands/install.py
+0
-1
src/pip/_internal/req/req_install.py
src/pip/_internal/req/req_install.py
+0
-2
src/pip/_internal/req/req_tracker.py
src/pip/_internal/req/req_tracker.py
+0
-1
src/pip/_internal/req/req_uninstall.py
src/pip/_internal/req/req_uninstall.py
+0
-3
src/pip/_internal/utils/temp_dir.py
src/pip/_internal/utils/temp_dir.py
+13
-24
tests/unit/test_utils.py
tests/unit/test_utils.py
+3
-5
未找到文件。
src/pip/_internal/build_env.py
浏览文件 @
85dcaa74
...
...
@@ -54,7 +54,6 @@ class BuildEnvironment(object):
def
__init__
(
self
):
# type: () -> None
self
.
_temp_dir
=
TempDirectory
(
kind
=
"build-env"
)
self
.
_temp_dir
.
create
()
self
.
_prefixes
=
OrderedDict
((
(
name
,
_Prefix
(
os
.
path
.
join
(
self
.
_temp_dir
.
path
,
name
)))
...
...
src/pip/_internal/cache.py
浏览文件 @
85dcaa74
...
...
@@ -193,7 +193,6 @@ class EphemWheelCache(SimpleWheelCache):
def
__init__
(
self
,
format_control
):
# type: (FormatControl) -> None
self
.
_temp_dir
=
TempDirectory
(
kind
=
"ephem-wheel-cache"
)
self
.
_temp_dir
.
create
()
super
(
EphemWheelCache
,
self
).
__init__
(
self
.
_temp_dir
.
path
,
format_control
...
...
src/pip/_internal/commands/install.py
浏览文件 @
85dcaa74
...
...
@@ -318,7 +318,6 @@ class InstallCommand(RequirementCommand):
# Create a target directory for using with the target option
target_temp_dir
=
TempDirectory
(
kind
=
"target"
)
target_temp_dir
.
create
()
target_temp_dir_path
=
target_temp_dir
.
path
install_options
.
append
(
'--home='
+
target_temp_dir_path
)
...
...
src/pip/_internal/req/req_install.py
浏览文件 @
85dcaa74
...
...
@@ -338,7 +338,6 @@ class InstallRequirement(object):
# builds (such as numpy). Thus, we ensure that the real path
# is returned.
self
.
_temp_build_dir
=
TempDirectory
(
kind
=
"req-build"
)
self
.
_temp_build_dir
.
create
()
self
.
_ideal_build_dir
=
build_dir
return
self
.
_temp_build_dir
.
path
...
...
@@ -606,7 +605,6 @@ class InstallRequirement(object):
# NOTE: This needs to be refactored to stop using atexit
self
.
_temp_dir
=
TempDirectory
(
delete
=
False
,
kind
=
"req-install"
)
self
.
_temp_dir
.
create
()
metadata_dir
=
os
.
path
.
join
(
self
.
_temp_dir
.
path
,
'pip-wheel-metadata'
,
...
...
src/pip/_internal/req/req_tracker.py
浏览文件 @
85dcaa74
...
...
@@ -28,7 +28,6 @@ class RequirementTracker(object):
self
.
_root
=
os
.
environ
.
get
(
'PIP_REQ_TRACKER'
)
if
self
.
_root
is
None
:
self
.
_temp_dir
=
TempDirectory
(
delete
=
False
,
kind
=
'req-tracker'
)
self
.
_temp_dir
.
create
()
self
.
_root
=
os
.
environ
[
'PIP_REQ_TRACKER'
]
=
self
.
_temp_dir
.
path
logger
.
debug
(
'Created requirements tracker %r'
,
self
.
_root
)
else
:
...
...
src/pip/_internal/req/req_uninstall.py
浏览文件 @
85dcaa74
...
...
@@ -227,10 +227,8 @@ class StashedUninstallPathSet(object):
try
:
save_dir
=
AdjacentTempDirectory
(
path
)
# type: TempDirectory
save_dir
.
create
()
except
OSError
:
save_dir
=
TempDirectory
(
kind
=
"uninstall"
)
save_dir
.
create
()
self
.
_save_dirs
[
os
.
path
.
normcase
(
path
)]
=
save_dir
return
save_dir
.
path
...
...
@@ -256,7 +254,6 @@ class StashedUninstallPathSet(object):
# Did not find any suitable root
head
=
os
.
path
.
dirname
(
path
)
save_dir
=
TempDirectory
(
kind
=
'uninstall'
)
save_dir
.
create
()
self
.
_save_dirs
[
head
]
=
save_dir
relpath
=
os
.
path
.
relpath
(
path
,
head
)
...
...
src/pip/_internal/utils/temp_dir.py
浏览文件 @
85dcaa74
...
...
@@ -19,21 +19,17 @@ class TempDirectory(object):
Attributes:
path
Location to the created temporary directory
or None
Location to the created temporary directory
delete
Whether the directory should be deleted when exiting
(when used as a contextmanager)
Methods:
create()
Creates a temporary directory and stores its path in the path
attribute.
cleanup()
Deletes the temporary directory
and sets path attribute to None
Deletes the temporary directory
When used as a context manager, a temporary directory is created on
entering the context and, if the delete attribute is True, on exiting the
context the created directory is deleted.
When used as a context manager, if the delete attribute is True, on
exiting the context the temporary directory is deleted.
"""
def
__init__
(
self
,
path
=
None
,
delete
=
None
,
kind
=
"temp"
):
...
...
@@ -44,6 +40,9 @@ class TempDirectory(object):
# an explicit delete option, then we'll default to deleting.
delete
=
True
if
path
is
None
:
path
=
self
.
_create
(
kind
)
self
.
path
=
path
self
.
delete
=
delete
self
.
kind
=
kind
...
...
@@ -52,30 +51,21 @@ class TempDirectory(object):
return
"<{} {!r}>"
.
format
(
self
.
__class__
.
__name__
,
self
.
path
)
def
__enter__
(
self
):
self
.
create
()
return
self
def
__exit__
(
self
,
exc
,
value
,
tb
):
if
self
.
delete
:
self
.
cleanup
()
def
create
(
self
):
self
.
path
=
self
.
_create
()
def
_create
(
self
):
def
_create
(
self
,
kind
):
"""Create a temporary directory and store its path in self.path
"""
if
self
.
path
is
not
None
:
logger
.
debug
(
"Skipped creation of temporary directory: {}"
.
format
(
self
.
path
)
)
return
self
.
path
# We realpath here because some systems have their default tmpdir
# symlinked to another directory. This tends to confuse build
# scripts, so we canonicalize the path by traversing potential
# symlinks here.
path
=
os
.
path
.
realpath
(
tempfile
.
mkdtemp
(
prefix
=
"pip-{}-"
.
format
(
self
.
kind
))
tempfile
.
mkdtemp
(
prefix
=
"pip-{}-"
.
format
(
kind
))
)
logger
.
debug
(
"Created temporary directory: {}"
.
format
(
path
))
return
path
...
...
@@ -83,9 +73,8 @@ class TempDirectory(object):
def
cleanup
(
self
):
"""Remove the temporary directory created and reset state
"""
if
self
.
path
is
not
None
and
os
.
path
.
exists
(
self
.
path
):
if
os
.
path
.
exists
(
self
.
path
):
rmtree
(
self
.
path
)
self
.
path
=
None
class
AdjacentTempDirectory
(
TempDirectory
):
...
...
@@ -110,8 +99,8 @@ class AdjacentTempDirectory(TempDirectory):
LEADING_CHARS
=
"-~.=%0123456789"
def
__init__
(
self
,
original
,
delete
=
None
):
super
(
AdjacentTempDirectory
,
self
).
__init__
(
delete
=
delete
)
self
.
original
=
original
.
rstrip
(
'/
\\
'
)
super
(
AdjacentTempDirectory
,
self
).
__init__
(
delete
=
delete
)
@
classmethod
def
_generate_names
(
cls
,
name
):
...
...
@@ -137,7 +126,7 @@ class AdjacentTempDirectory(TempDirectory):
if
new_name
!=
name
:
yield
new_name
def
_create
(
self
):
def
_create
(
self
,
kind
):
root
,
name
=
os
.
path
.
split
(
self
.
original
)
for
candidate
in
self
.
_generate_names
(
name
):
path
=
os
.
path
.
join
(
root
,
candidate
)
...
...
@@ -153,7 +142,7 @@ class AdjacentTempDirectory(TempDirectory):
else
:
# Final fallback on the default behavior.
path
=
os
.
path
.
realpath
(
tempfile
.
mkdtemp
(
prefix
=
"pip-{}-"
.
format
(
self
.
kind
))
tempfile
.
mkdtemp
(
prefix
=
"pip-{}-"
.
format
(
kind
))
)
logger
.
debug
(
"Created temporary directory: {}"
.
format
(
path
))
...
...
tests/unit/test_utils.py
浏览文件 @
85dcaa74
...
...
@@ -588,19 +588,17 @@ class TestTempDirectory(object):
create_file
(
tmp_dir
.
path
,
"subfolder"
,
"readonly-file"
)
readonly_file
(
tmp_dir
.
path
,
"subfolder"
,
"readonly-file"
)
assert
tmp_dir
.
path
is
None
assert
not
os
.
path
.
exists
(
tmp_dir
.
path
)
def
test_create_and_cleanup_work
(
self
):
tmp_dir
=
TempDirectory
()
assert
tmp_dir
.
path
is
None
tmp_dir
.
create
()
created_path
=
tmp_dir
.
path
assert
tmp_dir
.
path
is
not
None
assert
os
.
path
.
exists
(
created_path
)
tmp_dir
.
cleanup
()
assert
tmp_dir
.
path
is
None
assert
tmp_dir
.
path
is
not
None
assert
not
os
.
path
.
exists
(
created_path
)
@
pytest
.
mark
.
parametrize
(
"name"
,
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录