Skip to content

Commit

Permalink
‼️ Switch from virtualenv to venv
Browse files Browse the repository at this point in the history
Adapt the `VirtualenvProject` project class to rely on using `venv` instead of
`virtualenv`, renaming it to `VenvProject` in the process.

The `venv` package is part of the standard library, whereas `virtualenv` needs
to be installed separtely. This has the clear advantage that `venv` does not
need to be installed. Although `virtualenv` does have some upsides as well,
none of them are particularly relevant for `aiida-project`.
  • Loading branch information
mbercx committed Jun 8, 2023
1 parent d16c4e9 commit bf7b619
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aiida_project/commands/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def init(shell: Optional[ShellType] = None):
@app.command()
def create(
name: str,
engine: EngineType = EngineType.virtualenv,
engine: EngineType = EngineType.venv,
core_version: str = "latest",
plugins: Annotated[
List[str], typer.Option("--plugin", "-p", help="Extra plugins to install.")
Expand Down
2 changes: 1 addition & 1 deletion aiida_project/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ProjectDict:

def __init__(self):
if not self._projects_path.exists():
self._projects_path.joinpath("virtualenv").mkdir(parents=True, exist_ok=True)
self._projects_path.joinpath("venv").mkdir(parents=True, exist_ok=True)
self._projects_path.joinpath("conda").mkdir(parents=True, exist_ok=True)

@property
Expand Down
8 changes: 4 additions & 4 deletions aiida_project/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

from .base import BaseProject
from .conda import CondaProject
from .virtualenv import VirtualenvProject
from .venv import VenvProject

__all__ = ["BaseProject", "VirtualenvProject"]
__all__ = ["BaseProject", "VenvProject"]


def load_project_class(engine_type: str) -> Type[BaseProject]:
"""Load the project class corresponding the engine type."""
engine_project_dict = {
"virtualenv": VirtualenvProject,
"venv": VenvProject,
"conda": CondaProject,
}
return engine_project_dict[engine_type]


class EngineType(str, Enum):
virtualenv = "virtualenv"
venv = "venv"
conda = "conda"
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
from aiida_project.project.base import BaseProject


class VirtualenvProject(BaseProject):
"""An AiiDA environment based on `virtualenv`."""
class VenvProject(BaseProject):
"""An AiiDA environment based on `venv`."""

_engine = "virtualenv"
_engine = "venv"

def create(self, python_path: Optional[Path] = None) -> None:
super().create(python_path=None)
python = python_path or Path(sys.executable)
venv_command = ["virtualenv", f"--python={python.resolve()}", "."]
venv_command = [f"{python.resolve()}", "-m", "venv", "."]
self.venv_path.mkdir(
exist_ok=True,
parents=True,
Expand Down

0 comments on commit bf7b619

Please sign in to comment.