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

Refactor pytest_collection_modify hook #107

Merged
merged 4 commits into from
Feb 20, 2024
Merged

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented Feb 19, 2024

Refactor the doctest collection stage a bit.

The key simplifications are

  • for dev installs, only run pytest on the build-install folder. Its contents matches the installed version, so it should be identical to $ pytest --pyargs scipy for an installed scipy (I think?). This obviates the need for the PY_IGNORE_IMPORTMISMATCH=1 env var --- almost. The remaining need seems to be due to some weirdness in scipy.signal, which indeed has a matching .py and .so modules:
E   _pytest.pathlib.ImportPathMismatchError: ('scipy.signal._spectral', '/home/br/repos/scipy/scipy/build-install/lib/python3.10/site-packages/scipy/signal/_spectral.cpython-310-x86_64-linux-gnu.so', PosixPath('/home/br/repos/scipy/scipy/build-install/lib/python3.10/site-packages/scipy/signal/_spectral.py'))

This probably needs to be looked at on the scipy side.

  • The logfile generation can be done with pytest --collect-only ... and some light postprocessing (below the fold)

The full stanza to run this, including pytest ignores, is currently (I know)

$ python dev.py shell
$ cd ~/repos/scipy/scipy
$ PY_IGNORE_IMPORTMISMATCH=1 pytest build-install/lib/python3.10/site-packages/scipy/ --doctest-modules --ignore=build-install/lib/python3.10/site-packages/scipy/interpolate/_interpnd_info.py --ignore=build-install/lib/python3.10/site-packages/scipy/_lib --collect-only

Log posprocessing scripts are below the fold:

$ cat modify_log.py

# convert the result of 
# $ pytest ... --doctest-modules --collect-only
# to simplify comparing to the doctest_.log from doctest-based runs

PACKAGE = "scipy."

if __name__ == "__main__":
    import sys
    if len(sys.argv) != 2:
        print("Usage: modify_log.py LOGFILE")

    fname = sys.argv[1]
    with open(fname, 'r') as inf:
        in_lines = inf.readlines()

    out_lines = []
    for line in in_lines:
        line_ = line.strip()
         
        if line_.startswith("<DoctestItem"):
            out_lines.append(line_[13:-1])

    print("\n".join(sorted(out_lines)))

and

$ cat modify_doctest_log.py 
# strip module names from the doctest.log
# to simplify comparing to the doctest_.log from doctest-based runs

PACKAGE = "scipy."

if __name__ == "__main__":
    import sys
    if len(sys.argv) != 2:
        print("Usage: modify_log.py LOGFILE")

    fname = sys.argv[1]
    with open(fname, 'r') as inf:
        in_lines = inf.readlines()

    out_lines = []
    for j, line in enumerate(in_lines):
        line_ = line.strip()

        if line_.startswith("="):
            continue

        if j < len(in_lines) -1 and in_lines[j+1].startswith("="):
            continue

        out_lines.append(line_)

    print("\n".join(sorted(out_lines)))

With these, the logs agree for the following combination: https://github.com/ev-br/scipy/tree/doctest_plugin + this PR, and scipy/scipy#16391, modulo #106.

@ev-br
Copy link
Member Author

ev-br commented Feb 19, 2024

@Sheila-nk @melissawm any chance you could review this PR? Would be much appreciated.

@ev-br
Copy link
Member Author

ev-br commented Feb 19, 2024

scipy/scipy#20112 should take care of IGNORE_IMPORTSMISMATCH

@ev-br ev-br force-pushed the pytest_collection_modify branch 5 times, most recently from c59a358 to b877180 Compare February 19, 2024 20:04
.github/workflows/pip.yml Outdated Show resolved Hide resolved
@ev-br
Copy link
Member Author

ev-br commented Feb 20, 2024

Merging now to keep the ball rolling as I work on test errors after collection is successful. A post-merge review would still be most welcome.

@ev-br ev-br merged commit b07f1b6 into main Feb 20, 2024
1 check passed
@ev-br ev-br deleted the pytest_collection_modify branch February 20, 2024 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant