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

fix: Make file upload work when waved run separately #2225 #2232

Merged
merged 8 commits into from
Jan 23, 2024

Conversation

marek-mihok
Copy link
Contributor

The PR fulfills these requirements: (check all the apply)

  • It's submitted to the main branch.
  • When resolving a specific issue, it's referenced in the PR's title (e.g. feat: Add a button #xxx, where "xxx" is the issue number).
  • When resolving a specific issue, the PR description includes Closes #xxx, where "xxx" is the issue number.
  • If changes were made to ui folder, unit tests (make test) still pass.
  • New/updated tests are included

This PR fixes the issue when H2O_WAVE_WAVED_DIR has a wrong value in some scenarios. The fix is accomplished by finding the PID of the waved/waved.exe and getting its CWD which is then set to H2O_WAVE_WAVED_DIR env variable.

Successfully tested on both Mac and Windows.

Closes #2225

Copy link
Collaborator

@mturoci mturoci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @marek-mihok! Can we do without external lib though?

py/h2o_wave/pyproject.toml Outdated Show resolved Hide resolved
print('Could not connect to Wave server. Please start the Wave server (waved or waved.exe) prior to running any app.')
return

if not os.environ.get('H2O_WAVE_WAVED_DIR') and is_waved_present:
os.environ['H2O_WAVE_WAVED_DIR'] = sys.exec_prefix
os.environ['H2O_WAVE_WAVED_DIR'] = waved_cwd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works reliably, we can deprecate H2O_WAVE_WAVED_DIR. Add a TODO here for now.

waved_cwd = psutil.Process(proc.pid).cwd()
except psutil.NoSuchProcess:
pass
waved_path = os.path.join(waved_cwd, proc_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true for platform specific wheel files. Platform-agnostic whl does not contain waved binary.

@marek-mihok
Copy link
Contributor Author

Can we do without external lib though?

@mturoci my research shows there is no pythonic (or other simple) way of getting process cwd by its name on Windows. Libs like psutil or win32com use complex solutions for this simple problem.

Maybe we could include psutil as the os specific dependency? For Windows only? And use external lib free solution otherwise?

@mturoci
Copy link
Collaborator

mturoci commented Jan 17, 2024

there is no pythonic (or other simple) way of getting process cwd by its name on Windows

In that case, you can either implement for UNIX systems only and defer to HTTP on err and Windows or go for HTTP everywhere and keep using H2O_WAVE_WAVED_DIR for speedup if needed.

@mturoci
Copy link
Collaborator

mturoci commented Jan 17, 2024

Edit: Let's just go for HTTP uploads when waved is run separately and local uploads when waved is started automatically. This would be the safest and simplest option.

@mturoci
Copy link
Collaborator

mturoci commented Jan 18, 2024

Added a small refactor. @marek-mihok please verify if works. If it does, good to merge. Thanks!

@marek-mihok
Copy link
Contributor Author

@mturoci works, it's good to go.

@mturoci mturoci merged commit 1eaa8a0 into main Jan 23, 2024
2 checks passed
@mturoci mturoci deleted the feat/issue-2225 branch January 23, 2024 09:22
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.

File upload not working when waved run separately.
2 participants