-
-
Notifications
You must be signed in to change notification settings - Fork 440
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 (or suggested workaround) for syntactic macros (macropy/mcpy) #1004
Comments
I would like to see this, too. I'd like to use macros more in Python (only when actually appropriate!), but tooling support is needed. Based on my work on The default approach, which works for many (but not all) macros, is to just not care about this in the macro implementation, and let MacroPy fix up (as a postprocessing step) the missing mandatory information, particularly the line number. It's pretty good at that, but sometimes it misses, and you end up with a compile error until you (the macro author) figure out where it's going wrong, and manually I haven't tried On a side note, there is no longer strictly a need to write a wrapper script separately for each macro-enabled Python program using MacroPy. There's a generic (Disclaimer: I'm the author of |
I think the problem is more complex. The same macros show different coverage according to the Python version. I was using Python 3.7.3, when switched to 3.8.5 the decoration macros started to show the decorator as not covered. I was able to fix it by adding line information to the AST. But when I tried to do the same with the
I also learned that the .coverage file generated using Python 3.7 + Coverage 4.5.2 can't be analyzed on a system using Python 3.8 + Coverage 4.5.2 (Debian stable vs Debian testing). You get some bizarre things, like decorator lines reported as uncovered. I know nothing about Coverage internals, but the problems seems to be related to it.
May be, but when I tried to migrate my two macros (yes, just 2) to MacroPy I found two problems:
The speed penalty made me abandon the idea of migrating to MacroPy. I prefer spending a little bit more time writing the macros. |
That's interesting. Thanks for the additional details! My two euro-cents are, naturally, just from my own experience. What I do know is that if you repurpose The only other coverage issue I've had specifically with block macros is the Another coverage oddity I've encountered, in code using MacroPy, is that the module docstring of a module that uses macros is reported as not covered. I think MacroPy might be doing something here, but I'd need to re-read the import handler in its source to be sure. Regarding
Is there any material on |
None that I'm aware. But the code is much simpler than MacroPy, you should be able to fully understand all its functionality. I don't have much experience with Python and was able to understand how to modify it ;-) |
Thanks. I actually just read through all of Doing so also answered my most pressing questions. Right now I can't just drop in Summary of findings (as of September 2020, in case someone ends up reading this much later):
|
In the evenings during the last few weeks, I've been investigating this, by extending So, on that note, I'd like to introduce It has the features that were missing from I've been running my development on 3.6 and PyPy3; support for 3.7 and 3.8 is already done, but I still need to write automated tests and set up a CI workflow to actually test on those platforms. So it's not completely release-ready yet, but getting there. In any case, at least in my own private tests, I'm getting correct coverage with It's almost drop-in compatible with |
Just for the records: Using it I got correct coverage information. In addition it supports Python cache files. Thanks to it I'm getting better performance than using |
|
Just for the record, My opinion regarding coverage reporting for macro-enabled code is still that That is, when doing so is possible; there is at least one unavoidable philosophical issue. I think this is just something one needs to keep in mind when working with macros. So for me, with How about you, @set-soft ? @nedbat ? If you have the time, I'd like to hear your opinions on this. |
Hi @Technologicat ! |
Syntactic macros implemented in macropy (or a simplified version mcpy) allows code transformations after parsing the code and before compiling it.
One of the transformations allows to process code inside a with block:
When trying to meassure the coverage of such a code the first and last line are skipped (not always both, depends on the tool, macropy or mcpy, but always at least one).
One solution for this is to just exclude these lines from coverage. I can do it and is ok.
But I was wondering if there is a better solution.
Here is the simplest example I could find:
try_mymacros.py (the script you run)
mymacros.py (an empty macro, it doesn't matter what the macro does)
application.py (the important code)
Note that removing the
print()
statement the docstring is reported as covered.Also note that removing both the
print()
anda = 1
all the code is reported as covered.I created two examples with makefiles and more information as testbed for this issue:
The text was updated successfully, but these errors were encountered: