Skip to content

build system modules: decorators are now free-standing (and renamed)#2860

Merged
tgamblin merged 8 commits intospack:developfrom
epfl-scitas:features/alias_for_decorators
Jan 25, 2017
Merged

build system modules: decorators are now free-standing (and renamed)#2860
tgamblin merged 8 commits intospack:developfrom
epfl-scitas:features/alias_for_decorators

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Jan 18, 2017

Modifications
  • @run_before is the substitute for @*.precondition
  • @run_after is the substitute for @*.sanity_check
  • @on_package_attributes is the substitute for @*.on_package_attributes
  • added in code documentation

@adamjstewart
Copy link
Copy Markdown
Member

Is it still possible to convert:

@AutotoolsPackage.run_after('install')

to:

@run_after('install')

?

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 18, 2017

@adamjstewart It's another thing on my todo list, but not done here. I wouldn't mind implementing it in this PR if we don't want this to be an intermediate step.

@tgamblin
Copy link
Copy Markdown
Member

Any reason to keep the old names?

@tgamblin
Copy link
Copy Markdown
Member

Also, +1 on converting. I'm still thinking post_ and pre_ methods would be nice for users, but that can wait.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 18, 2017

Any reason to keep the old names?

@tgamblin If they are really sanity checks or precondition checks? But that's really a super minor point, so I wouldn't mind if we decide to delete them.

@adamjstewart
Copy link
Copy Markdown
Member

I don't mind keeping the old ones. Sometimes they really are for preconditions and sanity checks. But I also wouldn't be opposed to removing them. KISS principle always wins. I'll let someone else decide.

@tgamblin
Copy link
Copy Markdown
Member

I have an inconsistent argument. I think we should get rid of the old names so there's one way to do this. I also think we should add pre_ and post_ methods so we have one more (easier) way to do it.

Or, we could just use pre_ and post_ methods so that user-contributed packages are clearer... Homebrew has pre/post methods FWIW. I worry that things will get hard to read when we start stacking @when decorators on top of the before and after ones, and more confusing with multiple when/before/after combinations. If you restrict to a single pre or post method, the when combinations won't get quite so out of hand.

I'm not particularly passionate about this, though so if you just want to convert and leave one way to do it for now that's fine with me.

@adamjstewart
Copy link
Copy Markdown
Member

I agree with @tgamblin on adding pre_ and post_ methods. Decorators are kind of an advanced topic in Python. We don't want the learning curve to be too high. But I can see why also having the decorators would still be useful, so that you can have multiple pre and post methods, some defined in AutotoolsPackage that you don't want the user to override, like the check for the installation directory.

@tgamblin
Copy link
Copy Markdown
Member

KISS. Use the new ones.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 18, 2017

I worry that things will get hard to read when we start stacking @when decorators on top of the before and after ones, and more confusing with multiple when/before/after combinations.

On the other hand with a decorator you can separate different actions into different functions and execute them after or before the same phase. This helps maintaining the code clean.

@tgamblin
Copy link
Copy Markdown
Member

It'll also help new people read packages and contribute-- one less thing to learn.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 18, 2017

Decorators are kind of an advanced topic in Python

Maybe writing them (and not in this specific case). Using them should be a piece of cake if they are written correctly 😄

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 18, 2017

Ok, so I'll try to make them "free-standing" decorators and remove the old names. I'll ping people when done.

@adamjstewart
Copy link
Copy Markdown
Member

I know you would have liked to keep the old names, but I think:

@sanity_check('install')
def sanity_check_prefix:

is just as explanatory as:

@run_after('install')
def sanity_check_prefix:

You can always make it sound like a sanity check in the function name.

@tgamblin
Copy link
Copy Markdown
Member

Right, so I think for now let's go with one name for simple decorators and plan to add pre and post. Sound good?

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 18, 2017

@tgamblin How do you feel about:

  1. doing what we planned for decorators
  2. implement also a naming mechanism based on appended _pre_<phase> or _post_<phase>

What I have in mind is that:

@run_after('install')
def foo(self):
    ...

should be equivalent to:

def foo_post_install(self):
    ...

I don't think it requires a lot more code to do that.

@alalazo alalazo changed the title build system modules: added alias for decorators build system modules: decorators are now free-standing (and renamed) Jan 18, 2017
@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Jan 19, 2017

I was thinking just:

  • post_<phase>
  • pre_<phase>

For simplicity. Only challenge: maintain execution order == declaration order if these are mixed with decorators.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 19, 2017

