question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Embed resource files in final package at a given location

See original GitHub issue

From @theunkn0wn1

The feature I would like to see out of this is to be able to embed resource files into the wheel (and subsequently the installed package) at an arbitrary location.

For instance, in my project i would like to embed the pyproject.toml into the installed sources so the library may access this resource at runtime. I wish to do this to access the version string contained in the pyproject.toml. Presently, even if the tool.poetry.include directive is used the file does not end up in the installation directory and is consequently not usable to the installed application.

My application has the structure

/
/pyproject.toml
/src/...
/test/...

What I would like to do is copy, at build time, /pyproject.toml to /src/pyproject.toml so it may be included in the wheel and usable a resource via importlib.resources.

import importlib.resources as resources
import toml
import src  # root application package (renames are planned)
package_meta = toml.loads(resources.read_text(src, "pyproject.toml"))
src.__version__ = package_meta['tool']['poetry']['version']

_Originally posted by @theunkn0wn1 in https://github.com/python-poetry/core/pull/6#issuecomment-608017525_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dmyersturnbullcommented, May 1, 2020

@finswimmer @stephsamson Is there no current way to include resource files that are not in a package?

I’d like to include a changelog.md so it can be summarized when the package runs.

This is a more obscure use case, but I also have a self-hosting code that needs to store its own config setup, including its own pyproject.toml.

0reactions
finswimmercommented, Nov 27, 2022

Closing this as a duplicate of #4583

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundling resources with a Swift package - Apple Developer
From the File menu in Xcode, choose Add Files to [packageName]. Use Finder or the Terminal app. When you add a resource to...
Read more >
Create resource files - .NET - Microsoft Learn
Create a binary resource (.resources) file programmatically. You can then embed the file in an application executable or an application library ...
Read more >
Embedding resources (images, sound bits, etc) into a Java ...
I imported the image by right-clicking on the Project -> Import -> General/File System for the import source. Selected the folder which contained...
Read more >
How I Embedded Resources in Go - Level Up Coding
We store our all files inside a special directory called resources inside the box package. It can contain directories as well to organize ......
Read more >
embed-resource - crates.io: Rust Package Registry
Example: Embedding a Windows Manifest · Add the following to your cargo.toml: · In your project root directory, add a file named build.rs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found