Skip to content

Commit

Permalink
fix: always call hook in the generated setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Nov 29, 2022
1 parent 5dba890 commit 67db615
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/pdm/backend/hooks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,8 @@ def pdm_build_update_setup_kwargs(
Parameters:
context: The context for this build
kwargs: The arguments to be passed to the setup() function
Note:
This hook will be called in the subprocess of running setup.py
"""
...
10 changes: 3 additions & 7 deletions src/pdm/backend/hooks/setuptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
setup(**setup_kwargs)
"""

CUSTOM_HOOK_TEMPLATE = """\
HOOK_TEMPLATE = """\
import pickle
from pdm.backend.wheel import WheelBuilder
Expand Down Expand Up @@ -124,19 +124,15 @@ def cleanup() -> None:
def format_setup_py(self, context: Context) -> str:
before, extra, after = [], [], []
meta = context.config.metadata
config = context.config.build_config
kwargs = {
"name": meta["name"],
"version": meta["version"],
"description": meta["description"],
"url": (meta.get("project-urls", {})).get("homepage", ""),
}

if config.custom_hook:
# Run the pdm_build_update_setup_kwargs hook to update the kwargs
after.append(
CUSTOM_HOOK_TEMPLATE.format(context_dump=pickle.dumps(context))
)
# Run the pdm_build_update_setup_kwargs hook to update the kwargs
after.append(HOOK_TEMPLATE.format(context_dump=pickle.dumps(context)))

package_paths = context.config.convert_package_paths()
if package_paths["packages"]:
Expand Down

0 comments on commit 67db615

Please sign in to comment.