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

Editable mode is now mandatory #65

Merged
merged 1 commit into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Create and activate a virtual environment using your favorite tool. Run
``pip list`` to make sure ``pip``, ``setuptools`` and ``wheel`` are installed
in the virtualenv.

To install your project (in editable mode if supported) in the active virtual
To install your project in editable mode in the active virtual
environment, go to your project root directory and run:

.. code:: console
Expand Down Expand Up @@ -344,10 +344,6 @@ pip-df sync
your application to the latest allowed
version.

--editable / --no-editable Install the project in editable mode.
Defaults to editable if the project supports
it.

-x, --extras EXTRAS Extras to install and freeze to
requirements-{EXTRA}.txt.

Expand Down
4 changes: 4 additions & 0 deletions news/65.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
An editable installation of the project is now always done by pip-deepfreeze. The
`--editable` option is removed as well as the attempt to detect if the project is
editable. This allows correct support for projects that support PEP 660 and do not have
a `setup.py`.
16 changes: 0 additions & 16 deletions src/pip_deepfreeze/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import shutil
from pathlib import Path
from typing import Optional

import typer
from packaging.utils import canonicalize_name

from .detect import supports_editable
from .sanity import check_env
from .sync import sync as sync_operation
from .tree import tree as tree_operation
Expand Down Expand Up @@ -49,14 +47,6 @@ def sync(
metavar="EXTRAS",
help="Extras to install and freeze to requirements-{EXTRA}.txt.",
),
editable: Optional[bool] = typer.Option(
None,
help=(
"Install the project in editable mode. "
"Defaults to editable if the project supports it."
),
show_default=False,
),
uninstall_unneeded: bool = typer.Option(
None,
help=(
Expand All @@ -73,16 +63,10 @@ def sync(
update of dependencies to to the latest version that matches
constraints. Optionally uninstall unneeded dependencies.
"""
if editable is None:
editable = supports_editable()
elif editable and not supports_editable():
log_error("The project does not support editable installation.")
raise typer.Exit(1)
sync_operation(
ctx.obj.python,
upgrade_all,
comma_split(to_upgrade),
editable,
extras=[canonicalize_name(extra) for extra in comma_split(extras)],
uninstall_unneeded=uninstall_unneeded,
project_root=ctx.obj.project_root,
Expand Down
5 changes: 0 additions & 5 deletions src/pip_deepfreeze/detect.py

This file was deleted.

4 changes: 1 addition & 3 deletions src/pip_deepfreeze/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def pip_upgrade_project(
constraints_filename: Path,
project_root: Path,
extras: Optional[Sequence[NormalizedName]] = None,
editable: bool = True,
) -> None:
"""Upgrade a project.

Expand Down Expand Up @@ -82,8 +81,7 @@ def pip_upgrade_project(
project_name = get_project_name(python, project_root)
log_info(f"Installing/updating {project_name}")
cmd = [python, "-m", "pip", "install", "-c", f"{constraints_filename}"]
if editable:
cmd.append("-e")
cmd.append("-e")
if extras:
extras_str = ",".join(extras)
cmd.append(f"{project_root}[{extras_str}]")
Expand Down
2 changes: 0 additions & 2 deletions src/pip_deepfreeze/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def sync(
python: str,
upgrade_all: bool,
to_upgrade: List[str],
editable: bool,
extras: List[NormalizedName],
uninstall_unneeded: Optional[bool],
project_root: Path,
Expand Down Expand Up @@ -68,7 +67,6 @@ def sync(
python,
constraints_path,
project_root,
editable=editable,
extras=extras,
)
finally:
Expand Down
7 changes: 0 additions & 7 deletions tests/test_detect.py

This file was deleted.

114 changes: 0 additions & 114 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,78 +76,6 @@ def test_python_not_found(tmp_path):
assert "Python interpreter 'this-is-not-a-python' not found" in result.output


@pytest.fixture
def not_editable_foobar_path(tmp_path):
(tmp_path / "pyproject.toml").write_text(
textwrap.dedent(
"""
[build-system]
requires = ["flit_core >=2,<3"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "foobar"
author = "Toto"
"""
)
)
(tmp_path / "foobar.py").write_text(
textwrap.dedent(
"""
'''This is foobar'''
__version__ = '0.0.1'
"""
)
)
return tmp_path


def test_not_editable_default_install(virtualenv_python, not_editable_foobar_path):
subprocess.check_call(
[sys.executable, "-m", "pip_deepfreeze", "--python", virtualenv_python, "sync"],
cwd=not_editable_foobar_path,
)
# installed not editable by default
assert "foobar @ file://" in "\n".join(pip_freeze(virtualenv_python))


def test_not_editable_no_editable_install(virtualenv_python, not_editable_foobar_path):
subprocess.check_call(
[
sys.executable,
"-m",
"pip_deepfreeze",
"--python",
virtualenv_python,
"sync",
"--no-editable",
],
cwd=not_editable_foobar_path,
)
# installed no-editable as requested
assert "foobar @ file://" in "\n".join(pip_freeze(virtualenv_python))


def test_not_editable_editable_install(virtualenv_python, not_editable_foobar_path):
# trying to force editable fails gracefully
with pytest.raises(subprocess.CalledProcessError) as e:
subprocess.check_output(
[
sys.executable,
"-m",
"pip_deepfreeze",
"--python",
virtualenv_python,
"sync",
"--editable",
],
cwd=not_editable_foobar_path,
universal_newlines=True,
stderr=subprocess.STDOUT,
)
assert "The project does not support editable installation." in e.value.output


@pytest.fixture
def editable_foobar_path(tmp_path):
setup_py = tmp_path / "setup.py"
Expand All @@ -173,46 +101,11 @@ def test_editable_default_install(virtualenv_python, editable_foobar_path):
assert "-e " in "\n".join(pip_freeze(virtualenv_python))


def test_editable_editable_install(virtualenv_python, editable_foobar_path):
subprocess.check_call(
[
sys.executable,
"-m",
"pip_deepfreeze",
"--python",
virtualenv_python,
"sync",
"--editable",
],
cwd=editable_foobar_path,
)
# installed editable as requested
assert "-e " in "\n".join(pip_freeze(virtualenv_python))


def test_editable_no_editable_install(virtualenv_python, editable_foobar_path):
# force no-editable
subprocess.check_call(
[
sys.executable,
"-m",
"pip_deepfreeze",
"--python",
virtualenv_python,
"sync",
"--no-editable",
],
cwd=editable_foobar_path,
)
assert "foobar @ file://" in "\n".join(pip_freeze(virtualenv_python))


def test_sync_project_root(virtualenv_python, editable_foobar_path):
sync(
virtualenv_python,
upgrade_all=False,
to_upgrade=[],
editable=True,
extras=[],
uninstall_unneeded=False,
project_root=editable_foobar_path,
Expand All @@ -238,7 +131,6 @@ def test_sync_uninstall(virtualenv_python, tmp_path, testpkgs):
virtualenv_python,
upgrade_all=False,
to_upgrade=[],
editable=True,
extras=[],
uninstall_unneeded=False,
project_root=tmp_path,
Expand All @@ -259,7 +151,6 @@ def test_sync_uninstall(virtualenv_python, tmp_path, testpkgs):
virtualenv_python,
upgrade_all=False,
to_upgrade=[],
editable=True,
extras=[],
uninstall_unneeded=False,
project_root=tmp_path,
Expand All @@ -270,7 +161,6 @@ def test_sync_uninstall(virtualenv_python, tmp_path, testpkgs):
virtualenv_python,
upgrade_all=False,
to_upgrade=[],
editable=True,
extras=[],
uninstall_unneeded=True,
project_root=tmp_path,
Expand Down Expand Up @@ -319,7 +209,6 @@ def test_sync_update_new_dep(virtualenv_python, testpkgs, tmp_path):
virtualenv_python,
upgrade_all=False,
to_upgrade=["pkgc"],
editable=True,
extras=[],
uninstall_unneeded=False,
project_root=tmp_path,
Expand Down Expand Up @@ -368,7 +257,6 @@ def test_sync_update_all_new_dep(virtualenv_python, testpkgs, tmp_path):
virtualenv_python,
upgrade_all=True,
to_upgrade=[],
editable=True,
extras=[],
uninstall_unneeded=False,
project_root=tmp_path,
Expand Down Expand Up @@ -404,7 +292,6 @@ def test_sync_extras(virtualenv_python, testpkgs, tmp_path):
virtualenv_python,
upgrade_all=False,
to_upgrade=[],
editable=True,
extras=["c"],
uninstall_unneeded=False,
project_root=tmp_path,
Expand All @@ -423,7 +310,6 @@ def test_sync_extras(virtualenv_python, testpkgs, tmp_path):
virtualenv_python,
upgrade_all=False,
to_upgrade=[],
editable=True,
extras=["c"],
uninstall_unneeded=False,
project_root=tmp_path,
Expand Down