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

python3Packages.gradio: init at 3.20.1 #241558

Merged
merged 3 commits into from
Aug 8, 2023
Merged

Conversation

pbsds
Copy link
Member

@pbsds pbsds commented Jul 4, 2023

Description of changes

This PR adds gradio by @gradio-app, a web server framework for making AI (anything really) demos.

Original PR is #187032, which was closed due to a mass-ping resulting from a poorly thought out rebase onto staging.

Close #235184

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Pinging reviewers from prior pr:
@happysalada @Janik-Haag @VergeDX @SuperSandro2000

@pbsds pbsds changed the title Gradio init python3Packages.gradio: init at 3.20.1 Jul 4, 2023
@pbsds
Copy link
Member Author

pbsds commented Jul 4, 2023

@ofborg build python3Packages.gradio

@happysalada
Copy link
Contributor

@mweinelt the ci fails on aarch64-linux, the logs don't seem to say much. This could be due to a timeout. Is this of any concern to you ?

@happysalada
Copy link
Contributor

@pbsds this looks good to me, do you intend to do any more work on this ?

@happysalada
Copy link
Contributor

@pbsds I'm waiting for this to package FastChat, let me know if I can do anything to help.

Copy link
Member

@mweinelt mweinelt left a comment

Choose a reason for hiding this comment

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

The test phase of gradio looks annyoing to maintain.

pkgs/development/python-modules/ffmpy/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/markdown-it-py/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/gradio/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/gradio/default.nix Outdated Show resolved Hide resolved
@happysalada
Copy link
Contributor

@pbsds hey, it looks like you are a little busy, would you mind If I took over ?

@pbsds
Copy link
Member Author

pbsds commented Jul 20, 2023

@pbsds hey, it looks like you are a little busy, would you mind If I took over ?

My computer and network access this summer is spotty. I added you to my nixpkgs repo if you're interested in joint maintainership :)

@ofborg build python3Packages.gradio

@pbsds pbsds requested a review from happysalada July 20, 2023 16:07
@happysalada
Copy link
Contributor

This looks good to me.
Im happy to be pinged in case there are problems discovered during the staging PR.
@mweinelt might have more comments, so waiting a bit more.

pkgs/development/python-modules/ffmpy/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/ffmpy/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/ffmpy/default.nix Outdated Show resolved Hide resolved
Comment on lines 130 to 133
# Add pytest hook skipping tests that access network, marking them as "Expected fail" (xfail)
# We additionally xfail FileNotFoundError, as gradio often fail to upload test files to pypi.
preCheck = let
conftestSkipNetworkErrors = writeText "conftest-network-xfail.py" ''
from _pytest.runner import pytest_runtest_makereport as orig_pytest_runtest_makereport
import urllib, urllib3, httpx, requests, websockets

class NixNetworkAccessDeniedError(BaseException): pass
def deny_network_access(*a, **kw):
raise NixNetworkAccessDeniedError

def iterate_exc_chain(exc: Exception):
yield exc
if getattr(exc, "__context__", None) is not None:
yield from iterate_exc_chain(exc.__context__)
if getattr(exc, "__cause__", None) is not None:
yield from iterate_exc_chain(exc.__cause__)

httpx.Request = \
httpx.AsyncClient.get = \
httpx.AsyncClient.head = \
requests.head = \
requests.get = \
requests.post = \
urllib.request.urlopen = \
urllib.request.Request = \
urllib3.connection.HTTPSConnection._new_conn = \
websockets.connect = \
deny_network_access

def pytest_runtest_makereport(item, call):
tr = orig_pytest_runtest_makereport(item, call)
if call.excinfo is not None:
for exc in iterate_exc_chain(call.excinfo.value):
if isinstance(exc, NixNetworkAccessDeniedError):
tr.outcome, tr.wasxfail = 'skipped', "reason: Requires network access."
if isinstance(exc, FileNotFoundError):
tr.outcome, tr.wasxfail = 'skipped', "reason: Pypi dist bad."
return tr
'';
in ''
export HOME=$TMPDIR
cat ${conftestSkipNetworkErrors} >> test/conftest.py
'';
Copy link
Member

Choose a reason for hiding this comment

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

Is some of that upstreamable? Like a network marker? As I mentioned, this looks annoying to maintain.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this is too related to nix to matter upstream.
How about we keep this as is, and if for some reason this doesn't work anymore, we just disable the tests until someone has time to look into this.
Since there are quite a lot of packages depending on gradio, would you rather

  • disable the tests until we confirm with upstream if they are interested in this or not.
  • leave this as is for now and disable the tests if there is a failure related to this.

Copy link
Member

Choose a reason for hiding this comment

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

IMO this is too related to nix to matter upstream.

Having an extra marker to skip network tests is something not nix specific, many distros build their packages without networking. It can also be a great way to skip tests if no network is available or only very slow and flaky.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the prior pr I discussed generalizing this into a pytestCheckHook-esqe hook. The sentiment then was first pushing through this pr

Copy link
Member

Choose a reason for hiding this comment

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

If the usecase comes up, we can always move the implementation into a hook but I am not fully convinced that this is necessary here.

What's the problem with upstreaming this and adding a marker to skip network tests? We just have a build environment without internet access but we would still like to run as many tests as possible.

Copy link
Member Author

@pbsds pbsds Jul 24, 2023

Choose a reason for hiding this comment

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

I don't trust the gradio devs, who tend to move fast and loose, to support this use case. My reason is that i did this pr, to fix the missing test files on pypi. They they promptly broke it again within a few weeks.

I have bumped the version of the prior gradio pr about 3 times over the past year, and each time the list of tests to disable needed change. This proved quite time consuming to maintain (hence that debug helper comment). Network and non-network tests are not grouped in any meaningful sense, so disabledTestPaths proved too aggressive while disabledTests proved too surgical and unmaintainable.

The conftest network xfail approach came upon me in a dream as an easily generalizable drop-in way to run as many tests as possible, without maintaining a disabledTests list, nor relying on upstream devs to support us poor distro maintainers. It is my brain child and I will defend it with passion :P.

To argue in favor of generalizing this xfail approach and a future check hook, here is a very coarse estimate of the number of packages which disable network tests, and likely a lot more, with disableTestPaths:

$ rg disabledTestPaths pkgs/development/python-modules/ -l | xargs rg network | wc -l
137

The conftest network xfail approach will for these likely improve testing coverage by a lot, and I believe such a hook will even remove a lot of doChecks = false; found in throughout our python package set.

@happysalada
Copy link
Contributor

@mweinelt ready for another round of review.
I've added two commits that will later be squashed. I didn't want to replace the commits so that the OP would loose attribution.
let me know if anything.

pkgs/top-level/python-packages.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/ffmpy/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/markdown-it-py/default.nix Outdated Show resolved Hide resolved
# makes pytest freeze 50% of the time
"test/test_interfaces.py"
];
#pytestFlagsArray = [ "-x" "-W" "ignore" ]; # uncomment for debugging help
Copy link
Member

Choose a reason for hiding this comment

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

Can't we enable this by default to better debug hydra builds immediately? Would that be to spammy?

Copy link
Contributor

Choose a reason for hiding this comment

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

if we start getting failures on the package, I would say let's enable it. For now it's best to leave it disabled I think.

Comment on lines 130 to 133
# Add pytest hook skipping tests that access network, marking them as "Expected fail" (xfail)
# We additionally xfail FileNotFoundError, as gradio often fail to upload test files to pypi.
preCheck = let
conftestSkipNetworkErrors = writeText "conftest-network-xfail.py" ''
from _pytest.runner import pytest_runtest_makereport as orig_pytest_runtest_makereport
import urllib, urllib3, httpx, requests, websockets

class NixNetworkAccessDeniedError(BaseException): pass
def deny_network_access(*a, **kw):
raise NixNetworkAccessDeniedError

def iterate_exc_chain(exc: Exception):
yield exc
if getattr(exc, "__context__", None) is not None:
yield from iterate_exc_chain(exc.__context__)
if getattr(exc, "__cause__", None) is not None:
yield from iterate_exc_chain(exc.__cause__)

httpx.Request = \
httpx.AsyncClient.get = \
httpx.AsyncClient.head = \
requests.head = \
requests.get = \
requests.post = \
urllib.request.urlopen = \
urllib.request.Request = \
urllib3.connection.HTTPSConnection._new_conn = \
websockets.connect = \
deny_network_access

def pytest_runtest_makereport(item, call):
tr = orig_pytest_runtest_makereport(item, call)
if call.excinfo is not None:
for exc in iterate_exc_chain(call.excinfo.value):
if isinstance(exc, NixNetworkAccessDeniedError):
tr.outcome, tr.wasxfail = 'skipped', "reason: Requires network access."
if isinstance(exc, FileNotFoundError):
tr.outcome, tr.wasxfail = 'skipped', "reason: Pypi dist bad."
return tr
'';
in ''
export HOME=$TMPDIR
cat ${conftestSkipNetworkErrors} >> test/conftest.py
'';
Copy link
Member

Choose a reason for hiding this comment

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

IMO this is too related to nix to matter upstream.

