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

Build wheel with pip if build is not available #323

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
11 changes: 6 additions & 5 deletions cognite/pygen/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ def build_wheel(
try:
from build import ProjectBuilder # type: ignore[import]
except ImportError:
raise ImportError(
"'build' is required to build wheel. Install pygen with `pip install pygen[cli] or "
"install build directly `pip install build`."
) from None
import subprocess
import sys

data_model = _get_data_model(model_id, client, print)
folder_name = _create_folder_name(
Expand Down Expand Up @@ -97,7 +95,10 @@ def build_wheel(
generate_pyproject_toml(build_dir, top_level_package)

output_dir.mkdir(exist_ok=True, parents=True)
ProjectBuilder(build_dir).build(distribution="wheel", output_directory=str(output_dir))
if "build" in sys.modules:
ProjectBuilder(build_dir).build(distribution="wheel", output_directory=str(output_dir))
else:
subprocess.run([sys.executable, '-m', 'pip', 'wheel', '--no-deps', '--no-build-isolation', '-w', output_dir, build_dir], check=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--no-build-isolation wil make this work even when the user has no internet connection


print(f"Generated SDK wheel at {output_dir}")

Expand Down
Loading