8000 Make tests runnable out-of-tree for help with conda-packaging by h-vetinari · Pull Request #5560 · allenai/allennlp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Make tests runnable out-of-tree for help with conda-packaging #5560

Merged
merged 5 commits into from
Feb 14, 2022

Conversation

h-vetinari
Copy link
Contributor

The test suites of allennlp (and several sister/daughter libraries) implicitly depend on being run directly in the source directory, and cannot succeed being run against being actually installed somewhere on the system (e.g. the conda environment).

Since I like to run the full test suite wherever possible to validate that the library as packaged works correctly, I therefore need to patch this in most of the allennlp libraries. As conda-forge has now become one of the "officially" recommended ways of installation, I wanted to kindly ask if the project would consider picking up these patches (I'm using this PR as a stand-in for discussion, there'd be other very similar ones), which should hopefully not be intrusive and would help me a lot.

# to run test suite with finished package, which does not contain
# tests & fixtures, we must be able to look them up somewhere else
PROJECT_ROOT_FALLBACK = (
pathlib.Path(os.environ["SRC_DIR"]) if "SRC_DIR" in os.environ else PROJECT_ROOT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the current state of what I'm using on the feedstock, but if people are concerned that other users might (by accident) have an environment variable SRC_DIR, then the if-condition could easily be replaced by something less ambiguous (see e.g. here)

Suggested change
pathlib.Path(os.environ["SRC_DIR"]) if "SRC_DIR" in os.environ else PROJECT_ROOT
pathlib.Path(os.environ["SRC_DIR"]) if "CONDA_BUILD" in os.environ else PROJECT_ROOT

OTOH, I'm not sure how many users want to run the test suite of the installed package (where they'd run into the same problems as I do), but by being able to set SRC_DIR, they'd actually have a chance to succeed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SRC_DIR does sound a little too generic. But how about ALLENNLP_SRC_DIR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SRC_DIR is what conda build uses already (so using the presence of CONDA_BUILD, this would be the most efficient for me), but indeed, I could also set ALLENNLP_SRC_DIR.

Would you consider a two-part fall-back?

    PROJECT_ROOT_FALLBACK = (
        # users wanting to run test suite for installed package
        pathlib.Path(os.environ["ALLENNLP_SRC_DIR"])
        if "ALLENNLP_SRC_DIR" in os.environ
        else (
            # fallback for conda packaging
            pathlib.Path(os.environ["SRC_DIR"])
            if "CONDA_BUILD" in os.environ
            # stay in-tree
            else PROJECT_ROOT
        )
    )

That way, both cases would be covered - general users could set ALLENNLP_SRC_DIR, and I wouldn't have to set environment variables all over the place (e.g. if we took the same kind of approach for tango, I'd have to set it 6 times, one for each time some part of the test suite gets run).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that 🙂

Sign up for free to subscribe to this conversation on GitHub. 6203 Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0