• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

petl-developers / petl / 38016995676
94%

Build:
DEFAULT BRANCH: master
Ran 10 Oct 2026 02:28AM UTC
Jobs 1
Files 132
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

10 Oct 2026 02:26AM UTC coverage: 92.427% (+0.006%) from 92.421%
38016995676

push

github

web-flow
Allow importing petl when bz2 is not available (#731)

This PR has the objective of letting petl be imported on Python builds
that don't include the bz2 module, as reported in #415.

Python can be compiled without bz2 support (e.g. pyenv/source builds
without the bzip2 headers, some minimal containers). Right now
petl/io/sources.py imports bz2 at module level, so import petl
fails completely in that case, even if no .bz2 file is ever used:

```
$ python -c "import sys; sys.modules['bz2'] = None; import petl"
...
ModuleNotFoundError: import of bz2 halted; None in sys.modules
```

## Changes

1. Import `bz2` inside a `try`/`except ImportError` in
`petl/io/sources.py`.
2. `BZ2Source.open()` raises an `ImportError` explaining that `bz2` is
not available, so `fromcsv('file.csv.bz2')` / `tocsv(...,
'file.csv.bz2')` give a clear error. The `.bz2` codec stays registered
so these files are not silently read or written as plain text.
3. Added a test that runs a subprocess with `bz2` blocked, checks that
plain CSV still works and that reading and writing `.bz2` raise
`ImportError`. It fails on master because `import petl` itself fails.
4. Added an entry to `docs/changes.rst`.

Behavior with a normal Python build is unchanged.

## Checklist

* [x] Source Code guidelines:
  * [x] Includes unit tests
* [x] New functions have docstrings with examples that can be run with
doctest (no new functions)
  * [x] New functions are included in API docs (n/a)
* [x] Docstrings include notes for any changes to API or behavior (n/a)
  * [x] All changes are documented in docs/changes.rst
* [x] Versioning and history tracking guidelines:
  * [x] Using atomic commits whenever possible
  * [x] Commits are reversible whenever possible
  * [x] There are no incomplete changes in the pull request
  * [x] There is no accidental garbage added to the source code
* [x] Testing guidelines:
  * [x] Tested locally using `tox` / `pytest`
  * [x] Rebased to `master` branch and tested before send... (continued)

15 of 15 new or added lines in 2 files covered. (100.0%)

14988 of 16216 relevant lines covered (92.43%)

0.92 hits per line

Jobs
ID Job ID Ran Files Coverage
1 38016995676.1 10 Oct 2026 02:28AM UTC 132
92.43
GitHub Action Run
Source Files on build 38016995676
  • Tree
  • List 132
  • Changed 2
  • Source Changed 0
  • Coverage Changed 2
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • df9e2c5e on github
  • Prev Build on master (#38016517596)
  • Next Build on master (#38018001124)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc