ballistica icon indicating copy to clipboard operation
ballistica copied to clipboard

`python_directory_app, python_directory_app_site` not returning full paths

Open brostosjoined opened this issue 10 months ago • 5 comments

Description

While executing the code below the output is supposed to be a full path as seen by calling python_directory_user which points the full path to the mods folder, but instead it gives a segment of the path as shown below. They work well on Mac

print(bs.app.env.python_directory_app) #-> ba_data\python
print(bs.app.env.python_directory_app_site) #-> ba_data\python-site-packages
print(bs.app.env.python_directory_user) #-> C:\Users\rover\Desktop\Inventory\Games\BombSquad_Server_Windows_1.7.37\dist\ba_root\mods

Expected behavior

Should give the full path

print(bs.app.env.python_directory_app) #-> C:\Users\rover\Desktop\Inventory\Games\BombSquad_Server_Windows_1.7.37\dist\ba_data\python
print(bs.app.env.python_directory_app_site) #-> C:\Users\rover\Desktop\Inventory\Games\BombSquad_Server_Windows_1.7.37\dist\ba_data\python-site-packages
print(bs.app.env.python_directory_user) #-> C:\Users\rover\Desktop\Inventory\Games\BombSquad_Server_Windows_1.7.37\dist\ba_root\mods

Machine

Platform: Windows 11 / Ubuntu 22.04 LTS / Android 12 BombSquad version: 1.7.37

brostosjoined avatar Feb 20 '25 02:02 brostosjoined

I would say that the current behavior is the intended one since the first two directory paths are usually at the same fixed path relative to the game's execution path; while the user directory usually needs a full path due to the way GUI builds work.

EraOSBeta avatar Mar 11 '25 10:03 EraOSBeta

But it would be cleaner for the functions to work the same on all platforms not only mac. We can just get the current working directory then append it at the start of the affected methods, can't be that hard(•᷄- •᷅ ;)

brostosjoined avatar Mar 11 '25 15:03 brostosjoined

It is by design that it can be either. I like using relative paths sometimes to keep things short. That way if you're looking at things like exception tracebacks you'll hopefully see stuff like 'ba_data/python/babase/_app.py' instead of some crazy long absolute path you might see on some platforms like Android.

When writing a command line program that accepts a file path you need to be prepared to be passed 'foo' or '../foo' or '/abs/path/to/foo' or whatever else; just think of this in the same way. If you want to work with abs paths, just wrap the value with os.path.abspath().

I would wonder in this case why bs.app.env.python_directory_user is an absolute path. Maybe it'd be possible to get that to be relative as well for consistency. Though again it should be expected that they can be either, as sometimes relative isn't possible.

Maybe there's docs we should update to clarify this setup?

efroemling avatar Mar 11 '25 15:03 efroemling

I would wonder in this case why bs.app.env.python_directory_user is an absolute path

I would assume it's because the user directory is a fixed path and isn't placed relative to the executable in non-headless builds. In terms of consistency I think it's best if 6 new attributes are added with 3 of them explicitly returning the absolute path and the other 3 explicitly being relative to the execution path, with these original 3 being removed if/when api10 comes around.

EraOSBeta avatar Mar 11 '25 15:03 EraOSBeta

API 10 already!!! not even got time to mess with api 9 ui changes well.

brostosjoined avatar Mar 11 '25 16:03 brostosjoined