Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
6797a9d0
Commit
6797a9d0
authored
Nov 14, 2013
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merge support for loading credentials from .pypirc (based on pull request #11). Fixes #27.
parents
e9175087
915b99c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
1 deletion
+72
-1
docs/easy_install.txt
docs/easy_install.txt
+9
-0
setuptools/package_index.py
setuptools/package_index.py
+63
-1
No files found.
docs/easy_install.txt
View file @
6797a9d0
...
...
@@ -486,6 +486,15 @@ You can do this with both index page URLs and direct download URLs. As long
as any HTML pages read by easy_install use *relative* links to point to the
downloads, the same user ID and password will be used to do the downloading.
Using .pypirc Credentials
-------------------------
In additional to supplying credentials in the URL, ``easy_install`` will also
honor credentials if present in the .pypirc file. Teams maintaining a private
repository of packages may already have defined access credentials for
uploading packages according to the distutils documentation. ``easy_install``
will attempt to honor those if present. Refer to the distutils documentation
for Python 2.5 or later for details on the syntax.
Controlling Build Options
~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
setuptools/package_index.py
View file @
6797a9d0
...
...
@@ -17,7 +17,8 @@ from distutils.errors import DistutilsError
from
setuptools.compat
import
(
urllib2
,
httplib
,
StringIO
,
HTTPError
,
urlparse
,
urlunparse
,
unquote
,
splituser
,
url2pathname
,
name2codepoint
,
unichr
,
urljoin
,
urlsplit
,
urlunsplit
)
unichr
,
urljoin
,
urlsplit
,
urlunsplit
,
ConfigParser
)
from
setuptools.compat
import
filterfalse
from
fnmatch
import
translate
from
setuptools.py24compat
import
hashlib
...
...
@@ -920,6 +921,60 @@ def _encode_auth(auth):
# strip the trailing carriage return
return
encoded
.
rstrip
()
class
Credential
(
object
):
"""
A username/password pair. Use like a namedtuple.
"""
def
__init__
(
self
,
username
,
password
):
self
.
username
=
username
self
.
password
=
password
def
__iter__
(
self
):
yield
self
.
username
yield
self
.
password
def
__str__
(
self
):
return
'%(username)s:%(password)s'
%
vars
(
self
)
class
PyPIConfig
(
ConfigParser
.
ConfigParser
):
def
__init__
(
self
):
"""
Load from ~/.pypirc
"""
defaults
=
dict
.
fromkeys
([
'username'
,
'password'
,
'repository'
],
''
)
super
(
PyPIConfig
,
self
).
__init__
(
defaults
)
rc
=
os
.
path
.
join
(
os
.
path
.
expanduser
(
'~'
),
'.pypirc'
)
if
os
.
path
.
exists
(
rc
):
self
.
read
(
rc
)
@
property
def
creds_by_repository
(
self
):
sections_with_repositories
=
[
section
for
section
in
self
.
sections
()
if
self
.
get
(
section
,
'repository'
).
strip
()
]
return
dict
(
map
(
self
.
_get_repo_cred
,
sections_with_repositories
))
def
_get_repo_cred
(
self
,
section
):
repo
=
self
.
get
(
section
,
'repository'
).
strip
()
return
repo
,
Credential
(
self
.
get
(
section
,
'username'
).
strip
(),
self
.
get
(
section
,
'password'
).
strip
(),
)
def
find_credential
(
self
,
url
):
"""
If the URL indicated appears to be a repository defined in this
config, return the credential for that repository.
"""
for
repository
,
cred
in
self
.
creds_by_repository
.
items
():
if
url
.
startswith
(
repository
):
return
cred
def
open_with_auth
(
url
,
opener
=
urllib2
.
urlopen
):
"""Open a urllib2 request, handling HTTP authentication"""
...
...
@@ -935,6 +990,13 @@ def open_with_auth(url, opener=urllib2.urlopen):
else
:
auth
=
None
if
not
auth
:
cred
=
PyPIConfig
().
find_credential
(
url
)
if
cred
:
auth
=
str
(
cred
)
info
=
cred
.
username
,
url
log
.
info
(
'Authenticating as %s for %s (from .pypirc)'
%
info
)
if
auth
:
auth
=
"Basic "
+
_encode_auth
(
auth
)
new_url
=
urlunparse
((
scheme
,
host
,
path
,
params
,
query
,
frag
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment