Unverified Commit 065bb60a authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

Merge pull request #238601 from mdarocha/python-net

parents f127904a 6c376a4f
Loading
Loading
Loading
Loading
+79 −0
Original line number Diff line number Diff line
{ lib
, fetchPypi
, buildPythonPackage
, pytestCheckHook
, dotnetCorePackages
, setuptools
, buildDotnetModule
, cffi
}:

let
  pname = "clr_loader";
  version = "0.2.5";
  src = fetchPypi {
    inherit pname version;
    sha256 = "sha256-gu1ftlRynRT9iCludLtrhOss+5dv9LfUnU5En9eKIms=";
  };

  # This buildDotnetModule is used only to get nuget sources, the actual
  # build is done in `buildPythonPackage` below.
  dotnet-build = buildDotnetModule {
    inherit pname version src;
    projectFile = [ "netfx_loader/ClrLoader.csproj" "example/example.csproj" ];
    nugetDeps = ./deps.nix;
  };
in
buildPythonPackage {
  inherit pname version src;

  format = "pyproject";

  postPatch = ''
    substituteInPlace pyproject.toml \
      --replace 'dynamic = ["version"]' 'version = "${version}"'
  '';

  nativeBuildInputs = [
    setuptools
    dotnetCorePackages.sdk_6_0
  ];

  propagatedBuildInputs = [
    cffi
  ];

  nativeCheckInputs = [
    pytestCheckHook
  ];

  disabledTests = [
    # TODO: mono does not work due to https://github.com/NixOS/nixpkgs/issues/7307
    "test_mono"
    "test_mono_debug"
    "test_mono_signal_chaining"
    "test_mono_set_dir"
  ];

  # Perform dotnet restore based on the nuget-source
  preConfigure = ''
    dotnet restore "netfx_loader/ClrLoader.csproj" \
      -p:ContinuousIntegrationBuild=true \
      -p:Deterministic=true \
      --source "${dotnet-build.nuget-source}"

    dotnet restore "example/example.csproj" \
      -p:ContinuousIntegrationBuild=true \
      -p:Deterministic=true \
      --source "${dotnet-build.nuget-source}"
  '';

  passthru.fetch-deps = dotnet-build.fetch-deps;

  meta = with lib; {
    description = "Generic pure Python loader for .NET runtimes";
    homepage = "https://pythonnet.github.io/clr-loader/";
    license = licenses.mit;
    maintainers = with maintainers; [ mdarocha ];
  };
}
+11 −0
Original line number Diff line number Diff line
# This file was automatically generated by passthru.fetch-deps.
# Please dont edit it manually, your changes might get overwritten!

