-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support attr directive with static evaluation #1753
Conversation
I'd rather not add yet another way to load the version. There are already several viable techniques:
My favorites are the last two. I'm also not a fan of the two-word moniker ("literal attr"). Is there a way that
|
I merged the code for the two directives together like you said, but now some tests in (Some tests in |
Thanks John. This is looking great. I also am a bit surprised by the behavior. Both the tests (through |
If I add the breakpoint explicitly, I can avoid exiting the generators:
And see what's going on:
Somehow, |
I've figured it out. That test is doing something really complicated. It's creating a package The test has done its job and caught a real use-case that it's trying to protect. Next will be to figure out how to "find" a module without loading it (hint: Python has "finders" and "loaders" defined in PEP 302, though there's probably something better in later peps, probably PEP 451 and |
This latest version is almost working. The tests are passing, but I'm not sure how. The test that's there should probably be a separate unit test and not just some assertions on an existing test. I've removed the specialized tuple handling, but the test is still passing. That shouldn't be the case if the test is effectively capturing the feature. |
On second thought, I see that you're following the pattern of the test suite, so the test may be okay. But it definitely needs to fail before the patch is applied. |
That's really interesting. The tests are passing on macOS but not Windows or LInux. Seems
|
I'll be the issue is that the contents of |
Deleting the packages from |
Well, hell. This latest technique works on Ubuntu Python 3.6, but revives the failure on Windows. |
It looks like the last remaining failure is on Python 2. I was going to try to add Python 2 compatibility by pulling in importlib2, but then I found that project is broken and abandoned since 2015. So no Python 2 support for this one. |
I think importlib2 was a wholesale backport, these days there are separate projects like importlib_metadata and importlib_resources to backport submodules of stdlib importlib. |
Thanks for the help, @jaraco! |
Thanks a lot @jwodder for implementing this!! |
The ``importlib_metadata`` library is used to scan for setuptools entrypoints rather than pkg_resources. as importlib_metadata is a small library that is included as of Python 3.8, the compatibility library is installed as a dependency for Python versions older than 3.8. Unfortunately setuptools "attr:" is broken because it tries to import the module; seems like this is fixed as part of pypa/setuptools#1753 however this is too recent to rely upon for now. Added a new dialect token "mariadb" that may be used in place of "mysql" in the :func:`_sa.create_engine` URL. This will deliver a MariaDB dialect subclass of the MySQLDialect in use that forces the "is_mariadb" flag to True. The dialect will raise an error if a server version string that does not indicate MariaDB in use is received. This is useful for MariaDB-specific testing scenarios as well as to support applications that are hardcoding to MariaDB-only concepts. As MariaDB and MySQL featuresets and usage patterns continue to diverge, this pattern may become more prominent. Fixes: #5400 Fixes: #5496 Change-Id: I330815ebe572b6a9818377da56621397335fa702
Since setuptools 46.4.0 (May 2020), `attr:` are statically extracted using the `ast` module if possible: pypa/setuptools#1753
As I'm sure we all know, the
attr:
config directive for theversion
option insetup.cfg
doesn't work when the specified module imports one or more third-party packages, thereby forcing package authors to use a different strategy. Proposals have been made (#1316, #1679, others?) to add a function tosetuptools
that encapsulates the necessary code for strategy number 1, but these have been rejected, most recently with the comment:This pull request attempts to address this criticism by implementing the relevant functionality as a
setup.cfg
directive instead of as a user-visible function.Summary of changes
Implement a
literal_attr:
directive that can be used inversion
options insetup.cfg
. This directive is likeattr:
, except it extracts the variable assignment with theast
module, thereby supporting variables in modules with third-party imports at the cost of being unable to support variables that are not assigned constant expressions.Update documentation (The "Minimum Version" column for the
version
option in the table at https://setuptools.readthedocs.io/en/latest/setuptools.html#metadata has not been updated, as I'm not sure what the next version ofsetuptools
is going to be.)Pull Request Checklist