indygreg / indygreg/PyOxidizer

Aid requested re following resource callback guide

Open
#448 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
6.2k
Forks
256
PR merge metrics
No merged PRs in 30d

Description

Hi @indygreg,

I am trying to follow the documentation here:
https://pyoxidizer.readthedocs.io/en/latest/pyoxidizer_packaging_resources.html?highlight=resource_callback#using-callbacks-to-influence-resource-attributes

Here is the excerpt from my configuration file:

```python
def resource_callback(policy, resource):
if type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"):
if resource.package.startswith("rtai"):
resource.add_location = "in-memory"
else:
resource.add_location = "filesystem-relative:lib"

def make_exe():
dist = default_python_distribution(python_version = "3.9")

policy = dist.make_python_packaging_policy()
policy.register_resource_callback(resource_callback) # This line here is the issue

python_config = dist.make_python_interpreter_config()
python_config.module_search_paths = ["$ORIGIN/lib"]
python_config.run_module = "rtaisite"

exe = dist.to_python_executable(
name = "rtai",
packaging_policy = policy,
config = python_config,
)
exe.windows_runtime_dlls_mode = "always"
exe.windows_subsystem = "windows"
exe.add_python_resources(exe.pip_install(["--use-feature", "in-tree-build", "-r", "requirements.txt"]))

return exe
```

Essentially my goal is to have all dependencies be added to the library directory with their source code as normal, and have any module that starts with "rtai" be stored within memory.

If I change `policy.register_resource_callback(resource_callback)` to either:

* `policy.resources_location = "filesystem-relative:lib"` or
* `policy.resources_location = "in-memory"`

Both of those successfully build (only the filesystem version runs though due to a few of my deps not playing nice),

Nevertheless when I try and follow the [resource callback docs](https://pyoxidizer.readthedocs.io/en/latest/pyoxidizer_packaging_resources.html?highlight=resource_callback#using-callbacks-to-influence-resource-attributes) and use `policy.register_resource_callback(resource_callback)` I get the following error in the build:

```
resolving 1 targets
resolving target install
resolving target exe
resolving Python distribution Url { url: "https://github.com/indygreg/python-build-standalone/releases/download/20210724/cpython-3.9.6-x86_64-unknown-linux-gnu-pgo-20210724T1424.tar.zst", sha256: "343e2d349779efb7d46f7eb01ec6a202bff14293616ce8103bc8060c777bb231" }
Python distribution available at /home/simon/.cache/pyoxidizer/python_distributions/cpython-3.9.6-x86_64-unknown-linux-gnu-pgo-20210724T1424.tar.zst
reading data from Python distribution...
error[PYOXIDIZER_BUILD]: error converting PythonResource to Value: DiagnosedError(Diagnostic { level: Error, message: "Cannot .package on type PythonModuleSource", code: Some("CV00"), spans: [SpanLabel { span: Span { low: Pos(164), high: Pos(180) }, label: Some(".package not supported for type PythonModuleSource"), style: Primary }] })
--> ./pyoxidizer.bzl:18:11
|
18 | exe = dist.to_python_executable(
| ___________^
19 | | name = "rtai",
20 | | packaging_policy = policy,
21 | | config = python_config,
22 | | )
| |_____^ to_python_executable()

error: error converting PythonResource to Value: DiagnosedError(Diagnostic { level: Error, message: "Cannot .package on type PythonModuleSource", code: Some("CV00"), spans: [SpanLabel { span: Span { low: Pos(164), high: Pos(180) }, label: Some(".package not supported for type PythonModuleSource"), style: Primary }] })
```

Any pointers about where I may have tripped up?

Thanks :),
Cheers,
Simon

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the resource callback guide and the callback registration in pyoxidizer.bzl around line 18. Compare the documented resource types and callback behavior with the reported “Cannot .package on type PythonModuleSource” error. Done means the documented callback configuration either builds as shown or the guide clearly reflects the supported API.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.