Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import gclib relative to wwrando.py instead of current working directory #368

Merged
merged 1 commit into from
Mar 23, 2024

Conversation

Aelire
Copy link
Contributor

@Aelire Aelire commented Mar 23, 2024

Executing the randomizer from source currently only works when the working directory is the root of the repository, with gclib being loaded from a path relative to the working directory of the shell. This changes the gclib load path to be relative to the wwrando.py file so that it's possible to execute the randomizer from different directories.
A similar method is already used in the assemble.py script here:

wwrando/asm/assemble.py

Lines 14 to 16 in ccb32a3

asm_dir = os.path.dirname(__file__)
sys.path.insert(0, asm_dir + "/../gclib")

This might be linux-only (not sure how cwd works on other OS), and only shows up when running from source rather than release binaries (I tested that this change doesn't break a (linux) release binary though), so this is mostly for convenience when developing, but it would also be useful for the racetime.gg bot which can run multiple versions of the randomizer side-by-side

For example, on master when running from one directory up the tree it fails like this:

python wwrando/wwrando.py                                                                                                                                                                                                                                                                                                                                               
Traceback (most recent call last):
  File "<...>/wwrando/wwrando.py", line 294, in <module>
    run_with_ui(args)
  File "<...>/wwrando/wwrando.py", line 270, in run_with_ui
    from wwr_ui.randomizer_window import WWRandomizerWindow
  File "<...>/wwrando/wwr_ui/randomizer_window.py", line 5, in <module>
    from wwr_ui.uic.ui_randomizer_window import Ui_MainWindow
  File "<...>/wwrando/wwr_ui/uic/ui_randomizer_window.py", line 25, in <module>
    from wwr_ui.cosmetic_tab import CosmeticTab
  File "<...>/wwrando/wwr_ui/cosmetic_tab.py", line 20, in <module>
    import customizer
  File "<...>/wwrando/customizer.py", line 13, in <module>
    from gclib import fs_helpers as fs
ImportError: cannot import name 'fs_helpers' from 'gclib' (unknown location)
[1]    2494186 exit 1     python wwrando/wwrando.py

Fixes executing the randomizer from a different working directory than
the root of the repository
wooferzfg added a commit to wooferzfg/tww-rando-bot that referenced this pull request Mar 23, 2024
@LagoLunatic LagoLunatic merged commit 3a78be0 into LagoLunatic:master Mar 23, 2024
6 checks passed
@Aelire Aelire deleted the relative-gclib branch April 4, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants