-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[FAQ]: The tox answer should recommend poetry install --no-root
instead of poetry install
#1941
Comments
I believe Poetry should be left out of
|
You will have maintain duplicate lists of your dependencies if you do that, and you might not get the same version of the dependencies in the tox environment as you would in production because it wouldn't be honoring the poetry.lock file. |
In this workflow scenario the The tox tool is meant to test a library or application against multiple combinations of different versions of the Python interpreter and different versions of the dependencies. It is explicitly not intended to test just one combination. If it is your case, you probably don't need tox to begin with. Unless you are both the developer/maintainer and sole user of the project (application or library) and you can allow yourself to exactly pin the version numbers of all dependencies, there is little control over which versions of the other packages are installed in the environment your project runs in. I believe it is the responsibility of the user (integrator, system administrator) to pin the versions of the dependencies and thoroughly test this exact combination. Not the responsibility of the maintainers of the project. This is the kind of workflow scenario this suggestion is targeted at. A scenario where the solution currently presented in the FAQ could make sense (everything is pinned in |
I'm totally misunderstanding something then. How can I use tox or another tool to verify that |
Well, tox does exactly that. The first thing tox does is package a source distribution (sdist) of the project. Then it creates a virtual environment and installs the sdist in it. So tox executes the When To also run some tests against the project as installed from its wheel distribution, one could look into the tox-wheel plugin or something similar. Additionally I would also recommend doing something like the following to check the distributions with twine:
And it also goes without tox:
|
For my current PR #240 I'm adding `hypothesis` as a test dependency to allow generation of random input strings to better test parsing and escaping logic (see e44e4b3). I also changed how we load the grammar file, to make the package zip safe again (see 3cafe53). While working on how these could be integrated into our testsuite, I found out that `setup.py test` is deprecated ([1](pytest-dev/pytest#5534) [2](https://tox.readthedocs.io/en/latest/example/basic.html#integration-with-setup-py-test-command)). The recommendation was to use `tox` to test the generated package directly using `pytest` instead of relying on `setup.py` to test the sources. Additionally, there's a designated successor to `setup.py` and `setup.cfg` (in which we probably accumulated a few outdated definitions), the build-system independent `pyproject.toml`. Additionally, there are newer tools like `pipenv`, `flit` and `poetry` to help with the whole build and publishing process. As I was not quite happy with how the whole development process of ics.py was set up, I wanted to give them a shot. Collecting some opinion around the internet, it seemed that `flit` was mostly targeted at very simple low-configuration projects and the development of `pipenv` somehow stagnated, while `poetry` seemed to be a well suited solution. So this PR contains my attempt at migrating to `poetry`, with all ics.py sources moved according to the new recommended format. It's mostly the config files in the root directory that changed, but I also removed the `dev` directory as it should no longer be needed. Next to all files from the `./ics/` directory remain unchanged and are simply moved to `./src/ics/`. I didn't copy the tests over yet, as I plan to rewrite most of them in my other branch. The first of the two main configuration files is now `pyproject.toml`, where all meta-information on the project and how it can be installed (i.e. dependencies) and built are stored (without the need to actually execute the file and have some specific setuptools lying around). The second is `tox.ini`, where all testing related functionality is configured. A third file `.bumpversion.cfg` is from a small tool that helps with updating the version number in all places when doing a new release. The `poetry.lock` file optionally stores the dependency versions against which we want to develop, which is independent from the versions the library pulls in as dependency itself, where we are pretty liberal, and the versions we test against, which is always the latest releases. All library sourcecode now resides within a `src` folder, which is recommended as it prevents you from accidentally having the sources in your PATH when you want to test the final package. The root directory now looks very clean and all those files have their specific purpose. If you want to configure how testing is done, you find all information in [`tox.ini`](https://github.com/N-Coder/ics.py-poetry/blob/master/tox.ini). If you want to run the tests (i.e. pytest, doctest, flake8, mypy and check that the docs build), simply run `tox` - you don't have to worry about which versions in which venvs are installed and whether you're directly testing against the sources or against a built package, tox handles all that for you. This not only comes in very handy when running the tests manually, but should also ensure that [CI](https://github.com/N-Coder/ics.py-poetry/blob/master/.github/workflows/pythonpackage.yml) does exactly the same. On a side note, we're now again publishing [coverage data](https://codecov.io/gh/N-Coder/ics.py-poetry). If you just want to run the tests and don't need to fiddle around with the development version of ics in an interactive shell, that's all you need. For the fiddling part, just run [`poetry install`](https://python-poetry.org/docs/cli/#install) and you will have a turnkey development environment set up. Use `poetry shell` or `poetry run` to easily access the venv poetry set up for you. Publishing is now also very simple: just call `poetry publish --build` and the tool will take care of the rest. This made it very easy to make some releases on the [testing pypi instance](https://test.pypi.org/project/ics/#history). The third and last tool you might want is `bumpversion`, if you are making new releases. But there is no need anymore to handle any venvs yourself or to install all ics.py dependencies globally. To summarize, if you want to hit the ground running and publish a new release on a newly set-up machine, the following should suffice: ```bash git clone https://github.com/N-Coder/ics.py-poetry.git && cd ics.py-poetry pip install tox poetry bumpversion --user tox # make sure all the test run bumpversion --verbose release # 0.8.0-dev -> 0.8.0 (release) poetry build # build the package tox --recreate # ensure that the version numbers are consistent # check changelog and amend if necessary git push && git push --tags poetry publish # publish to pypi bumpversion --verbose minor # 0.8.0 (release) -> 0.9.0-dev git push && git push --tags ``` You can try that out if you want -- except for the publishing part maybe. Also note that `bumpversion` directly makes a commit with the new version if you don't pass `--no-commit` or `--dry-run`, but that's no problem as you can easily amend any changes you want to make, e.g. to the changelog. The above information on developing, testing and publishing can now also be found in the docs (see CONTRIBUTING.rst). As these changes are partially based upon #240 but are also quite fundamental, I wanted to collect feedback first before including the changes into #240. The only other thing #240 is still lacking is more testing (only few files already have close to 100% coverage), and I'd prefer to provide that using `tox` in this new environment. So that's also some kind of cyclic dependency. Sorry for the (now superfluous) issue I opened before. So @C4ptainCrunch (and maybe also @aureooms and @tomschr), what's your opinion on this? * migrate repo structure to poetry * fix src path for pytest * add doc skeleton * implement handling of attachments * import project files * set version * fix sphinx build with poetry * don't use poetry within tox see python-poetry/poetry#1941 (comment) * fix timezone tests * change coveralls action * try codecov * bugfixes * add bumpversion * separate src inspection (flake8+mypy src/) from package testing (pytest tests/) to fix PATH problems * bugfixes * Merge branch 'master' into new-parser-impl * remove old files * add dev and publish instructions * checker happiness `noqa` and `type: ignore` are now only used for actual bugs in the checkers unfortunately, current pyflakes dislikes `type: ignore[something]`, so we can't ignore specific mypy bugs until pyflakes 2.2 is in flakes8 * more checker happiness * Apply suggestions from code review Co-Authored-By: Tom Schraitle <[email protected]> * use gitignore directly from github instead of gitignore.io * Apply suggestions from code review to tox.ini * fix tox.ini * add pypy support Mostly by moving/splitting test dependencies to different sections in tox.ini as mypy and pypy don't work well together and it is sufficient to run mypy checks on CPython. * update developing documentation * fix non-ASCII whitespace handling * update test/dev dependencies
For my current PR #240 I'm adding `hypothesis` as a test dependency to allow generation of random input strings to better test parsing and escaping logic (see e44e4b3). I also changed how we load the grammar file, to make the package zip safe again (see 3cafe53). While working on how these could be integrated into our testsuite, I found out that `setup.py test` is deprecated ([1](pytest-dev/pytest#5534) [2](https://tox.readthedocs.io/en/latest/example/basic.html#integration-with-setup-py-test-command)). The recommendation was to use `tox` to test the generated package directly using `pytest` instead of relying on `setup.py` to test the sources. Additionally, there's a designated successor to `setup.py` and `setup.cfg` (in which we probably accumulated a few outdated definitions), the build-system independent `pyproject.toml`. Additionally, there are newer tools like `pipenv`, `flit` and `poetry` to help with the whole build and publishing process. As I was not quite happy with how the whole development process of ics.py was set up, I wanted to give them a shot. Collecting some opinion around the internet, it seemed that `flit` was mostly targeted at very simple low-configuration projects and the development of `pipenv` somehow stagnated, while `poetry` seemed to be a well suited solution. So this PR contains my attempt at migrating to `poetry`, with all ics.py sources moved according to the new recommended format. It's mostly the config files in the root directory that changed, but I also removed the `dev` directory as it should no longer be needed. Next to all files from the `./ics/` directory remain unchanged and are simply moved to `./src/ics/`. I didn't copy the tests over yet, as I plan to rewrite most of them in my other branch. The first of the two main configuration files is now `pyproject.toml`, where all meta-information on the project and how it can be installed (i.e. dependencies) and built are stored (without the need to actually execute the file and have some specific setuptools lying around). The second is `tox.ini`, where all testing related functionality is configured. A third file `.bumpversion.cfg` is from a small tool that helps with updating the version number in all places when doing a new release. The `poetry.lock` file optionally stores the dependency versions against which we want to develop, which is independent from the versions the library pulls in as dependency itself, where we are pretty liberal, and the versions we test against, which is always the latest releases. All library sourcecode now resides within a `src` folder, which is recommended as it prevents you from accidentally having the sources in your PATH when you want to test the final package. The root directory now looks very clean and all those files have their specific purpose. If you want to configure how testing is done, you find all information in [`tox.ini`](https://github.com/N-Coder/ics.py-poetry/blob/master/tox.ini). If you want to run the tests (i.e. pytest, doctest, flake8, mypy and check that the docs build), simply run `tox` - you don't have to worry about which versions in which venvs are installed and whether you're directly testing against the sources or against a built package, tox handles all that for you. This not only comes in very handy when running the tests manually, but should also ensure that [CI](https://github.com/N-Coder/ics.py-poetry/blob/master/.github/workflows/pythonpackage.yml) does exactly the same. On a side note, we're now again publishing [coverage data](https://codecov.io/gh/N-Coder/ics.py-poetry). If you just want to run the tests and don't need to fiddle around with the development version of ics in an interactive shell, that's all you need. For the fiddling part, just run [`poetry install`](https://python-poetry.org/docs/cli/#install) and you will have a turnkey development environment set up. Use `poetry shell` or `poetry run` to easily access the venv poetry set up for you. Publishing is now also very simple: just call `poetry publish --build` and the tool will take care of the rest. This made it very easy to make some releases on the [testing pypi instance](https://test.pypi.org/project/ics/#history). The third and last tool you might want is `bumpversion`, if you are making new releases. But there is no need anymore to handle any venvs yourself or to install all ics.py dependencies globally. To summarize, if you want to hit the ground running and publish a new release on a newly set-up machine, the following should suffice: ```bash git clone https://github.com/N-Coder/ics.py-poetry.git && cd ics.py-poetry pip install tox poetry bumpversion --user tox # make sure all the test run bumpversion --verbose release # 0.8.0-dev -> 0.8.0 (release) poetry build # build the package tox --recreate # ensure that the version numbers are consistent # check changelog and amend if necessary git push && git push --tags poetry publish # publish to pypi bumpversion --verbose minor # 0.8.0 (release) -> 0.9.0-dev git push && git push --tags ``` You can try that out if you want -- except for the publishing part maybe. Also note that `bumpversion` directly makes a commit with the new version if you don't pass `--no-commit` or `--dry-run`, but that's no problem as you can easily amend any changes you want to make, e.g. to the changelog. The above information on developing, testing and publishing can now also be found in the docs (see CONTRIBUTING.rst). As these changes are partially based upon #240 but are also quite fundamental, I wanted to collect feedback first before including the changes into #240. The only other thing #240 is still lacking is more testing (only few files already have close to 100% coverage), and I'd prefer to provide that using `tox` in this new environment. So that's also some kind of cyclic dependency. Sorry for the (now superfluous) issue I opened before. So @C4ptainCrunch (and maybe also @aureooms and @tomschr), what's your opinion on this? * migrate repo structure to poetry * fix src path for pytest * add doc skeleton * implement handling of attachments * import project files * set version * fix sphinx build with poetry * don't use poetry within tox see python-poetry/poetry#1941 (comment) * fix timezone tests * change coveralls action * try codecov * bugfixes * add bumpversion * separate src inspection (flake8+mypy src/) from package testing (pytest tests/) to fix PATH problems * bugfixes * Merge branch 'master' into new-parser-impl * remove old files * add dev and publish instructions * checker happiness `noqa` and `type: ignore` are now only used for actual bugs in the checkers unfortunately, current pyflakes dislikes `type: ignore[something]`, so we can't ignore specific mypy bugs until pyflakes 2.2 is in flakes8 * more checker happiness * Apply suggestions from code review Co-Authored-By: Tom Schraitle <[email protected]> * use gitignore directly from github instead of gitignore.io * Apply suggestions from code review to tox.ini * fix tox.ini * add pypy support Mostly by moving/splitting test dependencies to different sections in tox.ini as mypy and pypy don't work well together and it is sufficient to run mypy checks on CPython. * update developing documentation * fix non-ASCII whitespace handling * update test/dev dependencies
i maintain some applications distributed as a whole, with all dependencies included (if by distributed, you mean packaged into docker containers to be served to users). i still like using tox, because you can specify multiple test commands. i tell other developers of the application to just run so, i believe that there is still utility in using tox, even when what i want tox to do is to install just the things in my
|
@igor47 My point is: Do use tox, but don't call poetry from inside
The main reason for using tox is to test one's project against a wide range of combinations of dependencies and Python interpreters. So testing against the one and only combination registered in
Now I am open to admit that for some projects it might be the sensible thing to test only against one version of Python interpreter (in that case, the one in the Docker container) and the combination of dependencies registered in |
Tox is not just useful for testing combinations of different versions of packages or python interpreters. We use tox for automation: seperate tox environments are used to have things like It's also very useful for managing dependencies between test environments (ie, runs the "clean" environment before anything else, and the "code-coverage" collector environment after all other environments). |
@schinckel Those are all legitimate use cases for tox indeed, but... What would that mean for the current topic? What would be your recommendation? What should be written in the FAQ? In short, which tool should handle the creation of the virtual environments, the installation of the project, of its dependencies? Should it be tox or poetry? |
Thanks to everyone for the conversation. I agree with @sinoroc and others on the principle, that the whole goal of However, the goal of In that sense, I agree with @thejohnfreeman, @Alexspayne and @schinckel, that there is something sub-optimal about the current answers. In another issue, @wesleykendall provided an excellent alternate solution that is: Automatically export dependencies to a common API that |
I left a thumbs up on @sinoroc's explanation, but never explicitly said that he changed my opinion on this subject, after I copied his suggested pattern with success. I was unaware that tox would build the package with Poetry via the |
This is enabled by the This isolated build feature is the new standard (look up PEP 517 and PEP 518), works also with setuptools, flit, etc. The missing element here is about the development dependencies. How to let tox know what the dev dependencies are? This can be solved by using the extras (which is a standard, i.e. specified by a PEP), this pattern is quite common nowadays and is guaranteed to work across many different tools (not only tox, and poetry). On the other hand, generating a But again, if one wants to go all-in with poetry and use all its features (even the non standard ones), feel free. But it means that you will have to work harder to make it cooperate with other tools that do follow standards. Which could be fine, maybe there isn't even need for tox to begin with. Just running So my point is: in my opinion poetry's FAQ on the topic of tox is misleading and shows a largely sub-optimal pattern. I have been thinking for a while about writing a plugin for tox that would offer tox a way to automatically pick up poetry's dev dependencies. Maybe that would put this issue to rest. Or maybe there's already such a plugin? If you know of one, let us know. |
I'm hoping to be able to specify dependency groups in my CI once this is available: #1644 (planned for poetry 1.2) But until then, what is the recommended usage of poetry with tox when you need to install dev dependencies for e.g. linting/pytest or the other usual CI suspects? I've noticed that poetry's pyproject.toml itself differs from what the FAQ says on the build system declaration: I'm also contemplating whether I should try to use tox-current-env right now too, as all my tox envs end up identical in terms of dependencies but takes ages to build. And no I cannot use poetry's extras... Ping @abn @sdispater can someone please explain what is the current recommendation? |
Generating a
I knew of no such plugin, however some due-diligence Googling led me to discover a very unusual effort: There are some things that are unusual: The PyPi repo link is pointing to a different repo. The test coverage is 0%. The project seems to have been forked (a bit sloppily) from I think it would be an excellent idea to have a reliable plugin. |
I agree that using extras is not ideal. So here's what I have done in my most recent package,
This works wonderfully and allowed me to expand the compatibility of my package to versions different than my own (Py 3.8 right now). What I like about this solution is that I still only specify everything in one place, My next steps are:
[ If you find this useful, I would appreciate a ⭐ on my package 😅. ] |
One of the reasons I'm excited about PEP 518 ( Extras has good support across Python tools, so I have switched to using it instead of |
Good points @thejohnfreeman. Although I agree with you, I think the practice of having But personally I agree it makes more sense to use an existing mechanism for specifying an additional subset of dependencies. It would be nice if there was some PEP just to say "the best way to provide development dependencies is an 'extra' called 'dev'" or something like that. I wonder what the process would be for that to be suggested. Any ideas? |
Agreed. From my point of view it should be a convention (a recommendation), not a specification (a rule).
Maybe. PyPA is in the process of writing new PEPs, one of them in particular PEP 621 proposes to specify the way project's metadata should be stored in You might want to read these two threads first:
And then open a new thread on that forum to make your suggestion. But no guarantee: it might be considered out of scope for a PEP. |
I published on PyPI a plugin for Tox to instruct it to install Poetry's development dependencies in the test environments: tox-poetry-dev-dependencies. It's just a proof of concept. I didn't test much, only with a very simple project. |
Very exciting @sinoroc — can't wait to try it out!! |
I'd rather move away from Poetry
Tox only needs to install |
I also prefer extras for my projects, (see the very code of |
Version A will be rejected by pip when installing, either from a wheel or from source, and by PyPI when uploading a wheel:
|
Thanks for the confirmation that in version A the upload to PyPI fails. Although, I must say, that for me pip was able to install version A from its wheel (local file system, not PyPI) and from its source directory (again local file system, obviously). Would version B work for you? It requires specifying some of the development dependencies twice, but only those that require a direct URL. That would be the best compromise I can think of right now. |
I personally use Nox, but version B would work. Just a little gotcha to bear in mind. I can't imagine it crops up often. |
All of this seems like a work around to me. Is there something that needs to change on the tox side to make tox set up poetry environments correctly? In theory, it seems that the tox.ini should look the same for a poetry package as it would for a package using setup.py. I don't put "pip install" in a tox.ini for a setuptools project. If there are things that need to be fixed on the tox side, perhaps we can focus our efforts there. Sometimes, I have been able to get this to work, but other times it has not. I have yet to chase down all the different system configuration effects to understand why it does not always work. It seems that the goal should be that this would be all that would be needed.
|
based on discussion here: python-poetry/poetry#1941
Had a hard time continuing to use pipenv for dependency management while working with readthedocs automated builds. Migrated over to Poetry and its PEP517 compliance will allow for easier use with readthedocs and less overhead overall. Here are the sources I used to help make this decision: * python-poetry/poetry#1145 * python-poetry/poetry#1941 * readthedocs/readthedocs.org#3181
This commit swaps us to using poetry as our package manager, virtual environment manager, and build tool. Some of the changes: - Install poetry using they're recommended python installer, instead of off PyPI. IDK how important this really is, maybe it's overkill vs `python3 -m pip install poetry` - Dev dependencies only used to be available inside the specific tox environments they were used. This made it impossible to directly call `pytest`, for instance. You had to call `tox -e pytest`. Now developers have access to the toolchain directly more directly, though you still have to work within poetry's venv with `poetry run pytest`, or just start up a shell in the venv with `poetry shell` and then `pytest` directly should work. - Dev install is as easy as `poetry install -E dev`. Dependencies are only specified in one place now, pyproject.toml - Now the version info is necessarily in both pyproject.toml and in the source code, so add a simple test_meta.py file to make sure the two sources of truth stay in sync. version.py is no longer needed, so put the version info directly in __init__.py. - The [metadata] and [wheel] entries in setup.cfg are no longer needed since we're using poetry to build instead of setuptools. MANIFEST.in was never needed in the first place, since LICENSE has always by default been included in distributions. - Add a check with twine after building to ensure the built distributions are OK. - The GitHub actions workflows had to be tweaked a bit, though they are basically the same. - Add a makefile rule to update dependencies easily with `make update` - Specify using poetry as our build system in the [build-system] area of pyproject.toml. Now build and publish just with `poetry build` and `poetry publish` instead of using `python setup.py sdist upload` etc. Tell tox about this change with `isolated_build = True` intox.ini It was tricky deciding how to make tox and poetry play nicely with each other, in terms of making sure they used the same deps, the deps didn't have to be defined in multiple places, and the deps were available outside of tox. I used the extra dependencies method outlined in python-poetry/poetry#1941, though there are probably other ways to do this.
This commit swaps us to using poetry as our package manager, virtual environment manager, and build tool. Some of the changes: - Install poetry using they're recommended python installer, instead of off PyPI. IDK how important this really is, maybe it's overkill vs `python3 -m pip install poetry` - Dev dependencies only used to be available inside the specific tox environments they were used. This made it impossible to directly call `pytest`, for instance. You had to call `tox -e pytest`. Now developers have access to the toolchain directly more directly, though you still have to work within poetry's venv with `poetry run pytest`, or just start up a shell in the venv with `poetry shell` and then `pytest` directly should work. - Dev install is as easy as `poetry install -E dev`. Dependencies are only specified in one place now, pyproject.toml - Now the version info is necessarily in both pyproject.toml and in the source code, so add a simple test_meta.py file to make sure the two sources of truth stay in sync. version.py is no longer needed, so put the version info directly in __init__.py. - The [metadata] and [wheel] entries in setup.cfg are no longer needed since we're using poetry to build instead of setuptools. MANIFEST.in was never needed in the first place, since LICENSE has always by default been included in distributions. - Add a check with twine after building to ensure the built distributions are OK. - The GitHub actions workflows had to be tweaked a bit, though they are basically the same. - Add a makefile rule to update dependencies easily with `make update` - Specify using poetry as our build system in the [build-system] area of pyproject.toml. Now build and publish just with `poetry build` and `poetry publish` instead of using `python setup.py sdist upload` etc. Tell tox about this change with `isolated_build = True` intox.ini It was tricky deciding how to make tox and poetry play nicely with each other, in terms of making sure they used the same deps, the deps didn't have to be defined in multiple places, and the deps were available outside of tox. I used the extra dependencies method outlined in python-poetry/poetry#1941, though there are probably other ways to do this.
This commit swaps us to using poetry as our package manager, virtual environment manager, and build tool. Some of the changes: - Install poetry using they're recommended python installer, instead of off PyPI. IDK how important this really is, maybe it's overkill vs `python3 -m pip install poetry` - Dev dependencies only used to be available inside the specific tox environments they were used. This made it impossible to directly call `pytest`, for instance. You had to call `tox -e pytest`. Now developers have access to the toolchain directly more directly, though you still have to work within poetry's venv with `poetry run pytest`, or just start up a shell in the venv with `poetry shell` and then `pytest` directly should work. - Dev install is as easy as `poetry install -E dev`. Dependencies are only specified in one place now, pyproject.toml - Now the version info is necessarily in both pyproject.toml and in the source code, so add a simple test_meta.py file to make sure the two sources of truth stay in sync. version.py is no longer needed, so put the version info directly in __init__.py. - The [metadata] and [wheel] entries in setup.cfg are no longer needed since we're using poetry to build instead of setuptools. MANIFEST.in was never needed in the first place, since LICENSE has always by default been included in distributions. - Add a check with twine after building to ensure the built distributions are OK. - The GitHub actions workflows had to be tweaked a bit, though they are basically the same. - Add a makefile rule to update dependencies easily with `make update` - Specify using poetry as our build system in the [build-system] area of pyproject.toml. Now build and publish just with `poetry build` and `poetry publish` instead of using `python setup.py sdist upload` etc. Tell tox about this change with `isolated_build = True` intox.ini It was tricky deciding how to make tox and poetry play nicely with each other, in terms of making sure they used the same deps, the deps didn't have to be defined in multiple places, and the deps were available outside of tox. I used the extra dependencies method outlined in python-poetry/poetry#1941, though there are probably other ways to do this.
This commit swaps us to using poetry as our package manager, virtual environment manager, and build tool. Some of the changes: - Install poetry using they're recommended python installer, instead of off PyPI. IDK how important this really is, maybe it's overkill vs `python3 -m pip install poetry` - Dev dependencies only used to be available inside the specific tox environments they were used. This made it impossible to directly call `pytest`, for instance. You had to call `tox -e pytest`. Now developers have access to the toolchain directly more directly, though you still have to work within poetry's venv with `poetry run pytest`, or just start up a shell in the venv with `poetry shell` and then `pytest` directly should work. - Dev install is as easy as `poetry install -E dev`. Dependencies are only specified in one place now, pyproject.toml - Now the version info is necessarily in both pyproject.toml and in the source code, so add a simple test_meta.py file to make sure the two sources of truth stay in sync. version.py is no longer needed, so put the version info directly in __init__.py. - The [metadata] and [wheel] entries in setup.cfg are no longer needed since we're using poetry to build instead of setuptools. MANIFEST.in was never needed in the first place, since LICENSE has always by default been included in distributions. - Add a check with twine after building to ensure the built distributions are OK. - The GitHub actions workflows had to be tweaked a bit, though they are basically the same. - Add a makefile rule to update dependencies easily with `make update` - Specify using poetry as our build system in the [build-system] area of pyproject.toml. Now build and publish just with `poetry build` and `poetry publish` instead of using `python setup.py sdist upload` etc. Tell tox about this change with `isolated_build = True` intox.ini It was tricky deciding how to make tox and poetry play nicely with each other, in terms of making sure they used the same deps, the deps didn't have to be defined in multiple places, and the deps were available outside of tox. I used the extra dependencies method outlined in python-poetry/poetry#1941, though there are probably other ways to do this.
This commit swaps us to using poetry as our package manager, virtual environment manager, and build tool. Some of the changes: - Install poetry using they're recommended python installer, instead of off PyPI. IDK how important this really is, maybe it's overkill vs `python3 -m pip install poetry` - Dev dependencies only used to be available inside the specific tox environments they were used. This made it impossible to directly call `pytest`, for instance. You had to call `tox -e pytest`. Now developers have access to the toolchain directly more directly, though you still have to work within poetry's venv with `poetry run pytest`, or just start up a shell in the venv with `poetry shell` and then `pytest` directly should work. - Dev install is as easy as `poetry install -E dev`. Dependencies are only specified in one place now, pyproject.toml - Now the version info is necessarily in both pyproject.toml and in the source code, so add a simple test_meta.py file to make sure the two sources of truth stay in sync. version.py is no longer needed, so put the version info directly in __init__.py. - The [metadata] and [wheel] entries in setup.cfg are no longer needed since we're using poetry to build instead of setuptools. MANIFEST.in was never needed in the first place, since LICENSE has always by default been included in distributions. - Add a check with twine after building to ensure the built distributions are OK. - The GitHub actions workflows had to be tweaked a bit, though they are basically the same. - Add a makefile rule to update dependencies easily with `make update` - Specify using poetry as our build system in the [build-system] area of pyproject.toml. Now build and publish just with `poetry build` and `poetry publish` instead of using `python setup.py sdist upload` etc. Tell tox about this change with `isolated_build = True` intox.ini It was tricky deciding how to make tox and poetry play nicely with each other, in terms of making sure they used the same deps, the deps didn't have to be defined in multiple places, and the deps were available outside of tox. I used the extra dependencies method outlined in python-poetry/poetry#1941, though there are probably other ways to do this.
This commit swaps us to using poetry as our package manager, virtual environment manager, and build tool. Some of the changes: - Install poetry using they're recommended python installer, instead of off PyPI. IDK how important this really is, maybe it's overkill vs `python3 -m pip install poetry` - Dev dependencies only used to be available inside the specific tox environments they were used. This made it impossible to directly call `pytest`, for instance. You had to call `tox -e pytest`. Now developers have access to the toolchain directly more directly, though you still have to work within poetry's venv with `poetry run pytest`, or just start up a shell in the venv with `poetry shell` and then `pytest` directly should work. - Dev install is as easy as `poetry install -E dev`. Dependencies are only specified in one place now, pyproject.toml - Now the version info is necessarily in both pyproject.toml and in the source code, so add a simple test_meta.py file to make sure the two sources of truth stay in sync. version.py is no longer needed, so put the version info directly in __init__.py. - The [metadata] and [wheel] entries in setup.cfg are no longer needed since we're using poetry to build instead of setuptools. MANIFEST.in was never needed in the first place, since LICENSE has always by default been included in distributions. - Add a check with twine after building to ensure the built distributions are OK. - The GitHub actions workflows had to be tweaked a bit, though they are basically the same. - Add a makefile rule to update dependencies easily with `make update` - Specify using poetry as our build system in the [build-system] area of pyproject.toml. Now build and publish just with `poetry build` and `poetry publish` instead of using `python setup.py sdist upload` etc. Tell tox about this change with `isolated_build = True` intox.ini It was tricky deciding how to make tox and poetry play nicely with each other, in terms of making sure they used the same deps, the deps didn't have to be defined in multiple places, and the deps were available outside of tox. I used the extra dependencies method outlined in python-poetry/poetry#1941, though there are probably other ways to do this.
This commit swaps us to using poetry as our package manager, virtual environment manager, and build tool. Some of the changes: - Use the pip method of installing poetry. It's not the bash installer recommended by Poetry, but the bash installer wasn't working in CI. I decided it wasn't a big deal, just use the simple way. I'd imagine dependency conflicts when installing Poetry and its deps shouldn't happen that often. - Dev dependencies only used to be available inside the specific tox environments they were used. This made it impossible to directly call `pytest`, for instance. You had to call `tox -e pytest`. Now developers have access to the toolchain directly more directly, though you still have to work within poetry's venv with `poetry run pytest`, or just start up a shell in the venv with `poetry shell` and then `pytest` directly should work. - Dev install is as easy as `poetry install -E dev`. Dependencies are only specified in one place now, pyproject.toml - Now the version info is necessarily in both pyproject.toml and in the source code, so add a simple test_meta.py file to make sure the two sources of truth stay in sync. version.py is no longer needed, so put the version info directly in __init__.py. - The [metadata] and [wheel] entries in setup.cfg are no longer needed since we're using poetry to build instead of setuptools. MANIFEST.in was never needed in the first place, since LICENSE has always by default been included in distributions. - Add a check with twine after building to ensure the built distributions are OK. - The GitHub actions workflows had to be tweaked a bit, though they are basically the same. - Add a makefile rule to update dependencies easily with `make update` - Specify using poetry as our build system in the [build-system] area of pyproject.toml. Now build and publish just with `poetry build` and `poetry publish` instead of using `python setup.py sdist upload` etc. Tell tox about this change with `isolated_build = True` intox.ini It was tricky deciding how to make tox and poetry play nicely with each other, in terms of making sure they used the same deps, the deps didn't have to be defined in multiple places, and the deps were available outside of tox. I used the extra dependencies method outlined in python-poetry/poetry#1941, though there are probably other ways to do this.
This commit swaps us to using poetry as our package manager, virtual environment manager, and build tool. Some of the changes: - Use the pip method of installing poetry. It's not the bash installer recommended by Poetry, but the bash installer wasn't working in CI. I decided it wasn't a big deal, just use the simple way. I'd imagine dependency conflicts when installing Poetry and its deps shouldn't happen that often. - Dev dependencies only used to be available inside the specific tox environments they were used. This made it impossible to directly call `pytest`, for instance. You had to call `tox -e pytest`. Now developers have access to the toolchain directly more directly, though you still have to work within poetry's venv with `poetry run pytest`, or just start up a shell in the venv with `poetry shell` and then `pytest` directly should work. - Dev install is as easy as `poetry install -E dev`. Dependencies are only specified in one place now, pyproject.toml - Now the version info is necessarily in both pyproject.toml and in the source code, so add a simple test_meta.py file to make sure the two sources of truth stay in sync. version.py is no longer needed, so put the version info directly in __init__.py. - The [metadata] and [wheel] entries in setup.cfg are no longer needed since we're using poetry to build instead of setuptools. MANIFEST.in was never needed in the first place, since LICENSE has always by default been included in distributions. - Add a check with twine after building to ensure the built distributions are OK. - The GitHub actions workflows had to be tweaked a bit, though they are basically the same. - Add a makefile rule to update dependencies easily with `make update` - Specify using poetry as our build system in the [build-system] area of pyproject.toml. Now build and publish just with `poetry build` and `poetry publish` instead of using `python setup.py sdist upload` etc. Tell tox about this change with `isolated_build = True` intox.ini It was tricky deciding how to make tox and poetry play nicely with each other, in terms of making sure they used the same deps, the deps didn't have to be defined in multiple places, and the deps were available outside of tox. I used the extra dependencies method outlined in python-poetry/poetry#1941, though there are probably other ways to do this.
The Also I think using |
I don't know about you, but I also experienced issues with private package repository. I had strange issues on the 1st run only, I found that adding The crash experienced during the first run looked like this: $ tox
.package create: /Users/xxx/.tox/.tmp/package
.package installdeps: poetry-core>=1.0.0
py38 create: /Users/xxx/.tox/py38
py38 inst: /Users/xxx/.tox/.tmp/package/1/notapackage-0.1.0.tar.gz
ERROR: invocation failed (exit code 1), logfile:/Users/xxx/.tox/py38/log/py38-1.log
======================= log start =======================
Processing ./.tox/.tmp/package/1/this_is_not_a_service-0.1.0.tar.gz
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing wheel metadata: started
Preparing wheel metadata: finished with status 'done'
Collecting graphene-sqlalchemy<3
Using cached graphene_sqlalchemy-2.3.0-py2.py3-none-any.whl (38 kB)
...
ERROR: Could not find a version that satisfies the requirement some_private_package<0.10.0,>=0.9.1
ERROR: No matching distribution found for some_private_package<0.10.0,>=0.9.1
WARNING: You are using pip version 21.1.1; however, version 21.1.2 is available. Subsequent runs worked as expected and ( |
Tooling around pyproject.toml (and Poetry) is brand new to me, so I'm trying to fit this into my existing workflows and mental models around how Python package development works. The change I'm making here is to incorporate tox for testing without either creating a conflict with Poetry (for dependency/package management) or creating any sort of global Poetry dependency. The challenge is that the primary use case for tox and the primary use case for Poetry are different, and each tool is *very* good at its own primary use case. But they both serve a secondary overlapping use case of automating virtualenv management -- which I don't even want or need. I much prefer to stick with pyenv + pyenv-virtualenv and manage environments on my own explicitly. Both Poetry and tox also want you to install them globally, but I much prefer to keep them limited to their own virtualenvs that I can manage myself without needing to pollute my system Python. So far this setup seems to let me do this. Three things to note about how this works. 1. Instead of using `tool.poetry.dev-dependencies` for pytest, I set pytest as an optional (main) dependency and then set that to the extra group `test`. In the tox config, `extras` references that `test` group, which tells it to include that dependency during the installation. I've done it this way because `extras` is standard while `dev-dependencies` is not. (See: python-poetry/poetry#1941 (comment) 581602064). 2. I've used the legacy tox ini pattern to include the tox ini in `pyproject.toml`. Eventually they will incorporate tox configuration into the .toml format natively, but for now this is the only way to do it, without having a separate `tox.ini` file. See: https://tox.wiki/en/latest/example/basic.html#pyproject-toml-tox- legacy-ini 3. Since this is a package and not a project, the dependencies reflect a range of versions for py 3.7 to 3.10. When tox runs, it sets up two environments per supported Python version -- one with the oldest supported dependency versions, and one with the latest supported dependency versions. The `oldest` groups are the only ones we need to define explicitly, since the default install behavior is to install the latest supported version.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
In the FAQ, there is a recommendation for how to use tox with Poetry. It suggests this
tox.ini
:With this configuration, when a user runs tox:
inst-nodeps
).poetry install
, which installs the project dependencies, and then installs the project, as editable, overwriting what tox installed in step 3.poetry run pytest tests
which tests against the package as it exists in the working directory, not as it was packaged by Poetry.To fix this, the recommended
commands
should be:commands = poetry install --no-root -v poetry run pytest tests/
The text was updated successfully, but these errors were encountered: