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

SERVER-80633 setup a consistent USERPROFILE for windows builds #2

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

dmoody256
Copy link
Collaborator

On windows, python uses USERPROFILE to expanduser the "~" character: https://docs.python.org/3/library/os.path.html#os.path.expanduser

Some python packages require this to be resolvable. Bazel runs in isolated environments where USERPROFILE is not set. We can set it to a useable deterministic value so python packages and still work.

This is to fix this kind of error one windows:

[2023/11/29 16:24:19.144] ERROR: C:/cygwin/home/mci-exec/_bazel_mci-exec/rhe5vutp/external/poetry/BUILD:3496:15: Collecting pyyaml wheel from pypi failed: (Exit 1): pip.exe failed: error executing command (from target @poetry//:wheel_pyyaml) bazel-out\x64_windows-opt-exec-C0E80C5F\bin\external\pip_archive\pip.exe wheel --quiet --no-deps --use-pep517 --disable-pip-version-check --no-cache-dir --isolated --require-hashes --wheel-dir ... (remaining 3 arguments skipped)
[2023/11/29 16:24:19.144]   error: subprocess-exited-with-error
[2023/11/29 16:24:19.144]   Getting requirements to build wheel did not run successfully.
[2023/11/29 16:24:19.144]   exit code: 1
[2023/11/29 16:24:19.144]   [31 lines of output]
[2023/11/29 16:24:19.144]   Traceback (most recent call last):
[2023/11/29 16:24:19.144]     File "C:\data\mci\d9677c2757b05679569738f670babeb9\tmp\Bazel.runfiles_3gsslphe\runfiles\pip_archive\src\pip\_vendor\pep517\in_process\_in_process.py", line 351, in <module>
[2023/11/29 16:24:19.144]       main()
[2023/11/29 16:24:19.144]     File "C:\data\mci\d9677c2757b05679569738f670babeb9\tmp\Bazel.runfiles_3gsslphe\runfiles\pip_archive\src\pip\_vendor\pep517\in_process\_in_process.py", line 333, in main
[2023/11/29 16:24:19.144]       json_out['return_val'] = hook(**hook_input['kwargs'])
[2023/11/29 16:24:19.144]     File "C:\data\mci\d9677c2757b05679569738f670babeb9\tmp\Bazel.runfiles_3gsslphe\runfiles\pip_archive\src\pip\_vendor\pep517\in_process\_in_process.py", line 118, in get_requires_for_build_wheel
[2023/11/29 16:24:19.144]       return hook(config_settings)
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
[2023/11/29 16:24:19.144]       return self._get_build_requires(config_settings, requirements=['wheel'])
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
[2023/11/29 16:24:19.144]       self.run_setup()
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\build_meta.py", line 480, in run_setup
[2023/11/29 16:24:19.144]       super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
[2023/11/29 16:24:19.144]       exec(code, locals())
[2023/11/29 16:24:19.144]     File "<string>", line 291, in <module>
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 159, in setup
[2023/11/29 16:24:19.144]       dist.parse_config_files()
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\dist.py", line 621, in parse_config_files
[2023/11/29 16:24:19.144]       self._parse_config_files(filenames=inifiles)
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\dist.py", line 451, in _parse_config_files
[2023/11/29 16:24:19.144]       filenames = self.find_config_files()
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 338, in find_config_files
[2023/11/29 16:24:19.144]       files = [str(path) for path in self._gen_paths() if os.path.isfile(path)]
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 338, in <listcomp>
[2023/11/29 16:24:19.144]       files = [str(path) for path in self._gen_paths() if os.path.isfile(path)]
[2023/11/29 16:24:19.144]     File "Z:\data\mci\d9677c2757b05679569738f670babeb9\tmp\pip-build-env-e5xv80e9\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 354, in _gen_paths
[2023/11/29 16:24:19.144]       yield pathlib.Path('~').expanduser() / filename
[2023/11/29 16:24:19.144]     File "C:\data\mci\d9677c2757b05679569738f670babeb9\tmp\Bazel.runfiles_3gsslphe\runfiles\py_windows_x86_64\lib\pathlib.py", line 1440, in expanduser
[2023/11/29 16:24:19.144]       raise RuntimeError("Could not determine home directory.")
[2023/11/29 16:24:19.144]   RuntimeError: Could not determine home directory.
[2023/11/29 16:24:19.144]   [end of output]

@dmoody256 dmoody256 requested a review from a team November 30, 2023 03:41
@@ -11,6 +11,7 @@ def deterministic_env():
"PYTHONDONTWRITEBYTECODE": "1",
"PYTHONHASHSEED": "0",
"SOURCE_DATE_EPOCH": "315532800", # set wheel timestamps to 1980-01-01T00:00:00Z
"USERPROFILE":".",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alternatively it seems we could forgo this method based on the comment on line 5, I dont really understand the backwards compat here? This function seems like it would meant to be internal use only, but thats just my assumption

Copy link
Collaborator Author

@dmoody256 dmoody256 Nov 30, 2023

Choose a reason for hiding this comment

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

I briefly looked into it, I think it was alluding to using rules_python pip_install instead of the pip_install rule defined in this repo. But that rule seems be going away according to rules_python docs. rules_python is tending towards just passing locked requirements file as the sole strategy to install deps. This wont work for us with poetry until poetry can generate locked requirements files: python-poetry/poetry-plugin-export#186

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're referring to the note in https://rules-python.readthedocs.io/en/latest/pypi-dependencies.html#pip-rules right? Yeah that doesn't sound good. Do you think the pip_install defined in this repo will have compatibility issues with rules_python in the future as well?

Copy link
Collaborator Author

@dmoody256 dmoody256 Nov 30, 2023

Choose a reason for hiding this comment

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

I don't think so, this repo only use the py_library and py_binary from rules_python, which I don't think will change much, because they seem pretty wide spread in adoption (they are officially in the bazel docs: https://bazel.build/reference/be/python#py_library)

@dmoody256 dmoody256 merged commit fc645fa into master Nov 30, 2023
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

Successfully merging this pull request may close these issues.

2 participants