Skip to content

Commit

Permalink
Convert setup.py -> pyproject.toml, flat layout -> src layout
Browse files Browse the repository at this point in the history
pyproject.toml is the more modern way to do it, and we can remove all
setuptools dependence except for choosing it as the build backend.

src layout is less error prone than flat layout, given that tox is used.

Fix #38, #30, #24
  • Loading branch information
bluetech committed Jan 18, 2024
1 parent db00a1a commit b58973d
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 127 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ There you go - you just created a minimal pytest plugin:
pytest-awesome/
├── LICENSE
├── README.rst
├── docs
│   └── index.md
── mkdocs.yml
├── pytest_awesome.py
── setup.py
├── pyproject.toml
── src
│ └── pytest_awesome
├── __init__.py
│ └── plugin.py
├── tests
   ├── conftest.py
   └── test_awesome.py
├── conftest.py
└── test_awesome.py
└── tox.ini
```


## Features

- Installable [PyPI] package featuring a `setup.py`.
- Installable [PyPI] package featuring a `pyproject.toml`.
- Test suite running [tox] and [pytest] that makes sure your plugin is working
as expected
- Working example code for a fixture, a cli option, as well as a pytest.ini
Expand All @@ -78,15 +78,13 @@ pytest-awesome/
If you plan on submitting your plugin to the [pytest-dev organization] you need
to meet the following requirements:

- PyPI presence with a setup.py that contains a license, pytest-
- PyPI presence with a pyproject.toml that contains a license, pytest-
prefixed, version number, authors, short and long description.
- a tox.ini for running tests using tox.
- a README describing how to use the plugin and on which platforms
it runs.
- a LICENSE file or equivalent containing the licensing information,
with matching info in setup.py.
- an issue tracker unless you rather want to use the core pytest
issue tracker.
- a LICENSE file or equivalent containing the licensing information.
- an issue tracker

Please see the official guidelines at [Submit a Plugin].

Expand Down
11 changes: 4 additions & 7 deletions docs/user-guide/publish-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Essentially pytest plugins are not different from any other Python Package, so
you may want to create a distribution and submit it to the Python Package Index
([PyPI]).

By doing so, enables your users to easily install via ``easy-install`` or
``pip``.
By doing so, enables your users to easily install via ``pip``.

## Python Package Index

Expand All @@ -24,15 +23,13 @@ Please see the official [Python Packaging User Guide] for detailed information.
If you plan on submitting your plugin to the [pytest-dev organization] you need
to meet the following requirements:

- PyPI presence with a setup.py that contains a license, pytest-
- PyPI presence with a pyproject.toml that contains a license, pytest-
prefixed, version number, authors, short and long description.
- a tox.ini for running tests using tox.
- a README describing how to use the plugin and on which platforms
it runs.
- a LICENSE file or equivalent containing the licensing information,
with matching info in setup.py.
- an issue tracker unless you rather want to use the core pytest
issue tracker.
- a LICENSE file or equivalent containing the licensing information.
- an issue tracker.

Please see the official guidelines at [Submit a Plugin].

Expand Down
11 changes: 7 additions & 4 deletions docs/user-guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ Once you answered to the questions, Cookiecutter renders the the project:
pytest-awesome/
├── LICENSE
├── README.rst
├── pytest_awesome.py
├── setup.py
├── pyproject.toml
├── src
│ └── pytest_awesome
│ ├── __init__.py
│ └── plugin.py
├── tests
   ├── conftest.py
   └── test_awesome.py
├── conftest.py
└── test_awesome.py
└── tox.ini
```

Expand Down
5 changes: 0 additions & 5 deletions pytest-{{cookiecutter.plugin_name}}/MANIFEST.in

This file was deleted.

47 changes: 12 additions & 35 deletions pytest-{{cookiecutter.plugin_name}}/appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
# What Python version is installed where:
# https://www.appveyor.com/docs/build-environment/#python
# https://www.appveyor.com/docs/lang/python/
---
image:
- Visual Studio 2019

