-
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
Open
apotterri
wants to merge
2
commits into
master
Choose a base branch
from
web-validate_20210927
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,31 +23,37 @@ def check_python_version(): | |
except AppMapPyVerException as e: | ||
raise ValidationFailure(str(e)) | ||
|
||
def _check_version(dist, v): | ||
def _check_version(dist, versions): | ||
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 | ||
Comment on lines
27
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
return dist_version | ||
|
||
# Note that, per https://www.python.org/dev/peps/pep-0426/#name, | ||
# comparison of distribution names are case-insensitive. | ||
def check_django_version(): | ||
return _check_version('django', '3.2') | ||
return _check_version('django', ['2.2', '3.2']) | ||
|
||
def check_flask_version(): | ||
return _check_version('flask', '1.1') | ||
return _check_version('flask', ['1.1', '2.0']) | ||
|
||
def check_pytest_version(): | ||
return _check_version('pytest', '6.2') | ||
return _check_version('pytest', ['6.2']) | ||
|
||
def _run(): | ||
errors = [ValidationFailure('internal error')] # shouldn't ever see this | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
[tox] | ||
skipsdist = true | ||
envlist = py3{6,7,8,9}-django{32,22} | ||
envlist = py3{6,7,8,9}-django{32,22},py3{6,7,8,9}-flask{10,20} | ||
|
||
[testenv] | ||
deps= | ||
poetry | ||
django32: Django>=3.2,<4.0 | ||
django32: flask>=2.0 | ||
django22: Django>=2.2,<3.0 | ||
flask20: flask>=2.0 | ||
flask10: flask>=1.1,<2.0 | ||
commands = | ||
poetry install -v | ||
django32: poetry run {posargs:pytest -v} | ||
django22: poetry run pytest appmap/test/test_django.py | ||
django22: poetry run pytest appmap/test/test_django.py appmap/test/test_command.py | ||
flask20: poetry run pytest appmap/test/test_flask.py appmap/test/test_command.py | ||
flask10: poetry run pytest appmap/test/test_flask.py appmap/test/test_command.py |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.