F-string formatting syntaxError

@ogra
inside the directory, I’m doing the following steps:
$ snapcraft --debug
$ sudo snap install olibox-core_0.1dev_amd64.snap --devmode --dangerous

run the app with following command:
$ olibox-core

after this command, error appears.

make sure to run snapcraft clean if you made changes and trigger a new build, so the multipass vm gets wiped …

I do that every time before starting a new build but no luck!

hmm, the source: tree from your snapcraft.yaml seems to not exist on github …

@ogra I’m not sure but you can find the .yaml file here.

oh, in fact, you seem to have two source: entries in the snapcraft.yaml … make sure to comment the one pointing to the non-existing github tree !

(i wonder why the snapcraft yaml parser does not refuse to build with this … it should surely catch such duplcated lines)

still getting the same error.

looking again, you also have two base: entries, drop the one pointing to β€œcore” you can really only have one (and i guess snspcraft just picked the second one and defaulted to core instead of core18)

1 Like

I’m stupid.
I created a new repo (https://github.com/m-yahya/snap-tutorial.git) and dropping the extra core seems working.
So, at this moment I can read the config file.
I’ll open another topic to describe what I wanted to achieve at the end.
Thank you all for your precious time and help, very much appreciated.

1 Like

can you please say a few words about file path, how they are determine?
do I need to specify file path relative to modules or file path should be relative to home directory?
for example with the following app structure:

.
β”œβ”€β”€ config.toml
β”œβ”€β”€ environmentals
β”œβ”€β”€ LICENSE
β”œβ”€β”€ olibox_core
β”‚   └── olibox_core
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ olibox_core.py
β”‚       └── olibox_pkg
β”‚           β”œβ”€β”€ config.py
β”‚           β”œβ”€β”€ environments.py
β”‚           β”œβ”€β”€ __init__.py
β”‚           └── user.py
β”œβ”€β”€ olibox-core_0.1dev_amd64.snap
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ setup.py
β”œβ”€β”€ snap
β”‚   └── snapcraft.yaml
└── tests
    β”œβ”€β”€ helpers_tests.py
    └── oliboxcore_tests.py

if I want to access config.toml file inside environments.py then should I use '../../config.tml' or just config.toml?
thanks

if config.toml is copied into the root of your snap (either look inside the snap by unsquashing it, or use the snapcraft --debug feature to inspect the prime/ dir inside the builds (which is identical to the structure inside the snap) … you’d access it by using something like os.environ['SNAP'] to read the toplevel path of the snap from the environment.

but assuming your config file should actually be configurable ($SNAP is the readonly bit of your snap) you probably want to use a configure or install hook to copy it to $SNAP_DATA (which corresponds to /var/snap/<snapname>/current/ (needs root, due to being in /var)) or SNAP_USER_DATA (i.e.: ~/snap/<snapname>/current/)

and make the app read it from there …

1 Like

It’s really helpful, thanks
I’ll open a new topic and tag you there.

can you please look at this question: How to persist user config data to SNAP_USER_DATA?

thanks