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

add cwd to sys.path #1114

Open
AvihaiSam opened this issue Apr 30, 2024 · 4 comments
Open

add cwd to sys.path #1114

AvihaiSam opened this issue Apr 30, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@AvihaiSam
Copy link

Problem

I want to run kopf without the need to define cwd/pwd in PYTHONPATH.
I'm not sure why it's not there, might be related to venv.

Proposal

just make in automatic.

Code

import sys
import os

cwd = os.getcwd()
if not cwd in sys.path:
    sys.path.append(cwd)


### Additional information

_No response_
@AvihaiSam AvihaiSam added the enhancement New feature or request label Apr 30, 2024
@nolar
Copy link
Owner

nolar commented Apr 30, 2024

It is not about Kopf, it is about running a generic Python app and is (or is not) an issue of Python. Afair, this was the default behavor for years, but they reverted this behaviour — presumably, for security reasons. It is not up to a specialised niche framework to override that general approach of Python. The app developers can do this if they want, as they control the whole environment.

Also, if kopf is installed as a package normally, it will run without any path manipulation — because it (i.e. pip/poetry/whatnot) installs a bin script named kopf. I did not get what exactly is not working in your example.

@AvihaiSam
Copy link
Author

AvihaiSam commented Apr 30, 2024

when running kopf with -m some.module (assuming ./some/module dir exists and all paths include __init__.py) the import fails since PWD is not in path.

@AvihaiSam
Copy link
Author

i didn't know that behavior has changed, and I agree that it shouldn't be overridden in the framework - but maybe we can add that as a cli flag

@nolar
Copy link
Owner

nolar commented Apr 30, 2024

CLI already allows this, basically in any shell:

PYTHONPATH=. kopf run -m some.module
PYTHONPATH=/home/…/dir1:/opt/myoperator/dir2 kopf run -m some.module

Not specific to Kopf, this is a Python feature:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants