« | » Main « | »

Coverage.py 4.0a3

Tuesday 20 January 2015

Lots of things happening in coverage.py world these days. Turns out I broke the XML report a long time ago, so that directories were not reported as packages. I honestly don't know why I let that sit for so long. It's fixed now, but I feel bad that I've ignored people's bug reports and pull requests. I'll try to be more responsive.

The fix is in coverage.py v4.0a3. Also, the reports now use file names instead of a weird hybrid. Previously, the file "a/b/c.py" was reported as "a/b/c". Now it is shown as "a/b/c.py". This works better where non-Python files can be reported, so we can't assume the extension is .py.

Oh, did I mention that now you can coverage-measure your Django templates?

Also in the XML report, there's now a configuration setting to determine the directory depth that will be reported as packages. The default is that all directories will be reported as packages, but if you set the depth to 2, then only the upper two layers of directories will be reported.

Try coverage.py v4.0a3.

Kindling projects page

Monday 19 January 2015

New programmers often need small projects to work on as they hone their skills. Exercises in courses are too small, and don't leave much room for self-direction or extending to follow the interests of the student. "Real" projects, either in the open-source world or at work, tend to be overwhelming and come with real-world constraints that prevent experimentation.

Kindling projects are meant to fill this gap: simple enough that a new learner can take them on, but with possibilities for extension and creativity. Large enough that there isn't one right answer, but designed to be hacked on by a learner simply to flex their muscles.

To help people find projects like these, I've made a page: Kindling Projects. I'm hoping it will grow over time and be useful to people.

If you have suggestions, send them in.

Coverage.py for Django templates

Saturday 17 January 2015

A long experiment has come to fruition: coverage.py support for Django templates. I've added plugin support to coverage.py, and implemented a plugin for Django templates. If you want to try it in its current alpha state, read on.

The plugin itself is pip installable:

$ pip install django_coverage_plugin

To run it, add these settings to your .coveragerc:

# Makes it slower, won't be needed eventually
timid = True

plugins =

Then run your tests under coverage.py. It requires coverage.py >= 4.0a2, so it may not work with other coverage-related tools such as test-runner coverage plugins, or coveralls.io. The plugin works on Django >= 1.4, and Python 2 or 3.

You will see your templates listed in your coverage report alongside your Python modules. They have a .html extension but no directory, that's still to be fixed.

The technique used to measure the coverage is the same that Dmitry Trofimov used in dtcov, but integrated into coverage.py as a plugin, and made more performant. I'd love to see how well it works in a real production project. If you want to help me with it, feel free to drop me an email.

The coverage.py plugin mechanism is designed to be generally useful for hooking into the collection and reporting phases of coverage.py, specifically to support non-Python files. I've also got a plugin for Mako templates, but it needs some fixes from Mako. If you have non-Python files you'd like to support in coverage.py, let's talk.

Cog 2.4

Sunday 11 January 2015

The recent holidays gave us Christmas and New Year's Day on a Thursday, so I also had two Fridays off. This gave me two four-day weekends in a row. At the same time, I got a pull request against Cog from Doug Hellmann. Together, these gave me the time and the reason to update Cog.

So I cleaned up the couple of old pull requests, and open issues, and modernized the repo quite a bit.

Cog 2.4 is available now, with three new features:

  • A --delimiters option lets you control the three delimiters that separate the cog code and result from the rest of the file. Thanks, Doug Hellman.
  • A -n=ENCODING option that lets you specify the encoding for the input and output files. Thanks, Petr Gladkiy.
  • A --verbose option that lets you control how much chatter is in the output while cogging.

It was nice to revisit this old friend, and be able to tend it and ship it.

« | » Main « | »