def test_build_should_temporarily_remove_the_pyproject_file(tmp_dir, mocker): move = mocker.patch("shutil.move") tmp_dir = Path(tmp_dir) env = MockEnv(path=tmp_dir, pip_version="19.1", execute=False, sys_path=[]) module_path = fixtures_dir / "extended" builder = EditableBuilder(Factory().create_poetry(module_path), env, NullIO()) builder.build() expected = [[ sys.executable, "-m", "pip", "install", "-e", str(module_path) ]] assert expected == env.executed assert 2 == move.call_count expected_calls = [ mocker.call(str(module_path / "pyproject.toml"), str(module_path / "pyproject.tmp")), mocker.call(str(module_path / "pyproject.tmp"), str(module_path / "pyproject.toml")), ] assert expected_calls == move.call_args_list
def handle(self): from poetry.installation import Installer from poetry.io import NullIO from poetry.masonry.builders import EditableBuilder from poetry.masonry.utils.module import ModuleOrPackageNotFound installer = Installer( self.output, self.env, self.poetry.package, self.poetry.locker, self.poetry.pool, ) extras = [] for extra in self.option("extras"): if " " in extra: extras += [e.strip() for e in extra.split(" ")] else: extras.append(extra) installer.extras(extras) installer.dev_mode(not self.option("no-dev")) installer.develop(self.option("develop")) installer.dry_run(self.option("dry-run")) installer.verbose(self.option("verbose")) return_code = installer.run() if return_code != 0: return return_code if self.option("no-root"): return 0 try: builder = EditableBuilder(self.poetry, self._env, NullIO()) except ModuleOrPackageNotFound: # This is likely due to the fact that the project is an application # not following the structure expected by Poetry # If this is a true error it will be picked up later by build anyway. return 0 self.line( " - Installing <info>{}</info> (<comment>{}</comment>)".format( self.poetry.package.pretty_name, self.poetry.package.pretty_version)) if self.option("dry-run"): return 0 builder.build() return 0
def test_build_should_delegate_to_pip_for_non_pure_python_packages( tmp_dir, mocker): move = mocker.patch("shutil.move") tmp_dir = Path(tmp_dir) env = MockEnv(path=tmp_dir, pip_version="18.1", execute=False) env.site_packages.mkdir(parents=True) module_path = fixtures_dir / "extended" builder = EditableBuilder(Poetry.create(module_path), env, NullIO()) builder.build() expected = [["python", "-m", "pip", "install", "-e", str(module_path)]] assert expected == env.executed assert 0 == move.call_count
def handle(self) -> int: from poetry.core.masonry.utils.module import ModuleOrPackageNotFound from poetry.masonry.builders import EditableBuilder self._installer.use_executor( self.poetry.config.get("experimental.new-installer", False)) extras = [] for extra in self.option("extras"): if " " in extra: extras += [e.strip() for e in extra.split(" ")] else: extras.append(extra) self._installer.extras(extras) excluded_groups = [] included_groups = [] only_groups = [] if self.option("no-dev"): self.line_error( "<warning>The `<fg=yellow;options=bold>--no-dev</>` option is" " deprecated, use the `<fg=yellow;options=bold>--without dev</>`" " notation instead.</warning>") excluded_groups.append("dev") elif self.option("dev-only"): self.line_error( "<warning>The `<fg=yellow;options=bold>--dev-only</>` option is" " deprecated, use the `<fg=yellow;options=bold>--only dev</>` notation" " instead.</warning>") only_groups.append("dev") excluded_groups.extend([ group.strip() for groups in self.option("without") for group in groups.split(",") ]) included_groups.extend([ group.strip() for groups in self.option("with") for group in groups.split(",") ]) only_groups.extend([ group.strip() for groups in self.option("only") for group in groups.split(",") ]) if self.option("default"): only_groups.append("default") with_synchronization = self.option("sync") if self.option("remove-untracked"): self.line_error( "<warning>The `<fg=yellow;options=bold>--remove-untracked</>` option is" " deprecated, use the `<fg=yellow;options=bold>--sync</>` option" " instead.</warning>") with_synchronization = True self._installer.only_groups(only_groups) self._installer.without_groups(excluded_groups) self._installer.with_groups(included_groups) self._installer.dry_run(self.option("dry-run")) self._installer.requires_synchronization(with_synchronization) self._installer.verbose(self._io.is_verbose()) return_code = self._installer.run() if return_code != 0: return return_code if self.option("no-root") or self.option("only"): return 0 try: builder = EditableBuilder(self.poetry, self._env, self._io) except ModuleOrPackageNotFound: # This is likely due to the fact that the project is an application # not following the structure expected by Poetry # If this is a true error it will be picked up later by build anyway. return 0 log_install = ("<b>Installing</> the current project:" f" <c1>{self.poetry.package.pretty_name}</c1>" f" (<{{tag}}>{self.poetry.package.pretty_version}</>)") overwrite = self._io.output.is_decorated() and not self.io.is_debug() self.line("") self.write(log_install.format(tag="c2")) if not overwrite: self.line("") if self.option("dry-run"): self.line("") return 0 builder.build() if overwrite: self.overwrite(log_install.format(tag="success")) self.line("") return 0
def handle(self): from poetry.core.masonry.utils.module import ModuleOrPackageNotFound from poetry.masonry.builders import EditableBuilder self._installer.use_executor( self.poetry.config.get("experimental.new-installer", False) ) extras = [] for extra in self.option("extras"): if " " in extra: extras += [e.strip() for e in extra.split(" ")] else: extras.append(extra) self._installer.extras(extras) self._installer.dev_mode(not self.option("no-dev")) self._installer.dev_only(self.option("dev-only")) self._installer.dry_run(self.option("dry-run")) self._installer.remove_untracked(self.option("remove-untracked")) self._installer.verbose(self._io.is_verbose()) return_code = self._installer.run() if return_code != 0: return return_code if self.option("no-root") or self.option("dev-only"): return 0 try: builder = EditableBuilder(self.poetry, self._env, self._io) except ModuleOrPackageNotFound: # This is likely due to the fact that the project is an application # not following the structure expected by Poetry # If this is a true error it will be picked up later by build anyway. return 0 self.line("") if not self._io.supports_ansi() or self.io.is_debug(): self.line( "<b>Installing</> the current project: <c1>{}</c1> (<c2>{}</c2>)".format( self.poetry.package.pretty_name, self.poetry.package.pretty_version ) ) else: self.write( "<b>Installing</> the current project: <c1>{}</c1> (<c2>{}</c2>)".format( self.poetry.package.pretty_name, self.poetry.package.pretty_version ) ) if self.option("dry-run"): self.line("") return 0 builder.build() if self._io.supports_ansi() and not self.io.is_debug(): self.overwrite( "<b>Installing</> the current project: <c1>{}</c1> (<success>{}</success>)".format( self.poetry.package.pretty_name, self.poetry.package.pretty_version ) ) self.line("") return 0