Repository: spack/spack

Issue:
`spack versions --new edm4hep` not working as expected
<!-- Explain, in a clear and concise way, the command you ran and the result you were trying to achieve.
Example: "I ran `spack find` to list all the installed packages and ..." -->

`spack versions --new edm4hep` should give an empty output, but instead returns the latest tag. Seems to be connected to the `url_for_version` convention the package uses.

### Steps to reproduce the issue

```console
~/repo/spack (develop)$ spack versions  -s edm4hep
==> Safe versions (already checksummed):
  master  0.3.1  0.3
~/repo/spack (develop)$ spack versions  -r edm4hep
==> Remote versions (not yet checksummed):
  00-02-01  00-02  00-01  00-00
~/repo/spack (develop)$ spack versions  -n edm4hep
==> New remote versions (not yet checksummed):
  00-03-01

```


### Information on your system

~/repo/spack (lcg-develop)$ spack debug report
* **Spack:** 0.16.0-213-63f483a5c0
* **Python:** 3.8.5
* **Platform:** linux-ubuntu20.04-skylake
* **Concretizer:** original


### Additional information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have searched the issues of this repo and believe this is not a duplicate
- [x] I have run the failing commands in debug mode and reported the output

<!-- We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively!

If you want to ask a question about the tool (how to use it, what it can currently do, etc.), try the `#general` channel on our Slack first. We have a welcoming community and chances are you'll get your reply faster and without opening an issue.

Other than that, thanks for taking the time to contribute to Spack! -->

I'll look into this, opening this issue to keep track.



Discussion:

Resolving patch:
diff --git a/lib/spack/spack/cmd/versions.py b/lib/spack/spack/cmd/versions.py
--- a/lib/spack/spack/cmd/versions.py
+++ b/lib/spack/spack/cmd/versions.py
@@ -12,7 +12,7 @@
 
 import spack.cmd.common.arguments as arguments
 import spack.repo
-from spack.version import VersionList, ver
+from spack.version import ver, infinity_versions
 
 description = "list available versions of a package"
 section = "packaging"
@@ -66,7 +66,10 @@ def versions(parser, args):
     if args.new:
         if sys.stdout.isatty():
             tty.msg('New remote versions (not yet checksummed):')
-        highest_safe_version = VersionList(safe_versions).highest_numeric()
+        numeric_safe_versions = list(filter(
+            lambda v: str(v) not in infinity_versions,
+            safe_versions))
+        highest_safe_version = max(numeric_safe_versions)
         remote_versions  = set([ver(v) for v in set(fetched_versions)
                                 if v > highest_safe_version])
     else:


Test patch:
diff --git a/lib/spack/spack/test/cmd/versions.py b/lib/spack/spack/test/cmd/versions.py
--- a/lib/spack/spack/test/cmd/versions.py
+++ b/lib/spack/spack/test/cmd/versions.py
@@ -6,6 +6,7 @@
 import pytest
 
 from spack.main import SpackCommand
+from spack.version import Version
 
 versions = SpackCommand('versions')
 
@@ -37,12 +38,32 @@ def test_remote_versions_only():
     versions('--remote', 'zlib')
 
 
-@pytest.mark.maybeslow
 @pytest.mark.usefixtures('mock_packages')
-def test_new_versions_only():
+def test_new_versions_only(monkeypatch):
     """Test a package for which new versions should be available."""
-
-    versions('--new', 'brillig')
+    from spack.pkg.builtin.mock.brillig import Brillig
+
+    def mock_fetch_remote_versions(*args, **kwargs):
+        mock_remote_versions = {
+            # new version, we expect this to be in output:
+            Version('99.99.99'): {},
+            # some packages use '3.2' equivalently to '3.2.0'
+            # thus '3.2.1' is considered to be a new version
+            # and expected in the output also
+            Version('3.2.1'): {},  # new version, we expect this to be in output
+            Version('3.2'): {},
+            Version('1.0.0'): {},
+        }
+        return mock_remote_versions
+    mock_versions = {
+        # already checksummed versions:
+        Version('3.2'): {},
+        Version('1.0.0'): {},
+    }
+    monkeypatch.setattr(Brillig, 'versions', mock_versions)
+    monkeypatch.setattr(Brillig, 'fetch_remote_versions', mock_fetch_remote_versions)
+    v = versions('--new', 'brillig')
+    assert(v.strip(' \n\t') == "99.99.99\n  3.2.1")
 
 
 @pytest.mark.maybeslow