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
a960ee1c
Commit
a960ee1c
authored
May 14, 2018
by
Jeremy Bowman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support loading version from a file
parent
26b75f51
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
1 deletion
+37
-1
changelog.d/1359.change.rst
changelog.d/1359.change.rst
+2
-0
docs/setuptools.txt
docs/setuptools.txt
+5
-1
setuptools/config.py
setuptools/config.py
+13
-0
setuptools/tests/test_config.py
setuptools/tests/test_config.py
+17
-0
No files found.
changelog.d/1359.change.rst
0 → 100644
View file @
a960ee1c
Support using "file:" to load a PEP 440-compliant package version
from a text file.
docs/setuptools.txt
View file @
a960ee1c
...
...
@@ -2421,7 +2421,7 @@ Metadata
Key Aliases Type
============================== ================= =====
name str
version attr:, str
version attr:,
file:,
str
url home-page str
download_url download-url str
project_urls dict
...
...
@@ -2441,6 +2441,10 @@ requires list-comma
obsoletes list-comma
============================== ================= =====
.. note::
A version loaded using the ``file:`` directive must comply with PEP 440.
It is easy to accidentally put something other than a valid version
string in such a file, so validation is stricter in this case.
Options
-------
...
...
setuptools/config.py
View file @
a960ee1c
...
...
@@ -7,6 +7,7 @@ from functools import partial
from
importlib
import
import_module
from
distutils.errors
import
DistutilsOptionError
,
DistutilsFileError
from
setuptools.extern.packaging.version
import
LegacyVersion
,
parse
from
setuptools.extern.six
import
string_types
...
...
@@ -427,6 +428,18 @@ class ConfigMetadataHandler(ConfigHandler):
:rtype: str
"""
version
=
self
.
_parse_file
(
value
)
if
version
!=
value
:
version
=
version
.
strip
()
# Be strict about versions loaded from file because it's easy to
# accidentally include newlines and other unintended content
if
isinstance
(
parse
(
version
),
LegacyVersion
):
raise
DistutilsOptionError
(
'Version loaded from %s does not comply with PEP 440: %s'
%
(
value
,
version
))
return
version
version
=
self
.
_parse_attr
(
value
)
if
callable
(
version
):
...
...
setuptools/tests/test_config.py
View file @
a960ee1c
...
...
@@ -268,6 +268,23 @@ class TestMetadata:
with
get_dist
(
tmpdir
)
as
dist
:
assert
dist
.
metadata
.
version
==
'2016.11.26'
def
test_version_file
(
self
,
tmpdir
):
_
,
config
=
fake_env
(
tmpdir
,
'[metadata]
\
n
'
'version = file: fake_package/version.txt
\
n
'
)
tmpdir
.
join
(
'fake_package'
,
'version.txt'
).
write
(
'1.2.3
\
n
'
)
with
get_dist
(
tmpdir
)
as
dist
:
assert
dist
.
metadata
.
version
==
'1.2.3'
tmpdir
.
join
(
'fake_package'
,
'version.txt'
).
write
(
'1.2.3
\
n
4.5.6
\
n
'
)
with
pytest
.
raises
(
DistutilsOptionError
):
with
get_dist
(
tmpdir
)
as
dist
:
_
=
dist
.
metadata
.
version
def
test_unknown_meta_item
(
self
,
tmpdir
):
fake_env
(
...
...
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