Closed ValentinFrancois closed 1 year ago
Thanks for this.
I am very in favour in principle; I want to make sure that we do this correctly and that we don't needlessly limit compatibility with older versions.
@jwg4 cool, I clarified the PR description a bit.
I think I spotted an issue in minimal-test.yml
and test.yml
that was overwriting the target Flask
version from the matrix.
I also added python 3.10 to see which is the oldest supported version of Flask
(I already excluded 1.0
based on your README.md
).
thank you so much for this, I have left several comments. let me know if any that don't make sense or you don't think belong to this change.
as you will see, some of them relate to the failing tests which include several causes
@jwg4 sorry I didn't see your previous comments while I was still struggling to solve the issues with poetry & dependency handling. I think I've come to a good solution, I left a few comments explaining my recent changes.
The only thing I'm not sure about is why the output of flask_selfdoc
gets different line numbers depending on the installed python/Flask versions. For now I added some pre-processing function to remove the line numbers from the compared outputs in test_check_example.py
but maybe you'll want to investigate this deeper.
I tried adding tests for latest python as you suggested (3.x
, currently evaluating to 3.11.2
) but under this version, the unit tests for line numbers don't pass:
So I think there's something defninitely weird with inspect
and how it calculates line numbers of caller frames.
Even with a specific python version, the tests can fail depending on the OS because of different line numbers:
I'm removing the code I had added to ignore these line number differences, because it seems to be more important than I first thought.
By the way, I rewrote test.yml
to install the target Flask version with pip3
, which in the end was easier to use (especially under windows).
My understanding is that the code which retrieves the line number where a function is defined has changed to take decorators into account in a different way. I believe this is a change in a python built-in which flask uses and does not have control over. I don't know how OS type affects this.
Interesting, now python 3.11 seems to have changed again the way line number is calculated.
In this unit test, the frame now points to this line:
I suppose this is related to this: https://docs.python.org/3/whatsnew/3.11.html#whatsnew311-inspect but they didn't detail this behavior.
Anyway I figured out we could actually just read the source file and offset the line number by 1 as long as we don't find a line starting with def
. Do you think it's a good idea? I suppose it won't work for cythonized code but it's probably ok since this package is meant to document source files, and not files optimized for production?
In the end the PR got bigger than I first planned, but all tests are green now! I updated the PR description to my latest changes
just made it work again with pytest
, I suppose it didn't like the double inheritance trick
Sorry I didn't realize that
"${{ github.repositoryUrl }}@${{ github.head_ref }}"
would not work on your side,
because ${{ github.repositoryUrl }}
points to the repository where the action is running, and not the repository where the PR comes from.
I switched to "${{ github.event.pull_request.head.repo.git_url }}@${{ github.event.pull_request.head.ref }}"
,
based on https://stackoverflow.com/a/65027014.
Now the check_pip_install
tests should always install from the branch in the source repo (forked or not), which should work on your side too.
My bad, I forgot to do the same in the install step for Windows. Hoping it's the last iteration
Anything still blocking the merge?
I see one job that seems to be stuck for some reason
ping
hi, sorry for delay, I've been very busy with some other work.
No worries, just let me know if there's anything else I can help with. I don't really understand why a single job has stayed stuck this whole time:
do you think that you could rebase and squash your changes?
either into a single commit, into a small number of commits (if it's easy to separate the different changes like that), or failing that, just to remove the changes which were later rolled back or made obsolete by other changes.
after that's done I will give a final review and merge quickly.
is there any progress in merging this?
Oh thanks for the reminder! Just rebased into a few commits.
And btw is this library compatible with flask-restful?
No, the auto documentation logic relies on the Flask.route
decorator which is not used in flask-restful.
Issue 1
Cause
When installing
Flask
2.0 with python > 3.6, the chosen version of itsJinja2
dependency is >=3.1.0
:With python 3.6, the installed
Jinja2
dependency seems to be <3.1.0
which should not be problematic as I'll explain next.Consequences
import flask_selfdoc
will then raise anImportError
because it tries to import the follow function and class that were deprecated inJinja2
3.0 and removed inJinja2
3.1:jinja2.pass_eval_context
jinja2.utils.markupsafe.Markup
Issue 2
Cause
The way that the line number of a decorator is detected changed across python versions:
stack()[1].lineno
points to the line above the decorated function (= to the closest decorator, not necessarily the one that did the call tostack()
)stack()[1].lineno
points to the line of the decorated functionstack()[1].lineno
points to the exact line of the decorator that did the call tostack()
Example:
Consequences
-1
offset to the detected line number)What this PR does
Issue 1
Jinja2
-relatedImportError
by trying the old and the new import for each Jinja function/class that is now deprecatedFlask < 2.0
from the package dependenciesFlask
versions in the unit tests (WIP)minimal-test.yml
: remove python 3.7 (security support ends in 4 months), add python 3.10test.yml
: addFlask
2.1 (not compatible with python 3.6), add python 3.10 and 3.11 (not compatible withFlask
1.0)_app_ctx_stack
is removedpip3
(easier than withpoetry
) and manually override its dependency versions when they're too recent (itsdangerous
,Jinja2
andMarkupSafe
for Flask 1.X)Issue 2
def