rules_py icon indicating copy to clipboard operation
rules_py copied to clipboard

Only remove the venv_root directory if it has contents

Open kriscfoster opened this issue 9 months ago • 5 comments
trafficstars

When a k8s pod is configured with readOnlyRootFilesystem, we hit the following error:

Unable to create base venv directory
Read-only file system.

We then mounted a volume under the path where the venv directory was being created. We then hit:

Unable to remove venv_root directory
Read-only file system.

I think this should solve the issue. Basically, only try to delete the existing venv directory if it is non-empty. In our case, it is empty (when we are mounting an empty directory as a volume).

However, I'm not totally sure how I can actually test this in our environment without a release. I tried adding a patch for py/tools/py/src/venv.rs but that didn't work because I guess this actually gets bundled as a binary as part of the release. Do you have any hints for us to test this change?


Changes are visible to end-users: yes/no

  • Searched for relevant documentation and updated as needed: yes/no
  • Breaking change (forces users to change their own code or config): yes/no
  • Suggested release notes appear below: yes/no

Test plan

  • Covered by existing test cases
  • New test cases added
  • Manual testing; please provide instructions so we can reproduce:

kriscfoster avatar Jan 27 '25 18:01 kriscfoster

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 27 '25 18:01 CLAassistant

Test

9 test targets passed

Targets
//examples/multi_version:py_version_default_test [k8-fastbuild]                         1s
//examples/multi_version:py_version_test [k8-fastbuild-ST-494921797612]                 3s
//examples/pytest:nested/pytest [k8-fastbuild]                                          2s
//examples/pytest:pytest_test [k8-fastbuild]                                            2s
//examples/virtual_deps:pytest_test [k8-fastbuild]                                      2s
//py/tests/external-deps:test_can_import_runfiles_helper [k8-fastbuild]                 720ms
//py/tests/internal-deps:assert [k8-fastbuild]                                          566ms
//py/tests/py-test:test_env_vars [k8-fastbuild]                                         575ms
//py/tests/repo_relative_imports/test:test [k8-fastbuild]                               568ms

Total test execution time was 14s. 19 tests (67.9%) were fully cached saving 35s.

aspect-workflows[bot] avatar Jan 27 '25 18:01 aspect-workflows[bot]

My knowledge of rust is limited so looks like there's some issue. I'll work on fixing it in this PR tomorrow.

kriscfoster avatar Jan 27 '25 18:01 kriscfoster

If you switch to pulling rules_py from a SHA rather than a release, you'll get the "pre-release" which exposes the rust sources to your build and you can test this from HEAD.

Or of course you can reproduce your problem within the examples folder here, which always uses a pre-release

alexeagle avatar Jan 28 '25 20:01 alexeagle

I am curious about your end goal, ultimately we want to generate the venv runtime so it works with readonly filesystems.

thesayyn avatar Feb 06 '25 17:02 thesayyn

This should be obviated as of #551.

arrdem avatar Jun 09 '25 21:06 arrdem