hydpy-dev / hydpy

A framework for the development and application of hydrological models based on Python
GNU Lesser General Public License v3.0
35 stars 17 forks source link

Problems to run nox doctest session behind proxy #149

Open sivogel opened 2 months ago

sivogel commented 2 months ago

I have problems running the nox doctest session behind a proxy. The command "session.run("pip", "install", "numpy<2")" needs the proxy to be set. If I remove "with _clean_environment(session):"

tyralla commented 2 months ago

Could you please complete your error report?

However, I guess that we simply need to change this code:

    with _clean_environment(session):
        if numpy == "1":
            session.run("pip", "install", "numpy<2")
        elif numpy == "2":
            session.run("pip", "install", "numpy>1,<3")
        else:
            assert_never(numpy)
        session.run("python", "hydpy/tests/run_doctests.py", *session.posargs)

to that one:

    if numpy == "1":
        session.run("pip", "install", "numpy<2")
    elif numpy == "2":
        session.run("pip", "install", "numpy>1,<3")
    else:
        assert_never(numpy)
    with _clean_environment(session):
        session.run("python", "hydpy/tests/run_doctests.py", *session.posargs)

Could you please verify and, if it works, open a pull request?

sivogel commented 2 months ago

Oh pardon. Somehow the second part got lost: The following part did not work due to a SSL connection error (no proxy set for pip install)

with _clean_environment(session):
        if numpy == "1":
            session.run("pip", "install", "numpy<2")
        elif numpy == "2":
            session.run("pip", "install", "numpy>1,<3")

Removing the with _clean_environment(session): (from the whole statement) helped to run the session. Could you please explain why do you need the _clean_environment for the run_doctest session?

tyralla commented 2 months ago

I added the _clean_environment context manager to get the HydPy-Server doctests running, which were hanging in some cases when the environment variable HTTP_PROXY or HTTPS_PROXY was set. However, I don't know if it is still required after the change introduced in commit 7bb80bfd.

sivogel commented 2 months ago

In my case (behind a proxy) it is not needed (I run it without last week). But I think it also was no problem before, because localhost is added to my NO_PROXY environment variable. I think we can completely remove it.

tyralla commented 2 months ago

But removing _clean_environment would mean some nox sessions would not run if HTTP_PROXY is set without NO_PROXY being defined as you explained. We would have to explain this somewhere in the documentation. Hence, I see no advantage in removing _clean_environment compared to fixing the problem as suggested.

sivogel commented 2 months ago

I think setting up a proxy that ignores all local addresses is pretty standard. I would like to discuss this with Holger. He is more familiar this topic.