Skip to content

Commit

Permalink
remove no-setuptools config option
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Apr 23, 2024
1 parent 2ad0d93 commit 51e628a
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 89 deletions.
30 changes: 2 additions & 28 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = true
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs" # /path/to/cache/directory/virtualenvs
virtualenvs.prefer-active-python = false
Expand Down Expand Up @@ -391,35 +390,10 @@ Poetry, for its internal operations, uses the `pip` wheel embedded in the `virtu
in Poetry's runtime environment. If a user runs `poetry run pip` when this option is set to `true`, the `pip` the
embedded instance of `pip` is used.

You can safely set this, along with `no-setuptools`, to `true`, if you desire a virtual environment with no additional
packages. This is desirable for production environments.
You can safely set this to `true`, if you desire a virtual environment with no additional packages.
This is desirable for production environments.
{{% /note %}}

### `virtualenvs.options.no-setuptools`

**Type**: `boolean`

**Default**: `false`

**Environment Variable**: `POETRY_VIRTUALENVS_OPTIONS_NO_SETUPTOOLS`

*Introduced in 1.2.0*

If set to `true` the `--no-setuptools` parameter is passed to `virtualenv` on creation of the virtual environment. This
means when a new virtual environment is created, `setuptools` will not be installed in the environment. Poetry, for its
internal operations, does not require `setuptools` and this can safely be set to `true`.

For environments using python 3.12 or later, `virtualenv` defaults to not
installing `setuptools` when creating a virtual environment.
In such environments this poetry configuration option therefore has no effect:
`setuptools` is not installed either way.
If your project relies on `setuptools`, you should declare it as a dependency.

{{% warning %}}
Some development tools like IDEs, make an assumption that `setuptools` (and other) packages are always present and
available within a virtual environment. This can cause some features in these tools to not work as expected.
{{% /warning %}}

### `virtualenvs.options.system-site-packages`

**Type**: `boolean`
Expand Down
6 changes: 0 additions & 6 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ class Config:
"options": {
"always-copy": False,
"system-site-packages": False,
# we default to False here in order to prevent development environment
# breakages for IDEs etc. as when working in these environments
# assumptions are often made about virtual environments having pip and
# setuptools.
"no-pip": False,
"no-setuptools": False,
},
"prefer-active-python": False,
"prompt": "{project_name}-py{python_version}",
Expand Down Expand Up @@ -303,7 +298,6 @@ def _get_normalizer(name: str) -> Callable[[str], Any]:
"virtualenvs.in-project",
"virtualenvs.options.always-copy",
"virtualenvs.options.no-pip",
"virtualenvs.options.no-setuptools",
"virtualenvs.options.system-site-packages",
"virtualenvs.options.prefer-active-python",
"experimental.system-git-client",
Expand Down
4 changes: 0 additions & 4 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ def unique_config_values(self) -> dict[str, tuple[Any, Any]]:
boolean_normalizer,
),
"virtualenvs.options.no-pip": (boolean_validator, boolean_normalizer),
"virtualenvs.options.no-setuptools": (
boolean_validator,
boolean_normalizer,
),
"virtualenvs.path": (str, lambda val: str(Path(val))),
"virtualenvs.prefer-active-python": (boolean_validator, boolean_normalizer),
"virtualenvs.prompt": (str, str),
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/utils/env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def build_environment(
if not env or poetry.package.build_script:
with ephemeral_environment(
executable=env.python if env else None,
flags={"no-pip": True, "no-setuptools": True, "no-wheel": True},
flags={"no-pip": True},
) as venv:
if io:
requires = [
Expand Down
22 changes: 2 additions & 20 deletions src/poetry/utils/env/env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,34 +625,16 @@ def build_venv(
executable: Path | None = None,
flags: dict[str, str | bool] | None = None,
with_pip: bool | None = None,
with_wheel: bool | None = None,
with_setuptools: bool | None = None,
prompt: str | None = None,
) -> virtualenv.run.session.Session:
flags = flags or {}

if with_pip is not None:
flags["no-pip"] = not with_pip

if with_wheel is not None:
wheel_flags: dict[str, str | bool] = (
{"wheel": "bundle"} if with_wheel else {"no-wheel": True}
)
flags.update(wheel_flags)

if with_setuptools is not None:
setuptools_flags: dict[str, str | bool] = (
{"setuptools": "bundle"} if with_setuptools else {"no-setuptools": True}
)
flags.update(setuptools_flags)

flags.setdefault("no-pip", True)

if "setuptools" not in flags and "no-setuptools" not in flags:
flags["no-setuptools"] = True

if "wheel" not in flags and "no-wheel" not in flags:
flags["no-wheel"] = True
flags.setdefault("no-setuptools", True)
flags.setdefault("no-wheel", True)

if WINDOWS:
path = get_real_windows_path(path)
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/utils/isolated_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def isolated_builder(

with ephemeral_environment(
executable=python_executable,
flags={"no-pip": True, "no-setuptools": True, "no-wheel": True},
flags={"no-pip": True},
) as venv:
env = IsolatedEnv(venv, pool)
stdout = StringIO()
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ def venv_flags_default() -> dict[str, bool]:
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
}


Expand Down
1 change: 0 additions & 1 deletion tests/console/commands/env/test_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def test_activate_activates_non_existing_virtualenv_no_envs_file(
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.7",
)
Expand Down
6 changes: 0 additions & 6 deletions tests/console/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def test_list_displays_default_value_if_not_set(
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
Expand Down Expand Up @@ -99,7 +98,6 @@ def test_list_displays_set_get_setting(
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
Expand Down Expand Up @@ -153,7 +151,6 @@ def test_unset_setting(
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
Expand Down Expand Up @@ -185,7 +182,6 @@ def test_unset_repo_setting(
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
Expand Down Expand Up @@ -315,7 +311,6 @@ def test_list_displays_set_get_local_setting(
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
Expand Down Expand Up @@ -356,7 +351,6 @@ def test_list_must_not_display_sources_from_pyproject_toml(
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = {venv_path} # {config_cache_dir / 'virtualenvs'}
virtualenvs.prefer-active-python = false
Expand Down
2 changes: 1 addition & 1 deletion tests/masonry/builders/test_editable_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_builder_setup_generation_runs_with_pip_editable(
poetry = Factory().create_poetry(extended_project)

# we need a venv with pip and setuptools since we are verifying setup.py builds
with ephemeral_environment(flags={"no-setuptools": False, "no-pip": False}) as venv:
with ephemeral_environment(flags={"no-pip": False}) as venv:
builder = EditableBuilder(poetry, venv, NullIO())
builder.build()

Expand Down
1 change: 0 additions & 1 deletion tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ def test_create_poetry_with_local_config(fixture_dir: FixtureDirGetter) -> None:
assert not poetry.config.get("virtualenvs.create")
assert not poetry.config.get("virtualenvs.options.always-copy")
assert not poetry.config.get("virtualenvs.options.no-pip")
assert not poetry.config.get("virtualenvs.options.no-setuptools")
assert not poetry.config.get("virtualenvs.options.system-site-packages")


Expand Down
16 changes: 0 additions & 16 deletions tests/utils/env/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,7 @@ def test_env_system_packages_are_relative_to_lib(
("flags", "packages"),
[
({"no-pip": False}, {"pip"}),
({"no-pip": False, "no-wheel": True}, {"pip"}),
({"no-pip": False, "no-wheel": False}, {"pip", "wheel"}),
({"no-pip": True}, set()),
({"no-setuptools": False}, {"setuptools"}),
({"no-setuptools": True}, set()),
({"setuptools": "bundle"}, {"setuptools"}),
({"no-pip": True, "no-setuptools": False}, {"setuptools"}),
({"no-wheel": False}, {"wheel"}),
({"wheel": "bundle"}, {"wheel"}),
({}, set()),
],
)
Expand All @@ -338,14 +330,6 @@ def test_env_no_pip(
if package.name != "sqlite3"
}

# For python >= 3.12, virtualenv defaults to "--no-setuptools" and "--no-wheel"
# behaviour, so setting these values to False becomes meaningless.
if sys.version_info >= (3, 12):
if not flags.get("no-setuptools", True):
packages.discard("setuptools")
if not flags.get("no-wheel", True):
packages.discard("wheel")

assert installed_packages == packages


Expand Down
3 changes: 0 additions & 3 deletions tests/utils/env/test_env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def test_activate_in_project_venv_no_explicit_config(
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.7",
)
Expand Down Expand Up @@ -1181,7 +1180,6 @@ def test_create_venv_project_name_empty_sets_correct_prompt(
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="virtualenv-py3.7",
)
Expand Down Expand Up @@ -1231,7 +1229,6 @@ def mock_check_output(cmd: str, *args: Any, **kwargs: Any) -> str:
"always-copy": False,
"system-site-packages": False,
"no-pip": False,
"no-setuptools": False,
},
prompt="simple-project-py3.5",
)
Expand Down

0 comments on commit 51e628a

Please sign in to comment.