Only challenge: maintain execution order == declaration order if these are mixed with decorators.

That could be difficult without the __prepare__ hook to grant we use an ordered dict. Do we really need to ensure this ?

The contract I was thinking was weaker: no relative order ensured for functions in the same pool (e.g. the ones that execute before a given phase). After all if you need to execute foo strictly before bar maybe they should be only one function...

@davydden
Copy link
Copy Markdown
Member

davydden commented Jan 19, 2017

Any reason to keep the old names?

to have less things to remember, i would remove old names completely. Even if it's a sanity check, it still reads fine with run_after(install), package developers can always name the method properly or add a quick documentation string to explain that it's a sanity check.

p.s. apparently, the same point is already raised by @adamjstewart above #2860 (comment) 😄

@tgamblin
Copy link
Copy Markdown
Member

Fair enough. We do guarantee that whens are evaluated in order, though that hasn't really been a problem or come up at all. I suspect most packages will use one or the other of these. If they want order they can use decorators.

@davydden
Copy link
Copy Markdown
Member

I also think we should add pre_ and post_ methods so we have one more (easier) way to do it.

from a python noob's perspective, i don't know how decorators work, but it's enough to see a single example to adapt it to ones needs. Personally, i would not bother with pre_ and post_ to simplify package developer's life.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 19, 2017

@davydden You came late to the party 😆

Old names already removed, and decorators are not tied to base classes anymore. So:

@run_before('install')
def foo(self):
    ...

is the new

@AutotoolsPackage.precondition('install')
def foo(self):
    ...

Copy link
Copy Markdown
Member

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

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

I think this is a really good start! We can argue about pre_ and post_ methods in another issue. Everything looks good to me as long as there are no packages that still reference precondition and sanity_check.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 19, 2017

@tgamblin @adamjstewart Let me know if you want me to proceed further here or in another PR. I am not in a rush to get this in, so any solution is fine with me.

BTW, does the metaclass code look cleaner? I tried to make it less complicated while I was at it.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 21, 2017

@adamjstewart you may want to have a look at 6b64146. That's what I intended yesterday when I said in #2869 that I wanted to push the driver function for tests up in the hierarchy

@alalazo alalazo force-pushed the features/alias_for_decorators branch from 6b64146 to 0bb03dd Compare January 25, 2017 11:12
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 25, 2017

ping

@alalazo alalazo added ready and removed WIP labels Jan 25, 2017
@tgamblin tgamblin merged commit fc866ae into spack:develop Jan 25, 2017
@tgamblin
Copy link
Copy Markdown
Member

@alalazo: thanks! If you want to continue in another PR that is fine, but I don't think there is a rush.

@alalazo alalazo deleted the features/alias_for_decorators branch January 25, 2017 17:10
@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Jan 25, 2017

@tgamblin I'll try to fix #2386 first then.

diaena pushed a commit to diaena/spack that referenced this pull request May 26, 2017
…ack#2860)

* PackageMeta: `run_before` is an alias of `precondition`, `run_after` an alias of `sanity_check`

* PackageMeta: removed `precondition` and `sanity_check`

* PackageMeta: decorators are now free-standing

* package: modified/added docstrings. Fixed the semantics of `on_package_attributes`.

* package: added unit test assertion as side effects of install

* build_systems: factored build-time test running into base class

* r: updated decorators in package.py

* docs: updated decorator names
amklinv pushed a commit that referenced this pull request Jul 17, 2017
)

* PackageMeta: `run_before` is an alias of `precondition`, `run_after` an alias of `sanity_check`

* PackageMeta: removed `precondition` and `sanity_check`

* PackageMeta: decorators are now free-standing

* package: modified/added docstrings. Fixed the semantics of `on_package_attributes`.

* package: added unit test assertion as side effects of install

* build_systems: factored build-time test running into base class

* r: updated decorators in package.py

* docs: updated decorator names
healther pushed a commit to electronicvisions/spack that referenced this pull request Jul 26, 2017
…ack#2860)

* PackageMeta: `run_before` is an alias of `precondition`, `run_after` an alias of `sanity_check`

* PackageMeta: removed `precondition` and `sanity_check`

* PackageMeta: decorators are now free-standing

* package: modified/added docstrings. Fixed the semantics of `on_package_attributes`.

* package: added unit test assertion as side effects of install

* build_systems: factored build-time test running into base class

* r: updated decorators in package.py

* docs: updated decorator names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants