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

fix: Fix validation for web frameworks #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

apotterri
Copy link
Contributor

Both Django and Flask have two supported major versions. Fix validation
and update tests to reflect this.

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.
Copy link
Contributor

@dividedmind dividedmind left a 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.

Comment on lines 27 to +43
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
Copy link
Contributor

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
Copy link
Contributor

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.

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

Successfully merging this pull request may close these issues.

2 participants