environment:
matrix:
- PYTHON: "C:\\Python38"
TOX_ENV: "py38"
- TOXENV: "py38"
- TOXENV: "py39"
- TOXENV: "py310"
- TOXENV: "py311"
- TOXENV: "py312"

- PYTHON: "C:\\Python39"
TOX_ENV: "py39"

- PYTHON: "C:\\Python310"
TOX_ENV: "py310"

- PYTHON: "C:\\Python311"
TOX_ENV: "py311"

- PYTHON: "C:\\Python312"
TOX_ENV: "py312"

init:
- "%PYTHON%/python -V"
- "%PYTHON%/python -c \"import struct;print( 8 * struct.calcsize(\'P\'))\""
build: false

install:
- "%PYTHON%/Scripts/easy_install -U pip"
- "%PYTHON%/Scripts/pip install tox"
- "%PYTHON%/Scripts/pip install wheel"

build: false # Not a C# project, build stuff at the test step instead.
- py -m pip install tox

test_script:
- "%PYTHON%/Scripts/tox -e %TOX_ENV%"

after_test:
- "%PYTHON%/python setup.py bdist_wheel"
- ps: "ls dist"

artifacts:
- path: dist\*

#on_success:
# - TODO: upload the content of dist/*.whl to a public wheelhouse
- py -m tox
53 changes: 53 additions & 0 deletions pytest-{{cookiecutter.plugin_name}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[build-system]
requires = [
"setuptools>=61.0.0",
]
build-backend = "setuptools.build_meta"

[project]
name = "pytest-{{cookiecutter.plugin_name}}"
description = "{{cookiecutter.short_description}}"
version = "{{cookiecutter.version}}"
readme = "README.rst"
requires-python = ">=3.8"
authors = [
{ name = "{{cookiecutter.full_name}}", email = "{{cookiecutter.email}}" },
]
maintainers = [
{ name = "{{cookiecutter.full_name}}", email = "{{cookiecutter.email}}" },
]
license = {file = "LICENSE"}
classifiers = [
"Framework :: Pytest",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Topic :: Software Development :: Testing",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
{% if cookiecutter.license == "MIT" -%}
"License :: OSI Approved :: MIT License",
{%- elif cookiecutter.license == "BSD-3" -%}
"License :: OSI Approved :: BSD License",
{%- elif cookiecutter.license == "GNU GPL v3.0+" -%}
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
{%- elif cookiecutter.license == "Apache Software License 2.0" -%}
"License :: OSI Approved :: Apache Software License",
{%- elif cookiecutter.license == "Mozilla Public License 2.0" -%}
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
{%- endif %}
]
dependencies = [
"pytest>={{cookiecutter.pytest_version}}",
]
[project.urls]
Repository = "https://github.com/{{cookiecutter.github_username}}/pytest-{{cookiecutter.plugin_name}}"
[project.entry-points.pytest11]
django = "pytest_{{cookiecutter.module_name}}.plugin"
61 changes: 0 additions & 61 deletions pytest-{{cookiecutter.plugin_name}}/setup.py

This file was deleted.

Empty file.
2 changes: 1 addition & 1 deletion pytest-{{cookiecutter.plugin_name}}/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ commands = pytest {posargs:tests}
[testenv:flake8]
skip_install = true
deps = flake8
commands = flake8 pytest_{{cookiecutter.module_name}}.py setup.py tests
commands = flake8 src tests
3 changes: 2 additions & 1 deletion tests/test_create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def test_run_cookiecutter_and_plugin_tests(cookies):
assert result.exception is None
assert result.project.basename == 'pytest-foo-bar'
assert result.project.isdir()
assert result.project.join('pytest_foo_bar.py').isfile()
assert result.project.join('src', 'pytest_foo_bar', '__init__.py').isfile()
assert result.project.join('src', 'pytest_foo_bar', 'plugin.py').isfile()
assert result.project.join('tests', 'test_foo_bar.py').isfile()

run_tox(str(result.project))

0 comments on commit b58973d

Please sign in to comment.