{ fetchNuGet }: [
  (fetchNuGet { pname = "Microsoft.NETCore.Platforms"; version = "1.1.0"; sha256 = "08vh1r12g6ykjygq5d3vq09zylgb84l63k49jc4v8faw9g93iqqm"; })
  (fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies"; version = "1.0.0"; sha256 = "0na724xhvqm63vq9y18fl9jw9q2v99bdwr353378s5fsi11qzxp9"; })
  (fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies.net461"; version = "1.0.0"; sha256 = "00vkn4c6i0rn1l9pv912y0wgb9h6ks76qah8hvk441nari8fqbm1"; })
  (fetchNuGet { pname = "Microsoft.NETFramework.ReferenceAssemblies.net47"; version = "1.0.0"; sha256 = "00v56phfn01ahf4fq7zanz6hjyzpp00hkkk4a190l0dywrv387i6"; })
  (fetchNuGet { pname = "NETStandard.Library"; version = "2.0.3"; sha256 = "1fn9fxppfcg4jgypp2pmrpr6awl3qz1xmnri0cygpkwvyx27df1y"; })
  (fetchNuGet { pname = "NXPorts"; version = "1.0.0"; sha256 = "02zva596c3vsnlhi1b1391vbfl8a6142dvm61r8j1c70b07916lj"; })
]
+44 −68
Original line number Diff line number Diff line
{ stdenv
, lib
{ lib
, fetchPypi
, fetchNuGet
, buildPythonPackage
, pytestCheckHook
, pycparser
, psutil
, pkg-config
, dotnetbuildhelpers
, clang
, glib
, mono
, dotnet-sdk
, buildDotnetModule
, clr-loader
, setuptools
}:

let

  dotnetPkgs = [
    (fetchNuGet {
      pname = "UnmanagedExports";
      version = "1.2.7";
      sha256 = "0bfrhpmq556p0swd9ssapw4f2aafmgp930jgf00sy89hzg2bfijf";
      outputFiles = [ "*" ];
    })
    (fetchNuGet {
      pname = "NUnit";
      version = "3.12.0";
      sha256 = "1880j2xwavi8f28vxan3hyvdnph4nlh5sbmh285s4lc9l0b7bdk2";
      outputFiles = [ "*" ];
    })
    (fetchNuGet {
      pname = "System.ValueTuple";
      version = "4.5.0";
      sha256 = "00k8ja51d0f9wrq4vv5z2jhq8hy31kac2rg0rv06prylcybzl8cy";
      outputFiles = [ "*" ];
    })
  ];

in

buildPythonPackage rec {
  pname = "pythonnet";
  version = "2.5.2";

  version = "3.0.1";
  src = fetchPypi {
    inherit pname version;
    sha256 = "1qzdc6jd7i9j7p6bcihnr98y005gv1358xqdr1plpbpnl6078a5p";
    pname = "pythonnet";
    inherit version;
    sha256 = "sha256-7U9/f5VRVAQRLds9oWOOGhATy1bmTEjE+mAwPwKwo90=";
  };

  postPatch = ''
    substituteInPlace setup.py --replace 'self._install_packages()' '#self._install_packages()'
  '';
  # This buildDotnetModule is used only to get nuget sources, the actual
  # build is done in `buildPythonPackage` below.
  dotnet-build = buildDotnetModule {
    inherit pname version src;
    nugetDeps = ./deps.nix;
  };
in
buildPythonPackage {
  inherit pname version src;

  preConfigure = ''
    [ -z "''${dontPlacateNuget-}" ] && placate-nuget.sh
    [ -z "''${dontPlacatePaket-}" ] && placate-paket.sh
  format = "pyproject";

  postPatch = ''
    substituteInPlace pyproject.toml \
      --replace 'dynamic = ["version"]' 'version = "${version}"'
  '';

  nativeBuildInputs = [
    pycparser

    pkg-config
    dotnetbuildhelpers
    clang

    mono
    setuptools
    dotnet-sdk
  ];

  ] ++ dotnetPkgs;
  propagatedBuildInputs = [
    pycparser
    clr-loader
  ];

  buildInputs = [
    glib
    mono
  pytestFlagsArray = [
    # Run tests using .NET Core, Mono is unsupported for now due to find_library problem in clr-loader
    "--runtime coreclr"
  ];

  nativeCheckInputs = [
@@ -77,26 +56,23 @@ buildPythonPackage rec {
    psutil # needed for memory leak tests
  ];

  preBuild = ''
    rm -rf packages
    mkdir packages

    ${builtins.concatStringsSep "\n" (
        builtins.map (
            x: ''ln -s ${x}/lib/dotnet/${x.pname} ./packages/${x.pname}.${x.version}''
          ) dotnetPkgs)}

    # Setting TERM=xterm fixes an issue with terminfo in mono: System.Exception: Magic number is wrong: 542
    export TERM=xterm
  # Perform dotnet restore based on the nuget-source
  preConfigure = ''
    dotnet restore \
      -p:ContinuousIntegrationBuild=true \
      -p:Deterministic=true \
      --source ${dotnet-build.nuget-source}
  '';

  # Rerun this when updating to refresh Nuget dependencies
  passthru.fetch-deps = dotnet-build.fetch-deps;

  meta = with lib; {
    broken = stdenv.isDarwin;
    description = ".Net and Mono integration for Python";
    description = ".NET integration for Python";
    homepage = "https://pythonnet.github.io";
    license = licenses.mit;
    # <https://github.com/pythonnet/pythonnet/issues/898>
    badPlatforms = [ "aarch64-linux" ];
    maintainers = with maintainers; [ jraygauthier ];
    maintainers = with maintainers; [ jraygauthier mdarocha ];
  };
}
+194 −0

File added.

Preview size limit exceeded, changes collapsed.

+3 −5
Original line number Diff line number Diff line
@@ -1871,6 +1871,8 @@ self: super: with self; {

  clip-anytorch = callPackage ../development/python-modules/clip-anytorch { };

  clr-loader = callPackage ../development/python-modules/clr-loader { };

  cock = callPackage ../development/python-modules/cock { };

  class-doc = callPackage ../development/python-modules/class-doc { };
@@ -9957,11 +9959,7 @@ self: super: with self; {

  python-nest = callPackage ../development/python-modules/python-nest { };

  pythonnet = callPackage
    ../development/python-modules/pythonnet {
      # Using `mono > 5`, tests are failing..
      mono = pkgs.mono5;
    };
  pythonnet = callPackage ../development/python-modules/pythonnet { };

  python-nmap = callPackage ../development/python-modules/python-nmap { };