-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: Fix validation for web frameworks #148
base: master
Are you sure you want to change the base?
Conversation
Both Django and Flask have two supported major versions. Fix validation to reflect this.
Try to import appmap.django during initialization, to give us a chance to set up our middleware.
5e4c07c
to
f62bf4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but note this changes the semantics and it's not clear to me this is intended. In particular, consider what happens when a dependency is detected with a major version different from any on the list of supported ones.
dist_version = None | ||
try: | ||
dist_version = version(dist) | ||
for v in versions: | ||
try: | ||
dist_version = version(dist) | ||
|
||
required = parse(v) | ||
actual = parse(dist_version) | ||
if required.major != actual.major: | ||
dist_version = None | ||
continue | ||
|
||
required = parse(v) | ||
actual = parse(dist_version) | ||
if actual < required: | ||
raise ValidationFailure(f'{dist} must have version >= {required}, found {actual}') | ||
|
||
if actual < required: | ||
raise ValidationFailure(f'{dist} must have version >= {required}, found {actual}') | ||
except PackageNotFoundError: | ||
pass | ||
return dist_version | ||
except PackageNotFoundError: | ||
dist_version = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: this changed logic is a bit convoluted and difficult to follow. How about something like:
try:
dist_version = version(dist)
actual = parse(dist_version)
required = next(v for v in map(parse, versions) if v.major == actual.major)
if actual < required:
raise ValidationFailure
except PackageNotFoundError, StopIteration:
return None
return dist_version
from . import django | ||
except ImportError: | ||
# not using django | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok to me, python isn't as fragile re import order as ruby can be.
Both Django and Flask have two supported major versions. Fix validation
and update tests to reflect this.