-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework version handling in setup.py #515
Conversation
Codecov Report
@@ Coverage Diff @@
## master #515 +/- ##
==========================================
+ Coverage 65.23% 65.33% +0.09%
==========================================
Files 44 44
Lines 7056 7058 +2
Branches 1415 1415
==========================================
+ Hits 4603 4611 +8
+ Misses 2030 2024 -6
Partials 423 423
Continue to review full report at Codecov.
|
FWIW, I've confirmed that the
|
Okay, I'm not so happy with the new That makes the use of |
It looks as though |
setup.py
Outdated
git_revision : str | ||
The full commit hash for the current Git revision. | ||
""" | ||
with open(VERSION_FILE, "w") as version_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - maybe use io.open
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I did in a previous version, but setup.py gets picky about Unicode, so I ended up reverting to the "natural" combination of bytes on Python 2 and Unicode on Python 3 (and so plain old "open" everywhere). All the text being read and written is ASCII anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: b125c2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I did end up going back to io.open
, and adding u''
prefixes to a handful of important strings. It's an ugly solution: I really want to use from __future__ import unicode_literals
, but that breaks current setuptools: I get an error resembling the following
mirzakhani:traits mdickinson$ python etstool.py update --runtime 2.7
Re-installing in 'traits-test-2.7'
[EXECUTING] edm run -e traits-test-2.7 -- python -m pip install --no-deps .
Processing /Users/mdickinson/Enthought/ETS/traits
Complete output from command python setup.py egg_info:
Computed package version: (u'5.2.0.dev1233', u'b2cfb514f7d2674a24bb742b42431194d4a0f37d')
Writing version to version file /private/var/folders/07/jbbjv8b53bs5y9xyjdyn1zgw0000gn/T/pip-req-build-mZH0B0/traits/version.py.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/07/jbbjv8b53bs5y9xyjdyn1zgw0000gn/T/pip-req-build-mZH0B0/setup.py", line 243, in <module>
ext_modules=[setuptools.Extension("traits.ctraits", ["traits/ctraits.c"])],
File "/Users/mdickinson/.edm/envs/traits-test-2.7/lib/python2.7/site-packages/setuptools/extension.py", line 39, in __init__
_Extension.__init__(self, name, sources, *args, **kw)
File "/Users/mdickinson/.edm/envs/traits-test-2.7/lib/python2.7/distutils/extension.py", line 106, in __init__
assert type(name) is StringType, "'name' must be a string"
AssertionError: 'name' must be a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM apart from a minor nit-picky comment. Thanks for redoing the work!
…uild/rework-version-handling
…es even if Python 2 is used.
PR significantly updated:
I've edited the main PR description to add these points. |
One more update: fix the overengineered logic with something much simpler:
I think this should be good enough, and simpler to debug in case of failure. Moreover, it avoids someone doing a local pip install even trying to run the "git" executable. @rahulporuri Sorry for the premature PR. I think I've actually finished messing with it now. |
setup.py
Outdated
# Copyright (c) 2008-2019 by Enthought, Inc. | ||
# All rights reserved. | ||
|
||
\""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me feel a bit dirty. We're only actually escaping one of the three double quotes, but that's enough to avoid this being interpreted as the end of the triple-quoted string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually use triple single-quotes when I want to have a string with embedded triple double-quotes. I think doing that here might improve readability and make you feel less dirty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that. As a bonus, black leaves that solution unchanged. (I ran the entirety of setup.py
through black as part of this cleanup.)
…sion.py string constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't actually run it, but the refactor looks reasonably sane and adds to clarity.
… but that breaks setuptools / distutils.
Thanks @corranwebster and @rahulporuri for reviewing! I added a couple of Unicode-related tweaks, but nothing major. Merging when the CI completes. |
This PR reworks the version-handling code in
setup.py
, and cleans up the rest ofsetup.py
a bit en-route.Key points for version-related changes:
withinsetup.py
, versions are passed around aspackaging.version.Version
instances; this makes it easy to compare versions without writing our own custom logic for doing so.traits/_version.py
totraits/version.py
traits.__version__
andtraits.version
traits.version
contentstraits/version.py
traits/version.py
traits/version.py
to include only the version (previously, "full version") and the git revisionimport traits
will no longer fail if there's noversion.py
file. Note that if there's noversion.py
, that almost certainly means there's notraits.ctrait
extension module, so any attempt to anything significant with traits will still fail. However, a user debugging packaging problems should still be able to rely onimport traits
not failing.Other changes
traits/__init__.py
no longer provides__requires__
python setup.py
has been removed; that's just not the way that we do things any more.python_requires
keyword argumentSupersedes #513.
Fixes #478.