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

Test and fix with modern Pythons #244

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ test-tmpl: &test-tmpl
export DEBUG=1
export SERVER_FIXTURES_HOSTNAME=127.0.0.1
export SERVER_FIXTURES_JENKINS_WAR=
cat *.egg-info/top_level.txt | xargs -Ipysrc coverage run -p --source=pysrc setup.py test -sv -ra || touch ../FAILED-$(basename $PWD)
set -x
pwd
cat *.egg-info/top_level.txt
pytest --version
pytest -svvvvvv -ra tests/
pytest -svvvvvvv -ra $(cat *.egg-info/top_level.txt)
coverage run -p --source=$(cat *.egg-info/top_level.txt | tr '\n' ',') -m pytest -sv -ra $(cat *.egg-info/top_level.txt)

cat *.egg-info/top_level.txt | xargs -I {} coverage run -p --source={} -m pytest -sv -ra {} || touch ../FAILED-$(basename $PWD)

job-tmpl: &job-tmpl
machine:
Expand Down Expand Up @@ -160,6 +168,31 @@ jobs:
environment:
PYTHON: "python3.7"

py38:
<<: *job-tmpl
environment:
PYTHON: "python3.8"

py39:
<<: *job-tmpl
environment:
PYTHON: "python3.9"

py310:
<<: *job-tmpl
environment:
PYTHON: "python3.10"

py311:
<<: *job-tmpl
environment:
PYTHON: "python3.11"

py312:
<<: *job-tmpl
environment:
PYTHON: "python3.12"

pypi-release:
docker:
- image: cimg/python:3.11.0
Expand Down Expand Up @@ -212,7 +245,7 @@ jobs:
-n ${VERSION} \
-b "${CHANGES}" \
-soft \
${VERSION} /tmp/to-release/dist
"v${VERSION}" /tmp/to-release/dist


workflows:
Expand All @@ -221,10 +254,20 @@ workflows:
jobs:
- py36
- py37
- py38
- py39
- py310
- py311
- py312
- pypi-release:
requires:
- py36
- py37
- py38
- py39
- py310
- py311
- py312
filters:
branches:
only:
Expand All @@ -233,6 +276,11 @@ workflows:
requires:
- py36
- py37
- py38
- py39
- py310
- py311
- py312
filters:
branches:
only:
Expand Down
25 changes: 6 additions & 19 deletions common_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

from setuptools.command.test import test as TestCommand
from setuptools.command.egg_info import egg_info as EggInfoCommand
from wheel.bdist_wheel import bdist_wheel


class PyTest(TestCommand):
Expand All @@ -20,37 +20,24 @@ def finalize_options(self):
self.test_suite = True

def run_tests(self):
global pytest_args
logging.basicConfig(format='%(asctime)s %(levelname)s %(name)s %(message)s', level='DEBUG')

# import here, cause outside the eggs aren't loaded
import pytest

self.pytest_args.extend(['--junitxml', 'junit.xml'])
errno = pytest.main(self.pytest_args)
logger = logging.getLogger(__name__)
logger.info("Pytest args are {}".format(str(PyTest.pytest_args)))
errno = pytest.main(PyTest.pytest_args)
sys.exit(errno)


class EggInfo(EggInfoCommand):
""" Customisation of the package metadata creation. Changes are:
- Save the test requirements into an extra called 'tests'
"""
def run(self):
if self.distribution.extras_require is None:
self.distribution.extras_require = {}
if 'tests' not in self.distribution.extras_require and hasattr(self.distribution, 'tests_require'):
self.distribution.extras_require['tests'] = self.distribution.tests_require
EggInfoCommand.run(self)


def common_setup(src_dir):
this_dir = os.path.dirname(__file__)
readme_file = os.path.join(this_dir, 'README.md')
changelog_file = os.path.join(this_dir, 'CHANGES.md')
version_file = os.path.join(this_dir, 'VERSION')

long_description = open(readme_file).read()
changelog = open(changelog_file).read()

# Gather trailing arguments for pytest, this can't be done using setuptools' api
if 'test' in sys.argv:
PyTest.pytest_args = sys.argv[sys.argv.index('test') + 1:]
Expand All @@ -66,7 +53,7 @@ def common_setup(src_dir):
url='https://github.com/man-group/pytest-plugins',
license='MIT license',
platforms=['unix', 'linux'],
cmdclass={'test': PyTest, 'egg_info': EggInfo},
cmdclass={'test': PyTest, 'bdist_wheel': bdist_wheel},
include_package_data=True,
python_requires='>=3.6',
)
16 changes: 9 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ function install_python_packaging {
function install_python {
local py=$1
sudo apt-get install -y $py $py-dev
if [ "$py" = "python3.6" ]; then
sudo apt-get install python3.6-distutils || {
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/pip/3.6/get-pip.py | sudo $py
local version=$(echo $py | grep -oP '(?<=python)\d+\.\d+')

if [ "$version" = "3.6" ] || [ "$version" = "3.7" ]; then
sudo apt-get install ${py}-distutils || {
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/pip/$version/get-pip.py | sudo $py
sudo $py -m pip install setuptools
}
elif [ "$version" = "3.10" ] || [ "$version" = "3.11" ] || [ "$version" = "3.12" ]; then
sudo apt-get install ${py}-distutils
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo $py
else
sudo apt-get install python3.7-distutils || {
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/pip/3.7/get-pip.py | sudo $py
sudo $py -m pip install setuptools
}
sudo apt-get install ${py}-distutils
fi
install_python_packaging $py
}
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "pytest-plugins"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = []

[tool.uv.workspace]
members = ["pytest-profiling"]
62 changes: 62 additions & 0 deletions pytest-profiling/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "pytest-profiling"
description = "Profiling plugin for py.test"
readme = "README.md"
readme-content-type = "text/markdown"
license = {text = "MIT"}
authors = [{name = "Ed Catmur", email = "[email protected]"}]
classifiers = [
"License :: OSI Approved :: MIT License",
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing",
"Topic :: Utilities",
"Intended Audience :: Developers",
"Operating System :: POSIX",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"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"
]
dependencies = ["six", "pytest", "gprof2dot"]
requires-python = ">=3.6"
dynamic = ["version"]

[tool.hatch.version]
path = "../VERSION"
pattern = "^(?P<version>[^']+)$"

[tool.hatch.build.targets.wheel]
packages = ["src/pytest_profiling"]

[project.urls]
homepage = "https://github.com/man-group/pytest-plugins"

[project.optional-dependencies]
tests = ["pytest-virtualenv"]

[project.entry-points.pytest11]
profiling = "pytest_profiling"

[tool.pytest.ini_options]
norecursedirs = [".git", "*.egg", "build", "dist", "tests/integration/profile/tests"]

[tool.wheel]
universal = false

[tool.uv]
dev-dependencies = [
"importlib-metadata>=8.5.0",
"importlib-resources>=6.4.5",
"pytest-virtualenv",
]

[tool.uv.sources]
pytest-virtualenv = { path = "../pytest-virtualenv", editable = true }
2 changes: 1 addition & 1 deletion pytest-profiling/pytest_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def pytest_addoption(parser):
help="generate profiling graph (using gprof2dot and dot -Tsvg)")
group.addoption("--pstats-dir", nargs=1,
help="configure the dump directory of profile data files")
group.addoption("--element-number", action="store", type="int", default=20,
group.addoption("--element-number", action="store", type=int, default=20,
help="defines how many elements will display in a result")
group.addoption("--strip-dirs", action="store_true",
help="configure to show/hide the leading path information from file names")
Expand Down
12 changes: 0 additions & 12 deletions pytest-profiling/setup.cfg

This file was deleted.

48 changes: 0 additions & 48 deletions pytest-profiling/setup.py

This file was deleted.

22 changes: 18 additions & 4 deletions pytest-profiling/tests/integration/test_profile_integration.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
from distutils.dir_util import copy_tree
import shutil
from distutils.dir_util import copy_tree
from pathlib import Path

from pkg_resources import resource_filename, get_distribution
import pytest

try:
from importlib.metadata import distribution
except ImportError:
from importlib_metadata import distribution

try:
from importlib.resources import as_file, files
except ImportError:
from importlib_resources import as_file, files

def resource_filename(package, resource):
return files(package) / resource


from pytest_virtualenv import VirtualEnv


@pytest.yield_fixture(scope="session")
def virtualenv():
with VirtualEnv() as venv:
test_dir = resource_filename("pytest_profiling", "tests/integration/profile")
test_dir = Path(__file__).parent / "profile"

venv.install_package("more-itertools")

# Keep pytest version the same as what's running this test to ensure P27 keeps working
venv.install_package("pytest=={}".format(get_distribution("pytest").version))
venv.install_package("pytest=={}".format(distribution("pytest").version))

venv.install_package("pytest-cov")
venv.install_package("pytest-profiling")
Expand Down
4 changes: 2 additions & 2 deletions pytest-virtualenv/pytest_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from enum import Enum

import importlib_metadata as metadata
import pkg_resources
import packaging.requirements
from pytest import yield_fixture

from pytest_shutil.workspace import Workspace
Expand Down Expand Up @@ -273,7 +273,7 @@ def _install_editable_package(self, egg_link, package):
pth.write("\n")
for spec in package.requires:
if not _is_extra_requirement(spec):
dependency = next(pkg_resources.parse_requirements(spec), None)
dependency = packaging.requirements.Requirement(spec)
if dependency and (not dependency.marker or dependency.marker.evaluate()):
self.install_package(dependency.name, version=PackageVersion.CURRENT)

Expand Down
Loading