Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Add --setup-requires option to install pip packages before building wheels. #82

Merged
merged 1 commit into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions src/pypi2nix/buildout.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ buildout_file
{ buildout_file ? ""
, project_dir
, buildout_cache_dir
, python_version
, extra_build_inputs ? []
, setup_requires ? []
}:

let
Expand All @@ -12,23 +13,8 @@ let
inherit (pkgs) stdenv fetchurl unzip which makeWrapper;
inherit python;
};
in pkgs.stdenv.mkDerivation rec {
name = "pypi2nix-buildout";

buildInputs = with pkgs; [
pypi2nix_bootstrap
unzip
gitAndTools.git
] ++ (pkgs.lib.optional pkgs.stdenv.isLinux pkgs.glibcLocales)
++ (map (name: pkgs.lib.getAttrFromPath
(pkgs.lib.splitString "." name) pkgs) extra_build_inputs);

shellHook = ''
export GIT_SSL_CAINFO="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
export PYTHONPATH=${pypi2nix_bootstrap}/base
export LANG=en_US.UTF-8

scriptBuildout = (if buildout_file != "" then ''
mkdir -p ${buildout_cache_dir}/download ${buildout_cache_dir}/eggs

cat <<EOF > ${project_dir}/buildout.cfg
Expand All @@ -52,6 +38,33 @@ in pkgs.stdenv.mkDerivation rec {
PYTHONPATH=${pypi2nix_bootstrap}/extra:$PYTHONPATH buildout -vvv -c $PWD/pypi2nix.cfg

rm $PWD/pypi2nix.cfg
'';
}
'' else "");

scriptRequires = with builtins; (if (length setup_requires) > 0 then
''
mkdir -p ${project_dir}/setup_requires
PYTHONPATH=${pypi2nix_bootstrap}/extra:$PYTHONPATH \
pip install \
${builtins.concatStringsSep" "(setup_requires)} \
--target=${project_dir}/setup_requires
'' else "");

in pkgs.stdenv.mkDerivation rec {
name = "pypi2nix-buildout";

buildInputs = with pkgs; [
pypi2nix_bootstrap
unzip
gitAndTools.git
] ++ (pkgs.lib.optional pkgs.stdenv.isLinux pkgs.glibcLocales)
++ (map (name: pkgs.lib.getAttrFromPath
(pkgs.lib.splitString "." name) pkgs) extra_build_inputs);

shellHook = ''
export GIT_SSL_CAINFO="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
export PYTHONPATH=${pypi2nix_bootstrap}/base
export LANG=en_US.UTF-8

'' + scriptBuildout + scriptRequires;
}
15 changes: 13 additions & 2 deletions src/pypi2nix/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
type=str,
help=u'location/url to editable locations',
)
@click.option('-s', '--setup-requires',
default=None,
help=u'Extra Python dependencies needed before the installation'
u'to build wheels.'
)
def main(version,
verbose,
nix_path,
Expand All @@ -87,6 +92,7 @@ def main(version,
requirements,
buildout,
editable,
setup_requires,
):
"""SPECIFICATION should be requirements.txt (output of pip freeze).
"""
Expand Down Expand Up @@ -115,6 +121,9 @@ def main(version,
if extra_build_inputs:
extra_build_inputs = extra_build_inputs.split(' ')

if setup_requires:
setup_requires = setup_requires.split(' ')

if not cache_dir:
cache_dir = os.path.join(tmp_dir, 'cache')

Expand Down Expand Up @@ -200,7 +209,7 @@ def handle_requirements_file(project_dir, requirements_file):
click.echo('pypi2nix v{} running ...'.format(pypi2nix_version))
click.echo('')

if buildout:
if buildout or setup_requires:
click.echo('Stage0: Generating requirements.txt from buildout configuration ...')
buildout_requirements = pypi2nix.stage0.main(
verbose=verbose,
Expand All @@ -210,8 +219,10 @@ def handle_requirements_file(project_dir, requirements_file):
extra_build_inputs=extra_build_inputs,
python_version=pypi2nix.utils.PYTHON_VERSIONS[python_version],
nix_path=nix_path,
setup_requires=setup_requires,
)
requirements_files.append(buildout_requirements)
if buildout_requirements:
requirements_files.append(buildout_requirements)

if editable:
editable_file = os.path.join(tmp_dir, 'editable.txt')
Expand Down
2 changes: 1 addition & 1 deletion src/pypi2nix/pip.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ in pkgs.stdenv.mkDerivation rec {

mkdir -p ${project_dir}/wheel ${project_dir}/wheelhouse

PYTHONPATH=${pypi2nix_bootstrap}/extra:$PYTHONPATH \
PYTHONPATH=${pypi2nix_bootstrap}/extra:${project_dir}/setup_requires:$PYTHONPATH \
pip wheel \
${builtins.concatStringsSep" "(map (x: "-r ${x} ") requirements_files)} \
--wheel-dir ${project_dir}/wheel \
Expand Down
5 changes: 4 additions & 1 deletion src/pypi2nix/stage0.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def main(verbose,
buildout_cache_dir,
extra_build_inputs,
python_version,
setup_requires=None,
nix_path=None,
):
""" Converts buildout.cfg specifiation into requirements.txt file
Expand All @@ -23,6 +24,7 @@ def main(verbose,
buildout_cache_dir=buildout_cache_dir,
extra_build_inputs=extra_build_inputs,
python_version=python_version,
setup_requires=setup_requires,
)),
nix_path=nix_path \
and ' '.join('-I {}'.format(i) for i in nix_path) \
Expand All @@ -36,4 +38,5 @@ def main(verbose,
raise click.ClickException(
u'While trying to run the command something went wrong.')

return os.path.join(project_dir, 'buildout_requirements.txt')

return buildout_file and os.path.join(project_dir, 'buildout_requirements.txt') or None