Skip to content

Commit

Permalink
Add tox configuration to pyproject.toml
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jthomale committed Jan 20, 2022
1 parent b921236 commit f2a774b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ poetry.lock
.python-version
.cache/
.pytest_cache/
.tox/

53 changes: 43 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,61 @@ version = "1.0.0"
description = ""
authors = ["Jason Thomale <[email protected]>"]
packages = [
{ include = "solrfixtures", from = "src"}
{ include = "solrfixtures", from = "src"}
]

[tool.poetry.dependencies]
python = "^3.7"
pytz = [
{ version = ">=2020.5", python = "^3.9" },
{ version = ">=2020.4", python = "~3.7 || ~3.8" }
{ version = ">=2020.5", python = "^3.9" },
{ version = ">=2020.4", python = "~3.7 || ~3.8" }
]
ujson = [
{ version = ">=4.2.0", python = "^3.10" },
{ version = ">=4.0.0", python = "~3.9" },
{ version = ">=2.0.0", python = "~3.7 || ~3.8" }
{ version = ">=4.2.0", python = "^3.10" },
{ version = ">=4.0.0", python = "~3.9" },
{ version = ">=2.0.0", python = "~3.7 || ~3.8" }
]
[tool.poetry.dev-dependencies]
pytest = [
{ version = "^6.2.5", python = "^3.10" },
{ version = ">=5.4.2", python = "~3.9" },
{ version = ">=5.1.0", python= "~3.7 || ~3.8" }
{ version = "^6.2.5", python = "^3.10", optional = true },
{ version = ">=5.4.2", python = "~3.9" , optional = true },
{ version = ">=5.1.0", python= "~3.7 || ~3.8", optional = true }
]

[tool.poetry.extras]
test = ["pytest"]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py{37,38,39,310}-{oldest,latest}
isolated_build = True
[testenv]
extras =
test
commands =
pytest
[testenv:py{37,38}-oldest]
deps =
pytest==5.1.0
ujson==2.0.0
pytz==2020.4
[testenv:py39-oldest]
deps =
pytest==5.4.2
ujson==4.0.0
pytz==2020.5
[testenv:py310-oldest]
deps =
pytest==6.2.5
ujson==4.2.0
pytz==2020.5
"""

0 comments on commit f2a774b

Please sign in to comment.