Opened 15 years ago

Closed 14 years ago

#315 closed defect (fixed)

Avoid generating .pyc files in srcdir

Reported by: Richard Boulton Owned by: Olly Betts
Priority: normal Milestone: 1.0.20
Component: Build system Version: SVN trunk
Severity: minor Keywords:
Cc: Blocked By:
Blocking: Operating System: All

Description

Currently, when the python bindings testsuite is run, .pyc files are generated in the xapian-bindings/python/ srcdir. This could break concurrent builds sharing a srcdir using different versions of python. The only approach I've seen so far for fixing this is to copy the .py files into builddir before running them, so that the .pyc files get generated there. I'm hoping I'll come up with a cleaner solution soon.

Note that this isn't a problem if srcdir is not writable; in this situation, python simply doesn't store the generated bytecode. There don't seem to be any options to python to tell it not to generate bytecode, however.

Change History (4)

comment:1 by Olly Betts, 14 years ago

Milestone: 1.2.x

Another issue is that you can't just delete the build directory and have a clean source tree.

A slightly mad solution: ship directories in the source tarball called testsuite.pyc, etc since Python will then fail to write the .pyc file (which isn't an error)!

Python 2.6 adds a -B command line option (not easy to use) and PYTHONDONTWRITEBYTECODE environmental variable (more useful) to suppress generating .pyc and .pyo files. I've committed a change to trunk to use this (r14337) but that doesn't help for Python < 2.6.

Given it has been 17 months and we don't have a cleaner solution for all Python versions, I propose we either decide not to fix this further, or copy the files. Marking for 1.2.x so this doesn't just linger in trac indefinitely.

comment:2 by Olly Betts, 14 years ago

Owner: changed from Richard Boulton to Olly Betts
Status: newassigned

A non-mad idea - we could have a small wrapper script which is run from TEST_ENVIRONMENT to run a test case and after execution checks for a .pyc file and removes it if present. The ugliness is then localised to just this script, and can be dropped when we require at least Python 2.6.

I'll take a look at doing this, so taking ownership.

comment:3 by Olly Betts, 14 years ago

Milestone: 1.2.x1.0.20

Turns out it doesn't even need a wrapper script - a sh trap in TEST_ENVIRONMENT handles it cleanly - committed in r14338.

Marking for backport to 1.0.20.

comment:4 by Olly Betts, 14 years ago

Resolution: fixed
Status: assignedclosed

Backported r14337 and r14338 for 1.0.20 as r14346.

Note: See TracTickets for help on using tickets.