Allow arbitrary Prefix attributes#4591
Conversation
|
This is pretty awesome. I also thought a while ago of just adding a But you have to quote everything, so it's slightly uglier. And it has associativity issues if you want to do something to the result (e.g. you'd likely have to add parens). What if the subdirectory contains |
|
I didn't think about special characters. I guess the only way would be |
alalazo
left a comment
There was a problem hiding this comment.
I think this makes the Prefix class much more flexible, and covers 99% of the cases.
| :py:func:`join_path(prefix, *args) <spack.join_path>` | ||
| Like ``os.path.join``, this joins paths using the OS path separator. | ||
| However, this version allows an arbitrary number of arguments, so | ||
| you can string together many path components. |
There was a problem hiding this comment.
There seems to be some confusion here. Whoever wrote join_path was under the assumption that os.path.join only accepted 2 arguments, when in reality it accepts as many as you want.
I tried replacing join_path with os.path.join and discovered that the only difference between the two is that join_path converts every arg to a string first. At some point, we should start phasing out join_path, especially in Spack's core libraries. I'm fine with it in package.py files, but we shouldn't rely on it elsewhere.
* Allow arbitrary Prefix attributes * Test attribute type as well * Flake8 fixes * Remove __new__ method * Fewer uses of join_path in the docs
Previously, the following prefix attributes worked great:
prefix.binprefix.libbut as soon as you needed something new, you were S.O.L.:
prefix.examplesprefix.bin.perlThis led to several PRs adding new attributes to the
Prefixclass:prefix.include64prefix.bin64prefix.share_man[1-8]This is cumbersome, and more often than not leads to people using
join_path(prefix, 'examples'). I've never been a big fan ofjoin_path. It's just plain ugly...With this PR, these limitations have been removed. Now, any prefix attribute you can think of works:
prefix.foo.bar.baz == $prefix/foo/bar/bazAll prefix attributes are defined on the fly, so they don't need to be declared beforehand. This means that most of the uses of
join_pathare now obsolete. I won't remove all uses ofjoin_pathin this PR, but we should encourage users to do this from now on.