def install(self): if os.path.exists(self.projectPathDict["venvdir"]): message = QtGui.QMessageBox.information( self, "Install", "Virtual environment already installed.") return reply = QtGui.QMessageBox.warning(self, "Install", "This will install a new virtual environment.\n\nProceed?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: if len(self.useData.SETTINGS["InstalledInterpreters"]) == 0: message = QtGui.QMessageBox.information( self, "Install", "There is no Python installation to install against.\n\nPlease make sure Python is installed.") return if len(self.useData.SETTINGS["InstalledInterpreters"]) == 1: pythonPath = self.useData.SETTINGS["InstalledInterpreters"][0] else: pythonPath = SelectBox( "Choose Python installation", self.useData.SETTINGS["InstalledInterpreters"], self) if pythonPath.accepted: pythonPath = pythonPath.item else: return try: builder = EnvBuilder(pythonPath) builder.create(self.projectPathDict["venvdir"]) self.treeView.setModel(self.newFileSystemModel()) self.treeView.setRootIndex( self.treeView.model().index(self.packagesPath)) self.currentVersionLabel.setText(self.setVesionFromVenv()) message = QtGui.QMessageBox.information( self, "Install", "Install virtual environment completed.") except Exception as err: message = QtGui.QMessageBox.warning( self, "Failed Install", str(err)) else: return
def main() -> None: parser = argparse.ArgumentParser( description="Test wheel or source distribution for basic functionality." ) parser.add_argument("pypi", type=str) arguments = parser.parse_args() pypi = arguments.pypi with tempfile.TemporaryDirectory() as temporary_venv: venv = Path(temporary_venv) builder = EnvBuilder(system_site_packages=False, clear=True, with_pip=True) builder.create(venv) pyre_path = venv / "bin" / "pyre" # Confirm that pypi package can be successfully installed subprocess.run([venv / "bin" / "pip", "install", pypi]) production_assert(pyre_path.exists(), "Pyre was not installed.") # Create test project. with tempfile.TemporaryDirectory() as temporary_project: temporary_project_path = Path(temporary_project) python_file_path = temporary_project_path / "a.py" python_file_path.touch() python_file_path.write_text("# pyre-strict \ndef foo():\n\treturn 1") # Confirm we can run `pyre init` successfully. subprocess.run( [str(pyre_path), "init"], cwd=temporary_project_path, input=b"n\n.\n" ) configuration = json.loads( (temporary_project_path / ".pyre_configuration").read_text() ) print(json.dumps(configuration, indent=2)) # Confirm configuration contains actual typeshed and taint files. typeshed_path = Path(configuration["typeshed"]) taint_path = Path(configuration["taint_models_path"]) binary = Path(configuration["binary"]) production_assert(taint_path.is_dir(), "Taint path is not a directory.") production_assert( (taint_path / "taint.config").is_file(), "Taint config is not included." ) production_assert(typeshed_path.is_dir(), "Typeshed was not installed.") production_assert( (typeshed_path / "third_party").is_dir(), "`third_party` was not included in typeshed.", ) production_assert( (typeshed_path / "stdlib").is_dir(), "`stdlib` was not included in typeshed.", ) production_assert( binary.is_file(), "Binary was not included in pypi package." ) # Confirm Pyre reports errors as expected. result = subprocess.run( [pyre_path, "--output=json", "check"], capture_output=True, cwd=temporary_project_path, ) errors = json.loads(result.stdout) production_assert( errors[0]["name"] == "Missing return annotation", "Incorrect pyre error returned.", )
def run_sanity_test(version: str, use_wheel: bool) -> None: message = "wheel" if use_wheel else "source distribution" LOG.warning(f"Sanity testing {message}") with tempfile.TemporaryDirectory() as temporary_venv: venv = Path(temporary_venv) builder = EnvBuilder(system_site_packages=False, clear=True, with_pip=True) builder.create(venv) pyre_path = venv / "bin" / "pyre" pyre_upgrade_path = venv / "bin" / "pyre-upgrade" # Confirm that pypi package can be successfully installed LOG.warning("Testing PyPi package installation...") wheel_flag = "--only-binary" if use_wheel else "--no-binary" subprocess.run([ venv / "bin" / "pip", "install", "--proxy=http://fwdproxy:8080/", "--index-url", "https://test.pypi.org/simple/", "--extra-index-url", "https://pypi.org/simple", wheel_flag, "pyre-check", f"pyre-check=={version}", ]) production_assert(pyre_path.exists(), "Pyre was not installed.") production_assert(pyre_upgrade_path.exists(), "Pyre upgrade was not installed.") # Create test project. with tempfile.TemporaryDirectory() as temporary_project: temporary_project_path = Path(temporary_project) python_file_path = temporary_project_path / "a.py" python_file_path.touch() python_file_path.write_text( "# pyre-strict \ndef foo():\n\treturn 1") # Confirm we can run `pyre init` successfully. LOG.warning("Testing `pyre init`...") init_process = subprocess.run( [str(pyre_path), "init"], cwd=temporary_project_path, input=b"n\n.\n", stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) error_message = init_process.stderr.decode() production_assert( init_process.returncode == 0, f"Failed to run `pyre init` successfully: {error_message}", ) validate_configuration(temporary_project_path) # Confirm `pyre` reports errors as expected. LOG.warning("Testing `pyre` error reporting...") result = subprocess.run( [pyre_path, "--output=json", "check"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=temporary_project_path, ) try: errors = json.loads(result.stdout) except json.JSONDecodeError: error_message = result.stderr.decode() raise AssertionError( f"Pyre did not successfully finish type checking: {error_message}" ) production_assert( errors and errors[0]["name"] == "Missing return annotation", "Incorrect pyre errors returned." if errors else "Expected pyre errors but none returned.", ) # Confirm `pyre-upgrade` runs successfully. LOG.warning("Testing `pyre upgrade`...") upgrade_process = subprocess.run( [str(pyre_upgrade_path), "fixme"], cwd=temporary_project_path, input=b"[]", stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) error_message = upgrade_process.stderr.decode() production_assert( upgrade_process.returncode == 0, f"Failed to run `pyre-upgrade` successfully: {error_message}", )
def create_env(path): print(f"Creating virtualenv in {path}...") builder = EnvBuilder(with_pip=True) builder.create(path)
def create(self): # AppArmor dose not support symlinks well. env = EnvBuilder(symlinks=False) env.create(self._env_path)
from common import getEnvPath, runPip from venv import EnvBuilder env = EnvBuilder(with_pip=True) env.create(getEnvPath()) runPip('-r requirements.txt')
def create(cls, io, name=None) -> 'Venv': if 'VIRTUAL_ENV' not in os.environ: # Not in a virtualenv # Checking if we need to create one config = Config.create('config.toml') create_venv = config.setting('settings.virtualenvs.create') venv_path = config.setting('settings.virtualenvs.path') if venv_path is None: venv_path = Path(CACHE_DIR) / 'virtualenvs' else: venv_path = Path(venv_path) if not name: name = Path.cwd().name name = '{}-py{}'.format( name, '.'.join([str(v) for v in sys.version_info[:2]])) venv = venv_path / name if not venv.exists(): if create_venv is False: io.writeln('<fg=black;bg=yellow>' 'Skipping virtualenv creation, ' 'as specified in config file.' '</>') return cls() io.writeln('Creating virtualenv <info>{}</> in {}'.format( name, str(venv_path))) builder = EnvBuilder(with_pip=True) builder.create(str(venv)) else: if io.is_very_verbose(): io.writeln( 'Virtualenv <info>{}</> already exists.'.format(name)) os.environ['VIRTUAL_ENV'] = str(venv) # venv detection: # stdlib venv may symlink sys.executable, so we can't use realpath. # but others can symlink *to* the venv Python, # so we can't just use sys.executable. # So we just check every item in the symlink tree (generally <= 3) p = os.path.normcase(sys.executable) paths = [p] while os.path.islink(p): p = os.path.normcase( os.path.join(os.path.dirname(p), os.readlink(p))) paths.append(p) p_venv = os.path.normcase(os.environ['VIRTUAL_ENV']) if any(p.startswith(p_venv) for p in paths): # Running properly in the virtualenv, don't need to do anything return cls() venv = os.environ['VIRTUAL_ENV'] return cls(venv)
args = parse_args() command: Union[Literal["deps"], Literal["run"]] = args.command req = REQUIREMENTS.read_bytes() if command == "deps": deps: Sequence[str] = args.deps if not deps or "runtime" in deps: builder = EnvBuilder( system_site_packages=False, with_pip=True, upgrade=True, symlinks=True, clear=True, ) builder.create(RT_DIR) check_call(( RT_PY, "-m", "pip", "install", "--upgrade", "--force-reinstall", "--requirement", REQUIREMENTS, )) _LOCK_FILE.write_bytes(req) if not deps or "packages" in deps: if _EX != RT_PY: