Ejemplo n.º 1
0
Archivo: core.py Proyecto: pcskys/pdm
 def environment(self) -> Environment:
     if self.is_global:
         return GlobalEnvironment(self)
     if self.config["use_venv"] and "VIRTUAL_ENV" in os.environ:
         self.project_config["python.path"] = get_venv_python()
         return GlobalEnvironment(self)
     return Environment(self)
Ejemplo n.º 2
0
 def get_environment(self) -> Environment:
     """Get the environment selected by this project"""
     if self.is_global:
         env = GlobalEnvironment(self)
         # Rewrite global project's python requires to be
         # compatible with the exact version
         env.python_requires = PySpecSet(f"=={self.python.version}")
         return env
     if self.config["use_venv"] and is_venv_python(self.python.executable):
         # Only recognize venv created by python -m venv and virtualenv>20
         return GlobalEnvironment(self)
     return Environment(self)
Ejemplo n.º 3
0
 def environment(self) -> Environment:
     if self.is_global:
         env = GlobalEnvironment(self)
         # Rewrite global project's python requires to be
         # compatible with the exact version
         env.python_requires = PySpecSet(
             "==" + get_python_version(self.python_executable, True)[0])
         return env
     if self.config["use_venv"] and is_venv_python(self.python_executable):
         # Only recognize venv created by python -m venv and virtualenv>20
         return GlobalEnvironment(self)
     return Environment(self)
Ejemplo n.º 4
0
 def environment(self) -> Environment:
     if self.is_global:
         env = GlobalEnvironment(self)
         # Rewrite global project's python requires to be
         # compatible with the exact version
         env.python_requires = PySpecSet(
             "==" + get_python_version(env.python_executable, True))
         return env
     if self.config["use_venv"]:
         venv_python = get_venv_python(self.root)
         if venv_python:
             self.project_config["python.path"] = venv_python
             return GlobalEnvironment(self)
     return Environment(self)
Ejemplo n.º 5
0
 def get_environment(self) -> Environment:
     if self.is_global:
         env = GlobalEnvironment(self)
         # Rewrite global project's python requires to be
         # compatible with the exact version
         env.python_requires = PySpecSet(f"=={self.python.version}")
         return env
     if self.config["python.use_venv"]:
         if self.project_config.get("python.path") and not os.getenv(
                 "PDM_IGNORE_SAVED_PYTHON"):
             return (GlobalEnvironment(self) if is_venv_python(
                 self.python.executable) else Environment(self))
         if os.getenv("VIRTUAL_ENV"):
             venv = os.getenv("VIRTUAL_ENV")
             self.core.ui.echo(
                 f"Detected inside an active virtualenv {termui.green(venv)}, "
                 "reuse it.")
             # Temporary usage, do not save in .pdm.toml
             self._python = PythonInfo.from_path(get_venv_python(
                 Path(venv)))
             return GlobalEnvironment(self)
         existing_venv = next((venv for _, venv in iter_venvs(self)), None)
         if existing_venv:
             self.core.ui.echo(
                 f"Virtualenv {termui.green(str(existing_venv))} is reused.",
                 err=True,
             )
             path = existing_venv
         else:
             # Create a virtualenv using the selected Python interpreter
             self.core.ui.echo(
                 "python.use_venv is on, creating a virtualenv for this project...",
                 fg="yellow",
                 err=True,
             )
             backend: str = self.config["venv.backend"]
             venv_backend = BACKENDS[backend](self, None)
             path = venv_backend.create(None, (), False,
                                        self.config["venv.in_project"])
             self.core.ui.echo(f"Virtualenv {path} is created successfully")
         self.python = PythonInfo.from_path(get_venv_python(path))
         return GlobalEnvironment(self)
     else:
         return Environment(self)
Ejemplo n.º 6
0
 def environment(self) -> Environment:
     if self.is_global:
         env = GlobalEnvironment(self)
         # Rewrite global project's python requires to be
         # compatible with the exact version
         env.python_requires = PySpecSet(
             "==" + get_python_version(env.python_executable, True)[0])
         return env
     if not self.project_config.get(
             "python.path") and self.config["use_venv"]:
         venv_python = get_venv_python(self.root)
         if venv_python:
             self.project_config["python.path"] = venv_python
     if (self.config["use_venv"] and self.project_config.get("python.path")
             and Path(self.project_config.get("python.path")
                      ).parent.parent.joinpath("pyvenv.cfg").exists()):
         # Only recognize venv created by python -m venv and virtualenv>20
         return GlobalEnvironment(self)
     return Environment(self)