Skip to content

Python dependencies are not respected by rules_freecad #1

@meisam

Description

@meisam

When defining a py_binary target, bazel does not correctly set up the dependencies specified in the deps = [ ... ] attribute.

Details

Incorrect configuration, such as environment variables, seems to be causing this issue because bazel correctly builds and copies the runfiles for the dependencies into the folder for the by_binary. Also, a quick workaround (adding CWD to the sys.path) fixes the issue and is further evidence that the issue is caused by a misconfiguration when extracting and running the freecadcmd command.

How to reproduce the issue

The issue is easily reproducible:

  1. Check out the dependency-bug branch in the programming-rivers repo:
$ git clone --shallow --branch dependency-bug git@github.com:Programming-Rivers/woodwork.git
  1. [Optional] Verify you can run the //main.repro target without using the python bundled with FreeCAD.
% bazel run //main:repro                                                           
WARNING: Build option --platforms has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
INFO: Analyzed target //main:repro (0 packages loaded, 3452 targets configured).
INFO: Found 1 target...
Target //main:repro up-to-date:
  bazel-bin/main/repro
INFO: Elapsed time: 0.306s, Critical Path: 0.10s
INFO: 5 processes: 5 internal.
INFO: Build completed successfully, 5 total actions
INFO: Running command line: bazel-bin/main/repro
Hello, repro!
  1. Attempt to run the same //main.repro target WITH the python bundled with FreeCAD:
$  bazel run //main:repro --platforms=@rules_freecad//platforms:freecad_linux_x86_64

...
% bazel run //main:repro --platforms=@rules_freecad//platforms:freecad_linux_x86_64
INFO: Analyzed target //main:repro (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //main:repro up-to-date:
  bazel-bin/main/repro
INFO: Elapsed time: 0.392s, Critical Path: 0.00s
INFO: 1 process: 1 action cache hit, 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/main/repro
FreeCAD 1.0.2, Libs: 1.0.2R39319 (Git)
(C) 2001-2025 FreeCAD contributors
FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.

Exception while processing file: /path/to/bazel-out/k8-fastbuild/bin/main/repro.runfiles/_main/main/repro.py [No module named 'shapes']

Workaround

Add the current working directory to the list of system paths that python is searching to find dependencies:

sys.path.append(os.getcwd())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions