-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Isolate conda python from site packages, like venv does by default #24506
Changes from all commits
c4b3b69
1ee1277
de76820
750064c
c50ed1a
bba70c6
0c0aa9c
2b8ee2d
003192c
cb9b432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
BSD 3-clause license | ||
Copyright (c) 2015-2022, conda-forge contributors | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pathlib import Path | ||
|
||
from conda import plugins | ||
from conda.base.context import context | ||
from conda.core.prefix_data import PrefixData | ||
|
||
|
||
def action(argv: list) -> None: | ||
target_prefix = context.target_prefix | ||
python = PrefixData(target_prefix).get("python", None) | ||
if python: | ||
pyvenv_cfg = Path(target_prefix, "pyvenv.cfg") | ||
with pyvenv_cfg.open("x", encoding="utf-8") as f: | ||
f.write("include-system-site-packages = false\n") | ||
|
||
|
||
@plugins.hookimpl | ||
def conda_post_commands(): | ||
yield plugins.CondaPostCommand( | ||
name="no-user-site", | ||
action=action, | ||
run_for={"create"}, | ||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||
package: | ||||||
name: conda-create-no-user-site | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel a better name would be |
||||||
version: 0.1.0 | ||||||
|
||||||
source: | ||||||
path: . | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the maintenance model for this package? Feedstocks are not usually equipped to deal with release processes and PRs, so maybe it's a better idea to commit this to a separate repo (maybe under conda-incubator, if you are inclined). I like seeing more conda plugins in the world and it would help with visibility. |
||||||
|
||||||
build: | ||||||
script: {{ PYTHON }} -m pip install . -vv | ||||||
number: 0 | ||||||
|
||||||
requirements: | ||||||
host: | ||||||
- python | ||||||
- pip | ||||||
run: | ||||||
- python | ||||||
run_constrained: | ||||||
- python >=3.3 | ||||||
|
||||||
test: | ||||||
requires: | ||||||
- python | ||||||
commands: | ||||||
- python -c "import sys, site; sys.exit(0 if site.ENABLE_USER_SITE==False else 1)" | ||||||
|
||||||
about: | ||||||
home: http://conda-forge.org/ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
summary: conda create will configure Python to ignore packages outside the environment | ||||||
description: > | ||||||
This package extends `conda create` to configure Python so it will ignore packages | ||||||
installed with `pip install --user`. Envrionment creation will now add a | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
prefix-level "pyvenv.cfg" file with the line `include-system-site-packages = false`, | ||||||
which gets read by Python's `site` module whenver Python is run. This aligns Python | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
in conda environments with the default behavior of virtual environments created by | ||||||
Python's `venv` module. | ||||||
license: BSD-3-Clause | ||||||
license_family: BSD | ||||||
license_file: LICENSE.txt | ||||||
|
||||||
extra: | ||||||
recipe-maintainers: | ||||||
- itcarroll | ||||||
- mfansler |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "conda-create-no-user-site" | ||
version = "0.1.0" | ||
description = "Create a pyvenv.cfg in an environment created by conda." | ||
requires-python = ">=3.8" | ||
dependencies = ["conda"] | ||
|
||
[project.entry-points.conda] | ||
conda-create-no-user-site = "conda_create_no_user_site" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also consider adding
install
,remove
and maybe evenupdate
. The reasons:python
from the environment, and there's a lingeringpyvenv.cfg
file, which should be removed if possible.