Skip to content

Commit

Permalink
update post-build hook to a pre-build hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Jun 6, 2024
1 parent 94da850 commit 19e5a52
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions hatch_hooks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import subprocess
import sys

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from hatchling.plugin import hookimpl
Expand All @@ -14,20 +12,15 @@ class Psycopg2NoBinary(BuildHookInterface):

PLUGIN_NAME = "psycopg2"

def finalize(self, version, build_data, artifact_path) -> None:
def initialize(self, version, build_data) -> None:
if os.getenv("DBT_PSYCOPG2_NAME", "") == "psycopg2":
psycopg2_binary_pinned = [
package
for package in build_data["dependencies"]
if package.startswith("psycopg2-binary")
].pop()
psycopg2_pinned = psycopg2_binary_pinned.replace("-binary", "")
subprocess.check_call(
[sys.executable, "-m", "pip", "-y", "uninstall", "psycopg2-binary"]
)
subprocess.check_call(
[sys.executable, "-m", "pip", "-y", "install", f'"{psycopg2_pinned}"']
)
build_data["dependencies"].append(psycopg2_pinned)


@hookimpl
Expand Down

0 comments on commit 19e5a52

Please sign in to comment.