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

Suggestion to help complete idiots like me #389

Closed
gitonthescene opened this issue Jun 10, 2021 · 7 comments
Closed

Suggestion to help complete idiots like me #389

gitonthescene opened this issue Jun 10, 2021 · 7 comments

Comments

@gitonthescene
Copy link

Hi there,

First, thanks for this project. It looks great.

I think I know why I'm getting the following warning when trying to run nox:

$ poetry run nox 
nox > Running session test-3.7
nox > Creating virtual environment (virtualenv) using python3.7 in .nox/test-3-7
nox > pytest 
nox > Warning: pytest is not installed into the virtualenv, it is located at /Users/XXXX/Library/Caches/pypoetry/virtualenvs/XXXX-GBl6xnkr-py3.7/bin/pytest. This might cause issues! Pass external=True into run() to silence this message.
...

I'm guessing that nox must be run outside of poetry. Might it be a good idea to make this requirement explicit in the documentation? There are a lot of us idiots out there. ;-)

Thanks again

OS: iOS 11.1
Python: 3.7
nox: 2021.6.6
Expectation: That it would use the virtualenv provided by nox

@cjolowicz
Copy link
Owner

Hey, we're all idiots most of the time :)

The question of whether to install Nox in Poetry, or Poetry via nox-poetry, or Nox and Poetry next to each other keeps coming up. So giving some guidance sounds like a good idea. Or at least clarifying what nox-poetry depends on, and doesn't. Thanks :)

Generally, I advise people to install Nox and Poetry independently from each other, if only to simplify things. pipx is great for this kind of thing.

In your case though, I'm wondering what your session definition looks like. Did you actually install pytest into the session, using session.install("pytest")? Just installing your package with session.install(".") or session.installroot() is not going to install your development dependencies.

@gitonthescene
Copy link
Author

@cjolowicz I actually did not. But I have one thing going for me. At least I'm self-aware.. :D Thanks for your patience.

I do have pytest stored in my poetry environment, though. But I guess because it's a dev dependency it's not in the built wheel and so must be session.install-ed. Again, I'm not complaining. I'm just offering some feedback from a certain type of developer. 8-|

One reason that I like the idea of using poetry add --dev nox-poetry is that I try to shy away from installing things into my system python. The poetry install puts a minimal environment under ~/.poetry/lib which I've hacked to add poethepoet because trying to run poe from inside poetry gets the dependencies all messed up. I tried doing a similar hack for nox-poetry but it has more dependencies than poethepoet and thus is harder to work out. I guess the better suggestion is to use pipx but I hadn't worked my way around to that yet.

My version of nox_poetry (0.8.5) seems to have Session declared without the installroot() function. It's defined in _PoetrySession, but not exposed through the proxy.

class Session(_SessionProxy):
    """Proxy for :class:`nox.sessions.Session`, passed to session functions.

    This class overrides :meth:`session.install
    <nox_poetry.sessions._PoetrySession.install>`, and provides Poetry-related
    utilities:

    - :meth:`Session.poetry.installroot
      <nox_poetry.sessions._PoetrySession.installroot>`
    - :meth:`Session.poetry.build_package
      <nox_poetry.sessions._PoetrySession.build_package>`
    - :meth:`Session.poetry.export_requirements
      <nox_poetry.sessions._PoetrySession.export_requirements>`
    """

    def __init__(self, session: nox.Session) -> None:
        """Initialize."""
        super().__init__(session)
        self.poetry = _PoetrySession(session)

    def install(self, *args: str, **kwargs: Any) -> None:
        """Install packages into a Nox session using Poetry."""
        return self.poetry.install(*args, **kwargs)

But when I try from poetry with session.install(".") I get the following:

$ poetry run nox             
nox > Running session test-3.7
nox > Creating virtual environment (virtualenv) using python3.7 in .nox/test-3-7
nox > poetry build --format=wheel
nox > Command poetry build --format=wheel failed with exit code 1:
Building csv-reconcile (0.2.5)
 - Building wheel

[EnvCommandError]
Command ['/Users/XXXX/Python/wikidata/csv-reconcile/.nox/test-3-7/bin/python', '/Users/XXXX/Python/wikidata/csv-reconcile/setup.py', 'build', '-b', '/Users/XXXX/Python/wikidata/csv-reconcile/build'] errored with the following return code 2, and output: 
/opt/local/Library/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/XXXX/Python/wikidata/csv-reconcile/setup.py': [Errno 2] No such file or directory

nox > Session test-3.7 failed.

FWIW, this is the version I'm using of poetry:

$ poetry --version 
Poetry version 1.0.9
$

I get the same error when trying to run poetry build --format=wheel from the command line, but not when running poetry build.

After doing poetry self update it seems to work much better. I guess there's a requirement on a minimal version of poetry. I even see the errors with my package using python-3.8 that I was hoping to catch! (I started the package with python-3.7.)

Thanks again for your patience. I hope you find this feedback useful. I really do appreciate this project and it looks super useful. I hope all the noise doesn't obscure my appreciation.

Regards

@cjolowicz
Copy link
Owner

cjolowicz commented Jun 10, 2021

But I guess because it's a dev dependency it's not in the built wheel and so must be session.install-ed.

Correct. You're not the first to get confused by this, so we should probably improve the docs here.

I try to shy away from installing things into my system python.

That's a good habit. I can definitely recommend taking a look at pipx here.

In any case, I would recommend to keep the Nox and Poetry installations separate; hacking a Nox installation into ~/.poetry is asking for trouble. As to installing Nox with Poetry, you're needlessly constraining the dependencies of your project, and creating complexity by nesting multiple tools that manage Python environments.

My version of nox_poetry (0.8.5) seems to have Session declared without the installroot() function.

My bad, it's session.poetry.installroot. But never mind about that, just use session.install(".").

After doing poetry self update it seems to work much better. I guess there's a requirement on a minimal version of poetry.

I'm glad it's working for you now. I'll leave this open for now, as a reminder to clarify the docs. (Feel free to send a PR 😉)

Edit: I don't think nox-poetry requires more than Poetry >= 1.0.0, but it's true that a lot of bugs got fixed in Poetry since then.

@gitonthescene
Copy link
Author

Awesome. Thanks. If I get more comfortable with my set up, I don't mind sending a PR. I'm not sure I could write something cohesive just yet.

@gitonthescene
Copy link
Author

gitonthescene commented Jun 10, 2021

Grr... I tried installing poetry from pipx and now I'm having issues with it not using the right versions. I can't tell if this is nox-poetry picking up the wrong wheel because it's binary or because poetry won't build with the right environment.

FWIW, if I just run poetry build --format=wheel it picks up the version of python that poetry installed with and not the version in the pyproject.toml. This issue talks about using poetry env use to fix that. I wonder if there needs to be support for that in nox-poetry. I can open up a new issue if that seems more appropriate.

Notice it's csv_reconcile-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl, though it's a 3.7 test.

nox
nox > Running session test-3.7
nox > Creating virtual environment (virtualenv) using python3.7 in .nox/test-3-7
nox > poetry build --format=wheel
nox > pip uninstall --yes file:///Users/XXXX/Python/wikidata/csv-reconcile/dist/csv_reconcile-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl
nox > poetry export --format=requirements.txt --dev --without-hashes
nox > python -m pip install --constraint=.nox/test-3-7/tmp/requirements.txt file:///Users/XXXX/Python/wikidata/csv-reconcile/dist/csv_reconcile-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl
nox > Command python -m pip install --constraint=.nox/test-3-7/tmp/requirements.txt file:///Users/XXXX/Python/wikidata/csv-reconcile/dist/csv_reconcile-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl failed with exit code 1:
ERROR: csv_reconcile-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl is not a supported wheel on this platform.
nox > Session test-3.7 failed.

Double Grrr.. I think there's still a bug in poetry. It's not building the right binary even when I set poetry env use.

I'll add to that poetry issue, but it seems like something you'd want a heads up on.

Regards

P.S. If you'd like more context, just let me know. If it helps, my project is public.

@gitonthescene
Copy link
Author

gitonthescene commented Jun 10, 2021

FWIW, I opened an issue. This appears to be purely about poetry mis-naming the wheel.

@cjolowicz
Copy link
Owner

I opened #393 and #399 to track the documentation issues.

IIUC your new problem was caused by an upstream bug. So I'll close this now, but feel free to comment here or open another issue.

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