diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2019-08-23 23:11:00 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2019-08-26 21:33:28 +0200 |
commit | 5b9174aedaf9843ee5b3b6358461910e328e74d1 (patch) | |
tree | 4d32c28d3f0787bab7b73fb704cc6411bb08da9f /semantic_version/django_fields.py | |
parent | 0b0f9d3f2f5ffa1afe9452ec55d394d4bb1ba190 (diff) | |
download | semantic-version-5b9174aedaf9843ee5b3b6358461910e328e74d1.tar.gz |
Refactor spec/version matching.
Instead of choosing the comparison on each `.match()` call, the
expression is converted to a combination of `Range()` expressions
(simple comparison to a semver-compliant `Version`).
`Range()` objects can be combined with `And` and `Or` through the
`AnyOf` and `AllOf` clauses (sticking to Python's naming scheme).
Some specific flags have been provided to those range, allowing users to
subtly alter the matching behaviour - thus accomodating different
versioning schemes:
- `<0.1.2` won't match `0.1.2-rc1`, unless the prerelease_policy flag is
set to either `always` or `same-patch`
- `<0.1.2` will match `0.1.1-rc1`, unless the `prerelease_policy` flag
is set to `same-patch`
- `==0.1.2` will always match `0.1.2+build44`, unless the `build_policy`
is set to `strict`.
The `Spec` item has been updated, alongside `SpecItem`.
Those objects keep the original expression as attributes, but don't use
them for comparisons.
Diffstat (limited to 'semantic_version/django_fields.py')
-rw-r--r-- | semantic_version/django_fields.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/semantic_version/django_fields.py b/semantic_version/django_fields.py index 2e9be69..1af5bf5 100644 --- a/semantic_version/django_fields.py +++ b/semantic_version/django_fields.py @@ -74,10 +74,21 @@ class SpecField(SemVerField): } description = _("Version specification list") + def __init__(self, *args, **kwargs): + self.syntax = kwargs.pop('syntax', base.DEFAULT_SYNTAX) + super().__init__(*args, **kwargs) + + def deconstruct(self): + """Handle django.db.migrations.""" + name, path, args, kwargs = super().deconstruct() + if self.syntax != base.DEFAULT_SYNTAX: + kwargs['syntax'] = self.syntax + return name, path, args, kwargs + def to_python(self, value): """Converts any value to a base.Spec field.""" if value is None or value == '': return value - if isinstance(value, base.Spec): + if isinstance(value, base.BaseSpec): return value - return base.Spec(value) + return base.BaseSpec.parse(value, syntax=self.syntax) |