Skip to content

Commit fc58359

Browse files
committed
feat: Support passing extra args to pip install
1 parent de6ae34 commit fc58359

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ source_path = [
458458
- `:zip [source] [destination]` is a special command which creates content of current working directory (first argument) and places it inside of path (second argument).
459459
- `pip_requirements` - Controls whether to execute `pip install`. Set to `false` to disable this feature, `true` to run `pip install` with `requirements.txt` found in `path`. Or set to another filename which you want to use instead. When `source_path` is passed as a string containing a path (and not a list of maps), and `requirements.txt` is present, `pip install` is automatically executed.
460460
- `pip_tmp_dir` - Set the base directory to make the temporary directory for pip installs. Can be useful for Docker in Docker builds.
461+
- `pip_install_extra_args` - A list of additional pip arguments to add to the pip install command
461462
- `poetry_install` - Controls whether to execute `poetry export` and `pip install`. Set to `false` to disable this feature, `true` to run `poetry export` with `pyproject.toml` and `poetry.lock` found in `path`. When `source_path` is passed as a string containing a path (and not a list of maps), and `pyproject.toml` with a build system `poetry` is present, `poetry export` and `pip install` are automatically executed.
462463
- `poetry_export_extra_args` - A list of additional poetry arguments to add to the poetry export command
463464
- `npm_requirements` - Controls whether to execute `npm install`. Set to `false` to disable this feature, `true` to run `npm install` with `package.json` found in `path`. Or set to another filename which you want to use instead.

package.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def step(*x):
687687
def hash(path):
688688
source_paths.append(path)
689689

690-
def pip_requirements_step(path, prefix=None, required=False, tmp_dir=None):
690+
def pip_requirements_step(path, prefix=None, required=False, tmp_dir=None, pip_install_extra_args=[]):
691691
command = runtime
692692
requirements = path
693693
if os.path.isdir(path):
@@ -703,11 +703,11 @@ def pip_requirements_step(path, prefix=None, required=False, tmp_dir=None):
703703
"available in system PATH".format(command)
704704
)
705705

706-
step("pip", runtime, requirements, prefix, tmp_dir)
706+
step("pip", runtime, requirements, prefix, tmp_dir, pip_install_extra_args)
707707
hash(requirements)
708708

709709
def poetry_install_step(
710-
path, poetry_export_extra_args=[], prefix=None, required=False, tmp_dir=None
710+
path, poetry_export_extra_args=[], prefix=None, required=False, tmp_dir=None, pip_install_extra_args=[]
711711
):
712712
pyproject_file = path
713713
if os.path.isdir(path):
@@ -718,7 +718,7 @@ def poetry_install_step(
718718
"poetry configuration not found: {}".format(pyproject_file)
719719
)
720720
else:
721-
step("poetry", runtime, path, poetry_export_extra_args, prefix, tmp_dir)
721+
step("poetry", runtime, path, poetry_export_extra_args, prefix, tmp_dir, pip_install_extra_args)
722722
hash(pyproject_file)
723723
pyproject_path = os.path.dirname(pyproject_file)
724724
poetry_lock_file = os.path.join(pyproject_path, "poetry.lock")
@@ -819,6 +819,7 @@ def commands_step(path, commands):
819819
else:
820820
prefix = claim.get("prefix_in_zip")
821821
pip_requirements = claim.get("pip_requirements")
822+
pip_install_extra_args = claim.get("pip_install_extra_args", [])
822823
poetry_install = claim.get("poetry_install")
823824
poetry_export_extra_args = claim.get("poetry_export_extra_args", [])
824825
npm_requirements = claim.get(
@@ -833,13 +834,15 @@ def commands_step(path, commands):
833834
prefix,
834835
required=True,
835836
tmp_dir=claim.get("pip_tmp_dir"),
837+
pip_install_extra_args=pip_install_extra_args,
836838
)
837839
else:
838840
pip_requirements_step(
839841
pip_requirements,
840842
prefix,
841843
required=True,
842844
tmp_dir=claim.get("pip_tmp_dir"),
845+
pip_install_extra_args=pip_install_extra_args,
843846
)
844847

845848
if poetry_install and runtime.startswith("python"):
@@ -850,6 +853,7 @@ def commands_step(path, commands):
850853
poetry_export_extra_args=poetry_export_extra_args,
851854
required=True,
852855
tmp_dir=claim.get("poetry_tmp_dir"),
856+
pip_install_extra_args=pip_install_extra_args,
853857
)
854858

855859
if npm_requirements and runtime.startswith("nodejs"):
@@ -937,9 +941,9 @@ def execute(self, build_plan, zip_stream, query):
937941
else:
938942
zs.write_file(source_path, prefix=prefix, timestamp=ts)
939943
elif cmd == "pip":
940-
runtime, pip_requirements, prefix, tmp_dir = action[1:]
944+
runtime, pip_requirements, prefix, tmp_dir, pip_install_extra_args = action[1:]
941945
with install_pip_requirements(
942-
query, pip_requirements, tmp_dir
946+
query, pip_requirements, tmp_dir, pip_install_extra_args
943947
) as rd:
944948
if rd:
945949
if pf:
@@ -950,12 +954,12 @@ def execute(self, build_plan, zip_stream, query):
950954
# XXX: timestamp=0 - what actually do with it?
951955
zs.write_dirs(rd, prefix=prefix, timestamp=0)
952956
elif cmd == "poetry":
953-
(runtime, path, poetry_export_extra_args, prefix, tmp_dir) = action[
957+
(runtime, path, poetry_export_extra_args, prefix, tmp_dir, pip_install_extra_args) = action[
954958
1:
955959
]
956960
log.info("poetry_export_extra_args: %s", poetry_export_extra_args)
957961
with install_poetry_dependencies(
958-
query, path, poetry_export_extra_args, tmp_dir
962+
query, path, poetry_export_extra_args, tmp_dir, pip_install_extra_args
959963
) as rd:
960964
if rd:
961965
if pf:
@@ -1048,7 +1052,7 @@ def _zip_write_with_filter(
10481052

10491053

10501054
@contextmanager
1051-
def install_pip_requirements(query, requirements_file, tmp_dir):
1055+
def install_pip_requirements(query, requirements_file, tmp_dir, pip_install_extra_args):
10521056
# TODO:
10531057
# 1. Emit files instead of temp_dir
10541058

@@ -1125,7 +1129,7 @@ def install_pip_requirements(query, requirements_file, tmp_dir):
11251129
"--prefix=",
11261130
"--target=.",
11271131
"--requirement={}".format(requirements_filename),
1128-
]
1132+
] + pip_install_extra_args
11291133
if docker:
11301134
with_ssh_agent = docker.with_ssh_agent
11311135
pip_cache_dir = docker.docker_pip_cache
@@ -1175,7 +1179,7 @@ def install_pip_requirements(query, requirements_file, tmp_dir):
11751179

11761180

11771181
@contextmanager
1178-
def install_poetry_dependencies(query, path, poetry_export_extra_args, tmp_dir):
1182+
def install_poetry_dependencies(query, path, poetry_export_extra_args, tmp_dir, pip_install_extra_args):
11791183
# TODO:
11801184
# 1. Emit files instead of temp_dir
11811185

@@ -1301,7 +1305,7 @@ def copy_file_to_target(file, temp_dir):
13011305
"--prefix=",
13021306
"--target=.",
13031307
"--requirement=requirements.txt",
1304-
],
1308+
] + pip_install_extra_args,
13051309
]
13061310
if docker:
13071311
with_ssh_agent = docker.with_ssh_agent

0 commit comments

Comments
 (0)