Skip to content

Commit

Permalink
Rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking13 committed Feb 4, 2025
1 parent 04079e4 commit 4cf55ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pyodide_build/recipe/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,10 @@ def _download_and_extract(self) -> None:
shutil.move(self.build_dir / extract_dir_name, self.src_extract_dir)
self.src_dist_dir.mkdir(parents=True, exist_ok=True)

def _override_constraints(self) -> str:
def _create_constraints_file(self) -> str:
"""
Override global constraints (PIP_CONSTRAINT) with constraints specific to this package.
Creates a pip constraints file by concatenating global constraints (PIP_CONSTRAINT)
with constraints specific to this package.
returns the path to the new constraints file.
"""
Expand Down Expand Up @@ -411,7 +412,7 @@ def _compile(
)
build_env = runner.env

build_env["PIP_CONSTRAINT"] = str(self._override_constraints())
build_env["PIP_CONSTRAINT"] = str(self._create_constraints_file())

pypabuild.build(
self.src_extract_dir, self.src_dist_dir, build_env, config_settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package:
requirements:
constraint:
- numpy < 2.0
- scipy > 1.0
- pytest == 7.0
source:
path: src
10 changes: 5 additions & 5 deletions pyodide_build/tests/recipe/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,30 +216,30 @@ def rlist(input_dir):
assert n_moved == 3


def test_override_constraints_no_override(tmp_path, dummy_xbuildenv):
def test_create_constraints_file_no_override(tmp_path, dummy_xbuildenv):
builder = RecipeBuilder.get_builder(
recipe=RECIPE_DIR
/ "pkg_test_executable", # constraints not set, so no override
build_args=BuildArgs(),
build_dir=tmp_path,
)

path = builder._override_constraints()
path = builder._create_constraints_file()
assert path == get_build_flag("PIP_CONSTRAINT")


def test_override_constraints_override(tmp_path, dummy_xbuildenv):
def test_create_constraints_file_override(tmp_path, dummy_xbuildenv):
builder = RecipeBuilder.get_builder(
recipe=RECIPE_DIR / "pkg_test_constraint",
build_args=BuildArgs(),
build_dir=tmp_path,
)

path = builder._override_constraints()
path = builder._create_constraints_file()
assert path == str(tmp_path / "constraints.txt")

data = Path(path).read_text().strip().split("\n")
assert data[-3:] == ["numpy < 2.0", "scipy > 1.0", "pytest == 7.0"], data
assert data[-3:] == ["numpy < 2.0", "pytest == 7.0"], data


class MockSourceSpec(_SourceSpec):
Expand Down

0 comments on commit 4cf55ae

Please sign in to comment.