Having an extra marker to skip network tests is something not nix specific, many distros build their packages without networking. It can also be a great way to skip tests if no network is available or only very slow and flaky.

pkgs/development/python-modules/gradio/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/gradio/default.nix Outdated Show resolved Hide resolved
pkgs/development/python-modules/gradio/default.nix Outdated Show resolved Hide resolved
@happysalada
Copy link
Contributor

@SuperSandro2000 I think I've addressed all of your comments, but let me know if there is something that you think should be addressed differently.

I've also just tested to make sure this actually works.

@Janik-Haag
Copy link
Member

Are you sure the package even works if there are so many test failures?

@happysalada
Copy link
Contributor

First step is merging i think. Trying to rebuild all staging everytime to test us just not very efficient. First we make sure nothing breaks, then we should be able toake changes that impact much less things. I have locally packaged fast chat, ill open a PR as soon as this hits master.

@Janik-Haag
Copy link
Member

You can just do git switch master and then cherry pick the commits like this: git cherry-pick fdfcecedb72326c19772b4720a2e9c6df46347db 4324abf898a0ff5a14fe4b740f81f97ddc2e34a8 90500b167084b87a385c68f29de128418bc2da35 if you checked out this branch locally with gh pr checkout 241558. and then you can test locally without problem

@pbsds
Copy link
Member Author

pbsds commented Aug 7, 2023

I'm unable to reproduce your error on master. I also tried python 3.11, but that was blocked by tensorflow being marked broken on master. I'm disabling test_in_interface due to being flaky.

Are you sure the package even works if there are so many test failures?

The gradio devs tend to move fast and break things, and the functionality they provide is incredibly simple but pimped with lots of fancy webdev. The gradio test suite is mostly integration testing with all the major ML frameworks, hence the ginormous check closure.

Perhaps the future is doCheck = false, but as of now i consider this testing coverage a major success
image

@pbsds pbsds force-pushed the gradio-init branch 2 times, most recently from 12013e8 to 65a095c Compare August 7, 2023 12:45
@pbsds
Copy link
Member Author

pbsds commented Aug 7, 2023

You can just do git switch master and then cherry pick the commits like this: git cherry-pick fdfcecedb72326c19772b4720a2e9c6df46347db 4324abf898a0ff5a14fe4b740f81f97ddc2e34a8 90500b167084b87a385c68f29de128418bc2da35 if you checked out this branch locally with gh pr checkout 241558. and then you can test locally without problem

I use this one-liner, which assumes this pr is checked out in the worktree ../gradio-init:

git checkout master;  (cd ../gradio-init/; git log --oneline) | head -n3 | cut -d\  -f1 | tac | xe git cherry-pick

I'm surprised how nixpkgs-review does not have a cherry-pick or rebase strategy for staging PRs. (Mic92/nixpkgs-review#287)

@happysalada
Copy link
Contributor

@Janik-Haag have your concerns been addressed ?

Regarding my test failure, ive had other test failures on staging that couldbt be reproduced. I have had one on thrift, that was tested on another machine and couldnt be reproduced. So the one i had could be just a fluke.

@Janik-Haag
Copy link
Member

I currently am in a train so I have whonky internet, I'll try to check the package in the next ~8 hours once I have a stable connection again. But I really don't want to merge anything broken.

@happysalada
Copy link
Contributor

At this point, i dont think this paclage is broken, i think there could be flakiness in the tests or some potential problems with downstream dependents, but am not sure how we much more we could test.

Happy to wait one more day if you think we can potentially get more information.

pbsds and others added 2 commits August 7, 2023 15:30
linkify-it-py is on version 2.0.0, while markdown-it-py[linkify] depends on linkify-it-py~=1.0
@pbsds pbsds marked this pull request as draft August 7, 2023 13:32
@pbsds
Copy link
Member Author

pbsds commented Aug 7, 2023

I rebased onto the recent merge base between master and staging, and now it builds. So far I've waited one hour for the ofborg eval to be done. I'll marking the PR ready again once the eval is done, just for safety.

@pbsds pbsds marked this pull request as ready for review August 7, 2023 15:03
@pbsds
Copy link
Member Author

pbsds commented Aug 7, 2023

@ofborg build python3Packages.gradio

@happysalada
Copy link
Contributor

Ive built this on my machine and it worked like a charm this time.

@Janik-Haag
Copy link
Member

It now builds fine but when I try to run the binary it throws this error:

