Skip to content

Commit

Permalink
pex_rules.bzl: Avoid spurious rebuild of virtualenv due to pyc (#57)
Browse files Browse the repository at this point in the history
I noticed that when running anything that used the pex rules for the
second time, it would always rebuild pex_wrapper. The cause is that
when virtualenv is run, Python creates a .pyc file. The virtualenv
target uses a glob of "**/*", which detects a change. After that, it
will stay constant. To fix it: exclude .pyc files from the glob.

I suspect the Linux sandbox would not cause this error, but on Mac
the error can be reproduced as follows:

bazel clean --expunge
bazel build --subcommands //examples:foo
bazel build --subcommands --explain=explain.log //examples:foo

The second run will rebuild the target with the explaination:

Executing action 'Creating source manifest for
@virtualenv//:virtualenv [for host]': action command has changed.

Looking at the output of the command shows that the contents of
virtualenv.runfiles_manifest has added virtualenv.pyc
  • Loading branch information
Evan Jones authored and benley committed Dec 4, 2017
1 parent 6af3058 commit bde25c1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pex/pex_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ def pex_repositories():
"py_binary(",
" name = 'virtualenv',",
" srcs = ['virtualenv.py'],",
" data = glob(['**/*']),",
# exclude .pyc: Otherwise bazel detects a change after running virtualenv.py
" data = glob(['**/*'], exclude=['*.pyc']),",
" visibility = ['//visibility:public'],",
")",
])
Expand Down

0 comments on commit bde25c1

Please sign in to comment.