我尝试创建自己的Pypi存储库,考虑到https://www.python.org/dev/peps/pep-0503/。我的想法是把它放在一个共享目录中(我使用的是Windows),比如host1/my-pypi
。我已经生成了索引.html需要:
(dir) host1\my-pypi
-> (dir) toto
(file) index.html
(file) toto-1.0.0.whl
-> (file) index.html
index.html
文件看起来很正常(与pep-503中的文件相同)。我尝试在另一台计算机上,比如说host2
,它可以访问这个共享目录来安装toto包,方法是:
但是它失败了(当它试图读取带有OSError: [Errno 22] Invalid argument: '\\\\host1\\my-pypi\\'
的文件时)。在
首先,以前有人试过(并解决过)这个问题吗?(这是一个简单的解决方案:-)。在
第二,我对pip的代码进行了一些挖掘,有一些东西我不清楚(如果pip中有专业人士可以回答;-)。在
index.py
,方法find_all_candidates
:它会自动从[file://host1/my-pypi/toto]
更改我的url列表,因此它似乎从不尝试读取host1\my-pypi\index.html
。。。奇怪的?
index.py
,方法get_page
:好吧,点1并没有阻塞我,因为它神奇地匹配了我的架构,但是有一个奇怪的情况:
# Tack index.html onto file:// URLs that point to directories
(scheme, netloc, path, params, query, fragment) = \
urllib_parse.urlparse(url)
if (scheme == 'file' and
os.path.isdir(urllib_request.url2pathname(path))):
# add trailing slash if not present so urljoin doesn't trim
# final segment
if not url.endswith('/'):
url += '/'
url = urllib_parse.urljoin(url, 'index.html')
logger.debug(' file: URL is directory, getting %s', url)
resp = session.get(
url,
headers={
"Accept": "text/html",
"Cache-Control": "max-age=600",
},
)
好吧,正如预期的那样,我们有:
scheme = 'file'
netloc = 'host1'
path = '/my-pypi/'
但是检查条件os.path.isdir(urllib_request.url2pathname(path)))
显然是错误的,因为我们已经放弃了网络位置。因此,index.html
没有附加到路径中(否则是正确的),因此在试图读取不存在的文件时会出现错误。
对于远程UNC文件共享,请使用四个斜杠指定文件URL:
在本例中,解析的
netloc
为空,path
仍包含UNC格式的服务器主机名,因此isdir
工作正常,index.html
将按预期追加。在相关问题 更多 >
编程相关推荐