Skip to content

Refer to mirrors by name, path, or url#34891

Merged
tgamblin merged 2 commits intospack:developfrom
haampie:fix/mirror-path-url-2
Jan 16, 2023
Merged

Refer to mirrors by name, path, or url#34891
tgamblin merged 2 commits intospack:developfrom
haampie:fix/mirror-path-url-2

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Jan 11, 2023

With this change we get the invariant that mirror.fetch_url and
mirror.push_url return valid URLs, even when the backing config
file is actually using (relative) paths with potentially $spack and
$env like variables.

Secondly it avoids expanding mirror path / URLs too early,
so if I say spack mirror add name ./path, it stays ./path in my
config. When it's retrieved through MirrorCollection() we
exand it to say file://<env dir>/path if ./path was set in an
environment scope.

Thirdly, the interface is simplified for the relevant buildcache
commands, so it's more like git push:

spack buildcache create [mirror] [specs...]

mirror is either a mirror name, a path, or a URL.

Resolving the relevant mirror goes as follows:

  • If it contains either / or \ it is used as an anonymous mirror with
    path or url.
  • Otherwise, it's interpreted as a named mirror, which must exist.

This helps to guard against typos, e.g. typing my-mirror when there
is no such named mirror now errors with:

$ spack -e . buildcache create my-mirror
==> Error: no mirror named "my-mirror". Did you mean ./my-mirror?

instead of creating a directory in the current working directory. I
think this is reasonable, as the alternative (requiring that a local dir
exists) feels a bit pendantic in the general case -- spack is happy to
create the build cache dir when needed, saving a mkdir.

The old (now deprecated) format will still be available in Spack 0.20,
but is scheduled to be removed in 0.21:

spack buildcache create (--directory | --mirror-url | --mirror-name) [specs...]

This PR also touches tmp_scope in tests, because it didn't really
work for me, since spack fixes the possible --scope values once and
for all across tests, so tests failed when run out of order.

@spackbot-app spackbot-app bot added commands core PR affects Spack core functionality fetching tests General test capability(ies) utilities labels Jan 11, 2023
@haampie haampie force-pushed the fix/mirror-path-url-2 branch 3 times, most recently from 9f87a9c to a6a6eb8 Compare January 11, 2023 19:46
"""Add a mirror to Spack."""
url = url_util.format(args.url)
spack.mirror.add(args.name, url, args.scope, args)
spack.mirror.add(args.name, args.url, args.scope, args)
Copy link
Copy Markdown
Member Author

@haampie haampie Jan 11, 2023

Choose a reason for hiding this comment

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

@tgamblin so, I'm just adding mirror urls/paths verbatim now, what do you think? That way you can do spack -e . mirror add my_mirror '$env/../mirror' properly. Expanding/canonicalizing/urlifying is done when mirror_instance.fetch_url is retrieved whenever mirrors are actually used.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like this because it goes along with respecting the user said -- either on the CLI or in a YAML file. I guess the only only question I have is what happens if the user says:

spack mirror add ./foo

When the scope to add ./foo in is an environment but the user is not in the env directory? I am not 100% sure whether in that case we should be absolutifying the path. I wonder how much this comes up.

It looks like git does what you do and stores the path verbatim. Here's an example in a directory that is not alongside my spack installation in ~/src/spack:

(spackbook):2022> git init ../foobar
Initialized empty Git repository in /Users/gamblin2/pubs/presentations/foobar/.git/
(spackbook):2022> git -C ~/src/spack remote add blah ../foobar
(spackbook):2022> git -C ~/src/spack remote -v|grep foobar
blah	../foobar (fetch)
blah	../foobar (push)
(spackbook):2022> git -C ~/src/spack pull blah
fatal: '../foobar' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
(spackbook):2022> mv ../foobar ~/src
(spackbook):2022> git -C ~/src/spack pull blah
You asked to pull from the remote 'blah', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

So I think what you're doing is fine -- I know I've never actually noticed this issue for git so I doubt I would notice it for spack. I suspect people using relative paths will be trying to do for some special environment.

SPACK_COMPREPLY="-h --help -r --rel -f --force -u --unsigned -a --allow-root -k --key -d --directory -m --mirror-name --mirror-url --rebuild-index --spec-file --only"
else
_all_packages
_mirrors
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a bit sad, but nothing I can do about it :(

@haampie haampie force-pushed the fix/mirror-path-url-2 branch from a6a6eb8 to 6dd7355 Compare January 11, 2023 19:59
@haampie haampie force-pushed the fix/mirror-path-url-2 branch 2 times, most recently from 43c44f0 to e903efb Compare January 12, 2023 14:03
With this change we get that `mirror.fetch_url` and `mirror.push_url`
always return valid URLs, even when the config is actually using
(relative) paths.

Also change the interface so that we can now do e.g.

```
spack buildache create [mirror] [specs...]
```

where `mirror` is either a mirror name, a path, or a URL.

Resolving the relevant mirror goes as follows:

- If it contains either / or \ it is used as an anonymous mirror with
  path or url.
- Otherwise, it's interpreted as a named mirror, which must exist.

This guards against typos in mirror names (e.g. avoid pushing to a
local dir), and it's easy to validate without hitting the filesystem:

```
$ spack -e . buildcache create my-mirror
==> Error: no mirror named "my-mirror". Did you mean ./my-mirror?
```

It's up to the `[fetch/push]_url` properties to distinguish between URLs
and paths. Right now it's considered a URL when the scheme matches
something that is supported, otherwise it's a path. When it is a path,
we further use canonicalization, and transform to a file URL.
@haampie haampie force-pushed the fix/mirror-path-url-2 branch from e903efb to 8648f83 Compare January 12, 2023 14:04
@spackbot-app spackbot-app bot added the documentation Improvements or additions to documentation label Jan 12, 2023
@tgamblin
Copy link
Copy Markdown
Member

@blue42u FYI

@haampie haampie mentioned this pull request Jan 13, 2023
3 tasks
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Jan 13, 2023

Would be good to get this merged 🔜 , since in total 4 people have reported issues in #34532 / #34371

@blue42u
Copy link
Copy Markdown
Contributor

blue42u commented Jan 13, 2023

I like the direction this is going, thanks!

Would this be easy to extend to spack ci (generate|rebuild) as well, á la the proposal in #32958?

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Jan 15, 2023

Can we consider merging this @tgamblin?

RikkiButler20 pushed a commit to RikkiButler20/spack that referenced this pull request Jan 24, 2023
With this change we get the invariant that `mirror.fetch_url` and
`mirror.push_url` return valid URLs, even when the backing config
file is actually using (relative) paths with potentially `$spack` and
`$env` like variables.

Secondly it avoids expanding mirror path / URLs too early,
so if I say `spack mirror add name ./path`, it stays `./path` in my
config. When it's retrieved through MirrorCollection() we
exand it to say `file://<env dir>/path` if `./path` was set in an
environment scope.

Thirdly, the interface is simplified for the relevant buildcache
commands, so it's more like `git push`:

```
spack buildcache create [mirror] [specs...]
```

`mirror` is either a mirror name, a path, or a URL.

Resolving the relevant mirror goes as follows:
    
- If it contains either / or \ it is used as an anonymous mirror with
   path or url.
- Otherwise, it's interpreted as a named mirror, which must exist.

This helps to guard against typos, e.g. typing `my-mirror` when there
is no such named mirror now errors with:

```
$ spack -e . buildcache create my-mirror
==> Error: no mirror named "my-mirror". Did you mean ./my-mirror?
```

instead of creating a directory in the current working directory. I
think this is reasonable, as the alternative (requiring that a local dir
exists) feels a bit pendantic in the general case -- spack is happy to
create the build cache dir when needed, saving a `mkdir`.

The old (now deprecated) format will still be available in Spack 0.20,
but is scheduled to be removed in 0.21:

```
spack buildcache create (--directory | --mirror-url | --mirror-name) [specs...]
```

This PR also touches `tmp_scope` in tests, because it didn't really
work for me, since spack fixes the possible --scope values once and
for all across tests, so tests failed when run out of order.
nhanford pushed a commit to nhanford/spack that referenced this pull request Feb 15, 2023
With this change we get the invariant that `mirror.fetch_url` and
`mirror.push_url` return valid URLs, even when the backing config
file is actually using (relative) paths with potentially `$spack` and
`$env` like variables.

Secondly it avoids expanding mirror path / URLs too early,
so if I say `spack mirror add name ./path`, it stays `./path` in my
config. When it's retrieved through MirrorCollection() we
exand it to say `file://<env dir>/path` if `./path` was set in an
environment scope.

Thirdly, the interface is simplified for the relevant buildcache
commands, so it's more like `git push`:

```
spack buildcache create [mirror] [specs...]
```

`mirror` is either a mirror name, a path, or a URL.

Resolving the relevant mirror goes as follows:
    
- If it contains either / or \ it is used as an anonymous mirror with
   path or url.
- Otherwise, it's interpreted as a named mirror, which must exist.

This helps to guard against typos, e.g. typing `my-mirror` when there
is no such named mirror now errors with:

```
$ spack -e . buildcache create my-mirror
==> Error: no mirror named "my-mirror". Did you mean ./my-mirror?
```

instead of creating a directory in the current working directory. I
think this is reasonable, as the alternative (requiring that a local dir
exists) feels a bit pendantic in the general case -- spack is happy to
create the build cache dir when needed, saving a `mkdir`.

The old (now deprecated) format will still be available in Spack 0.20,
but is scheduled to be removed in 0.21:

```
spack buildcache create (--directory | --mirror-url | --mirror-name) [specs...]
```

This PR also touches `tmp_scope` in tests, because it didn't really
work for me, since spack fixes the possible --scope values once and
for all across tests, so tests failed when run out of order.
amd-toolchain-support pushed a commit to amd-toolchain-support/spack that referenced this pull request Feb 16, 2023
With this change we get the invariant that `mirror.fetch_url` and
`mirror.push_url` return valid URLs, even when the backing config
file is actually using (relative) paths with potentially `$spack` and
`$env` like variables.

Secondly it avoids expanding mirror path / URLs too early,
so if I say `spack mirror add name ./path`, it stays `./path` in my
config. When it's retrieved through MirrorCollection() we
exand it to say `file://<env dir>/path` if `./path` was set in an
environment scope.

Thirdly, the interface is simplified for the relevant buildcache
commands, so it's more like `git push`:

```
spack buildcache create [mirror] [specs...]
```

`mirror` is either a mirror name, a path, or a URL.

Resolving the relevant mirror goes as follows:
    
- If it contains either / or \ it is used as an anonymous mirror with
   path or url.
- Otherwise, it's interpreted as a named mirror, which must exist.

This helps to guard against typos, e.g. typing `my-mirror` when there
is no such named mirror now errors with:

```
$ spack -e . buildcache create my-mirror
==> Error: no mirror named "my-mirror". Did you mean ./my-mirror?
```

instead of creating a directory in the current working directory. I
think this is reasonable, as the alternative (requiring that a local dir
exists) feels a bit pendantic in the general case -- spack is happy to
create the build cache dir when needed, saving a `mkdir`.

The old (now deprecated) format will still be available in Spack 0.20,
but is scheduled to be removed in 0.21:

```
spack buildcache create (--directory | --mirror-url | --mirror-name) [specs...]
```

This PR also touches `tmp_scope` in tests, because it didn't really
work for me, since spack fixes the possible --scope values once and
for all across tests, so tests failed when run out of order.
techxdave pushed a commit to Tech-XCorp/spack that referenced this pull request Feb 17, 2023
With this change we get the invariant that `mirror.fetch_url` and
`mirror.push_url` return valid URLs, even when the backing config
file is actually using (relative) paths with potentially `$spack` and
`$env` like variables.

Secondly it avoids expanding mirror path / URLs too early,
so if I say `spack mirror add name ./path`, it stays `./path` in my
config. When it's retrieved through MirrorCollection() we
exand it to say `file://<env dir>/path` if `./path` was set in an
environment scope.

Thirdly, the interface is simplified for the relevant buildcache
commands, so it's more like `git push`:

```
spack buildcache create [mirror] [specs...]
```

`mirror` is either a mirror name, a path, or a URL.

Resolving the relevant mirror goes as follows:
    
- If it contains either / or \ it is used as an anonymous mirror with
   path or url.
- Otherwise, it's interpreted as a named mirror, which must exist.

This helps to guard against typos, e.g. typing `my-mirror` when there
is no such named mirror now errors with:

```
$ spack -e . buildcache create my-mirror
==> Error: no mirror named "my-mirror". Did you mean ./my-mirror?
```

instead of creating a directory in the current working directory. I
think this is reasonable, as the alternative (requiring that a local dir
exists) feels a bit pendantic in the general case -- spack is happy to
create the build cache dir when needed, saving a `mkdir`.

The old (now deprecated) format will still be available in Spack 0.20,
but is scheduled to be removed in 0.21:

```
spack buildcache create (--directory | --mirror-url | --mirror-name) [specs...]
```

This PR also touches `tmp_scope` in tests, because it didn't really
work for me, since spack fixes the possible --scope values once and
for all across tests, so tests failed when run out of order.
jmcarcell pushed a commit to key4hep/spack that referenced this pull request Apr 13, 2023
With this change we get the invariant that `mirror.fetch_url` and
`mirror.push_url` return valid URLs, even when the backing config
file is actually using (relative) paths with potentially `$spack` and
`$env` like variables.

Secondly it avoids expanding mirror path / URLs too early,
so if I say `spack mirror add name ./path`, it stays `./path` in my
config. When it's retrieved through MirrorCollection() we
exand it to say `file://<env dir>/path` if `./path` was set in an
environment scope.

Thirdly, the interface is simplified for the relevant buildcache
commands, so it's more like `git push`:

```
spack buildcache create [mirror] [specs...]
```

`mirror` is either a mirror name, a path, or a URL.

Resolving the relevant mirror goes as follows:
    
- If it contains either / or \ it is used as an anonymous mirror with
   path or url.
- Otherwise, it's interpreted as a named mirror, which must exist.

This helps to guard against typos, e.g. typing `my-mirror` when there
is no such named mirror now errors with:

```
$ spack -e . buildcache create my-mirror
==> Error: no mirror named "my-mirror". Did you mean ./my-mirror?
```

instead of creating a directory in the current working directory. I
think this is reasonable, as the alternative (requiring that a local dir
exists) feels a bit pendantic in the general case -- spack is happy to
create the build cache dir when needed, saving a `mkdir`.

The old (now deprecated) format will still be available in Spack 0.20,
but is scheduled to be removed in 0.21:

```
spack buildcache create (--directory | --mirror-url | --mirror-name) [specs...]
```

This PR also touches `tmp_scope` in tests, because it didn't really
work for me, since spack fixes the possible --scope values once and
for all across tests, so tests failed when run out of order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands core PR affects Spack core functionality documentation Improvements or additions to documentation fetching tests General test capability(ies) utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants