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
31ca6309
Commit
31ca6309
authored
Jan 08, 2009
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed #4394 make the storage of the password optional in .pypirc
parent
ecf83b1f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
117 additions
and
38 deletions
+117
-38
command/register.py
command/register.py
+17
-13
command/upload.py
command/upload.py
+5
-0
config.py
config.py
+2
-2
dist.py
dist.py
+1
-0
tests/test_register.py
tests/test_register.py
+63
-23
tests/test_upload.py
tests/test_upload.py
+29
-0
No files found.
command/register.py
View file @
31ca6309
...
...
@@ -173,19 +173,23 @@ Your selection [default 1]: ''', log.INFO)
log
.
INFO
)
# possibly save the login
if
not
self
.
has_config
and
code
==
200
:
self
.
announce
((
'I can store your PyPI login so future '
'submissions will be faster.'
),
log
.
INFO
)
self
.
announce
(
'(the login will be stored in %s)'
%
\
self
.
_get_rc_file
(),
log
.
INFO
)
choice
=
'X'
while
choice
.
lower
()
not
in
'yn'
:
choice
=
raw_input
(
'Save your login (y/N)?'
)
if
not
choice
:
choice
=
'n'
if
choice
.
lower
()
==
'y'
:
self
.
_store_pypirc
(
username
,
password
)
if
code
==
200
:
if
self
.
has_config
:
# sharing the password in the distribution instance
# so the upload command can reuse it
self
.
distribution
.
password
=
password
else
:
self
.
announce
((
'I can store your PyPI login so future '
'submissions will be faster.'
),
log
.
INFO
)
self
.
announce
(
'(the login will be stored in %s)'
%
\
self
.
_get_rc_file
(),
log
.
INFO
)
choice
=
'X'
while
choice
.
lower
()
not
in
'yn'
:
choice
=
raw_input
(
'Save your login (y/N)?'
)
if
not
choice
:
choice
=
'n'
if
choice
.
lower
()
==
'y'
:
self
.
_store_pypirc
(
username
,
password
)
elif
choice
==
'2'
:
data
=
{
':action'
:
'user'
}
...
...
command/upload.py
View file @
31ca6309
...
...
@@ -50,6 +50,11 @@ class upload(PyPIRCCommand):
self
.
repository
=
config
[
'repository'
]
self
.
realm
=
config
[
'realm'
]
# getting the password from the distribution
# if previously set by the register command
if
not
self
.
password
and
self
.
distribution
.
password
:
self
.
password
=
self
.
distribution
.
password
def
run
(
self
):
if
not
self
.
distribution
.
dist_files
:
raise
DistutilsOptionError
(
"No dist file created in earlier command"
)
...
...
config.py
View file @
31ca6309
...
...
@@ -82,12 +82,12 @@ class PyPIRCCommand(Command):
for
server
in
_servers
:
current
=
{
'server'
:
server
}
current
[
'username'
]
=
config
.
get
(
server
,
'username'
)
current
[
'password'
]
=
config
.
get
(
server
,
'password'
)
# optional params
for
key
,
default
in
((
'repository'
,
self
.
DEFAULT_REPOSITORY
),
(
'realm'
,
self
.
DEFAULT_REALM
)):
(
'realm'
,
self
.
DEFAULT_REALM
),
(
'password'
,
None
)):
if
config
.
has_option
(
server
,
key
):
current
[
key
]
=
config
.
get
(
server
,
key
)
else
:
...
...
dist.py
View file @
31ca6309
...
...
@@ -206,6 +206,7 @@ Common commands: (see '--help-commands' for more)
self
.
extra_path
=
None
self
.
scripts
=
None
self
.
data_files
=
None
self
.
password
=
''
# And now initialize bookkeeping stuff that can't be supplied by
# the caller at all. 'command_obj' maps command names to
...
...
tests/test_register.py
View file @
31ca6309
...
...
@@ -2,6 +2,7 @@
import
sys
import
os
import
unittest
import
getpass
from
distutils.command.register
import
register
from
distutils.core
import
Distribution
...
...
@@ -9,6 +10,26 @@ from distutils.core import Distribution
from
distutils.tests
import
support
from
distutils.tests.test_config
import
PYPIRC
,
PyPIRCCommandTestCase
PYPIRC_NOPASSWORD
=
"""
\
[distutils]
index-servers =
server1
[server1]
username:me
"""
WANTED_PYPIRC
=
"""
\
[distutils]
index-servers =
pypi
[pypi]
username:tarek
password:password
"""
class
RawInputs
(
object
):
"""Fakes user inputs."""
def
__init__
(
self
,
*
answers
):
...
...
@@ -21,18 +42,33 @@ class RawInputs(object):
finally
:
self
.
index
+=
1
WANTED_PYPIRC
=
"""
\
[distutils]
index-servers =
pypi
class
FakeServer
(
object
):
"""Fakes a PyPI server"""
def
__init__
(
self
):
self
.
calls
=
[]
[pypi]
username:tarek
password:xxx
"""
def
__call__
(
self
,
*
args
):
# we want to compare them, so let's store
# something comparable
els
=
args
[
0
].
items
()
els
.
sort
()
self
.
calls
.
append
(
tuple
(
els
))
return
200
,
'OK'
class
registerTestCase
(
PyPIRCCommandTestCase
):
def
setUp
(
self
):
PyPIRCCommandTestCase
.
setUp
(
self
)
# patching the password prompt
self
.
_old_getpass
=
getpass
.
getpass
def
_getpass
(
prompt
):
return
'password'
getpass
.
getpass
=
_getpass
def
tearDown
(
self
):
getpass
.
getpass
=
self
.
_old_getpass
PyPIRCCommandTestCase
.
tearDown
(
self
)
def
test_create_pypirc
(
self
):
# this test makes sure a .pypirc file
# is created when requested.
...
...
@@ -56,25 +92,11 @@ class registerTestCase(PyPIRCCommandTestCase):
# Here's what we are faking :
# use your existing login (choice 1.)
# Username : 'tarek'
# Password : '
xxx
'
# Password : '
password
'
# Save your login (y/N)? : 'y'
inputs
=
RawInputs
(
'1'
,
'tarek'
,
'y'
)
from
distutils.command
import
register
as
register_module
register_module
.
raw_input
=
inputs
.
__call__
def
_getpass
(
prompt
):
return
'xxx'
register_module
.
getpass
.
getpass
=
_getpass
class
FakeServer
(
object
):
def
__init__
(
self
):
self
.
calls
=
[]
def
__call__
(
self
,
*
args
):
# we want to compare them, so let's store
# something comparable
els
=
args
[
0
].
items
()
els
.
sort
()
self
.
calls
.
append
(
tuple
(
els
))
return
200
,
'OK'
cmd
.
post_to_server
=
pypi_server
=
FakeServer
()
...
...
@@ -102,6 +124,24 @@ class registerTestCase(PyPIRCCommandTestCase):
self
.
assert_
(
len
(
pypi_server
.
calls
),
2
)
self
.
assert_
(
pypi_server
.
calls
[
0
],
pypi_server
.
calls
[
1
])
def
test_password_not_in_file
(
self
):
f
=
open
(
self
.
rc
,
'w'
)
f
.
write
(
PYPIRC_NOPASSWORD
)
f
.
close
()
dist
=
Distribution
()
cmd
=
register
(
dist
)
cmd
.
post_to_server
=
FakeServer
()
cmd
.
_set_config
()
cmd
.
finalize_options
()
cmd
.
send_metadata
()
# dist.password should be set
# therefore used afterwards by other commands
self
.
assertEquals
(
dist
.
password
,
'password'
)
def
test_suite
():
return
unittest
.
makeSuite
(
registerTestCase
)
...
...
tests/test_upload.py
View file @
31ca6309
...
...
@@ -9,6 +9,17 @@ from distutils.core import Distribution
from
distutils.tests
import
support
from
distutils.tests.test_config
import
PYPIRC
,
PyPIRCCommandTestCase
PYPIRC_NOPASSWORD
=
"""
\
[distutils]
index-servers =
server1
[server1]
username:me
"""
class
uploadTestCase
(
PyPIRCCommandTestCase
):
def
test_finalize_options
(
self
):
...
...
@@ -26,6 +37,24 @@ class uploadTestCase(PyPIRCCommandTestCase):
(
'repository'
,
'http://pypi.python.org/pypi'
)):
self
.
assertEquals
(
getattr
(
cmd
,
attr
),
waited
)
def
test_saved_password
(
self
):
# file with no password
f
=
open
(
self
.
rc
,
'w'
)
f
.
write
(
PYPIRC_NOPASSWORD
)
f
.
close
()
# make sure it passes
dist
=
Distribution
()
cmd
=
upload
(
dist
)
cmd
.
finalize_options
()
self
.
assertEquals
(
cmd
.
password
,
None
)
# make sure we get it as well, if another command
# initialized it at the dist level
dist
.
password
=
'xxx'
cmd
=
upload
(
dist
)
cmd
.
finalize_options
()
self
.
assertEquals
(
cmd
.
password
,
'xxx'
)
def
test_suite
():
return
unittest
.
makeSuite
(
uploadTestCase
)
...
...
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