Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Conversation

@embray
Copy link
Member

@embray embray commented Dec 11, 2014

Add support for pre- and post-command hooks that can be provided by setup_package modules (along with the other get_ functions they can provide.

The hooks should be variables in the setup_package module with names like pre_<command_name>_hook. For example to implement a pre-build_ext hook there should be a pre_build_ext_hook defined in setup_package.

Every setup_package module can provide hooks, though their run order should not be relied in. In other words, there is no way currently to ensure that hooks defined for the same command are run in a specific order. One can also define a post_<command_name>_hook.

This also adds an optional srcdir option to register_commands so that it can be passed through to the find_packages call that register_commands now makes.

The pre_<command_name>_hook variable may either be a callable, or a string specifying the import path for some callable defined elsewhere. The callable must take a single argument, which is the Command object for the command being hooked. This provides access to all the command's options.

If this is implemented there should probably also be an update to the developer docs to mention this feature. There might be some existing code that can make use of this feature as well, but I haven't looked in-depth yet. I kept this separate from #110 for now, but once that PR is merged I will rebase this on top of it.

@embray
Copy link
Member Author

embray commented Dec 11, 2014

Rebased on #110 .

@embray
Copy link
Member Author

embray commented Dec 11, 2014

@astrofrog Does this look good for you for astropy/astropy#3166 ? I think it would mostly suffice to change the preprocess_sources for the erfa package now to pre_build_py_hook(cmd). Would you like to try that out, or shall I?

@astrofrog
Copy link
Member

@embray - thanks for your work on this - this is awesome! I will try it out in astropy/astropy#3166 now :)

@embray
Copy link
Member Author

embray commented Dec 15, 2014

Rebased to include ee59f09, so this should still work with astropy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@embray: traceback isn't defined

@embray
Copy link
Member Author

embray commented Dec 15, 2014

Thanks for catching those.

@astrofrog
Copy link
Member

@embray - one more issue, I currently get the following traceback:

Traceback (most recent call last):
  File "setup.py", line 112, in <module>
    **package_info
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/command/build.py", line 126, in run
    self.run_command(cmd_name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/Users/tom/Dropbox/Code/development/Astropy/astropy/astropy_helpers/astropy_helpers/commands/build_ext.py", line 168, in run
    invalidate_caches()
NameError: name 'invalidate_caches' is not defined

Pyflakes also is warning me about a missing import for shutil on line 80.

@astrofrog
Copy link
Member

(it also looks like Travis is failing)

@embray
Copy link
Member Author

embray commented Dec 15, 2014

The failures on travis are due solely to the SSL thing.

@astrofrog
Copy link
Member

Ok, see #113 for a fix for the SSL

@embray
Copy link
Member Author

embray commented Dec 15, 2014

Should be really, truly fixed by 336997d. And this time I tested building astropy itself too ;)

Just goes to show the wealth of open holes in the test suite for this package.

@embray
Copy link
Member Author

embray commented Dec 15, 2014

I might actually consider adding a test_can_build_astropy after all...

@astrofrog
Copy link
Member

@embray - if this and astropy/astropy#3166 pass, can I go ahead and merge this PR tomorrow morning, or did you want to do more work on it?

@embray
Copy link
Member Author

embray commented Dec 16, 2014

Just adding a changelog entry, then I'll merge.

@embray embray added this to the v1.0 milestone Dec 16, 2014
…d_packages and loop over all the setup_package modules twice in order to pick up pre-/post-command hooks.
…tate dict for the package cache rather than a normal global variable, so that it can be easily reset at the end of test runs--this was causing some tests to fail depending on the order in which they were run.
setup_package modules (along with the other get_ functions they can
provide.

The hooks should be variables in the setup_package module with names
like pre_<command_name>_hook.  For example to implement a pre-build_ext
hook there should be a pre_build_ext_hook defined in setup_package.
Every setup_package module can provide hooks, though their run order
should not be relied in.  In other words, there is no way currently
to ensure that hooks defined for the same command are run in a specific
order.  One can also define a post_<command_name>_hook.

This also adds an optional srcdir option to register_commands so that it
can be passed through to the find_packages call that register_commands
now makes.
@astrofrog
Copy link
Member

Ok, 👍

@embray
Copy link
Member Author

embray commented Dec 16, 2014

Rebased once more and added changelog entry. Good to go.

embray added a commit that referenced this pull request Dec 16, 2014
@embray embray merged commit 36db545 into astropy:master Dec 16, 2014
@embray embray deleted the command-hooks branch December 16, 2014 15:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants