Skip to content

Commit

Permalink
Add option to use "pip install"
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Flannery <juftin@juftin.com>
  • Loading branch information
oprypin and juftin committed Dec 5, 2023
1 parent c38d746 commit 1d5f100
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion hatch_pip_compile/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ def __init__(self, *args, **kwargs):
env_name=self.name,
project_name=self.metadata.name,
)
install_method = self.config.get("pip-compile-installer", "pip")
if install_method == "pip":
self.__class__ = PipCompileEnvironmentWithPipInstall
elif install_method == "pip-sync":
self.__class__ = PipCompileEnvironmentWithPipSync
else:
msg = (
f"Invalid pip-tools install method: {self.install_method} - "
"must be 'pip' or 'pip-sync'"
)
raise HatchPipCompileError(msg)

@staticmethod
def get_option_types() -> Dict[str, Any]:
Expand All @@ -70,6 +81,7 @@ def get_option_types() -> Dict[str, Any]:
"pip-compile-hashes": bool,
"pip-compile-args": List[str],
"pip-compile-constraint": str,
"pip-compile-installer": str,
}

def _pip_compile_cli(self) -> None:
Expand Down Expand Up @@ -270,6 +282,25 @@ def pipools_environment_dict(self) -> Dict[str, Any]:
"""
return self.metadata.hatch.config.get("envs", {})


class PipCompileEnvironmentWithPipInstall(PipCompileEnvironment):
def sync_dependencies(self) -> None:
"""
Install the project with `pip`
"""
with self.safe_activation():
if not self.lockfile_up_to_date:
self.virtual_env.platform.check_command(
self.construct_pip_install_command(["pip-tools"])
)
self._pip_compile_cli()
extra_args = self.config.get("pip-compile-install-args", [])
args = [*extra_args, "--requirement", str(self._piptools_lock_file)]
install_command = self.construct_pip_install_command(args=args)
self.virtual_env.platform.check_command(install_command)


class PipCompileEnvironmentWithPipSync(PipCompileEnvironment):
def _hatch_pip_compile_install(self):
"""
Run the full hatch-pip-compile install process
Expand Down Expand Up @@ -299,7 +330,7 @@ def _hatch_pip_compile_install(self):

def _pip_sync_cli(self) -> None:
"""
run pip-sync
Install the dependencies with `pip-sync`
In the event that a lockfile exists, but there are no dependencies,
pip-sync will uninstall everything in the environment before
Expand Down

0 comments on commit 1d5f100

Please sign in to comment.