NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.1k stars 14.15k forks source link

Some files of selenium python module are not packaged #230232

Open contrun opened 1 year ago

contrun commented 1 year ago

Describe the bug

Some files of selenium python module is not packaged. webdriver_prefs.json is one of they.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Running nix shell --impure --expr 'with import <nixpkgs>{}; python3.withPackages (ps: [ ps.selenium ])' -c python -c 'from selenium import webdriver; webdriver.FirefoxProfile(".")' produces
    <string>:1: DeprecationWarning: firefox_profile has been deprecated, please use an Options object
    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/nix/store/g182hmqdw2bk7bynfpb2wm20nw9sdar5-python3-3.10.9-env/lib/python3.10/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 60, in __init__
    with open(
    FileNotFoundError: [Errno 2] No such file or directory: '/nix/store/g182hmqdw2bk7bynfpb2wm20nw9sdar5-python3-3.10.9-env/lib/python3.10/site-packages/selenium/webdriver/firefox/webdriver_prefs.json'
  2. This error is not found on in a fresh python container, docker run -it --rm python bash and pip install selenium && python -c 'from selenium import webdriver; webdriver.FirefoxProfile(".")'. Moreover in this python container find / -name webdriver_prefs.json shows
    /usr/local/lib/python3.11/site-packages/selenium/webdriver/firefox/webdriver_prefs.json

    While ls "$(dirname "$(find / -name webdriver_prefs.json)")" shows

    __init__.py  extension_connection.py  firefox_profile.py  remote_connection.py  webdriver.py
    __pycache__  firefox_binary.py        options.py          service.py            webdriver_prefs.json

    But on nixos ls /nix/store/g182hmqdw2bk7bynfpb2wm20nw9sdar5-python3-3.10.9-env/lib/python3.10/site-packages/selenium/webdriver/firefox shows

    extension_connection.py  firefox_profile.py  options.py   remote_connection.py  webdriver.py
    firefox_binary.py        __init__.py         __pycache__  service.py`

Expected behavior

I expected nix shell --impure --expr 'with import <nixpkgs>{}; python3.withPackages (ps: [ ps.selenium ])' -c python -c 'from selenium import webdriver; webdriver.FirefoxProfile(".")' works.

Notify maintainers

@jraygauthier @SuperSandro2000

Additional Context

Upstream copied webdriver_prefs.json into webdriver/firefox/ https://github.com/SeleniumHQ/selenium/blob/deceb80a74102eae1ffc56b83c4cf963ba3c0e39/py/BUILD.bazel#L91-L95

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

nix-shell -p nix-info --run "nix-info -m"

 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.89, NixOS, 23.05 (Stoat), 23.05pre457777.b1f87ca164a`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.2`
 - channels(root): `"nixos"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
SuperSandro2000 commented 1 year ago

Upstream copied webdriver_prefs.json into webdriver/firefox/ SeleniumHQ/selenium@deceb80/py/BUILD.bazel#L91-L95

That all wouldn't be a problem if upstream wouldn't be using a distro hostile build system like bazel.

lapp0 commented 1 year ago

Here's the hack I used to get it working

with import <nixpkgs> {};

let
  webdriver_prefs_json = fetchurl {
    url = "https://raw.githubusercontent.com/SeleniumHQ/selenium/trunk/third_party/js/selenium/webdriver.json";
    sha256 = "sha256-lGrdKYpeI0bj1T0cvorXwz5JlBMFEfbYt5JovlC3o0w=";
  };

  myPython = python3.override {
    packageOverrides = self: super: {
      selenium = super.selenium.overrideAttrs (oldAttrs: rec {
        postInstall = ''
          cp ${webdriver_prefs_json} $out/lib/python3.10/site-packages/selenium/webdriver/firefox/webdriver_prefs.json
        '';
      });
    };
  };
in
pkgs.mkShell {
  buildInputs = [
    myPython.pkgs.pythonPackages.selenium
  ];
}