Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate-bids should use lowest supported BIDS version for earlier ones #950

Closed
yarikoptic opened this issue Apr 6, 2022 · 6 comments
Closed
Assignees

Comments

@yarikoptic
Copy link
Member

per our face-to-face discussion, if BIDSVersion has no present schemadata -- use 1.7.0+012 we carry after issuing a warning about that. As for version comparison -- seems to NOT work with semantic_version we already use

(git)lena:~/proj/dandi/dandi-cli-master[master]git
$> python -c 'from semantic_version import Version; print(Version("1.7.0")<Version("1.7.0+012"))' 
False

$> python -c 'from semantic_version import Version; print(Version("1.7.0+011")<Version("1.7.0+012"))'
False

$> python -c 'from semantic_version import Version; print(Version("1.7.0+013")<Version("1.7.0+012"))'
False

so let's not sweat about that for now with all the +s we have ATM.

@TheChymera
Copy link
Contributor

TheChymera commented Apr 18, 2022

Solved in 5fc7b06 other than presenting a warning. Not sure what sort of warning would be appropriate...

As for version comparison, Python auto-referencing of the ASCII table (or is it unicode?) has us covered:

>>> "1.7.0"<"1.7.0+012"
True
>>> "1.7.0+011"<"1.7.0+012"
True
>>> "1.7.0+013"<"1.7.0+012"
False
>>> "1.7.0+012"<"1.7.0+012+dandi001"
True
>>> "1.7.0+012+dandi002"<"1.7.0+012+dandi001"
False
>>> "1.7.0+013"<"1.7.0+012+dandi001"
False

AFAICT the only surprises that this could cause are due to the fact that both ASCII and unicode list uppercase before lowercase, so:

>>> "1.7.0+012+DANDI002"<"1.7.0+012+dandi001"
True

@yarikoptic
Copy link
Member Author

I would prefer to avoid relying on plain string comparison of semantic versions composed from numbers, could just bite somehow unexpectedly e.g

>>> "1.7.0+012"< "1.7.0+99"
True

it is just a matter of semver to have "Identifiers MUST NOT be empty. Build metadata MUST be ignored when determining version precedence. "

although difference between <= and == and < confuses me -- may be a bug in semver?
$> python3 -c 'from semantic_version import Version; print(Version("1.7.0")==Version("1.7.0+012"))'
False

$> python3 -c 'from semantic_version import Version; print(Version("1.7.0")<Version("1.7.0+012"))'
False

$> python3 -c 'from semantic_version import Version; print(Version("1.7.0")<=Version("1.7.0+012"))'
True

hence we should ignore it is as well. I gave a sketch for possible tune up in https://github.com/dandi/dandi-cli/pull/955/files#r852231652

@TheChymera
Copy link
Contributor

TheChymera commented Apr 18, 2022

"1.7.0+012"< "1.7.0+99"

I thought the 3-digit length is fixed... Ok then :( I really liked the idea of leveraging plain string comparison, though, since it's refreshingly simple :)

@TheChymera
Copy link
Contributor

Revisiting this, since semantic_version doesn't like our DANDI nomenclature:

>>> from semantic_version import Version
>>> Version("1.7.0+012")<=Version("1.7.0+012+dandi001")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/semantic_version/base.py", line 105, in __init__
    major, minor, patch, prerelease, build = self.parse(version_string, partial)
  File "/usr/lib/python3.9/site-packages/semantic_version/base.py", line 311, in parse
    raise ValueError('Invalid version string: %r' % version_string)
ValueError: Invalid version string: '1.7.0+012+dandi001'

Given that this is the dandi-cli bundled version of the validator and we haven't even started trying to push *.ngff and *.h5 yet — we need to fall back on 1.7.0+012+dandi001 and not 1.7.0+012. Additionally, for upstream code, semantic_version isn't a dep, and given the minimal aspiration I think it makes sense to try to add zero libs.

At this point I'd say it would be best in both cases to either (1) accept the risk of plain string comparison, or (2) write a small function to implement the comparison we need. I thing the former is cooler :)

Leaving this open for now, pending your feedback on the solution. Warning and working string comparison is in as of 1a6d835 and previous.

@yarikoptic
Copy link
Member Author

ok, you convinced me -- just do string comparison for now.

@yarikoptic
Copy link
Member Author

I believe #955 addressed this, and should have closed it .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants