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

Install all dependencies without installing wheel #680

Open
johnthagen opened this issue May 3, 2022 · 6 comments
Open

Install all dependencies without installing wheel #680

johnthagen opened this issue May 3, 2022 · 6 comments

Comments

@johnthagen
Copy link

Is it possible to install all of the root dependencies though nox-poetry but not try to build/install the wheel? I have sessions where I need to install all dependencies but don't want to install the package itself (this is an application, so the wheel is not actually used).

My session looks like:

from nox_poetry import Session, session

@session
def type_check(s: Session) -> None:
    s.install(".", "mypy")
    s.run("mypy", "app")

And when I run nox -s type_check, I see nox building, uninstalling, and installing a wheel for the local code that is not needed.

In tox, the equivalent would be skipsdist global option or the skip_install session option.

@cjolowicz
Copy link
Owner

cjolowicz commented May 11, 2022

Hi @johnthagen you could use poetry install directly for this:

    session.run_always("poetry", "install", "--no-root", "--no-dev", external=True)
    session.install("mypy")

When reusing virtualenvs, the --no-dev will cause mypy to be re-installed each time, unfortunately.

Alternatively, you could export the non-dev dependencies to a requirements file using poetry export, then install them with session.install("-r", requirements).

I'll also say that it's good practice to run all checks against the installed package. This prevents spurious outcomes due to dirty source trees or broken packaging. But you do say that your application is not intended to be installed as a package, so I understand your use case is slightly different.

@johnthagen
Copy link
Author

johnthagen commented May 11, 2022

@cjolowicz Thanks for the reply (and the great package you've created).

But you do say that your application is not intended to be installed as a package, so I understand your use case is slightly different.

Yeah, I do feel like this is probably a decent market share, for example Pipenv targets only applications and it still ended up being very popular. I see streamlining that use case as being valuable as well.

When reusing virtualenvs, the --no-dev will cause mypy to be re-installed each time, unfortunately.

Ah, that's too bad, I wonder if in practice (running type checking multiple times during development) if the delay of that would end up being overall worse. When I get some time I will try both methods and compare.

I'll also say that it's good practice to run all checks against the installed package.

Yeah, I totally agree for packages/libraries this is the case.

@cjolowicz
Copy link
Owner

cjolowicz commented May 11, 2022

When reusing virtualenvs, the --no-dev will cause mypy to be re-installed each time, unfortunately.

Ah, that's too bad, I wonder if in practice (running type checking multiple times during development) if the delay of that would end up being overall worse. When I get some time I will try both methods and compare.

Actually, you can benefit from nox -R here. This is a newer option that will skip session.install and session.run_always when reusing virtualenvs. (It's a shorthand for --reuse-existing-virtualenvs --no-install.) When running checks against the installed package, this is problematic due to stale code being tested. But as you run the checks against the source tree, the behavior is fine; you only really need to perform install commands when your dependencies change.

@johnthagen
Copy link
Author

Hmm, I tried out:

session.run_always("poetry", "install", "--no-root", "--no-dev", external=True)
...

But the problem I hit is this modifies the environment that nox is running in and uninstalls the development dependencies (like nox and nox-poetry itself).

nox -s licenses
nox > Running session licenses
nox > Re-using existing virtual environment at .nox/licenses.
nox > poetry install --no-root --no-dev
Installing dependencies from lock file

Package operations: 0 installs, 0 updates, 69 removals

  • Removing argcomplete (1.12.3)
  • Removing attrs (21.4.0)
  • Removing beautifulsoup4 (4.11.1)
import nox
from nox_poetry import Session, session

nox.options.reuse_existing_virtualenvs = True


@session
def licenses(s: Session) -> None:
    s.run_always("poetry", "install", "--no-root", "--no-dev", external=True)
    s.run("pip-licenses", *s.posargs)

Should nox-poetry be applying the poetry install operation to the nox session venv itself rather than the current env where nox itself is running?

@johnthagen
Copy link
Author

johnthagen commented May 25, 2022

Okay, the best workaround I could get working for this is:

@session
def licenses(s: Session) -> None:
    with NamedTemporaryFile() as requirements_file:
        s.run_always(
            "poetry",
            "export",
            "--without-hashes",
            "-o",
            requirements_file.name,
            external=True,
        )
        s.install("pip-licenses", "-r", requirements_file.name)
    s.run("pip-licenses", *s.posargs)

It would be great if nox-poetry had some kind of --no-root equivalent for session.install(".") to make this cleaner.

Edit: This exact snippet will not work on Windows as Poetry can't write to the open temporary file: https://stackoverflow.com/a/23212515

@johnthagen
Copy link
Author

johnthagen commented May 31, 2022

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

No branches or pull requests

2 participants