./result/bin/gradio
Traceback (most recent call last):
  File "/nix/store/3nap39bl8f7wbrbzfkl1dbj15lnab8aj-python3.10-gradio-3.20.1/bin/.gradio-wrapped", line 6, in <module>
    from gradio.reload import run_in_reload_mode
  File "/nix/store/3nap39bl8f7wbrbzfkl1dbj15lnab8aj-python3.10-gradio-3.20.1/lib/python3.10/site-packages/gradio/__init__.py", line 3, in <module>
    import gradio.components as components
  File "/nix/store/3nap39bl8f7wbrbzfkl1dbj15lnab8aj-python3.10-gradio-3.20.1/lib/python3.10/site-packages/gradio/components.py", line 33, in <module>
    from gradio.blocks import Block, BlockContext
  File "/nix/store/3nap39bl8f7wbrbzfkl1dbj15lnab8aj-python3.10-gradio-3.20.1/lib/python3.10/site-packages/gradio/blocks.py", line 24, in <module>
    from gradio import (
  File "/nix/store/3nap39bl8f7wbrbzfkl1dbj15lnab8aj-python3.10-gradio-3.20.1/lib/python3.10/site-packages/gradio/networking.py", line 17, in <module>
    from gradio.routes import App
  File "/nix/store/3nap39bl8f7wbrbzfkl1dbj15lnab8aj-python3.10-gradio-3.20.1/lib/python3.10/site-packages/gradio/routes.py", line 25, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

@pbsds
Copy link
Member Author

pbsds commented Aug 8, 2023

Great catch! I fixed it, and also added a postInstallCheck testing for this.
I'm surprised the pythonImportsCheck runs in the python stdenv.

I hosted a gradio service last year, so it didn't strike me to check the shell entrypoint as I kept bumping the version of the prior PR.

Copy link
Member

@Janik-Haag Janik-Haag left a comment

Choose a reason for hiding this comment

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

LGTM now, sorry for all the trouble but I want to avoid merging broken stuff.

@happysalada happysalada merged commit 94ea536 into NixOS:staging Aug 8, 2023
4 checks passed
@happysalada
Copy link
Contributor

@Janik-Haag on the contrary, thank you for your thoroughness.

@pbsds thanks for sticking with this PR for so long!

@pbsds pbsds mentioned this pull request Oct 14, 2023
12 tasks
@Magellol
Copy link

Magellol commented Mar 29, 2024

Unfortunately, It doesn't look like I can build this on aarch64-darwin :/ — Anyone has an idea? I'm not super knowledgeable with the ins and outs of python.

error: builder for '/nix/store/j5m87whdmc1ryjy21l99r0rinf3rzmlz-python3.11-gradio-client-0.10.1.drv' failed with exit code 4;
       last 10 log lines:
       > /nix/store/9nasxys60wirmhqs07akfb68n83pip6x-python3.11-gradio-sans-client-4.20.1/lib/python3.11/site-packages/gradio/routes.py:81: in <module>
       >     from gradio.server_messages import (
       > /nix/store/9nasxys60wirmhqs07akfb68n83pip6x-python3.11-gradio-sans-client-4.20.1/lib/python3.11/site-packages/gradio/server_messages.py:64: in <module>
       >     class UnexpectedErrorMessage(BaseModel):
       > /nix/store/9nasxys60wirmhqs07akfb68n83pip6x-python3.11-gradio-sans-client-4.20.1/lib/python3.11/site-packages/gradio/server_messages.py:65: in UnexpectedErrorMessage
       >     msg: Literal[ServerMessage.unexpected_error] = ServerMessage.unexpected_error
       > /nix/store/c05vbvkjxarxkws9zkwrcwrzlsx9nd68-python3-3.11.8/lib/python3.11/enum.py:784: in __getattr__
       >     raise AttributeError(name) from None
       > E   AttributeError: unexpected_error
       > /nix/store/gamm276nsv0l0qm71qhywpz833niaxkx-stdenv-darwin/setup: line 1587: pop_var_context: head of shell_variables not a function context

My flake looks like this

{
  description = "A flake for pythonification";

  inputs = {
    # Ensure our nixpkgs revision is green in Hydra for both Linux and macOS (i.e. there are
    # prebuilt binaries in the cache):
    #   https://status.nixos.org
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system:
    let
      pkgs = import nixpkgs {
        inherit system;
      };
    in rec {
      devShell = pkgs.mkShell {
        buildInputs = with pkgs; [
          (python3.withPackages(ps: with ps; [
            gradio-client
          ]))
        ];
      };
    }
  );
}

@pbsds
Copy link
Member Author

pbsds commented Mar 29, 2024

I'm sorry to say that I'm unable to test on mac.

The failure is expected

The error printout you provided cuts of too early, but hydra did get the same error. It fails to read this attribute, which makes no sense. It may be a circular import problem where utils is only partially evaluated, and this i cannot fix trivially

Consider overriding the package with doCheck = False, or opening an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants