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

Path issue in tuf import in examples/client and examples/repository #2786

Open
venkat-iiita opened this issue Feb 11, 2025 · 6 comments
Open

Comments

@venkat-iiita
Copy link

While running /examples/client/client and /examples/repository/_simplerepo.py, encountered with errors because of the path issue with the tuf.

The following statements resolved the error.

import os

parent_dir = Path(__file__).resolve().parent.parent.parent
sys.path.append(str(parent_dir))

or it can be as follows.

import os

parent_dir = Path(__file__).resolve().parent[2]
sys.path.append(str(parent_dir))

The above can be updated in the actual code.

@jku
Copy link
Member

jku commented Feb 11, 2025

Can you provide the error message and actual reproduction instructions?

I'm guessing this might be a result of 4e889e7: the source dir is not installed anymore -- it may be that it actually should be installed in requirements/dev.txt even if tests don't require it anymore since otherwise the examples might indeed not work.

Can you confirm if the above sounds like your problem or if pip install -e . in the source root dir fixes the issue for you?

@venkat-iiita
Copy link
Author

Following is the error i got when I run ./client

Traceback (most recent call last):
File "///supplychain/python-tuf/examples/client/./client", line 19, in
from tuf.api.exceptions import DownloadError, RepositoryError
ModuleNotFoundError: No module named 'tuf'

Line 19 is as follows

from tuf.api.exceptions import DownloadError, RepositoryError

The following two statements overcome the issue

parent_dir = Path(__file__).resolve().parent.parent.parent
sys.path.append(str(parent_dir))

Python Version I am using: Python 3.9.2

In my initial query, suggested the following as an alternate solution to overcome the issue however this also shows error. Hence drop the following suggestion.
parent_dir = Path(__file__).resolve().parent[2]

@venkat-iiita
Copy link
Author

pip install -e .

Yes, the above resolved the issue

@jku
Copy link
Member

jku commented Feb 12, 2025

Thanks for the extra info. I think we want to add -e . back into requirements/dev.txt then.

I'm not fond of using sys.path.append as that would prevent trying the example code with tuf installed from other sources.

@venkat-iiita
Copy link
Author

This one may also be considered. I am in a network where proxy is used hence I have to set proxy in my system. When I run the ./examples/repository/client then I fail to download the default files. The following resolved my issue

os.environ["NO_PROXY"] = "127.0.0.1"

This may be given in the TODO to help someone who has the proxy setting.

@jku
Copy link
Member

jku commented Feb 14, 2025

fyi in case you are running git version of python-tuf: we've just broken proxy env var settings temporarily in the develop branch. They should came back in #2789

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

No branches or pull requests

2 participants