Skip to content

Added worker to pythonpath #1215

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

Merged
merged 6 commits into from
Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions python/prodV4/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# User packages
PKGS_PATH = "site/wwwroot/.python_packages"
VENV_PKGS_PATH = "site/wwwroot/worker_venv"
WORKER_DIR = "azure_functions_worker"

PKGS = "lib/site-packages"

Expand Down Expand Up @@ -50,18 +51,20 @@ def determine_user_pkg_paths():

if __name__ == '__main__':
# worker.py lives in the same directory as azure_functions_worker
current_dir = str(Path(__file__).absolute())
worker_path = os.path.join(current_dir, WORKER_DIR)
func_worker_dir = str(Path(__file__).absolute().parent)
env = os.environ

# Setting up python path for all environments to prioritize
# third-party user packages over worker packages in PYTHONPATH
user_pkg_paths = determine_user_pkg_paths()
joined_pkg_paths = os.pathsep.join(user_pkg_paths)
env['PYTHONPATH'] = f'{joined_pkg_paths}:{func_worker_dir}'
env['PYTHONPATH'] = f'{worker_path}:{joined_pkg_paths}:{func_worker_dir}'
Copy link
Member

Choose a reason for hiding this comment

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

Any way to add test for this? in the docker test as least?


if is_azure_environment():
os.execve(sys.executable,
[sys.executable, '-m', 'azure_functions_worker']
[sys.executable, '-m', WORKER_DIR]
+ sys.argv[1:],
env)
else:
Expand Down