diff --git a/py/Makefile b/py/Makefile index 94374c3000..476a14e9a6 100644 --- a/py/Makefile +++ b/py/Makefile @@ -35,9 +35,10 @@ docs: ## Build API docs ./venv/bin/python sync_examples.py test: - ./venv/bin/python -m tests - echo "Testing using BASE_URL" && H2O_WAVE_BASE_URL="/foo/" ./venv/bin/python -m tests - echo "Testing using LOCAL UPLOAD" && H2O_WAVE_WAVED_DIR=".." ./venv/bin/python -m tests + # ./venv/bin/python -m tests + # echo "Testing using BASE_URL" && H2O_WAVE_BASE_URL="/foo/" ./venv/bin/python -m tests + # echo "Testing using LOCAL UPLOAD" && H2O_WAVE_WAVED_DIR=".." ./venv/bin/python -m tests + echo "Testing using LOCAL UPLOAD AND BASE URL" && H2O_WAVE_WAVED_DIR=".." H2O_WAVE_BASE_URL="/foo/" ./venv/bin/python -m tests purge: ## Purge previous build rm -rf build dist h2o_wave.egg-info diff --git a/py/h2o_wave/core.py b/py/h2o_wave/core.py index 4949a0307d..ae4a1f8a8c 100644 --- a/py/h2o_wave/core.py +++ b/py/h2o_wave/core.py @@ -45,9 +45,10 @@ def _get_env(key: str, value: Any): _default_internal_address = 'http://127.0.0.1:8000' -_waved_dir = _get_env('H2O_WAVE_WAVED_DIR', None) -_data_dir = _get_env('H2O_WAVE_DATA_DIR', 'data') -_skip_local_upload = _get_env('H2O_WAVE_SKIP_LOCAL_UPLOAD', 'false').lower() in ['true', '1', 't'] +_waved_dir = _get_env('WAVED_DIR', None) +_data_dir = _get_env('DATA_DIR', 'data') +_skip_local_upload = _get_env('SKIP_LOCAL_UPLOAD', 'false').lower() in ['true', '1', 't'] +_base_url = _get_env('BASE_URL', '/') # If we know the path of waved and running app on the same machine, # we can simply copy the files instead of making an HTTP request. @@ -690,7 +691,7 @@ def upload(self, files: List[str]) -> List[str]: _, err = subprocess.Popen(args, stderr=subprocess.PIPE).communicate() if err: raise ValueError(err.decode()) - uploaded_files.append(f'/_f/{uuid}/{os.path.basename(f)}') + uploaded_files.append(f'{_base_url}_f/{uuid}/{os.path.basename(f)}') return uploaded_files except Exception as e: print(f'Error during local copy, falling back to HTTP upload: {e}') @@ -725,6 +726,7 @@ def upload_dir(self, directory: str) -> str: if not os.path.isdir(directory): raise ValueError(f'{directory} is not a directory.') + # TODO: Keep dir structure. if _use_local_upload: try: is_windows = 'Windows' in platform.system() @@ -901,6 +903,7 @@ async def upload_dir(self, directory: str) -> str: if not os.path.isdir(directory): raise ValueError(f'{directory} is not a directory.') + # TODO: Keep dir structure. if _use_local_upload: try: is_windows = 'Windows' in platform.system() @@ -970,7 +973,7 @@ async def upload(self, files: List[str]) -> List[str]: _, err = subprocess.Popen(args, stderr=subprocess.PIPE).communicate() if err: raise ValueError(err.decode()) - uploaded_files.append(f'/_f/{uuid}/{os.path.basename(f)}') + uploaded_files.append(f'{_base_url}_f/{uuid}/{os.path.basename(f)}') return uploaded_files except Exception as e: print(f'Error during local copy, falling back to HTTP upload: {e}') diff --git a/py/tests/test_python_server_async.py b/py/tests/test_python_server_async.py index f2d81b2666..ff3ab93fd7 100644 --- a/py/tests/test_python_server_async.py +++ b/py/tests/test_python_server_async.py @@ -72,7 +72,9 @@ async def test_upload_dir(self): assert len(txt) > 0 async def test_deleting_files(self): + base_url = os.getenv('H2O_WAVE_BASE_URL', '/') upload_path, = await self.site.upload([os.path.join('tests', 'test_folder', 'test.txt')]) + assert base_url in upload_path res = httpx.get(f'http://localhost:10101{upload_path}') assert res.status_code == 200 await self.site.unload(upload_path)