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
ae857907
Commit
ae857907
authored
May 16, 2009
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
parent
6f1556e5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
72 deletions
+179
-72
command/register.py
command/register.py
+27
-30
command/sdist.py
command/sdist.py
+24
-32
tests/support.py
tests/support.py
+20
-0
tests/test_register.py
tests/test_register.py
+73
-6
tests/test_sdist.py
tests/test_sdist.py
+35
-4
No files found.
command/register.py
View file @
ae857907
...
...
@@ -9,6 +9,7 @@ __revision__ = "$Id$"
import
os
,
string
,
urllib2
,
getpass
,
urlparse
import
StringIO
from
warnings
import
warn
from
distutils.core
import
PyPIRCCommand
from
distutils.errors
import
*
...
...
@@ -20,18 +21,34 @@ class register(PyPIRCCommand):
user_options
=
PyPIRCCommand
.
user_options
+
[
(
'list-classifiers'
,
None
,
'list the valid Trove classifiers'
),
(
'strict'
,
None
,
'Will stop the registering if the meta-data are not fully compliant'
)
]
boolean_options
=
PyPIRCCommand
.
boolean_options
+
[
'verify'
,
'list-classifiers'
]
'verify'
,
'list-classifiers'
,
'strict'
]
sub_commands
=
[(
'check'
,
lambda
self
:
True
)]
def
initialize_options
(
self
):
PyPIRCCommand
.
initialize_options
(
self
)
self
.
list_classifiers
=
0
self
.
strict
=
0
def
finalize_options
(
self
):
PyPIRCCommand
.
finalize_options
(
self
)
# setting options for the `check` subcommand
check_options
=
{
'strict'
:
(
'register'
,
self
.
strict
),
'restructuredtext'
:
(
'register'
,
1
)}
self
.
distribution
.
command_options
[
'check'
]
=
check_options
def
run
(
self
):
self
.
finalize_options
()
self
.
_set_config
()
self
.
check_metadata
()
# Run sub commands
for
cmd_name
in
self
.
get_sub_commands
():
self
.
run_command
(
cmd_name
)
if
self
.
dry_run
:
self
.
verify_metadata
()
elif
self
.
list_classifiers
:
...
...
@@ -40,34 +57,14 @@ class register(PyPIRCCommand):
self
.
send_metadata
()
def
check_metadata
(
self
):
"""Ensure that all required elements of meta-data (name, version,
URL, (author and author_email) or (maintainer and
maintainer_email)) are supplied by the Distribution object; warn if
any are missing.
"""
metadata
=
self
.
distribution
.
metadata
missing
=
[]
for
attr
in
(
'name'
,
'version'
,
'url'
):
if
not
(
hasattr
(
metadata
,
attr
)
and
getattr
(
metadata
,
attr
)):
missing
.
append
(
attr
)
if
missing
:
self
.
warn
(
"missing required meta-data: "
+
string
.
join
(
missing
,
", "
))
if
metadata
.
author
:
if
not
metadata
.
author_email
:
self
.
warn
(
"missing meta-data: if 'author' supplied, "
+
"'author_email' must be supplied too"
)
elif
metadata
.
maintainer
:
if
not
metadata
.
maintainer_email
:
self
.
warn
(
"missing meta-data: if 'maintainer' supplied, "
+
"'maintainer_email' must be supplied too"
)
else
:
self
.
warn
(
"missing meta-data: either (author and author_email) "
+
"or (maintainer and maintainer_email) "
+
"must be supplied"
)
"""Deprecated API."""
warn
(
"distutils.command.register.check_metadata is deprecated,
\
use the check command instead"
,
PendingDeprecationWarning
)
check
=
self
.
distribution
.
get_command_obj
(
'check'
)
check
.
ensure_finalized
()
check
.
strict
=
self
.
strict
check
.
restructuredtext
=
1
check
.
run
()
def
_set_config
(
self
):
''' Reads the configuration file and set attributes.
...
...
command/sdist.py
View file @
ae857907
...
...
@@ -8,6 +8,8 @@ import os, string
import
sys
from
types
import
*
from
glob
import
glob
from
warnings
import
warn
from
distutils.core
import
Command
from
distutils
import
dir_util
,
dep_util
,
file_util
,
archive_util
from
distutils.text_file
import
TextFile
...
...
@@ -34,6 +36,12 @@ class sdist(Command):
description
=
"create a source distribution (tarball, zip file, etc.)"
def
checking_metadata
(
self
):
"""Callable used for the check sub-command.
Placed here so user_options can view it"""
return
self
.
metadata_check
user_options
=
[
(
'template='
,
't'
,
"name of manifest template file [default: MANIFEST.in]"
),
...
...
@@ -63,11 +71,14 @@ class sdist(Command):
(
'dist-dir='
,
'd'
,
"directory to put the source distribution archive(s) in "
"[default: dist]"
),
(
'medata-check'
,
None
,
"Ensure that all required elements of meta-data "
"are supplied. Warn if any missing. [default]"
),
]
boolean_options
=
[
'use-defaults'
,
'prune'
,
'manifest-only'
,
'force-manifest'
,
'keep-temp'
]
'keep-temp'
,
'metadata-check'
]
help_options
=
[
(
'help-formats'
,
None
,
...
...
@@ -80,6 +91,8 @@ class sdist(Command):
default_format
=
{
'posix'
:
'gztar'
,
'nt'
:
'zip'
}
sub_commands
=
[(
'check'
,
checking_metadata
)]
def
initialize_options
(
self
):
# 'template' and 'manifest' are, respectively, the names of
# the manifest template and manifest file.
...
...
@@ -99,6 +112,7 @@ class sdist(Command):
self
.
dist_dir
=
None
self
.
archive_files
=
None
self
.
metadata_check
=
1
def
finalize_options
(
self
):
if
self
.
manifest
is
None
:
...
...
@@ -128,9 +142,9 @@ class sdist(Command):
# manifest
self
.
filelist
=
FileList
()
#
Ensure that all required meta-data is given; warn if not (but
# don't die, it's not *that* serious!)
self
.
check_metadata
(
)
#
Run sub commands
for
cmd_name
in
self
.
get_sub_commands
():
self
.
run_command
(
cmd_name
)
# Do whatever it takes to get the list of files to process
# (process the manifest template, read an existing manifest,
...
...
@@ -146,34 +160,12 @@ class sdist(Command):
self
.
make_distribution
()
def
check_metadata
(
self
):
"""Ensure that all required elements of meta-data (name, version,
URL, (author and author_email) or (maintainer and
maintainer_email)) are supplied by the Distribution object; warn if
any are missing.
"""
metadata
=
self
.
distribution
.
metadata
missing
=
[]
for
attr
in
(
'name'
,
'version'
,
'url'
):
if
not
(
hasattr
(
metadata
,
attr
)
and
getattr
(
metadata
,
attr
)):
missing
.
append
(
attr
)
if
missing
:
self
.
warn
(
"missing required meta-data: "
+
string
.
join
(
missing
,
", "
))
if
metadata
.
author
:
if
not
metadata
.
author_email
:
self
.
warn
(
"missing meta-data: if 'author' supplied, "
+
"'author_email' must be supplied too"
)
elif
metadata
.
maintainer
:
if
not
metadata
.
maintainer_email
:
self
.
warn
(
"missing meta-data: if 'maintainer' supplied, "
+
"'maintainer_email' must be supplied too"
)
else
:
self
.
warn
(
"missing meta-data: either (author and author_email) "
+
"or (maintainer and maintainer_email) "
+
"must be supplied"
)
"""Deprecated API."""
warn
(
"distutils.command.sdist.check_metadata is deprecated,
\
use the check command instead"
,
PendingDeprecationWarning
)
check
=
self
.
distribution
.
get_command_obj
(
'check'
)
check
.
ensure_finalized
()
check
.
run
()
def
get_file_list
(
self
):
"""Figure out the list of files to include in the source
...
...
tests/support.py
View file @
ae857907
...
...
@@ -12,11 +12,31 @@ class LoggingSilencer(object):
def
setUp
(
self
):
super
(
LoggingSilencer
,
self
).
setUp
()
self
.
threshold
=
log
.
set_threshold
(
log
.
FATAL
)
# catching warnings
# when log will be replaced by logging
# we won't need such monkey-patch anymore
self
.
_old_log
=
log
.
Log
.
_log
log
.
Log
.
_log
=
self
.
_log
self
.
logs
=
[]
def
tearDown
(
self
):
log
.
set_threshold
(
self
.
threshold
)
log
.
Log
.
_log
=
self
.
_old_log
super
(
LoggingSilencer
,
self
).
tearDown
()
def
_log
(
self
,
level
,
msg
,
args
):
self
.
logs
.
append
((
level
,
msg
,
args
))
def
get_logs
(
self
,
*
levels
):
def
_format
(
msg
,
args
):
if
len
(
args
)
==
0
:
return
msg
return
msg
%
args
return
[
_format
(
msg
,
args
)
for
level
,
msg
,
args
in
self
.
logs
if
level
in
levels
]
def
clear_logs
(
self
):
self
.
logs
=
[]
class
TempdirManager
(
object
):
"""Mix-in class that handles temporary directories for test cases.
...
...
tests/test_register.py
View file @
ae857907
...
...
@@ -4,10 +4,14 @@ import os
import
unittest
import
getpass
import
urllib2
import
warnings
from
test.test_support
import
check_warnings
from
distutils.command
import
register
as
register_module
from
distutils.command.register
import
register
from
distutils.core
import
Distribution
from
distutils.errors
import
DistutilsSetupError
from
distutils.tests
import
support
from
distutils.tests.test_config
import
PYPIRC
,
PyPIRCCommandTestCase
...
...
@@ -59,7 +63,7 @@ class FakeOpener(object):
def
read
(
self
):
return
'xxx'
class
r
egisterTestCase
(
PyPIRCCommandTestCase
):
class
R
egisterTestCase
(
PyPIRCCommandTestCase
):
def
setUp
(
self
):
PyPIRCCommandTestCase
.
setUp
(
self
)
...
...
@@ -76,10 +80,11 @@ class registerTestCase(PyPIRCCommandTestCase):
urllib2
.
build_opener
=
self
.
old_opener
PyPIRCCommandTestCase
.
tearDown
(
self
)
def
_get_cmd
(
self
):
metadata
=
{
'url'
:
'xxx'
,
'author'
:
'xxx'
,
'author_email'
:
'xxx'
,
'name'
:
'xxx'
,
'version'
:
'xxx'
}
def
_get_cmd
(
self
,
metadata
=
None
):
if
metadata
is
None
:
metadata
=
{
'url'
:
'xxx'
,
'author'
:
'xxx'
,
'author_email'
:
'xxx'
,
'name'
:
'xxx'
,
'version'
:
'xxx'
}
pkg_info
,
dist
=
self
.
create_dist
(
**
metadata
)
return
register
(
dist
)
...
...
@@ -184,8 +189,70 @@ class registerTestCase(PyPIRCCommandTestCase):
self
.
assertEquals
(
headers
[
'Content-length'
],
'290'
)
self
.
assert_
(
'tarek'
in
req
.
data
)
def
test_strict
(
self
):
# testing the script option
# when on, the register command stops if
# the metadata is incomplete or if
# long_description is not reSt compliant
# empty metadata
cmd
=
self
.
_get_cmd
({})
cmd
.
ensure_finalized
()
cmd
.
strict
=
1
self
.
assertRaises
(
DistutilsSetupError
,
cmd
.
run
)
# we don't test the reSt feature if docutils
# is not installed
try
:
import
docutils
except
ImportError
:
return
# metadata are OK but long_description is broken
metadata
=
{
'url'
:
'xxx'
,
'author'
:
'xxx'
,
'author_email'
:
'xxx'
,
'name'
:
'xxx'
,
'version'
:
'xxx'
,
'long_description'
:
'title
\
n
==
\
n
\
n
text'
}
cmd
=
self
.
_get_cmd
(
metadata
)
cmd
.
ensure_finalized
()
cmd
.
strict
=
1
self
.
assertRaises
(
DistutilsSetupError
,
cmd
.
run
)
# now something that works
metadata
[
'long_description'
]
=
'title
\
n
=====
\
n
\
n
text'
cmd
=
self
.
_get_cmd
(
metadata
)
cmd
.
ensure_finalized
()
cmd
.
strict
=
1
inputs
=
RawInputs
(
'1'
,
'tarek'
,
'y'
)
register_module
.
raw_input
=
inputs
.
__call__
# let's run the command
try
:
cmd
.
run
()
finally
:
del
register_module
.
raw_input
# strict is not by default
cmd
=
self
.
_get_cmd
()
cmd
.
ensure_finalized
()
inputs
=
RawInputs
(
'1'
,
'tarek'
,
'y'
)
register_module
.
raw_input
=
inputs
.
__call__
# let's run the command
try
:
cmd
.
run
()
finally
:
del
register_module
.
raw_input
def
test_check_metadata_deprecated
(
self
):
# makes sure make_metadata is deprecated
cmd
=
self
.
_get_cmd
()
with
check_warnings
()
as
w
:
warnings
.
simplefilter
(
"always"
)
cmd
.
check_metadata
()
self
.
assertEquals
(
len
(
w
.
warnings
),
1
)
def
test_suite
():
return
unittest
.
makeSuite
(
r
egisterTestCase
)
return
unittest
.
makeSuite
(
R
egisterTestCase
)
if
__name__
==
"__main__"
:
unittest
.
main
(
defaultTest
=
"test_suite"
)
tests/test_sdist.py
View file @
ae857907
...
...
@@ -6,7 +6,9 @@ import zipfile
from
os.path
import
join
import
sys
import
tempfile
import
warnings
from
test.test_support
import
check_warnings
from
test.test_support
import
captured_stdout
from
distutils.command.sdist
import
sdist
...
...
@@ -16,6 +18,7 @@ from distutils.tests.test_config import PyPIRCCommandTestCase
from
distutils.errors
import
DistutilsExecError
,
DistutilsOptionError
from
distutils.spawn
import
find_executable
from
distutils.tests
import
support
from
distutils.log
import
WARN
from
distutils.archive_util
import
ARCHIVE_FORMATS
SETUP_PY
=
"""
...
...
@@ -38,12 +41,12 @@ somecode%(sep)sdoc.dat
somecode%(sep)sdoc.txt
"""
class
sd
istTestCase
(
PyPIRCCommandTestCase
):
class
SD
istTestCase
(
PyPIRCCommandTestCase
):
def
setUp
(
self
):
# PyPIRCCommandTestCase creates a temp dir already
# and put it in self.tmp_dir
super
(
sd
istTestCase
,
self
).
setUp
()
super
(
SD
istTestCase
,
self
).
setUp
()
# setting up an environment
self
.
old_path
=
os
.
getcwd
()
os
.
mkdir
(
join
(
self
.
tmp_dir
,
'somecode'
))
...
...
@@ -57,7 +60,7 @@ class sdistTestCase(PyPIRCCommandTestCase):
def
tearDown
(
self
):
# back to normal
os
.
chdir
(
self
.
old_path
)
super
(
sd
istTestCase
,
self
).
tearDown
()
super
(
SD
istTestCase
,
self
).
tearDown
()
def
get_cmd
(
self
,
metadata
=
None
):
"""Returns a cmd"""
...
...
@@ -214,6 +217,34 @@ class sdistTestCase(PyPIRCCommandTestCase):
manifest
=
open
(
join
(
self
.
tmp_dir
,
'MANIFEST'
)).
read
()
self
.
assertEquals
(
manifest
,
MANIFEST
%
{
'sep'
:
os
.
sep
})
def
test_metadata_check_option
(
self
):
# testing the `medata-check` option
dist
,
cmd
=
self
.
get_cmd
(
metadata
=
{})
# this should raise some warnings !
# with the `check` subcommand
cmd
.
ensure_finalized
()
cmd
.
run
()
warnings
=
self
.
get_logs
(
WARN
)
self
.
assertEquals
(
len
(
warnings
),
2
)
# trying with a complete set of metadata
self
.
clear_logs
()
dist
,
cmd
=
self
.
get_cmd
()
cmd
.
ensure_finalized
()
cmd
.
metadata_check
=
0
cmd
.
run
()
warnings
=
self
.
get_logs
(
WARN
)
self
.
assertEquals
(
len
(
warnings
),
0
)
def
test_check_metadata_deprecated
(
self
):
# makes sure make_metadata is deprecated
dist
,
cmd
=
self
.
get_cmd
()
with
check_warnings
()
as
w
:
warnings
.
simplefilter
(
"always"
)
cmd
.
check_metadata
()
self
.
assertEquals
(
len
(
w
.
warnings
),
1
)
def
test_show_formats
(
self
):
with
captured_stdout
()
as
stdout
:
show_formats
()
...
...
@@ -247,7 +278,7 @@ class sdistTestCase(PyPIRCCommandTestCase):
def
test_suite
():
return
unittest
.
makeSuite
(
sd
istTestCase
)
return
unittest
.
makeSuite
(
SD
istTestCase
)
if
__name__
==
"__main__"
:
unittest
.
main
(
defaultTest
=
"test_suite"
)
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