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

local dependencies? #23

Closed
tbenst opened this issue May 25, 2020 · 3 comments
Closed

local dependencies? #23

tbenst opened this issue May 25, 2020 · 3 comments

Comments

@tbenst
Copy link

tbenst commented May 25, 2020

Wondering how to do the equivalent of python setup.py for a local project. many thanks for this package!

@DavHau
Copy link
Owner

DavHau commented May 26, 2020

If i understand correctly, you are looking for a method to create a python environment from the source code of a python package.
Currently there is no function in mach-nix which is equivalent to nixpkgs` buildPythonPackage or buildPythonApplication.
This feature is planned: #19
In the meantime, you can achieve what you are looking for by using the low level API of mach-nix. Your project needs to have a requirements.txt for this to work:

let
  pkgs = import <unstable> {};
  machnix_src = builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "2.0.1";
  };
  machnix = import machnix_src;
  autoPatchelfHook = import "${machnix_src}/mach_nix/nix/auto_patchelf_hook.nix" {inherit (pkgs) fetchurl makeSetupHook writeText;};
  result = machnix.machNix {
    requirements = builtins.readFile ./requirements.txt;
    python = pkgs.python3;
  };
  overrides_machnix = result.overrides pkgs.pythonManylinuxPackages.manylinux1 pkgs.autoPatchelfHook;
  my_python = pkgs.python3.override {
    packageOverrides = overrides_machnix;
  };
  my_package = my_python.pkgs.buildPythonPackage {
    name = "my-package";
    src = ./.;
    propagatedBuildInputs = result.select_pkgs my_python.pkgs;
    doCheck = false;
    doInstallCheck = false;
  };
in
my_python.withPackages (ps: [ my_package ])

This calls machnix.machNix on your requirements.txt to get pythonOverrides and a package list (select_pkgs) which satisfies the requirements of your project. This is then used to build my_package with the correct build inputs and your source code.

@DavHau
Copy link
Owner

DavHau commented Jul 3, 2020

The dev version now supports buildPythonApplication and buildPythonPackage.
For example to build parsedmarc from github:

let
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "dev";
    rev = "a5c33aec758c1ec73327915f93c92e8d80bd0c28";
  });
in mach-nix.buildPythonApplication rec {
  pname = "parsedmarc";
  version = "lalala";
  src = builtins.fetchGit{
    url = "https://github.com/domainaware/parsedmarc";
    ref = "master";
  };
  doCheck = false;
  doInstallCheck = false;
  requirements = builtins.readFile "${src}/requirements.txt";
}

@DavHau
Copy link
Owner

DavHau commented Jul 5, 2020

buildPythonApplication and buildPythonPackage are available in version 2.1.0 now

@DavHau DavHau closed this as completed Jul 22, 2020
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