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
6bd66765
Commit
6bd66765
authored
Nov 10, 2013
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merge with 3.3 for Issue #19544 and Issue #7457
parents
cc989869
5edd62fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
18 deletions
+101
-18
dist.py
dist.py
+73
-17
tests/test_dist.py
tests/test_dist.py
+28
-1
No files found.
dist.py
View file @
6bd66765
...
...
@@ -5,6 +5,7 @@ being built/installed/distributed.
"""
import
sys
,
os
,
re
from
email
import
message_from_file
try
:
import
warnings
...
...
@@ -999,25 +1000,80 @@ class DistributionMetadata:
"provides"
,
"requires"
,
"obsoletes"
,
)
def
__init__
(
self
):
self
.
name
=
None
self
.
version
=
None
self
.
author
=
None
self
.
author_email
=
None
def
__init__
(
self
,
path
=
None
):
if
path
is
not
None
:
self
.
read_pkg_file
(
open
(
path
))
else
:
self
.
name
=
None
self
.
version
=
None
self
.
author
=
None
self
.
author_email
=
None
self
.
maintainer
=
None
self
.
maintainer_email
=
None
self
.
url
=
None
self
.
license
=
None
self
.
description
=
None
self
.
long_description
=
None
self
.
keywords
=
None
self
.
platforms
=
None
self
.
classifiers
=
None
self
.
download_url
=
None
# PEP 314
self
.
provides
=
None
self
.
requires
=
None
self
.
obsoletes
=
None
def
read_pkg_file
(
self
,
file
):
"""Reads the metadata values from a file object."""
msg
=
message_from_file
(
file
)
def
_read_field
(
name
):
value
=
msg
[
name
]
if
value
==
'UNKNOWN'
:
return
None
return
value
def
_read_list
(
name
):
values
=
msg
.
get_all
(
name
,
None
)
if
values
==
[]:
return
None
return
values
metadata_version
=
msg
[
'metadata-version'
]
self
.
name
=
_read_field
(
'name'
)
self
.
version
=
_read_field
(
'version'
)
self
.
description
=
_read_field
(
'summary'
)
# we are filling author only.
self
.
author
=
_read_field
(
'author'
)
self
.
maintainer
=
None
self
.
author_email
=
_read_field
(
'author-email'
)
self
.
maintainer_email
=
None
self
.
url
=
None
self
.
license
=
None
self
.
description
=
None
self
.
long_description
=
None
self
.
keywords
=
None
self
.
platforms
=
None
self
.
classifiers
=
None
self
.
download_url
=
None
# PEP 314
self
.
provides
=
None
self
.
requires
=
None
self
.
obsoletes
=
None
self
.
url
=
_read_field
(
'home-page'
)
self
.
license
=
_read_field
(
'license'
)
if
'download-url'
in
msg
:
self
.
download_url
=
_read_field
(
'download-url'
)
else
:
self
.
download_url
=
None
self
.
long_description
=
_read_field
(
'description'
)
self
.
description
=
_read_field
(
'summary'
)
if
'keywords'
in
msg
:
self
.
keywords
=
_read_field
(
'keywords'
).
split
(
','
)
self
.
platforms
=
_read_list
(
'platform'
)
self
.
classifiers
=
_read_list
(
'classifier'
)
# PEP 314 - these fields only exist in 1.1
if
metadata_version
==
'1.1'
:
self
.
requires
=
_read_list
(
'requires'
)
self
.
provides
=
_read_list
(
'provides'
)
self
.
obsoletes
=
_read_list
(
'obsoletes'
)
else
:
self
.
requires
=
None
self
.
provides
=
None
self
.
obsoletes
=
None
def
write_pkg_info
(
self
,
base_dir
):
"""Write the PKG-INFO file into the release tree.
...
...
tests/test_dist.py
View file @
6bd66765
...
...
@@ -8,7 +8,7 @@ import textwrap
from
unittest
import
mock
from
distutils.dist
import
Distribution
,
fix_help_options
from
distutils.dist
import
Distribution
,
fix_help_options
,
DistributionMetadata
from
distutils.cmd
import
Command
from
test.support
import
TESTFN
,
captured_stdout
,
run_unittest
...
...
@@ -388,6 +388,33 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self
.
assertTrue
(
output
)
def
test_read_metadata
(
self
):
attrs
=
{
"name"
:
"package"
,
"version"
:
"1.0"
,
"long_description"
:
"desc"
,
"description"
:
"xxx"
,
"download_url"
:
"http://example.com"
,
"keywords"
:
[
'one'
,
'two'
],
"requires"
:
[
'foo'
]}
dist
=
Distribution
(
attrs
)
metadata
=
dist
.
metadata
# write it then reloads it
PKG_INFO
=
io
.
StringIO
()
metadata
.
write_pkg_file
(
PKG_INFO
)
PKG_INFO
.
seek
(
0
)
metadata
.
read_pkg_file
(
PKG_INFO
)
self
.
assertEquals
(
metadata
.
name
,
"package"
)
self
.
assertEquals
(
metadata
.
version
,
"1.0"
)
self
.
assertEquals
(
metadata
.
description
,
"xxx"
)
self
.
assertEquals
(
metadata
.
download_url
,
'http://example.com'
)
self
.
assertEquals
(
metadata
.
keywords
,
[
'one'
,
'two'
])
self
.
assertEquals
(
metadata
.
platforms
,
[
'UNKNOWN'
])
self
.
assertEquals
(
metadata
.
obsoletes
,
None
)
self
.
assertEquals
(
metadata
.
requires
,
[
'foo'
])
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
DistributionTestCase
))
...
...
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