Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
f903eb0d
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,发现更多精彩内容 >>
提交
f903eb0d
编写于
3月 19, 2011
作者:
C
Carl Meyer
浏览文件
操作
浏览文件
下载
差异文件
Merged in python3 branch.
上级
c3d639f4
f3fe9dd4
变更
47
隐藏空白更改
内联
并排
Showing
47 changed file
with
578 addition
and
365 deletion
+578
-365
LICENSE.txt
LICENSE.txt
+1
-2
docs/conf.py
docs/conf.py
+1
-1
docs/index.txt
docs/index.txt
+1
-0
docs/installing.txt
docs/installing.txt
+28
-0
docs/news.txt
docs/news.txt
+3
-0
pip/__init__.py
pip/__init__.py
+8
-7
pip/_pkgutil.py
pip/_pkgutil.py
+6
-3
pip/backwardcompat.py
pip/backwardcompat.py
+56
-4
pip/basecommand.py
pip/basecommand.py
+7
-6
pip/baseparser.py
pip/baseparser.py
+7
-6
pip/commands/completion.py
pip/commands/completion.py
+1
-1
pip/commands/help.py
pip/commands/help.py
+2
-3
pip/commands/search.py
pip/commands/search.py
+2
-2
pip/commands/zip.py
pip/commands/zip.py
+1
-1
pip/download.py
pip/download.py
+12
-10
pip/index.py
pip/index.py
+11
-11
pip/locations.py
pip/locations.py
+2
-2
pip/req.py
pip/req.py
+34
-27
pip/util.py
pip/util.py
+7
-6
pip/vcs/__init__.py
pip/vcs/__init__.py
+2
-3
pip/vcs/git.py
pip/vcs/git.py
+4
-3
pip/vcs/mercurial.py
pip/vcs/mercurial.py
+4
-2
pip/vcs/subversion.py
pip/vcs/subversion.py
+2
-2
pip/venv.py
pip/venv.py
+3
-3
run-tests-py3k
run-tests-py3k
+7
-0
setup.py
setup.py
+23
-19
tests/__init__.py
tests/__init__.py
+0
-0
tests/local_repos.py
tests/local_repos.py
+12
-7
tests/path.py
tests/path.py
+18
-4
tests/pypi_server.py
tests/pypi_server.py
+30
-40
tests/test_all_pip.py
tests/test_all_pip.py
+18
-18
tests/test_basic.py
tests/test_basic.py
+38
-37
tests/test_bundle.py
tests/test_bundle.py
+3
-3
tests/test_cleanup.py
tests/test_cleanup.py
+9
-8
tests/test_compat.py
tests/test_compat.py
+1
-1
tests/test_completion.py
tests/test_completion.py
+1
-1
tests/test_config.py
tests/test_config.py
+4
-4
tests/test_download.py
tests/test_download.py
+2
-2
tests/test_file_scheme_index.py
tests/test_file_scheme_index.py
+3
-3
tests/test_freeze.py
tests/test_freeze.py
+10
-46
tests/test_pip.py
tests/test_pip.py
+132
-20
tests/test_proxy.py
tests/test_proxy.py
+3
-2
tests/test_requirements.py
tests/test_requirements.py
+21
-17
tests/test_search.py
tests/test_search.py
+12
-5
tests/test_uninstall.py
tests/test_uninstall.py
+14
-10
tests/test_upgrade.py
tests/test_upgrade.py
+7
-7
tests/test_vcs_backends.py
tests/test_vcs_backends.py
+5
-6
未找到文件。
LICENSE.txt
浏览文件 @
f903eb0d
Copyright (c) 2008-2010 Ian Bicking and Contributors
Copyright (c) 2011 The virtualenv developers
Copyright (c) 2008-2011 The pip developers (see AUTHORS.txt file)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
...
...
docs/conf.py
浏览文件 @
f903eb0d
...
...
@@ -47,7 +47,7 @@ copyright = '2008-2011, The pip developers'
# built documents.
#
# The short X.Y version.
release
=
"0.
8.3.post
1"
release
=
"0.
9.0.pre
1"
version
=
'.'
.
join
(
release
.
split
(
'.'
)[:
2
])
# The language for content autogenerated by Sphinx. Refer to documentation
...
...
docs/index.txt
浏览文件 @
f903eb0d
...
...
@@ -7,6 +7,7 @@ pip installs Python packages.
:maxdepth: 1
news
installing
requirement-format
configuration
how-to-contribute
...
...
docs/installing.txt
0 → 100644
浏览文件 @
f903eb0d
Installing pip
==============
Using easy_install
------------------
This may have to be run as root. ::
$ easy_install -U pip
Using source
------------
You can find the source on PyPi: http://pypi.python.org/pypi/pip::
$ tar xvfz pip-*.*.*.tar.gz
$ cd pip-*.*.*
$ python setup.py install # may need to be root
Installing development version
------------------------------
First you will need to clone the git repo::
$ git clone https://github.com/pypa/pip.git
Now we can install from the repo::
$ cd pip
$ python setup.py install # may need to be root
docs/news.txt
浏览文件 @
f903eb0d
...
...
@@ -4,6 +4,9 @@ News for pip
tip (unreleased)
----------------
* Added Python 3 support! Huge thanks to Vinay Sajip, Vitaly Babiy, Kelsey
Hightower, and Alex Grönholm, among others.
* Download progress only shown on a real TTY. Thanks Alex Morega.
* Fixed finding of VCS binaries to not be fooled by same-named directories.
...
...
pip/__init__.py
浏览文件 @
f903eb0d
...
...
@@ -12,7 +12,7 @@ from pip.baseparser import parser
from
pip.exceptions
import
InstallationError
from
pip.log
import
logger
from
pip.util
import
get_installed_distributions
from
pip.backwardcompat
import
walk_packages
from
pip.backwardcompat
import
u
,
walk_packages
def
autocomplete
():
...
...
@@ -53,7 +53,7 @@ def autocomplete():
# if there are no dists installed, fall back to option completion
if
installed
:
for
dist
in
installed
:
print
dist
print
(
dist
)
sys
.
exit
(
1
)
subcommand
=
command_dict
.
get
(
subcommand_name
)
options
+=
[(
opt
.
get_opt_string
(),
opt
.
nargs
)
...
...
@@ -61,7 +61,7 @@ def autocomplete():
if
opt
.
help
!=
optparse
.
SUPPRESS_HELP
]
# filter out previously specified options from available options
prev_opts
=
[
x
.
split
(
'='
)[
0
]
for
x
in
cwords
[
1
:
cword
-
1
]]
options
=
filter
(
lambda
(
x
,
v
):
x
not
in
prev_opts
,
options
)
options
=
[(
x
,
v
)
for
(
x
,
v
)
in
options
if
x
not
in
prev_opts
]
# filter options by current input
options
=
[(
k
,
v
)
for
k
,
v
in
options
if
k
.
startswith
(
current
)]
for
option
in
options
:
...
...
@@ -69,14 +69,14 @@ def autocomplete():
# append '=' to options which require args
if
option
[
1
]:
opt_label
+=
'='
print
opt_label
print
(
opt_label
)
else
:
# show options of main parser only when necessary
if
current
.
startswith
(
'-'
)
or
current
.
startswith
(
'--'
):
subcommands
+=
[
opt
.
get_opt_string
()
for
opt
in
parser
.
option_list
if
opt
.
help
!=
optparse
.
SUPPRESS_HELP
]
print
' '
.
join
(
filter
(
lambda
x
:
x
.
startswith
(
current
),
subcommands
))
print
(
' '
.
join
([
x
for
x
in
subcommands
if
x
.
startswith
(
current
)]
))
sys
.
exit
(
1
)
...
...
@@ -213,7 +213,8 @@ def call_subprocess(cmd, show_stdout=True,
proc
=
subprocess
.
Popen
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
stdin
=
None
,
stdout
=
stdout
,
cwd
=
cwd
,
env
=
env
)
except
Exception
,
e
:
except
Exception
:
e
=
sys
.
exc_info
()[
1
]
logger
.
fatal
(
"Error %s while executing command %s"
%
(
e
,
command_desc
))
raise
...
...
@@ -221,7 +222,7 @@ def call_subprocess(cmd, show_stdout=True,
if
stdout
is
not
None
:
stdout
=
proc
.
stdout
while
1
:
line
=
stdout
.
readline
(
)
line
=
u
(
stdout
.
readline
()
)
if
not
line
:
break
line
=
line
.
rstrip
()
...
...
pip/_pkgutil.py
浏览文件 @
f903eb0d
...
...
@@ -324,7 +324,7 @@ try:
from
zipimport
import
zipimporter
def
iter_zipimport_modules
(
importer
,
prefix
=
''
):
dirlist
=
zipimport
.
_zip_directory_cache
[
importer
.
archive
].
keys
(
)
dirlist
=
list
(
zipimport
.
_zip_directory_cache
[
importer
.
archive
].
keys
()
)
dirlist
.
sort
()
_prefix
=
importer
.
prefix
plen
=
len
(
_prefix
)
...
...
@@ -522,8 +522,10 @@ def extend_path(path, name):
path
=
path
[:]
# Start with a copy of the existing path
from
pip.backwardcompat
import
string_types
for
dir
in
sys
.
path
:
if
not
isinstance
(
dir
,
basestring
)
or
not
os
.
path
.
isdir
(
dir
):
if
not
isinstance
(
dir
,
string_types
)
or
not
os
.
path
.
isdir
(
dir
):
continue
subdir
=
os
.
path
.
join
(
dir
,
pname
)
# XXX This may still add duplicate entries to path on
...
...
@@ -537,7 +539,8 @@ def extend_path(path, name):
if
os
.
path
.
isfile
(
pkgfile
):
try
:
f
=
open
(
pkgfile
)
except
IOError
,
msg
:
except
IOError
:
msg
=
sys
.
exc_info
()[
1
]
sys
.
stderr
.
write
(
"Can't open %s: %s
\n
"
%
(
pkgfile
,
msg
))
else
:
...
...
pip/backwardcompat.py
浏览文件 @
f903eb0d
"""Stuff that
isn't in some old versions of Python
"""
"""Stuff that
differs in different Python versions
"""
import
sys
import
os
...
...
@@ -9,7 +9,9 @@ __all__ = ['any', 'WindowsError', 'md5', 'copytree']
try
:
WindowsError
=
WindowsError
except
NameError
:
WindowsError
=
None
class
NeverUsedException
(
Exception
):
"""this exception should never be raised"""
WindowsError
=
NeverUsedException
try
:
from
hashlib
import
md5
except
ImportError
:
...
...
@@ -20,7 +22,7 @@ try:
from
pkgutil
import
walk_packages
except
ImportError
:
# let's fall back as long as we can
from
_pkgutil
import
walk_packages
from
pip.
_pkgutil
import
walk_packages
try
:
any
=
any
...
...
@@ -32,6 +34,56 @@ except NameError:
return
True
return
False
if
sys
.
version_info
>=
(
3
,):
from
io
import
StringIO
from
functools
import
reduce
from
urllib.error
import
URLError
,
HTTPError
from
queue
import
Queue
,
Empty
from
urllib.request
import
url2pathname
from
urllib.request
import
urlretrieve
from
email
import
message
as
emailmessage
import
urllib.parse
as
urllib
import
urllib.request
as
urllib2
import
configparser
as
ConfigParser
import
xmlrpc.client
as
xmlrpclib
import
urllib.parse
as
urlparse
import
http.client
as
httplib
def
cmp
(
a
,
b
):
return
(
a
>
b
)
-
(
a
<
b
)
def
b
(
s
):
return
s
.
encode
(
'utf-8'
)
def
u
(
s
):
return
s
.
decode
(
'utf-8'
)
string_types
=
(
str
,)
raw_input
=
input
else
:
from
cStringIO
import
StringIO
from
urllib2
import
URLError
,
HTTPError
from
Queue
import
Queue
,
Empty
from
urllib
import
url2pathname
,
urlretrieve
from
email
import
Message
as
emailmessage
import
urllib
import
urllib2
import
urlparse
import
ConfigParser
import
xmlrpclib
import
httplib
def
b
(
s
):
return
s
def
u
(
s
):
return
s
string_types
=
(
basestring
,)
reduce
=
reduce
cmp
=
cmp
raw_input
=
raw_input
try
:
from
email.parser
import
FeedParser
except
ImportError
:
# python lesser than 2.5
from
email.FeedParser
import
FeedParser
from
distutils.sysconfig
import
get_python_lib
,
get_python_version
def
copytree
(
src
,
dst
):
if
sys
.
version_info
<
(
2
,
5
):
...
...
@@ -47,7 +99,7 @@ def copytree(src, dst):
def
product
(
*
args
,
**
kwds
):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools
=
map
(
tuple
,
args
)
*
kwds
.
get
(
'repeat'
,
1
)
pools
=
list
(
map
(
tuple
,
args
)
)
*
kwds
.
get
(
'repeat'
,
1
)
result
=
[[]]
for
pool
in
pools
:
result
=
[
x
+
[
y
]
for
x
in
result
for
y
in
pool
]
...
...
pip/basecommand.py
浏览文件 @
f903eb0d
"""Base Command class, and related routines"""
from
cStringIO
import
StringIO
import
os
import
socket
import
sys
...
...
@@ -13,7 +12,7 @@ from pip.baseparser import parser, ConfigOptionParser, UpdatingDefaultsHelpForma
from
pip.download
import
urlopen
from
pip.exceptions
import
BadCommand
,
InstallationError
,
UninstallationError
from
pip.venv
import
restart_in_venv
from
pip.backwardcompat
import
walk_packages
from
pip.backwardcompat
import
StringIO
,
urllib
,
urllib2
,
walk_packages
__all__
=
[
'command_dict'
,
'Command'
,
'load_all_commands'
,
'load_command'
,
'command_names'
]
...
...
@@ -125,11 +124,13 @@ class Command(object):
exit
=
0
try
:
self
.
run
(
options
,
args
)
except
(
InstallationError
,
UninstallationError
),
e
:
except
(
InstallationError
,
UninstallationError
):
e
=
sys
.
exc_info
()[
1
]
logger
.
fatal
(
str
(
e
))
logger
.
info
(
'Exception information:
\n
%s'
%
format_exc
())
exit
=
1
except
BadCommand
,
e
:
except
BadCommand
:
e
=
sys
.
exc_info
()[
1
]
logger
.
fatal
(
str
(
e
))
logger
.
info
(
'Exception information:
\n
%s'
%
format_exc
())
exit
=
1
...
...
@@ -174,8 +175,8 @@ def open_logfile(filename, mode='a'):
log_fp
=
open
(
filename
,
mode
)
if
exists
:
print
>>
log_fp
,
'-'
*
60
print
>>
log_fp
,
'%s run on %s'
%
(
sys
.
argv
[
0
],
time
.
strftime
(
'%c'
))
log_fp
.
write
(
'%s
\n
'
%
(
'-'
*
60
))
log_fp
.
write
(
'%s run on %s
\n
'
%
(
sys
.
argv
[
0
],
time
.
strftime
(
'%c'
)
))
return
log_fp
...
...
pip/baseparser.py
浏览文件 @
f903eb0d
...
...
@@ -3,9 +3,9 @@
import
sys
import
optparse
import
pkg_resources
import
ConfigParser
import
os
from
distutils.util
import
strtobool
from
pip.backwardcompat
import
ConfigParser
,
string_types
from
pip.locations
import
default_config_file
,
default_log_file
...
...
@@ -50,7 +50,7 @@ class ConfigOptionParser(optparse.OptionParser):
# 2. environmental variables
config
.
update
(
dict
(
self
.
get_environ_vars
()))
# Then set the options with those values
for
key
,
val
in
config
.
ite
rite
ms
():
for
key
,
val
in
config
.
items
():
key
=
key
.
replace
(
'_'
,
'-'
)
if
not
key
.
startswith
(
'--'
):
key
=
'--%s'
%
key
# only prefer long opts
...
...
@@ -68,8 +68,9 @@ class ConfigOptionParser(optparse.OptionParser):
val
=
strtobool
(
val
)
try
:
val
=
option
.
convert_value
(
key
,
val
)
except
optparse
.
OptionValueError
,
e
:
print
(
"An error occured during configuration: %s"
%
e
)
except
optparse
.
OptionValueError
:
e
=
sys
.
exc_info
()[
1
]
print
(
"An error occured during configuration: %s"
%
e
)
sys
.
exit
(
3
)
defaults
[
option
.
dest
]
=
val
return
defaults
...
...
@@ -82,7 +83,7 @@ class ConfigOptionParser(optparse.OptionParser):
def
get_environ_vars
(
self
,
prefix
=
'PIP_'
):
"""Returns a generator with all environmental vars with prefix PIP_"""
for
key
,
val
in
os
.
environ
.
ite
rite
ms
():
for
key
,
val
in
os
.
environ
.
items
():
if
key
.
startswith
(
prefix
):
yield
(
key
.
replace
(
prefix
,
''
).
lower
(),
val
)
...
...
@@ -96,7 +97,7 @@ class ConfigOptionParser(optparse.OptionParser):
defaults
=
self
.
update_defaults
(
self
.
defaults
.
copy
())
# ours
for
option
in
self
.
_get_all_options
():
default
=
defaults
.
get
(
option
.
dest
)
if
isinstance
(
default
,
basestring
):
if
isinstance
(
default
,
string_types
):
opt_str
=
option
.
get_opt_string
()
defaults
[
option
.
dest
]
=
option
.
check_value
(
opt_str
,
default
)
return
optparse
.
Values
(
defaults
)
...
...
pip/commands/completion.py
浏览文件 @
f903eb0d
...
...
@@ -53,7 +53,7 @@ class CompletionCommand(Command):
shell_options
=
[
'--'
+
shell
for
shell
in
sorted
(
shells
)]
if
options
.
shell
in
shells
:
script
=
COMPLETION_SCRIPTS
.
get
(
options
.
shell
,
''
)
print
BASE_COMPLETION
%
{
'script'
:
script
,
'shell'
:
options
.
shell
}
print
(
BASE_COMPLETION
%
{
'script'
:
script
,
'shell'
:
options
.
shell
})
else
:
sys
.
stderr
.
write
(
'ERROR: You must pass %s
\n
'
%
' or '
.
join
(
shell_options
))
...
...
pip/commands/help.py
浏览文件 @
f903eb0d
...
...
@@ -19,14 +19,13 @@ class HelpCommand(Command):
command
.
parser
.
print_help
()
return
parser
.
print_help
()
print
print
'Commands available:'
print
(
'
\n
Commands available:'
)
commands
=
list
(
set
(
command_dict
.
values
()))
commands
.
sort
(
key
=
lambda
x
:
x
.
name
)
for
command
in
commands
:
if
command
.
hidden
:
continue
print
' %s: %s'
%
(
command
.
name
,
command
.
summary
)
print
(
' %s: %s'
%
(
command
.
name
,
command
.
summary
)
)
HelpCommand
()
pip/commands/search.py
浏览文件 @
f903eb0d
import
sys
import
xmlrpclib
import
textwrap
import
pkg_resources
import
pip.download
from
pip.basecommand
import
Command
from
pip.util
import
get_terminal_size
from
pip.log
import
logger
from
pip.backwardcompat
import
xmlrpclib
,
reduce
,
cmp
from
distutils.version
import
StrictVersion
,
LooseVersion
...
...
@@ -69,7 +69,7 @@ def transform_hits(hits):
packages
[
name
][
'score'
]
=
score
# each record has a unique name now, so we will convert the dict into a list sorted by score
package_list
=
sorted
(
packages
.
values
(),
lambda
x
,
y
:
cmp
(
y
[
'score'
],
x
[
'score'
])
)
package_list
=
sorted
(
packages
.
values
(),
key
=
lambda
x
:
x
[
'score'
],
reverse
=
True
)
return
package_list
...
...
pip/commands/zip.py
浏览文件 @
f903eb0d
...
...
@@ -217,7 +217,7 @@ class ZipCommand(Command):
if
lines
!=
new_lines
:
logger
.
info
(
'Removing reference to %s from .pth file %s'
%
(
display_path
(
filename
),
display_path
(
pth
)))
if
not
filter
(
None
,
new_lines
)
:
if
not
[
line
for
line
in
new_lines
if
line
]
:
logger
.
info
(
'%s file would be empty: deleting'
%
display_path
(
pth
))
if
not
self
.
simulate
:
os
.
unlink
(
pth
)
...
...
pip/download.py
浏览文件 @
f903eb0d
import
xmlrpclib
import
re
import
getpass
import
urllib
import
urllib2
import
urlparse
import
sys
import
os
import
mimetypes
import
shutil
import
tempfile
from
pip.backwardcompat
import
md5
,
copytree
from
pip.backwardcompat
import
(
md5
,
copytree
,
xmlrpclib
,
urllib
,
urllib2
,
urlparse
,
string_types
,
HTTPError
)
from
pip.exceptions
import
InstallationError
from
pip.util
import
(
splitext
,
rmtree
,
format_size
,
display_path
,
backup_dir
,
ask
,
...
...
@@ -54,7 +52,8 @@ def get_file_content(url, comes_from=None):
try
:
f
=
open
(
url
)
content
=
f
.
read
()
except
IOError
,
e
:
except
IOError
:
e
=
sys
.
exc_info
()[
1
]
raise
InstallationError
(
'Could not open requirements file: %s'
%
str
(
e
))
else
:
f
.
close
()
...
...
@@ -82,7 +81,8 @@ class URLOpener(object):
if
username
is
None
:
try
:
response
=
urllib2
.
urlopen
(
self
.
get_request
(
url
))
except
urllib2
.
HTTPError
,
e
:
except
urllib2
.
HTTPError
:
e
=
sys
.
exc_info
()[
1
]
if
e
.
code
!=
401
:
raise
response
=
self
.
get_response
(
url
)
...
...
@@ -95,7 +95,7 @@ class URLOpener(object):
Wraps the URL to retrieve to protects against "creative"
interpretation of the RFC: http://bugs.python.org/issue8732
"""
if
isinstance
(
url
,
basestring
):
if
isinstance
(
url
,
string_types
):
url
=
urllib2
.
Request
(
url
,
headers
=
{
'Accept-encoding'
:
'identity'
})
return
url
...
...
@@ -455,10 +455,12 @@ def unpack_http_url(link, location, download_cache, only_download):
def
_get_response_from_url
(
target_url
,
link
):
try
:
resp
=
urlopen
(
target_url
)
except
urllib2
.
HTTPError
,
e
:
except
urllib2
.
HTTPError
:
e
=
sys
.
exc_info
()[
1
]
logger
.
fatal
(
"HTTP error %s while getting %s"
%
(
e
.
code
,
link
))
raise
except
IOError
,
e
:
except
IOError
:
e
=
sys
.
exc_info
()[
1
]
# Typically an FTP error
logger
.
fatal
(
"Error %s while getting %s"
%
(
e
,
link
))
raise
...
...
pip/index.py
浏览文件 @
f903eb0d
...
...
@@ -7,19 +7,18 @@ import mimetypes
import
threading
import
posixpath
import
pkg_resources
import
urllib
import
urllib2
import
urlparse
import
random
import
socket
import
string
from
Queue
import
Queue
from
Queue
import
Empty
as
QueueEmpty
from
pip.log
import
logger
from
pip.util
import
Inf
from
pip.util
import
normalize_name
,
splitext
from
pip.exceptions
import
DistributionNotFound
from
pip.backwardcompat
import
WindowsError
,
product
from
pip.backwardcompat
import
(
WindowsError
,
Queue
,
httplib
,
urlparse
,
URLError
,
HTTPError
,
u
,
product
,
url2pathname
)
from
pip.backwardcompat
import
Empty
as
QueueEmpty
from
pip.download
import
urlopen
,
path_to_url2
,
url_to_path
,
geturl
,
Urllib2HeadRequest
__all__
=
[
'PackageFinder'
]
...
...
@@ -432,7 +431,7 @@ class HTMLPage(object):
# Tack index.html onto file:// URLs that point to directories
(
scheme
,
netloc
,
path
,
params
,
query
,
fragment
)
=
urlparse
.
urlparse
(
url
)
if
scheme
==
'file'
and
os
.
path
.
isdir
(
url
lib
.
url
2pathname
(
path
)):
if
scheme
==
'file'
and
os
.
path
.
isdir
(
url2pathname
(
path
)):
# add trailing slash if not present so urljoin doesn't trim final segment
if
not
url
.
endswith
(
'/'
):
url
+=
'/'
...
...
@@ -443,21 +442,22 @@ class HTMLPage(object):
real_url
=
geturl
(
resp
)
headers
=
resp
.
info
()
inst
=
cls
(
resp
.
read
(),
real_url
,
headers
)
except
(
urllib2
.
HTTPError
,
urllib2
.
URLError
,
socket
.
timeout
,
socket
.
error
,
OSError
,
WindowsError
),
e
:
inst
=
cls
(
u
(
resp
.
read
()),
real_url
,
headers
)
except
(
HTTPError
,
URLError
,
socket
.
timeout
,
socket
.
error
,
OSError
,
WindowsError
):
e
=
sys
.
exc_info
()[
1
]
desc
=
str
(
e
)
if
isinstance
(
e
,
socket
.
timeout
):
log_meth
=
logger
.
info
level
=
1
desc
=
'timed out'
elif
isinstance
(
e
,
urllib2
.
URLError
):
elif
isinstance
(
e
,
URLError
):
log_meth
=
logger
.
info
if
hasattr
(
e
,
'reason'
)
and
isinstance
(
e
.
reason
,
socket
.
timeout
):
desc
=
'timed out'
level
=
1
else
:
level
=
2
elif
isinstance
(
e
,
urllib2
.
HTTPError
)
and
e
.
code
==
404
:
elif
isinstance
(
e
,
HTTPError
)
and
e
.
code
==
404
:
## FIXME: notify?
log_meth
=
logger
.
info
level
=
2
...
...
pip/locations.py
浏览文件 @
f903eb0d
...
...
@@ -2,7 +2,7 @@
import
sys
import
os
from
distutils
import
sysconfig
from
pip.backwardcompat
import
get_python_lib
def
running_under_virtualenv
():
...
...
@@ -29,7 +29,7 @@ src_prefix = os.path.abspath(src_prefix)
# FIXME doesn't account for venv linked to global site-packages
site_packages
=
sysconfig
.
get_python_lib
()
site_packages
=
get_python_lib
()
user_dir
=
os
.
path
.
expanduser
(
'~'
)
if
sys
.
platform
==
'win32'
:
bin_py
=
os
.
path
.
join
(
sys
.
prefix
,
'Scripts'
)
...
...
pip/req.py
浏览文件 @
f903eb0d
...
...
@@ -5,12 +5,6 @@ import re
import
zipfile
import
pkg_resources
import
tempfile
import
urlparse
import
urllib2
import
urllib
import
ConfigParser
from
distutils.sysconfig
import
get_python_version
from
email.FeedParser
import
FeedParser
from
pip.locations
import
bin_py
,
running_under_virtualenv
from
pip.exceptions
import
InstallationError
,
UninstallationError
from
pip.vcs
import
vcs
...
...
@@ -21,7 +15,10 @@ from pip.util import is_installable_dir, is_local, dist_is_local
from
pip.util
import
renames
,
normalize_path
,
egg_link_path
from
pip.util
import
make_path_relative
from
pip
import
call_subprocess
from
pip.backwardcompat
import
any
,
copytree
from
pip.backwardcompat
import
(
any
,
copytree
,
urlparse
,
urllib
,
ConfigParser
,
string_types
,
HTTPError
,
FeedParser
,
get_python_version
,
b
)
from
pip.index
import
Link
from
pip.locations
import
build_prefix
from
pip.download
import
(
get_file_content
,
is_url
,
url_to_path
,
...
...
@@ -37,7 +34,7 @@ class InstallRequirement(object):
def
__init__
(
self
,
req
,
comes_from
,
source_dir
=
None
,
editable
=
False
,
url
=
None
,
update
=
True
):
if
isinstance
(
req
,
basestring
):
if
isinstance
(
req
,
string_types
):
req
=
pkg_resources
.
Requirement
.
parse
(
req
)
self
.
req
=
req
self
.
comes_from
=
comes_from
...
...
@@ -110,7 +107,7 @@ class InstallRequirement(object):
if
self
.
satisfied_by
is
not
None
:
s
+=
' in %s'
%
display_path
(
self
.
satisfied_by
.
location
)
if
self
.
comes_from
:
if
isinstance
(
self
.
comes_from
,
basestring
):
if
isinstance
(
self
.
comes_from
,
string_types
):
comes_from
=
self
.
comes_from
else
:
comes_from
=
self
.
comes_from
.
from_path
()
...
...
@@ -123,7 +120,7 @@ class InstallRequirement(object):
return
None
s
=
str
(
self
.
req
)
if
self
.
comes_from
:
if
isinstance
(
self
.
comes_from
,
basestring
):
if
isinstance
(
self
.
comes_from
,
string_types
):
comes_from
=
self
.
comes_from
else
:
comes_from
=
self
.
comes_from
.
from_path
()
...
...
@@ -239,7 +236,7 @@ def replacement_run(self):
writer(self, ep.name, egg_info.os.path.join(self.egg_info,ep.name))
self.find_sources()
egg_info.egg_info.run = replacement_run
exec
file(__file__
)
exec
(compile(open(__file__).read(), __file__, 'exec')
)
"""
def
egg_info_data
(
self
,
filename
):
...
...
@@ -521,7 +518,7 @@ execfile(__file__)
dirname
=
os
.
path
.
join
(
dirpath
,
dirname
)
name
=
self
.
_clean_zip_name
(
dirname
,
dir
)
zipdir
=
zipfile
.
ZipInfo
(
self
.
name
+
'/'
+
name
+
'/'
)
zipdir
.
external_attr
=
0
755
<<
16L
zipdir
.
external_attr
=
0
x1ED
<<
16
# 0o755
zip
.
writestr
(
zipdir
,
''
)
for
filename
in
filenames
:
if
filename
==
PIP_DELETE_MARKER_FILENAME
:
...
...
@@ -551,7 +548,7 @@ execfile(__file__)
install_args
=
[
sys
.
executable
,
'-c'
,
"import setuptools;__file__=%r;"
\
"exec
file(__file__
)"
%
self
.
setup_py
]
+
\
"exec
(compile(open(__file__).read(), __file__, 'exec')
)"
%
self
.
setup_py
]
+
\
list
(
global_options
)
+
[
'install'
,
'--single-version-externally-managed'
,
...
...
@@ -621,7 +618,7 @@ execfile(__file__)
## FIXME: should we do --install-headers here too?
call_subprocess
(
[
sys
.
executable
,
'-c'
,
"import setuptools; __file__=%r; exec
file(%r)"
%
(
self
.
setup_py
,
self
.
setup_py
)
]
"import setuptools; __file__=%r; exec
(compile(open(__file__).read(), __file__, 'exec'))"
%
self
.
setup_py
]
+
list
(
global_options
)
+
[
'develop'
,
'--no-deps'
]
+
list
(
install_options
),
cwd
=
self
.
source_dir
,
filter_stdout
=
self
.
_filter_install
,
...
...
@@ -818,7 +815,7 @@ class RequirementSet(object):
@
property
def
has_requirements
(
self
):
return
self
.
requirements
.
values
(
)
or
self
.
unnamed_requirements
return
list
(
self
.
requirements
.
values
()
)
or
self
.
unnamed_requirements
@
property
def
has_editables
(
self
):
...
...
@@ -858,7 +855,7 @@ class RequirementSet(object):
## FIXME: duplicates code from install_files; relevant code should
## probably be factored out into a separate method
unnamed
=
list
(
self
.
unnamed_requirements
)
reqs
=
self
.
requirements
.
values
(
)
reqs
=
list
(
self
.
requirements
.
values
()
)
while
reqs
or
unnamed
:
if
unnamed
:
req_to_install
=
unnamed
.
pop
(
0
)
...
...
@@ -894,7 +891,7 @@ class RequirementSet(object):
def
prepare_files
(
self
,
finder
,
force_root_egg_info
=
False
,
bundle
=
False
):
"""Prepare process. Create temp directories, download and/or unpack files."""
unnamed
=
list
(
self
.
unnamed_requirements
)
reqs
=
self
.
requirements
.
values
(
)
reqs
=
list
(
self
.
requirements
.
values
()
)
while
reqs
or
unnamed
:
if
unnamed
:
req_to_install
=
unnamed
.
pop
(
0
)
...
...
@@ -957,7 +954,8 @@ class RequirementSet(object):
if
url
:
try
:
self
.
unpack_url
(
url
,
location
,
self
.
is_download
)
except
urllib2
.
HTTPError
,
e
:
except
HTTPError
:
e
=
sys
.
exc_info
()[
1
]
logger
.
fatal
(
'Could not install requirement %s because of error %s'
%
(
req_to_install
,
e
))
raise
InstallationError
(
...
...
@@ -1007,7 +1005,8 @@ class RequirementSet(object):
for
req
in
req_to_install
.
requirements
():
try
:
name
=
pkg_resources
.
Requirement
.
parse
(
req
).
project_name
except
ValueError
,
e
:
except
ValueError
:
e
=
sys
.
exc_info
()[
1
]
## FIXME: proper warning
logger
.
error
(
'Invalid requirement: %r (%s) in requirement %s'
%
(
req
,
e
,
req_to_install
))
continue
...
...
@@ -1439,19 +1438,21 @@ class UninstallPthEntries(object):
def
remove
(
self
):
logger
.
info
(
'Removing pth entries from %s:'
%
self
.
file
)
fh
=
open
(
self
.
file
,
'r'
)
fh
=
open
(
self
.
file
,
'rb'
)
# windows uses '\r\n' with py3k, but uses '\n' with py2.x
lines
=
fh
.
readlines
()
self
.
_saved_lines
=
lines
fh
.
close
()
try
:
for
entry
in
self
.
entries
:
logger
.
info
(
'Removing entry: %s'
%
entry
)
if
any
(
b
(
'
\r\n
'
)
in
line
for
line
in
lines
):
endline
=
'
\r\n
'
else
:
endline
=
'
\n
'
for
entry
in
self
.
entries
:
try
:
lines
.
remove
(
entry
+
'
\n
'
)
logger
.
info
(
'Removing entry: %s'
%
entry
)
lines
.
remove
(
b
(
entry
+
endline
))
except
ValueError
:
pass
finally
:
pass
fh
=
open
(
self
.
file
,
'wb'
)
fh
.
writelines
(
lines
)
fh
.
close
()
...
...
@@ -1475,6 +1476,12 @@ class FakeFile(object):
def
readline
(
self
):
try
:
return
self
.
_gen
.
next
()
try
:
return
next
(
self
.
_gen
)
except
NameError
:
return
self
.
_gen
.
next
()
except
StopIteration
:
return
''
def
__iter__
(
self
):
return
self
.
_gen
pip/util.py
浏览文件 @
f903eb0d
...
...
@@ -8,7 +8,7 @@ import pkg_resources
import
zipfile
import
tarfile
from
pip.exceptions
import
InstallationError
from
pip.backwardcompat
import
WindowsError
from
pip.backwardcompat
import
WindowsError
,
string_types
,
raw_input
from
pip.locations
import
site_packages
,
running_under_virtualenv
from
pip.log
import
logger
...
...
@@ -70,7 +70,7 @@ def find_command(cmd, paths=None, pathext=None):
"""Searches the PATH for the given command and returns its path"""
if
paths
is
None
:
paths
=
os
.
environ
.
get
(
'PATH'
,
[]).
split
(
os
.
pathsep
)
if
isinstance
(
paths
,
basestring
):
if
isinstance
(
paths
,
string_types
):
paths
=
[
paths
]
# check if there are funny path extensions for executables, e.g. Windows
if
pathext
is
None
:
...
...
@@ -101,8 +101,8 @@ def ask(message, options):
response
=
raw_input
(
message
)
response
=
response
.
strip
().
lower
()
if
response
not
in
options
:
print
'Your response (%r) was not one of the expected responses: %s'
%
(
response
,
', '
.
join
(
options
))
print
(
'Your response (%r) was not one of the expected responses: %s'
%
(
response
,
', '
.
join
(
options
))
)
else
:
return
response
...
...
@@ -158,7 +158,7 @@ def is_svn_page(html):
def
file_contents
(
filename
):
fp
=
open
(
filename
,
'rb'
)
try
:
return
fp
.
read
()
return
fp
.
read
()
.
decode
(
'utf-8'
)
finally
:
fp
.
close
()
...
...
@@ -418,7 +418,8 @@ def untar_file(filename, location):
else
:
try
:
fp
=
tar
.
extractfile
(
member
)
except
(
KeyError
,
AttributeError
),
e
:
except
(
KeyError
,
AttributeError
):
e
=
sys
.
exc_info
()[
1
]
# Some corrupt tar files seem to produce this
# (specifically bad symlinks)
logger
.
warn
(
...
...
pip/vcs/__init__.py
浏览文件 @
f903eb0d
...
...
@@ -2,9 +2,8 @@
import
os
import
shutil
import
urlparse
import
urllib
from
pip.backwardcompat
import
urlparse
,
urllib
from
pip.exceptions
import
BadCommand
from
pip.log
import
logger
from
pip.util
import
display_path
,
backup_dir
,
find_command
,
ask
,
rmtree
...
...
@@ -28,7 +27,7 @@ class VcsSupport(object):
@
property
def
backends
(
self
):
return
self
.
_registry
.
values
(
)
return
list
(
self
.
_registry
.
values
()
)
@
property
def
dirnames
(
self
):
...
...
pip/vcs/git.py
浏览文件 @
f903eb0d
...
...
@@ -4,8 +4,9 @@ from pip import call_subprocess
from
pip.util
import
display_path
,
rmtree
from
pip.vcs
import
vcs
,
VersionControl
from
pip.log
import
logger
from
urllib
import
url2pathname
from
urlparse
import
urlsplit
,
urlunsplit
from
pip.backwardcompat
import
url2pathname
,
urlparse
urlsplit
=
urlparse
.
urlsplit
urlunsplit
=
urlparse
.
urlunsplit
class
Git
(
VersionControl
):
name
=
'git'
...
...
@@ -66,7 +67,7 @@ class Git(VersionControl):
"""
revisions
=
self
.
get_tag_revs
(
dest
)
revisions
.
update
(
self
.
get_branch_revs
(
dest
))
inverse_revisions
=
dict
((
v
,
k
)
for
k
,
v
in
revisions
.
ite
rite
ms
())
inverse_revisions
=
dict
((
v
,
k
)
for
k
,
v
in
revisions
.
items
())
# Check if rev is a branch name
origin_rev
=
'origin/%s'
%
rev
if
origin_rev
in
inverse_revisions
:
...
...
pip/vcs/mercurial.py
浏览文件 @
f903eb0d
import
os
import
tempfile
import
re
import
ConfigParser
import
sys
from
pip
import
call_subprocess
from
pip.util
import
display_path
,
rmtree
from
pip.log
import
logger
from
pip.vcs
import
vcs
,
VersionControl
from
pip.download
import
path_to_url2
from
pip.backwardcompat
import
ConfigParser
class
Mercurial
(
VersionControl
):
...
...
@@ -53,7 +54,8 @@ class Mercurial(VersionControl):
config_file
=
open
(
repo_config
,
'w'
)
config
.
write
(
config_file
)
config_file
.
close
()
except
(
OSError
,
ConfigParser
.
NoSectionError
),
e
:
except
(
OSError
,
ConfigParser
.
NoSectionError
):
e
=
sys
.
exc_info
()[
1
]
logger
.
warn
(
'Could not switch Mercurial repository to %s: %s'
%
(
url
,
e
))
...
...
pip/vcs/subversion.py
浏览文件 @
f903eb0d
...
...
@@ -124,7 +124,7 @@ class Subversion(VersionControl):
f
.
close
()
if
data
.
startswith
(
'8'
)
or
data
.
startswith
(
'9'
)
or
data
.
startswith
(
'10'
):
data
=
map
(
str
.
splitlines
,
data
.
split
(
'
\n\x0c\n
'
))
data
=
list
(
map
(
str
.
splitlines
,
data
.
split
(
'
\n\x0c\n
'
)
))
del
data
[
0
][
0
]
# get rid of the '8'
dirurl
=
data
[
0
][
3
]
revs
=
[
int
(
d
[
9
])
for
d
in
data
if
len
(
d
)
>
9
and
d
[
9
]]
+
[
0
]
...
...
@@ -174,7 +174,7 @@ class Subversion(VersionControl):
data
=
f
.
read
()
f
.
close
()
if
data
.
startswith
(
'8'
)
or
data
.
startswith
(
'9'
)
or
data
.
startswith
(
'10'
):
data
=
map
(
str
.
splitlines
,
data
.
split
(
'
\n\x0c\n
'
))
data
=
list
(
map
(
str
.
splitlines
,
data
.
split
(
'
\n\x0c\n
'
)
))
del
data
[
0
][
0
]
# get rid of the '8'
return
data
[
0
][
3
]
elif
data
.
startswith
(
'<?xml'
):
...
...
pip/venv.py
浏览文件 @
f903eb0d
...
...
@@ -25,10 +25,10 @@ def restart_in_venv(venv, base, site_packages, args):
try
:
import
virtualenv
except
ImportError
:
print
'The virtual environment does not exist: %s'
%
venv
print
'and virtualenv is not installed, so a new environment cannot be created'
print
(
'The virtual environment does not exist: %s'
%
venv
)
print
(
'and virtualenv is not installed, so a new environment cannot be created'
)
sys
.
exit
(
3
)
print
'Creating new virtualenv environment in %s'
%
venv
print
(
'Creating new virtualenv environment in %s'
%
venv
)
virtualenv
.
logger
=
logger
logger
.
indent
+=
2
virtualenv
.
create_environment
(
venv
,
site_packages
=
site_packages
)
...
...
run-tests-py3k
0 → 100755
浏览文件 @
f903eb0d
#!/bin/bash
python
-c
'import mock'
2>/dev/null
||
easy_install mock
python
-c
'import nose'
2>/dev/null
||
easy_install http://bitbucket.org/jpellerin/nose3/get/539ffaa993f4.zip
python
-c
'import scripttest'
2>/dev/null
||
easy_install http://bitbucket.org/ianb/scripttest/get/4782629a179f.zip
python setup.py
install
nosetests3
-v
setup.py
浏览文件 @
f903eb0d
...
...
@@ -3,7 +3,7 @@ import os
from
setuptools
import
setup
# If you change this version, change it also in docs/conf.py
version
=
"0.
8.3.post
1"
version
=
"0.
9.0.pre
1"
doc_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"docs"
)
index_filename
=
os
.
path
.
join
(
doc_dir
,
"index.txt"
)
...
...
@@ -26,23 +26,27 @@ setup(name="pip",
description
=
"pip installs packages. Python packages. An easy_install replacement"
,
long_description
=
long_description
,
classifiers
=
[
"Development Status :: 4 - Beta"
,
#"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers"
,
"License :: OSI Approved :: MIT License"
,
"Topic :: Software Development :: Build Tools"
,
"Programming Language :: Python :: 2.4"
,
"Programming Language :: Python :: 2.5"
,
"Programming Language :: Python :: 2.6"
,
"Programming Language :: Python :: 2.7"
,
'Development Status :: 4 - Beta'
,
#'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers'
,
'License :: OSI Approved :: MIT License'
,
'Topic :: Software Development :: Build Tools'
,
'Programming Language :: Python :: 2'
,
'Programming Language :: Python :: 2.4'
,
'Programming Language :: Python :: 2.5'
,
'Programming Language :: Python :: 2.6'
,
'Programming Language :: Python :: 2.7'
,
'Programming Language :: Python :: 3'
,
'Programming Language :: Python :: 3.1'
,
'Programming Language :: Python :: 3.2'
,
],
keywords
=
"easy_install distutils setuptools egg virtualenv"
,
author
=
"The pip developers"
,
author_email
=
"python-virtualenv@groups.google.com"
,
url
=
"http://www.pip-installer.org"
,
license
=
"MIT"
,
packages
=
[
"pip"
,
"pip.commands"
,
"pip.vcs"
],
entry_points
=
dict
(
console_scripts
=
[
"pip=pip:main"
,
"pip-%s=pip:main"
%
sys
.
version
[:
3
]]),
test_suite
=
"nose.collector"
,
tests_require
=
[
"nose"
,
"virtualenv"
,
"scripttest"
,
"mock"
],
keywords
=
'easy_install distutils setuptools egg virtualenv'
,
author
=
'The pip developers'
,
author_email
=
'python-virtualenv@groups.google.com'
,
url
=
'http://www.pip-installer.org'
,
license
=
'MIT'
,
packages
=
[
'pip'
,
'pip.commands'
,
'pip.vcs'
],
entry_points
=
dict
(
console_scripts
=
[
'pip=pip:main'
,
'pip-%s=pip:main'
%
sys
.
version
[:
3
]]),
test_suite
=
'nose.collector'
,
tests_require
=
[
'nose'
,
'scripttest'
,
'mock'
],
zip_safe
=
False
)
tests/__init__.py
0 → 100644
浏览文件 @
f903eb0d
tests/local_repos.py
浏览文件 @
f903eb0d
import
os
import
subprocess
import
urllib
from
pip.vcs
import
subversion
,
git
,
bazaar
,
mercurial
from
path
import
Path
from
test_pip
import
path_to_url
,
here
from
pypi_server
import
PyPIProxy
from
pip.backwardcompat
import
urlretrieve
from
tests.test_pip
import
path_to_url
from
tests.pypi_server
import
PyPIProxy
if
hasattr
(
subprocess
,
"check_call"
):
subprocess_call
=
subprocess
.
check_call
else
:
subprocess_call
=
subprocess
.
call
def
_create_initools_repository
():
subprocess
.
check
_call
(
'svnadmin create INITools'
.
split
(),
cwd
=
_get_vcs_folder
())
subprocess_call
(
'svnadmin create INITools'
.
split
(),
cwd
=
_get_vcs_folder
())
def
_dump_initools_repository
():
filename
,
_
=
url
lib
.
url
retrieve
(
'http://bitbucket.org/hltbra/pip-initools-dump/raw/8b55c908a320/INITools_modified.dump'
)
filename
,
_
=
urlretrieve
(
'http://bitbucket.org/hltbra/pip-initools-dump/raw/8b55c908a320/INITools_modified.dump'
)
initools_folder
=
os
.
path
.
join
(
_get_vcs_folder
(),
'INITools'
)
devnull
=
open
(
os
.
devnull
,
'w'
)
dump
=
open
(
filename
)
subprocess
.
check
_call
([
'svnadmin'
,
'load'
,
initools_folder
],
stdin
=
dump
,
stdout
=
devnull
)
subprocess_call
([
'svnadmin'
,
'load'
,
initools_folder
],
stdin
=
dump
,
stdout
=
devnull
)
dump
.
close
()
devnull
.
close
()
os
.
remove
(
filename
)
...
...
tests/path.py
浏览文件 @
f903eb0d
# -*- coding: utf-8 -*-
# Author: Aziz Köksal
import
os
import
sys
import
shutil
if
sys
.
version_info
>=
(
3
,):
unicode
=
str
u
=
str
else
:
unicode
=
unicode
u
=
lambda
s
:
s
.
decode
(
'utf-8'
)
_base
=
os
.
path
.
supports_unicode_filenames
and
unicode
or
str
...
...
@@ -23,17 +31,23 @@ class Path(_base):
""" path_obj / 'bc.d' """
""" path_obj / path_obj2 """
return
Path
(
self
,
path
)
__truediv__
=
__div__
def
__rdiv__
(
self
,
path
):
""" Joins this path with another path. """
""" "/home/a" / path_obj """
return
Path
(
path
,
self
)
__rtruediv__
=
__rdiv__
def
__idiv__
(
self
,
path
):
""" Like __div__ but also assigns to the variable. """
""" path_obj /= 'bc.d' """
return
Path
(
self
,
path
)
__itruediv__
=
__idiv__
def
__floordiv__
(
self
,
paths
):
""" Returns a list of paths prefixed with 'self'. """
""" '/home/a' // [bc.d, ef.g] -> [/home/a/bc.d, /home/a/ef.g] """
...
...
@@ -59,7 +73,7 @@ class Path(_base):
return
Path
(
path
+
_base
(
self
))
def
__repr__
(
self
):
return
u
"Path(%s)"
%
_base
.
__repr__
(
self
)
return
u
(
"Path(%s)"
%
_base
.
__repr__
(
self
)
)
def
__hash__
(
self
):
return
_base
.
__hash__
(
self
)
...
...
@@ -145,12 +159,12 @@ class Path(_base):
del
kwargs
[
"followlinks"
]
return
os
.
walk
(
self
,
**
kwargs
)
def
mkdir
(
self
,
mode
=
0
777
):
def
mkdir
(
self
,
mode
=
0
x1FF
):
# 0o777
""" Creates a directory, if it doesn't exist already. """
if
not
self
.
exists
:
os
.
mkdir
(
self
,
mode
)
def
makedirs
(
self
,
mode
=
0
777
):
def
makedirs
(
self
,
mode
=
0
x1FF
):
# 0o777
""" Like mkdir(), but also creates parent directories. """
if
not
self
.
exists
:
os
.
makedirs
(
self
,
mode
)
...
...
@@ -188,6 +202,6 @@ class Path(_base):
def
glob
(
self
,
pattern
):
from
glob
import
glob
return
map
(
Path
,
glob
(
_base
(
self
/
pattern
)))
return
list
(
map
(
Path
,
glob
(
_base
(
self
/
pattern
)
)))
curdir
=
Path
(
os
.
path
.
curdir
)
tests/pypi_server.py
浏览文件 @
f903eb0d
import
urllib
import
urllib2
import
os
from
UserDict
import
DictMixin
import
pip.backwardcompat
from
pip.backwardcompat
import
urllib
,
string_types
,
b
,
u
,
emailmessage
urlopen_original
=
urllib2
.
urlopen
class
IgnoringCaseDict
(
DictMixin
):
def
__init__
(
self
):
self
.
_dict
=
dict
()
def
__getitem__
(
self
,
key
):
return
self
.
_dict
[
key
.
lower
()]
def
__setitem__
(
self
,
key
,
value
):
self
.
_dict
[
key
.
lower
()]
=
value
def
keys
(
self
):
return
self
.
_dict
.
keys
()
urlopen_original
=
pip
.
backwardcompat
.
urllib2
.
urlopen
class
CachedResponse
(
object
):
...
...
@@ -32,16 +16,17 @@ class CachedResponse(object):
"""
def
__init__
(
self
,
url
,
folder
):
self
.
headers
=
IgnoringCaseDict
()
# maybe use httplib.HTTPMessage ??
self
.
headers
=
emailmessage
.
Message
()
self
.
code
=
500
self
.
msg
=
'Internal Server Error'
# url can be a simple string, or a urllib2.Request object
if
isinstance
(
url
,
basestring
):
if
isinstance
(
url
,
string_types
):
self
.
url
=
url
else
:
self
.
url
=
url
.
get_full_url
()
self
.
headers
.
update
(
url
.
headers
)
self
.
_body
=
''
for
key
,
value
in
url
.
headers
.
items
():
self
.
headers
[
key
]
=
value
self
.
_body
=
b
(
''
)
self
.
_set_all_fields
(
folder
)
def
_set_all_fields
(
self
,
folder
):
...
...
@@ -50,16 +35,17 @@ class CachedResponse(object):
self
.
_cache_url
(
filename
)
fp
=
open
(
filename
,
'rb'
)
try
:
line
=
fp
.
next
().
strip
()
line
=
fp
.
readline
().
strip
()
self
.
code
,
self
.
msg
=
line
.
split
(
None
,
1
)
except
ValueError
:
raise
ValueError
(
'Bad field line: %r'
%
line
)
self
.
code
=
int
(
self
.
code
)
self
.
msg
=
u
(
self
.
msg
)
for
line
in
fp
:
if
line
==
'
\n
'
:
if
line
==
b
(
'
\n
'
)
:
break
key
,
value
=
line
.
split
(
': '
)
self
.
headers
[
key
]
=
value
.
strip
(
)
key
,
value
=
line
.
split
(
b
(
': '
),
1
)
self
.
headers
[
u
(
key
)]
=
u
(
value
.
strip
()
)
for
line
in
fp
:
self
.
_body
+=
line
fp
.
close
()
...
...
@@ -91,10 +77,10 @@ class CachedResponse(object):
fp
=
open
(
filepath
,
'wb'
)
# when it uses file:// scheme, code is None and there is no msg attr
# but it has been successfully opened
status
=
'%s %s'
%
(
getattr
(
response
,
'code'
,
200
)
or
200
,
getattr
(
response
,
'msg'
,
'OK'
))
headers
=
[
'%s: %s'
%
(
key
,
value
)
for
key
,
value
in
response
.
headers
.
items
(
)]
status
=
b
(
'%s %s'
%
(
getattr
(
response
,
'code'
,
200
)
or
200
,
getattr
(
response
,
'msg'
,
'OK'
)
))
headers
=
[
b
(
'%s: %s'
%
(
key
,
value
))
for
key
,
value
in
list
(
response
.
headers
.
items
()
)]
body
=
response
.
read
()
fp
.
write
(
'
\n
'
.
join
([
status
]
+
headers
+
[
''
,
body
]))
fp
.
write
(
b
(
'
\n
'
).
join
([
status
]
+
headers
+
[
b
(
''
)
,
body
]))
fp
.
close
()
...
...
@@ -111,29 +97,33 @@ class PyPIProxy(object):
def
_monkey_patch_urllib2_to_cache_everything
(
self
):
def
urlopen
(
url
):
return
CachedResponse
(
url
,
self
.
CACHE_PATH
)
urllib2
.
urlopen
=
urlopen
pip
.
backwardcompat
.
urllib2
.
urlopen
=
urlopen
def
_create_cache_folder
(
self
):
if
not
os
.
path
.
exists
(
self
.
CACHE_PATH
):
os
.
mkdir
(
self
.
CACHE_PATH
)
def
assert_equal
(
a
,
b
):
assert
a
==
b
,
"
\n
expected:
\n
%r
\n
got:
\n
%r"
%
(
b
,
a
)
def
test_cache_proxy
():
url
=
'http://example.com'
here
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
filepath
=
os
.
path
.
join
(
here
,
urllib
.
quote
(
url
,
''
))
if
os
.
path
.
exists
(
filepath
):
os
.
remove
(
filepath
)
response
=
urllib2
.
urlopen
(
url
)
response
=
pip
.
backwardcompat
.
urllib2
.
urlopen
(
url
)
r
=
CachedResponse
(
url
,
here
)
try
:
assert
r
.
code
==
response
.
code
assert
r
.
msg
==
response
.
msg
assert
r
.
read
()
==
response
.
read
(
)
assert
r
.
url
==
response
.
url
assert
r
.
geturl
()
==
response
.
geturl
(
)
assert
r
.
headers
.
keys
()
==
response
.
headers
.
keys
(
)
assert
r
.
info
().
keys
()
==
response
.
info
().
keys
(
)
assert
r
.
headers
[
'content-length'
]
==
response
.
headers
[
'content-length'
]
assert
_equal
(
r
.
code
,
response
.
code
)
assert
_equal
(
r
.
msg
,
response
.
msg
)
assert
_equal
(
r
.
read
(),
response
.
read
()
)
assert
_equal
(
r
.
url
,
response
.
url
)
assert
_equal
(
r
.
geturl
(),
response
.
geturl
()
)
assert
_equal
(
set
(
r
.
headers
.
keys
()),
set
(
response
.
headers
.
keys
())
)
assert
_equal
(
set
(
r
.
info
().
keys
()),
set
(
response
.
info
().
keys
())
)
assert
_equal
(
r
.
headers
[
'content-length'
],
response
.
headers
[
'content-length'
])
finally
:
os
.
remove
(
filepath
)
tests/test_all_pip.py
浏览文件 @
f903eb0d
import
urllib2
import
re
import
sys
import
os
import
subprocess
import
shutil
from
pip.backwardcompat
import
urllib
from
os.path
import
dirname
,
abspath
...
...
@@ -11,7 +11,7 @@ src_folder = dirname(dirname(abspath(__file__)))
def
all_projects
():
data
=
urllib
2
.
urlopen
(
'http://pypi.python.org/simple/'
).
read
()
data
=
urllib
.
urlopen
(
'http://pypi.python.org/simple/'
).
read
()
projects
=
[
m
.
group
(
1
)
for
m
in
re
.
finditer
(
r
'<a.*?>(.+)</a>'
,
data
)]
return
projects
...
...
@@ -20,60 +20,60 @@ def main(args=None):
if
args
is
None
:
args
=
sys
.
argv
[
1
:]
if
not
args
:
print
'Usage: test_all_pip.py <output-dir>'
print
(
'Usage: test_all_pip.py <output-dir>'
)
sys
.
exit
(
1
)
output
=
os
.
path
.
abspath
(
args
[
0
])
if
not
os
.
path
.
exists
(
output
):
print
'Creating %s'
%
output
print
(
'Creating %s'
%
output
)
os
.
makedirs
(
output
)
pending_fn
=
os
.
path
.
join
(
output
,
'pending.txt'
)
if
not
os
.
path
.
exists
(
pending_fn
):
print
'Downloading pending list'
print
(
'Downloading pending list'
)
projects
=
all_projects
()
print
'Found %s projects'
%
len
(
projects
)
print
(
'Found %s projects'
%
len
(
projects
)
)
f
=
open
(
pending_fn
,
'w'
)
for
name
in
projects
:
f
.
write
(
name
+
'
\n
'
)
f
.
close
()
print
'Starting testing...'
print
(
'Starting testing...'
)
while
os
.
stat
(
pending_fn
).
st_size
:
_test_packages
(
output
,
pending_fn
)
print
'Finished all pending!'
print
(
'Finished all pending!'
)
def
_test_packages
(
output
,
pending_fn
):
package
=
get_last_item
(
pending_fn
)
print
'Testing package %s'
%
package
print
(
'Testing package %s'
%
package
)
dest_dir
=
os
.
path
.
join
(
output
,
package
)
print
'Creating virtualenv in %s'
%
dest_dir
print
(
'Creating virtualenv in %s'
%
dest_dir
)
create_venv
(
dest_dir
)
print
'Uninstalling actual pip'
print
(
'Uninstalling actual pip'
)
code
=
subprocess
.
check_call
([
os
.
path
.
join
(
dest_dir
,
'bin'
,
'pip'
),
'uninstall'
,
'-y'
,
'pip'
])
assert
not
code
,
'pip uninstallation failed'
print
'Installing development pip'
print
(
'Installing development pip'
)
code
=
subprocess
.
check_call
([
os
.
path
.
join
(
dest_dir
,
'bin'
,
'python'
),
'setup.py'
,
'install'
],
cwd
=
src_folder
)
assert
not
code
,
'pip installation failed'
print
'Trying installation of %s'
%
dest_dir
print
(
'Trying installation of %s'
%
dest_dir
)
code
=
subprocess
.
check_call
([
os
.
path
.
join
(
dest_dir
,
'bin'
,
'pip'
),
'install'
,
package
])
if
code
:
print
'Installation of %s failed'
%
package
print
'Now checking easy_install...'
print
(
'Installation of %s failed'
%
package
)
print
(
'Now checking easy_install...'
)
create_venv
(
dest_dir
)
code
=
subprocess
.
check_call
([
os
.
path
.
join
(
dest_dir
,
'bin'
,
'easy_install'
),
package
])
if
code
:
print
'easy_install also failed'
print
(
'easy_install also failed'
)
add_package
(
os
.
path
.
join
(
output
,
'easy-failure.txt'
),
package
)
else
:
print
'easy_install succeeded'
print
(
'easy_install succeeded'
)
add_package
(
os
.
path
.
join
(
output
,
'failure.txt'
),
package
)
pop_last_item
(
pending_fn
,
package
)
else
:
print
'Installation of %s succeeded'
%
package
print
(
'Installation of %s succeeded'
%
package
)
add_package
(
os
.
path
.
join
(
output
,
'success.txt'
),
package
)
pop_last_item
(
pending_fn
,
package
)
shutil
.
rmtree
(
dest_dir
)
...
...
tests/test_basic.py
浏览文件 @
f903eb0d
...
...
@@ -4,10 +4,10 @@ import filecmp
import
textwrap
import
sys
from
os.path
import
abspath
,
join
,
curdir
,
pardir
from
test
_pip
import
here
,
reset_env
,
run_pip
,
pyversion
,
mkdir
,
src_folder
,
write_file
from
local_repos
import
local_checkout
from
path
import
Path
from
test
s.test_pip
import
(
here
,
reset_env
,
run_pip
,
pyversion
,
mkdir
,
src_folder
,
write_file
)
from
tests.local_repos
import
local_checkout
from
tests.path
import
Path
def
test_correct_pip_version
():
"""
...
...
@@ -47,10 +47,10 @@ def test_pip_second_command_line_interface_works():
assert
initools_folder
in
result
.
files_created
,
str
(
result
)
def
test_distutils_configuration_setting
():
"""
Test the distutils-configuration-setting command (which is distinct from other commands).
"""
#
def test_distutils_configuration_setting():
#
"""
#
Test the distutils-configuration-setting command (which is distinct from other commands).
#
"""
#print run_pip('-vv', '--distutils-cfg=easy_install:index_url:http://download.zope.org/ppix/', expect_error=True)
#Script result: python ../../poacheggs.py -E .../poacheggs-tests/test-scratch -vv --distutils-cfg=easy_install:index_url:http://download.zope.org/ppix/
#-- stdout: --------------------
...
...
@@ -213,10 +213,11 @@ def test_install_editable_from_git():
Test cloning from Git.
"""
reset_env
()
result
=
run_pip
(
'install'
,
'-e'
,
'%s#egg=django-feedutil'
%
local_checkout
(
'git+http://github.com/jezdez/django-feedutil.git'
),
expect_error
=
True
)
args
=
[
'install'
]
args
.
extend
([
'-e'
,
'%s#egg=django-feedutil'
%
local_checkout
(
'git+http://github.com/jezdez/django-feedutil.git'
)])
result
=
run_pip
(
*
args
,
**
{
"expect_error"
:
True
})
result
.
assert_installed
(
'django-feedutil'
,
with_files
=
[
'.git'
])
...
...
@@ -312,7 +313,7 @@ if sys.version_info < (2, 6):
"""
Test --user option on older Python versions (pre 2.6) fails intelligibly
"""
env
=
reset_env
()
reset_env
()
run_from
=
abspath
(
join
(
here
,
'packages'
,
'FSPkg'
))
result
=
run_pip
(
'install'
,
'--user'
,
curdir
,
cwd
=
run_from
,
expect_error
=
True
)
assert
'--user is only supported in Python version 2.6 and newer'
in
result
.
stdout
...
...
@@ -322,9 +323,7 @@ else:
"""
Test installing current directory ('.') into usersite
"""
env
=
reset_env
()
# expect error because distribute tries to patch setuptools
env
.
run
(
'easy_install'
,
'distribute'
,
expect_error
=
True
)
env
=
reset_env
(
use_distribute
=
True
)
run_from
=
abspath
(
join
(
here
,
'packages'
,
'FSPkg'
))
result
=
run_pip
(
'install'
,
'--user'
,
curdir
,
cwd
=
run_from
,
expect_error
=
False
)
fspkg_folder
=
env
.
user_site
/
'fspkg'
...
...
@@ -333,13 +332,11 @@ else:
assert
egg_info_folder
in
result
.
files_created
,
str
(
result
)
def
test_install_subversion_usersite_editable_with_distribute
():
def
test_install_subversion_usersite_editable_with_distribute
():
# VMS fails because abiflags not in environment
"""
Test installing current directory ('.') into usersite after installing distribute
"""
env
=
reset_env
()
# expect error because distribute tries to patch setuptools
env
.
run
(
'easy_install'
,
'distribute'
,
expect_error
=
True
)
env
=
reset_env
(
use_distribute
=
True
)
(
env
.
lib_path
/
'no-global-site-packages.txt'
).
rm
()
# this one reenables user_site
result
=
run_pip
(
'install'
,
'--user'
,
'-e'
,
...
...
@@ -348,18 +345,20 @@ else:
result
.
assert_installed
(
'INITools'
,
use_user_site
=
True
)
def
test_install_subversion_usersite_editable_with_setuptools_fails
():
"""
Test installing current directory ('.') into usersite using setuptools
"""
env
=
reset_env
()
(
env
.
lib_path
/
'no-global-site-packages.txt'
).
rm
()
# this one reenables user_site
if
sys
.
version_info
<
(
3
,):
# We don't try to use setuptools for 3.X.
def
test_install_subversion_usersite_editable_with_setuptools_fails
():
"""
Test installing current directory ('.') into usersite using setuptools
"""
env
=
reset_env
()
(
env
.
lib_path
/
'no-global-site-packages.txt'
).
rm
()
# this one reenables user_site
result
=
run_pip
(
'install'
,
'--user'
,
'-e'
,
'%s#egg=initools-dev'
%
local_checkout
(
'svn+http://svn.colorstudy.com/INITools/trunk'
),
expect_error
=
True
)
assert
'--user --editable not supported with setuptools, use distribute'
in
result
.
stdout
result
=
run_pip
(
'install'
,
'--user'
,
'-e'
,
'%s#egg=initools-dev'
%
local_checkout
(
'svn+http://svn.colorstudy.com/INITools/trunk'
),
expect_error
=
True
)
assert
'--user --editable not supported with setuptools, use distribute'
in
result
.
stdout
def
test_install_pardir
():
"""
...
...
@@ -390,7 +389,7 @@ def test_install_with_pax_header():
"""
reset_env
()
run_from
=
abspath
(
join
(
here
,
'packages'
))
r
esult
=
r
un_pip
(
'install'
,
'paxpkg.tar.bz2'
,
cwd
=
run_from
)
run_pip
(
'install'
,
'paxpkg.tar.bz2'
,
cwd
=
run_from
)
def
test_install_using_install_option_and_editable
():
"""
...
...
@@ -399,8 +398,9 @@ def test_install_using_install_option_and_editable():
env
=
reset_env
()
folder
=
'script_folder'
mkdir
(
folder
)
url
=
'git+git://github.com/pypa/virtualenv'
result
=
run_pip
(
'install'
,
'-e'
,
'%s#egg=virtualenv'
%
local_checkout
(
'hg+http://bitbucket.org/ianb/virtualenv'
),
local_checkout
(
url
),
'--install-option=--script-dir=%s'
%
folder
)
virtualenv_bin
=
env
.
venv
/
'src'
/
'virtualenv'
/
folder
/
'virtualenv'
+
env
.
exe
assert
virtualenv_bin
in
result
.
files_created
...
...
@@ -411,10 +411,11 @@ def test_install_global_option_using_editable():
Test using global distutils options, but in an editable installation
"""
reset_env
()
url
=
'hg+http://bitbucket.org/runeh/anyjson'
result
=
run_pip
(
'install'
,
'--global-option=--version'
,
'-e'
,
'%s
#egg=virtualenv
'
%
local_checkout
(
'hg+http://bitbucket.org/ianb/virtualenv@1.4.1'
))
assert
'
1.4.1
\n
'
in
result
.
stdout
'-e'
,
'%s
@0.2.5#egg=anyjson
'
%
local_checkout
(
url
))
assert
'
0.2.5
\n
'
in
result
.
stdout
def
test_install_package_with_same_name_in_curdir
():
...
...
@@ -475,7 +476,7 @@ def test_install_folder_using_relative_path():
def
test_install_package_which_contains_dev_in_name
():
"""
Test installing package from pypi w
it
ch contains 'dev' in name
Test installing package from pypi w
hi
ch contains 'dev' in name
"""
env
=
reset_env
()
result
=
run_pip
(
'install'
,
'django-devserver==0.0.4'
)
...
...
tests/test_bundle.py
浏览文件 @
f903eb0d
...
...
@@ -2,9 +2,9 @@ import zipfile
import
textwrap
from
os.path
import
join
from
pip.download
import
path_to_url2
from
test_pip
import
here
,
reset_env
,
run_pip
,
write_file
from
path
import
Path
from
local_repos
import
local_checkout
from
test
s.test
_pip
import
here
,
reset_env
,
run_pip
,
write_file
from
tests.
path
import
Path
from
tests.
local_repos
import
local_checkout
def
test_create_bundle
():
...
...
tests/test_cleanup.py
浏览文件 @
f903eb0d
import
os
import
textwrap
from
os.path
import
abspath
,
exists
,
join
from
test
_pip
import
here
,
reset_env
,
run_pip
,
write_file
,
mkdir
from
local_repos
import
local_checkout
from
path
import
Path
from
test
s.test_pip
import
(
here
,
reset_env
,
run_pip
,
write_file
,
mkdir
,
pyversion
)
from
tests.local_repos
import
local_checkout
from
tests.path
import
Path
def
test_cleanup_after_install_from_pypi
():
"""
...
...
@@ -49,7 +49,6 @@ def test_cleanup_after_install_from_local_directory():
assert
not
exists
(
build
),
"unexpected build/ dir exists: %s"
%
build
assert
not
exists
(
src
),
"unexpected src/ dir exist: %s"
%
src
def
test_cleanup_after_create_bundle
():
"""
Test clean up after making a bundle. Make sure (build|src)-bundle/ dirs are removed but not src/.
...
...
@@ -57,9 +56,11 @@ def test_cleanup_after_create_bundle():
"""
env
=
reset_env
()
# Install an editable to create a src/ dir.
run_pip
(
'install'
,
'-e'
,
'%s#egg=django-feedutil'
%
local_checkout
(
'git+http://github.com/jezdez/django-feedutil.git'
))
args
=
[
'install'
]
args
.
extend
([
'-e'
,
'%s#egg=django-feedutil'
%
local_checkout
(
'git+http://github.com/jezdez/django-feedutil.git'
)])
run_pip
(
*
args
)
build
=
env
.
venv_path
/
"build"
src
=
env
.
venv_path
/
"src"
assert
not
exists
(
build
),
"build/ dir still exists: %s"
%
build
...
...
tests/test_compat.py
浏览文件 @
f903eb0d
...
...
@@ -3,7 +3,7 @@ Tests for compatibility workarounds.
"""
import
os
from
test_pip
import
reset_env
,
run_pip
,
pyversion
,
assert_all_changes
from
test
s.test
_pip
import
reset_env
,
run_pip
,
pyversion
,
assert_all_changes
def
test_debian_egg_name_workaround
():
...
...
tests/test_completion.py
浏览文件 @
f903eb0d
import
os
from
test_pip
import
reset_env
,
run_pip
,
get_env
from
test
s.test
_pip
import
reset_env
,
run_pip
,
get_env
def
test_completion_for_bash
():
...
...
tests/test_config.py
浏览文件 @
f903eb0d
import
os
import
tempfile
import
textwrap
from
test_pip
import
reset_env
,
run_pip
,
clear_environ
,
write_file
from
test
s.test
_pip
import
reset_env
,
run_pip
,
clear_environ
,
write_file
def
test_options_from_env_vars
():
...
...
@@ -58,9 +58,9 @@ def test_command_line_appends_correctly():
environ
[
'PIP_FIND_LINKS'
]
=
'http://pypi.pinaxproject.com http://example.com'
reset_env
(
environ
)
result
=
run_pip
(
'install'
,
'-vvv'
,
'INITools'
,
expect_error
=
True
)
print
result
.
stdout
assert
"Analyzing links from page http://pypi.pinaxproject.com"
in
result
.
stdout
assert
"Analyzing links from page http://example.com"
in
result
.
stdout
assert
"Analyzing links from page http://pypi.pinaxproject.com"
in
result
.
stdout
,
result
.
stdout
assert
"Analyzing links from page http://example.com"
in
result
.
stdout
,
result
.
stdout
def
test_config_file_override_stack
():
...
...
tests/test_download.py
浏览文件 @
f903eb0d
import
textwrap
from
test_pip
import
reset_env
,
run_pip
,
write_file
from
path
import
Path
from
test
s.test
_pip
import
reset_env
,
run_pip
,
write_file
from
tests.
path
import
Path
def
test_download_if_requested
():
...
...
tests/test_file_scheme_index.py
浏览文件 @
f903eb0d
import
urllib
from
test_pip
import
here
,
reset_env
,
run_pip
,
pyversion
from
path
import
Path
from
pip.backwardcompat
import
urllib
from
test
s.test
_pip
import
here
,
reset_env
,
run_pip
,
pyversion
from
tests.
path
import
Path
index_url
=
'file://'
+
urllib
.
quote
(
str
(
Path
(
here
).
abspath
/
'in dex'
).
replace
(
'
\\
'
,
'/'
))
...
...
tests/test_freeze.py
浏览文件 @
f903eb0d
...
...
@@ -2,8 +2,8 @@ import sys
import
re
import
textwrap
from
doctest
import
OutputChecker
,
ELLIPSIS
from
test
_pip
import
reset_env
,
run_pip
,
write_file
,
get_env
from
local_repos
import
local_checkout
,
local_repo
from
test
s.test_pip
import
reset_env
,
run_pip
,
write_file
,
get_env
,
pyversion
from
tests.
local_repos
import
local_checkout
,
local_repo
distribute_re
=
re
.
compile
(
'^distribute==[0-9.]+
\n
'
,
re
.
MULTILINE
)
...
...
@@ -32,8 +32,7 @@ def _check_output(result, expected):
return
'
\n
========== %s ==========
\n
'
%
msg
assert
checker
.
check_output
(
expected
,
actual
,
ELLIPSIS
),
banner
(
'EXPECTED'
)
+
expected
+
banner
(
'ACTUAL'
)
+
actual
+
banner
(
6
*
'='
)
def
test_freeze
():
def
test_freeze_basic
():
"""
Some tests of freeze, first we have to install some stuff. Note that
the test is a little crude at the end because Python 2.5+ adds egg
...
...
@@ -41,15 +40,12 @@ def test_freeze():
the freezing. (Probably that should be accounted for in pip, but
currently it is not).
TODO: refactor this test into multiple tests? (and maybe different
test style instead of using doctest output checker)
"""
env
=
reset_env
()
write_file
(
'initools-req.txt'
,
textwrap
.
dedent
(
"""
\
INITools==0.2
# and something else to test out:
simplejson<=1.7.4
MarkupSafe<=0.12
"""
))
result
=
run_pip
(
'install'
,
'-r'
,
env
.
scratch_path
/
'initools-req.txt'
)
result
=
run_pip
(
'freeze'
,
expect_stderr
=
True
)
...
...
@@ -57,11 +53,13 @@ def test_freeze():
Script result: pip freeze
-- stdout: --------------------
INITools==0.2
simplejson==1.7.4
...
MarkupSafe==0.12
...
<BLANKLINE>"""
)
_check_output
(
result
,
expected
)
# Now lets try it with an svn checkout::
def
test_freeze_svn
():
"""Now lets try it with an svn checkout"""
env
=
reset_env
()
result
=
env
.
run
(
'svn'
,
'co'
,
'-r10'
,
local_repo
(
'svn+http://svn.colorstudy.com/INITools/trunk'
),
'initools-trunk'
)
...
...
@@ -71,42 +69,8 @@ def test_freeze():
expected
=
textwrap
.
dedent
(
"""
\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@10#egg=INITools-0.3.1dev_r10-py2...-dev_r10
simplejson==1.7.4...
<BLANKLINE>"""
%
local_checkout
(
'svn+http://svn.colorstudy.com/INITools/trunk'
))
_check_output
(
result
,
expected
)
# Now, straight from trunk (but not editable/setup.py develop)::
result
=
env
.
run
(
'svn'
,
'co'
,
local_repo
(
'svn+http://svn.colorstudy.com/INITools/trunk'
),
'initools_to_easy_install'
)
result
=
env
.
run
(
'easy_install'
,
env
.
scratch_path
/
'initools_to_easy_install'
)
result
=
run_pip
(
'freeze'
,
expect_stderr
=
True
)
expected
=
textwrap
.
dedent
(
"""
\
Script result: ...pip freeze
-- stderr: --------------------
Warning: cannot find svn location for INITools==...dev-r...
<BLANKLINE>
-- stdout: --------------------
## FIXME: could not find svn URL in dependency_links for this package:
INITools==...dev-r...
simplejson==1.7.4...
<BLANKLINE>"""
)
_check_output
(
result
,
expected
)
# Bah, that's no good! Let's give it a hint::
result
=
run_pip
(
'freeze'
,
'-f'
,
'%s#egg=INITools-dev'
%
local_checkout
(
'svn+http://svn.colorstudy.com/INITools/trunk'
),
expect_stderr
=
True
)
expected
=
textwrap
.
dedent
(
"""
\
Script result: ...pip freeze -f %(repo)s#egg=INITools-dev
-- stdout: --------------------
-f %(repo)s#egg=INITools-dev
# Installing as editable to satisfy requirement INITools==...dev-r...:
-e %(repo)s@...#egg=INITools-...dev_r...
simplejson==1.7.4...
<BLANKLINE>"""
%
{
'repo'
:
local_checkout
(
'svn+http://svn.colorstudy.com/INITools/trunk'
)})
-e %s@10#egg=INITools-0.3.1dev_r10-py...-dev_r10
..."""
%
local_checkout
(
'svn+http://svn.colorstudy.com/INITools/trunk'
))
_check_output
(
result
,
expected
)
...
...
tests/test_pip.py
浏览文件 @
f903eb0d
...
...
@@ -6,9 +6,8 @@ import shutil
import
glob
import
atexit
import
textwrap
import
urllib
from
scripttest
import
TestFileEnvironment
from
path
import
Path
,
curdir
from
tests.path
import
Path
,
curdir
,
u
pyversion
=
sys
.
version
[:
3
]
...
...
@@ -81,7 +80,7 @@ except NameError:
def
clear_environ
(
environ
):
return
dict
(((
k
,
v
)
for
k
,
v
in
environ
.
ite
rite
ms
()
return
dict
(((
k
,
v
)
for
k
,
v
in
environ
.
items
()
if
not
k
.
lower
().
startswith
(
'pip_'
)))
...
...
@@ -103,9 +102,13 @@ def install_setuptools(env):
env
=
None
def
reset_env
(
environ
=
None
):
def
reset_env
(
environ
=
None
,
use_distribute
=
None
):
global
env
env
=
TestPipEnvironment
(
environ
)
# FastTestPipEnv reuses env, not safe if use_distribute specified
if
use_distribute
is
None
:
env
=
FastTestPipEnvironment
(
environ
)
else
:
env
=
TestPipEnvironment
(
environ
,
use_distribute
=
use_distribute
)
return
env
...
...
@@ -137,11 +140,11 @@ class TestPipResult(object):
self
.
_impl
=
impl
if
verbose
:
print
self
.
stdout
print
(
self
.
stdout
)
if
self
.
stderr
:
print
'======= stderr ========'
print
self
.
stderr
print
'======================='
print
(
'======= stderr ========'
)
print
(
self
.
stderr
)
print
(
'======================='
)
def
__getattr__
(
self
,
attr
):
return
getattr
(
self
.
_impl
,
attr
)
...
...
@@ -187,15 +190,15 @@ class TestPipResult(object):
if
not
(
# FIXME: I don't understand why there's a trailing . here
egg_link_file
.
bytes
.
endswith
(
'.'
)
and
egg_link_file
.
bytes
[:
-
1
].
strip
().
endswith
(
pkg_dir
)):
raise
TestFailure
(
textwrap
.
dedent
(
u
'''
\
raise
TestFailure
(
textwrap
.
dedent
(
u
(
'''
\
Incorrect egg_link file %r
Expected ending: %r
------- Actual contents -------
%s
-------------------------------'''
%
(
egg_link_file
,
pkg_dir
+
u
'
\n
.'
,
egg_link_file
.
bytes
)))
pkg_dir
+
u
(
'
\n
.'
)
,
egg_link_file
.
bytes
)))
)
if
use_user_site
:
pth_file
=
Path
.
string
(
e
.
user_site
/
'easy-install.pth'
)
...
...
@@ -256,7 +259,7 @@ class TestPipEnvironment(TestFileEnvironment):
verbose
=
False
def
__init__
(
self
,
environ
=
None
):
def
__init__
(
self
,
environ
=
None
,
use_distribute
=
None
):
self
.
root_path
=
Path
(
tempfile
.
mkdtemp
(
'-piptest'
))
...
...
@@ -268,7 +271,7 @@ class TestPipEnvironment(TestFileEnvironment):
if
not
environ
:
environ
=
os
.
environ
.
copy
()
environ
=
clear_environ
(
environ
)
environ
[
'PIP_DOWNLOAD_CACHE'
]
=
download_cache
environ
[
'PIP_DOWNLOAD_CACHE'
]
=
str
(
download_cache
)
environ
[
'PIP_NO_INPUT'
]
=
'1'
environ
[
'PIP_LOG_FILE'
]
=
str
(
self
.
root_path
/
'pip-log.txt'
)
...
...
@@ -281,7 +284,8 @@ class TestPipEnvironment(TestFileEnvironment):
demand_dirs
(
self
.
venv_path
)
demand_dirs
(
self
.
scratch_path
)
use_distribute
=
os
.
environ
.
get
(
'PIP_TEST_USE_DISTRIBUTE'
,
False
)
if
use_distribute
is
None
:
use_distribute
=
os
.
environ
.
get
(
'PIP_TEST_USE_DISTRIBUTE'
,
False
)
# Create a virtualenv and remember where it's putting things.
virtualenv_paths
=
create_virtualenv
(
self
.
venv_path
,
distribute
=
use_distribute
)
...
...
@@ -309,7 +313,7 @@ class TestPipEnvironment(TestFileEnvironment):
self
.
environ
[
'PATH'
]
=
Path
.
pathsep
.
join
((
self
.
bin_path
,
self
.
environ
[
'PATH'
]))
# test that test-scratch virtualenv creation produced sensible venv python
result
=
self
.
run
(
'python'
,
'-c'
,
'import sys; print
sys.executable
'
)
result
=
self
.
run
(
'python'
,
'-c'
,
'import sys; print
(sys.executable)
'
)
pythonbin
=
result
.
stdout
.
strip
()
if
Path
(
pythonbin
).
noext
!=
self
.
bin_path
/
'python'
:
...
...
@@ -325,16 +329,23 @@ class TestPipEnvironment(TestFileEnvironment):
# Earlier versions of pip were incapable of
# self-uninstallation on Windows, so we use the one we're testing.
self
.
run
(
'python'
,
'-c'
,
'
import sys;sys.path.insert(0, %r);import pip;sys.exit(pip.main());
'
%
os
.
path
.
dirname
(
here
),
'
"import sys; sys.path.insert(0, %r); import pip; sys.exit(pip.main());"
'
%
os
.
path
.
dirname
(
here
),
'uninstall'
,
'-vvv'
,
'-y'
,
'pip'
)
# Install this version instead
self
.
run
(
'python'
,
'setup.py'
,
'install'
,
cwd
=
src_folder
,
expect_stderr
=
True
)
self
.
_use_cached_pypi_server
()
def
_ignore_file
(
self
,
fn
):
if
fn
.
endswith
(
'__pycache__'
):
result
=
True
else
:
result
=
super
(
TestPipEnvironment
,
self
).
_ignore_file
(
fn
)
return
result
def
run
(
self
,
*
args
,
**
kw
):
if
self
.
verbose
:
print
'>> running'
,
args
,
kw
print
(
'>> running %s %s'
%
(
args
,
kw
))
cwd
=
kw
.
pop
(
'cwd'
,
None
)
run_from
=
kw
.
pop
(
'run_from'
,
None
)
assert
not
cwd
or
not
run_from
,
"Don't use run_from; it's going away"
...
...
@@ -355,8 +366,109 @@ class TestPipEnvironment(TestFileEnvironment):
pth
.
close
()
class
FastTestPipEnvironment
(
TestPipEnvironment
):
def
__init__
(
self
,
environ
=
None
):
import
virtualenv
self
.
root_path
=
here
/
'tests_cache'
/
'test_ws'
self
.
backup_path
=
here
/
'tests_cache'
/
'test_ws_backup'
self
.
scratch_path
=
self
.
root_path
/
self
.
scratch
# We will set up a virtual environment at root_path.
self
.
venv_path
=
self
.
root_path
/
self
.
venv
if
not
environ
:
environ
=
os
.
environ
.
copy
()
environ
=
clear_environ
(
environ
)
environ
[
'PIP_DOWNLOAD_CACHE'
]
=
str
(
download_cache
)
environ
[
'PIP_NO_INPUT'
]
=
'1'
environ
[
'PIP_LOG_FILE'
]
=
str
(
self
.
root_path
/
'pip-log.txt'
)
TestFileEnvironment
.
__init__
(
self
,
self
.
root_path
,
ignore_hidden
=
False
,
environ
=
environ
,
split_cmd
=
False
,
start_clear
=
False
,
cwd
=
self
.
scratch_path
,
capture_temp
=
True
,
assert_no_temp
=
True
)
virtualenv_paths
=
virtualenv
.
path_locations
(
self
.
venv_path
)
for
id
,
path
in
zip
((
'venv'
,
'lib'
,
'include'
,
'bin'
),
virtualenv_paths
):
setattr
(
self
,
id
+
'_path'
,
Path
(
path
))
setattr
(
self
,
id
,
relpath
(
self
.
root_path
,
path
))
assert
self
.
venv
==
TestPipEnvironment
.
venv
# sanity check
self
.
site_packages
=
self
.
lib
/
'site-packages'
self
.
user_base_path
=
self
.
venv_path
/
'user'
self
.
user_site_path
=
self
.
venv_path
/
'user'
/
'lib'
/
self
.
lib
.
name
/
'site-packages'
self
.
user_site
=
relpath
(
self
.
root_path
,
self
.
user_site_path
)
self
.
environ
[
"PYTHONUSERBASE"
]
=
self
.
user_base_path
# put the test-scratch virtualenv's bin dir first on the PATH
self
.
environ
[
'PATH'
]
=
Path
.
pathsep
.
join
((
self
.
bin_path
,
self
.
environ
[
'PATH'
]))
if
self
.
root_path
.
exists
:
shutil
.
rmtree
(
self
.
root_path
)
if
self
.
backup_path
.
exists
:
shutil
.
copytree
(
self
.
backup_path
,
self
.
root_path
,
True
)
else
:
demand_dirs
(
self
.
venv_path
)
demand_dirs
(
self
.
scratch_path
)
use_distribute
=
os
.
environ
.
get
(
'PIP_TEST_USE_DISTRIBUTE'
,
False
)
# Create a virtualenv and remember where it's putting things.
create_virtualenv
(
self
.
venv_path
,
distribute
=
use_distribute
)
demand_dirs
(
self
.
user_site_path
)
# create easy-install.pth in user_site, so we always have it updated instead of created
open
(
self
.
user_site_path
/
'easy-install.pth'
,
'w'
).
close
()
# test that test-scratch virtualenv creation produced sensible venv python
result
=
self
.
run
(
'python'
,
'-c'
,
'import sys; print(sys.executable)'
)
pythonbin
=
result
.
stdout
.
strip
()
if
Path
(
pythonbin
).
noext
!=
self
.
bin_path
/
'python'
:
raise
RuntimeError
(
"Oops! 'python' in our test environment runs %r"
" rather than expected %r"
%
(
pythonbin
,
self
.
bin_path
/
'python'
))
# make sure we have current setuptools to avoid svn incompatibilities
if
not
use_distribute
:
install_setuptools
(
self
)
# Uninstall whatever version of pip came with the virtualenv.
# Earlier versions of pip were incapable of
# self-uninstallation on Windows, so we use the one we're testing.
self
.
run
(
'python'
,
'-c'
,
'"import sys; sys.path.insert(0, %r); import pip; sys.exit(pip.main());"'
%
os
.
path
.
dirname
(
here
),
'uninstall'
,
'-vvv'
,
'-y'
,
'pip'
)
# Install this version instead
self
.
run
(
'python'
,
'setup.py'
,
'install'
,
cwd
=
src_folder
,
expect_stderr
=
True
)
shutil
.
copytree
(
self
.
root_path
,
self
.
backup_path
,
True
)
self
.
_use_cached_pypi_server
()
assert
self
.
root_path
.
exists
def
__del__
(
self
):
pass
# shutil.rmtree(str(self.root_path), ignore_errors=True)
def
run_pip
(
*
args
,
**
kw
):
return
env
.
run
(
'pip'
,
*
args
,
**
kw
)
result
=
env
.
run
(
'pip'
,
*
args
,
**
kw
)
ignore
=
[]
for
path
,
f
in
result
.
files_before
.
items
():
if
path
in
result
.
files_updated
:
full_path
=
env
.
base_path
/
path
s
=
str
(
full_path
)
if
os
.
path
.
isdir
(
s
)
and
'__pycache__'
in
os
.
listdir
(
s
):
ignore
.
append
(
path
)
for
path
in
ignore
:
del
result
.
files_updated
[
path
]
return
result
def
write_file
(
filename
,
text
,
dest
=
None
):
...
...
@@ -452,7 +564,7 @@ def assert_all_changes(start_state, end_state, expected_changes):
end_files
=
end_state
.
files_after
diff
=
diff_states
(
start_files
,
end_files
,
ignore
=
expected_changes
)
if
diff
.
values
(
)
!=
[{},
{},
{}]:
if
list
(
diff
.
values
()
)
!=
[{},
{},
{}]:
raise
TestFailure
(
'Unexpected changes:
\n
'
+
'
\n
'
.
join
(
[
k
+
': '
+
', '
.
join
(
v
.
keys
())
for
k
,
v
in
diff
.
items
()]))
...
...
tests/test_proxy.py
浏览文件 @
f903eb0d
...
...
@@ -13,10 +13,11 @@ import os
import
pip
import
getpass
from
pip.basecommand
import
get_proxy
from
test_pip
import
here
from
tests.test_pip
import
here
def
new_getpass
(
prompt
,
answer
=
'passwd'
):
print
'%s%s'
%
(
prompt
,
answer
)
print
(
'%s%s'
%
(
prompt
,
answer
)
)
return
answer
...
...
tests/test_requirements.py
浏览文件 @
f903eb0d
import
textwrap
from
pip.req
import
Requirements
from
test_pip
import
reset_env
,
run_pip
,
write_file
,
pyversion
from
local_repos
import
local_checkout
from
tests.test_pip
import
reset_env
,
run_pip
,
write_file
,
pyversion
from
tests.local_repos
import
local_checkout
def
test_requirements_file
():
"""
Test installing from a requirements file.
"""
other_lib_name
,
other_lib_version
=
'anyjson'
,
'0.3'
env
=
reset_env
()
write_file
(
'initools-req.txt'
,
textwrap
.
dedent
(
"""
\
INITools==0.2
# and something else to test out:
simplejson<=1.7.4
"""
))
%s<=%s
"""
%
(
other_lib_name
,
other_lib_version
)
))
result
=
run_pip
(
'install'
,
'-r'
,
env
.
scratch_path
/
'initools-req.txt'
)
assert
env
.
site_packages
/
'INITools-0.2-py%s.egg-info'
%
pyversion
in
result
.
files_created
assert
env
.
site_packages
/
'initools'
in
result
.
files_created
assert
result
.
files_created
[
env
.
site_packages
/
'simplejson'
].
dir
assert
result
.
files_created
[
env
.
site_packages
/
'simplejson-1.7.4-py%s.egg-info'
%
pyversion
].
dir
assert
result
.
files_created
[
env
.
site_packages
/
other_lib_name
].
dir
fn
=
'%s-%s-py%s.egg-info'
%
(
other_lib_name
,
other_lib_version
,
pyversion
)
assert
result
.
files_created
[
env
.
site_packages
/
fn
].
dir
def
test_multiple_requirements_files
():
...
...
@@ -27,16 +28,19 @@ def test_multiple_requirements_files():
Test installing from multiple nested requirements files.
"""
other_lib_name
,
other_lib_version
=
'anyjson'
,
'0.3'
env
=
reset_env
()
write_file
(
'initools-req.txt'
,
textwrap
.
dedent
(
"""
\
-e %s@10#egg=INITools-dev
-r simplejson-req.txt"""
%
local_checkout
(
'http://svn.colorstudy.com/INITools/trunk'
)))
write_file
(
'simplejson-req.txt'
,
textwrap
.
dedent
(
"""
\
simplejson<=1.7.4
"""
))
-r %s-req.txt"""
%
(
local_checkout
(
'svn+http://svn.colorstudy.com/INITools/trunk'
),
other_lib_name
)))
write_file
(
'%s-req.txt'
%
other_lib_name
,
textwrap
.
dedent
(
"""
\
%s<=%s
"""
%
(
other_lib_name
,
other_lib_version
)))
result
=
run_pip
(
'install'
,
'-r'
,
env
.
scratch_path
/
'initools-req.txt'
)
assert
result
.
files_created
[
env
.
site_packages
/
'simplejson'
].
dir
assert
result
.
files_created
[
env
.
site_packages
/
'simplejson-1.7.4-py%s.egg-info'
%
pyversion
].
dir
assert
result
.
files_created
[
env
.
site_packages
/
other_lib_name
].
dir
fn
=
'%s-%s-py%s.egg-info'
%
(
other_lib_name
,
other_lib_version
,
pyversion
)
assert
result
.
files_created
[
env
.
site_packages
/
fn
].
dir
assert
env
.
venv
/
'src'
/
'initools'
in
result
.
files_created
...
...
@@ -50,9 +54,9 @@ def test_respect_order_in_requirements_file():
result
=
run_pip
(
'install'
,
'-r'
,
env
.
scratch_path
/
'frameworks-req.txt'
)
downloaded
=
[
line
for
line
in
result
.
stdout
.
split
(
'
\n
'
)
if
'Downloading/unpacking'
in
line
]
assert
'bidict'
in
downloaded
[
0
],
'First download should '
\
'be "bidict" but was "%s"'
%
downloaded
[
0
]
'be "bidict" but was "%s"'
%
downloaded
[
0
]
assert
'ordereddict'
in
downloaded
[
1
],
'Second download should '
\
'be "ordereddict" but was "%s"'
%
downloaded
[
1
]
assert
'mock'
in
downloaded
[
2
],
'Third download should '
\
...
...
@@ -65,8 +69,8 @@ def test_requirements_data_structure_keeps_order():
requirements
[
'nose'
]
=
'nose'
requirements
[
'coverage'
]
=
'coverage'
assert
[
'pip'
,
'nose'
,
'coverage'
]
==
requirements
.
values
(
)
assert
[
'pip'
,
'nose'
,
'coverage'
]
==
requirements
.
keys
(
)
assert
[
'pip'
,
'nose'
,
'coverage'
]
==
list
(
requirements
.
values
()
)
assert
[
'pip'
,
'nose'
,
'coverage'
]
==
list
(
requirements
.
keys
()
)
def
test_requirements_data_structure_implements__repr__
():
requirements
=
Requirements
()
...
...
tests/test_search.py
浏览文件 @
f903eb0d
import
xmlrpclib
import
pip.download
from
pip.commands.search
import
(
compare_versions
,
highest_version
,
transform_hits
,
SearchCommand
,)
from
pip.backwardcompat
import
xmlrpclib
,
b
from
mock
import
Mock
from
test_pip
import
run_pip
,
reset_env
from
tests.test_pip
import
run_pip
,
reset_env
,
pyversion
from
tests.pypi_server
import
assert_equal
if
pyversion
>=
'3'
:
VERBOSE_FALSE
=
False
else
:
VERBOSE_FALSE
=
0
def
test_version_compare
():
...
...
@@ -30,7 +37,7 @@ def test_pypi_xml_transformation():
{
'_pypi_ordering'
:
50
,
'name'
:
'bar'
,
'summary'
:
'bar summary'
,
'version'
:
'1.0'
}]
expected
=
[{
'score'
:
200
,
'versions'
:
[
'1.0'
,
'2.0'
],
'name'
:
'foo'
,
'summary'
:
'foo summary v2'
},
{
'score'
:
50
,
'versions'
:
[
'1.0'
],
'name'
:
'bar'
,
'summary'
:
'bar summary'
}]
assert
expected
==
transform_hits
(
pypi_hits
)
assert
_equal
(
expected
,
transform_hits
(
pypi_hits
)
)
def
test_search
():
...
...
@@ -49,10 +56,10 @@ def test_searching_through_Search_class():
"""
pip
.
download
.
xmlrpclib_transport
=
fake_transport
=
Mock
()
query
=
'mylittlequerythatdoesnotexists'
dumped_xmlrpc_request
=
xmlrpclib
.
dumps
(({
'name'
:
query
,
'summary'
:
query
},
'or'
),
'search'
)
dumped_xmlrpc_request
=
b
(
xmlrpclib
.
dumps
(({
'name'
:
query
,
'summary'
:
query
},
'or'
),
'search'
)
)
expected
=
[{
'_pypi_ordering'
:
100
,
'name'
:
'foo'
,
'summary'
:
'foo summary'
,
'version'
:
'1.0'
}]
fake_transport
.
request
.
return_value
=
(
expected
,)
pypi_searcher
=
SearchCommand
()
result
=
pypi_searcher
.
search
(
query
,
'http://pypi.python.org/pypi'
)
assert
expected
==
result
,
result
fake_transport
.
request
.
assert_called_with
(
'pypi.python.org'
,
'/pypi'
,
dumped_xmlrpc_request
,
verbose
=
0
)
fake_transport
.
request
.
assert_called_with
(
'pypi.python.org'
,
'/pypi'
,
dumped_xmlrpc_request
,
verbose
=
VERBOSE_FALSE
)
tests/test_uninstall.py
浏览文件 @
f903eb0d
...
...
@@ -3,8 +3,8 @@ import sys
import
shutil
from
os.path
import
join
from
tempfile
import
mkdtemp
from
test_pip
import
reset_env
,
run_pip
,
assert_all_changes
,
write_file
from
local_repos
import
local_repo
,
local_checkout
from
test
s.test
_pip
import
reset_env
,
run_pip
,
assert_all_changes
,
write_file
from
tests.
local_repos
import
local_repo
,
local_checkout
def
test_simple_uninstall
():
...
...
@@ -53,9 +53,11 @@ def test_uninstall_console_scripts():
"""
env
=
reset_env
()
result
=
run_pip
(
'install'
,
'virtualenv'
,
expect_error
=
True
)
assert
env
.
bin
/
'virtualenv'
+
env
.
exe
in
result
.
files_created
,
sorted
(
result
.
files_created
.
keys
())
result2
=
run_pip
(
'uninstall'
,
'virtualenv'
,
'-y'
,
expect_error
=
True
)
args
=
[
'install'
]
args
.
append
(
'discover'
)
result
=
run_pip
(
*
args
,
**
{
"expect_error"
:
True
})
assert
env
.
bin
/
'discover'
+
env
.
exe
in
result
.
files_created
,
sorted
(
result
.
files_created
.
keys
())
result2
=
run_pip
(
'uninstall'
,
'discover'
,
'-y'
,
expect_error
=
True
)
assert_all_changes
(
result
,
result2
,
[
env
.
venv
/
'build'
,
'cache'
])
...
...
@@ -65,9 +67,11 @@ def test_uninstall_easy_installed_console_scripts():
"""
env
=
reset_env
()
result
=
env
.
run
(
'easy_install'
,
'virtualenv'
,
expect_stderr
=
True
)
assert
env
.
bin
/
'virtualenv'
+
env
.
exe
in
result
.
files_created
,
sorted
(
result
.
files_created
.
keys
())
result2
=
run_pip
(
'uninstall'
,
'virtualenv'
,
'-y'
)
args
=
[
'easy_install'
]
args
.
append
(
'discover'
)
result
=
env
.
run
(
*
args
,
**
{
"expect_stderr"
:
True
})
assert
env
.
bin
/
'discover'
+
env
.
exe
in
result
.
files_created
,
sorted
(
result
.
files_created
.
keys
())
result2
=
run_pip
(
'uninstall'
,
'discover'
,
'-y'
)
assert_all_changes
(
result
,
result2
,
[
env
.
venv
/
'build'
,
'cache'
])
...
...
@@ -100,9 +104,9 @@ def test_uninstall_editable_with_source_outside_venv():
def
_test_uninstall_editable_with_source_outside_venv
(
tmpdir
):
env
=
reset_env
()
result
=
env
.
run
(
'
hg'
,
'clone'
,
local_repo
(
'hg+http://bitbucket.org/ianb
/virtualenv'
),
tmpdir
)
result
=
env
.
run
(
'
git'
,
'clone'
,
local_repo
(
'git+git://github.com/pypa
/virtualenv'
),
tmpdir
)
result2
=
run_pip
(
'install'
,
'-e'
,
tmpdir
)
assert
(
join
(
env
.
site_packages
,
'virtualenv.egg-link'
)
in
result2
.
files_created
),
result2
.
files_created
.
keys
(
)
assert
(
join
(
env
.
site_packages
,
'virtualenv.egg-link'
)
in
result2
.
files_created
),
list
(
result2
.
files_created
.
keys
()
)
result3
=
run_pip
(
'uninstall'
,
'-y'
,
'virtualenv'
,
expect_error
=
True
)
assert_all_changes
(
result
,
result3
,
[
env
.
venv
/
'build'
])
...
...
tests/test_upgrade.py
浏览文件 @
f903eb0d
import
textwrap
from
test_pip
import
(
here
,
reset_env
,
run_pip
,
assert_all_changes
,
write_file
,
_create_test_package
,
_change_test_package_version
,
pyversion
)
from
os.path
import
join
from
tests.test_pip
import
(
here
,
reset_env
,
run_pip
,
assert_all_changes
,
write_file
,
pyversion
,
_create_test_package
,
_change_test_package_version
)
def
test_no_upgrade_unless_requested
():
...
...
@@ -109,13 +110,12 @@ def test_uninstall_rollback():
"""
env
=
reset_env
()
find_links
=
'file://'
+
here
/
'packages'
find_links
=
'file://'
+
join
(
here
,
'packages'
)
result
=
run_pip
(
'install'
,
'-f'
,
find_links
,
'--no-index'
,
'broken==0.1'
)
assert
env
.
site_packages
/
'broken.py'
in
result
.
files_created
,
result
.
files_created
.
keys
(
)
assert
env
.
site_packages
/
'broken.py'
in
result
.
files_created
,
list
(
result
.
files_created
.
keys
()
)
result2
=
run_pip
(
'install'
,
'-f'
,
find_links
,
'--no-index'
,
'broken==0.2broken'
,
expect_error
=
True
)
assert
result2
.
returncode
==
1
,
str
(
result2
)
env
.
run
(
'python'
,
'-c'
,
"import broken; print broken.VERSION"
).
stdout
'0.1
\n
'
assert
env
.
run
(
'python'
,
'-c'
,
"import broken; print(broken.VERSION)"
).
stdout
==
'0.1
\n
'
assert_all_changes
(
result
.
files_after
,
result2
,
[
env
.
venv
/
'build'
,
'pip-log.txt'
])
...
...
tests/test_vcs_backends.py
浏览文件 @
f903eb0d
from
test
_pip
import
(
reset_env
,
run_pip
,
pyversion
,
from
test
s.test_pip
import
(
reset_env
,
run_pip
,
_create_test_package
,
_change_test_package_version
)
from
local_repos
import
local_checkout
from
tests.local_repos
import
local_checkout
def
test_install_editable_from_git_with_https
():
"""
Test cloning from Git with https.
"""
env
=
reset_env
()
reset_env
()
result
=
run_pip
(
'install'
,
'-e'
,
'%s#egg=django-feedutil'
%
local_checkout
(
'git+https://github.com/jezdez/django-feedutil.git'
),
...
...
@@ -95,7 +94,7 @@ def test_git_with_non_editable_unpacking():
def
test_git_with_editable_where_egg_contains_dev_string
():
"""
Test cloning a git repository from an editable url w
it
ch contains "dev" string
Test cloning a git repository from an editable url w
hi
ch contains "dev" string
"""
reset_env
()
result
=
run_pip
(
'install'
,
'-e'
,
'%s#egg=django-devserver'
%
...
...
@@ -104,7 +103,7 @@ def test_git_with_editable_where_egg_contains_dev_string():
def
test_git_with_non_editable_where_egg_contains_dev_string
():
"""
Test cloning a git repository from a non-editable url w
it
ch contains "dev" string
Test cloning a git repository from a non-editable url w
hi
ch contains "dev" string
"""
env
=
reset_env
()
result
=
run_pip
(
'install'
,
'%s#egg=django-devserver'
%
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录