From fd8564dfd972de3e699bd04160ebd97d57eec66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Andrei?= Date: Tue, 5 Dec 2023 10:15:57 -0300 Subject: [PATCH] Implement plone/meta (Fixes #6) --- .editorconfig | 24 ++- .flake8 | 22 +++ .github/workflows/changelog.yml | 16 -- .github/workflows/code-analysis.yml | 54 ------- .github/workflows/meta.yml | 66 +++++++++ .github/workflows/tests.yml | 37 ----- .gitignore | 70 ++++++--- .meta.toml | 29 ++++ .pre-commit-config.yaml | 94 ++++++++++++ CHANGES.md | 12 +- MANIFEST.in | 11 +- Makefile | 97 ++++++------ README.md | 2 +- constraints.txt | 1 + instance.yaml | 10 ++ mx.ini | 16 ++ news/.changelog_template.jinja | 15 ++ news/.gitkeep | 1 + news/6.internal | 1 + pyproject.toml | 205 ++++++++++++++++++++------ requirements.txt | 3 +- setup.py | 15 +- tests/conftest.py | 34 ++--- tests/test_fixtures.py | 1 - tox.ini | 220 ++++++++++++++++++++++++++++ 25 files changed, 794 insertions(+), 262 deletions(-) create mode 100644 .flake8 delete mode 100644 .github/workflows/changelog.yml delete mode 100644 .github/workflows/code-analysis.yml create mode 100644 .github/workflows/meta.yml delete mode 100644 .github/workflows/tests.yml create mode 100644 .meta.toml create mode 100644 .pre-commit-config.yaml create mode 100644 constraints.txt create mode 100644 instance.yaml create mode 100644 mx.ini create mode 100644 news/.changelog_template.jinja create mode 100644 news/.gitkeep create mode 100644 news/6.internal create mode 100644 tox.ini diff --git a/.editorconfig b/.editorconfig index 63aa5e6..8ae05aa 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,9 @@ -# EditorConfig Configurtaion file, for more details see: -# https://EditorConfig.org +# Generated from: +# https://github.com/plone/meta/tree/master/config/default +# See the inline comments on how to expand/tweak this configuration file +# +# EditorConfig Configuration file, for more details see: +# http://EditorConfig.org # EditorConfig is a convention description, that could be interpreted # by multiple editors to enforce common coding conventions for specific # file types @@ -25,12 +29,26 @@ max_line_length = off # 4 space indentation indent_size = 4 -[*.{html,dtml,pt,zpt,xml,zcml,js,json,less,css,yml,yaml}] +[*.{yml,zpt,pt,dtml,zcml}] # 2 space indentation indent_size = 2 +[*.{json,jsonl,js,jsx,ts,tsx,css,less,scss,html}] # Frontend development +# 2 space indentation +indent_size = 2 +max_line_length = 80 + [{Makefile,.gitmodules}] # Tab indentation (no size specified, but view as 4 spaces) indent_style = tab indent_size = unset tab_width = unset + + +## +# Add extra configuration options in .meta.toml: +# [editorconfig] +# extra_lines = """ +# _your own configuration lines_ +# """ +## diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..7ef4f64 --- /dev/null +++ b/.flake8 @@ -0,0 +1,22 @@ +# Generated from: +# https://github.com/plone/meta/tree/master/config/default +# See the inline comments on how to expand/tweak this configuration file +[flake8] +doctests = 1 +ignore = + # black takes care of line length + E501, + # black takes care of where to break lines + W503, + # black takes care of spaces within slicing (list[:]) + E203, + # black takes care of spaces after commas + E231, + +## +# Add extra configuration options in .meta.toml: +# [flake8] +# extra_lines = """ +# _your own configuration lines_ +# """ +## diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml deleted file mode 100644 index be23198..0000000 --- a/.github/workflows/changelog.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Changelog check -on: - pull_request: - types: [assigned, opened, synchronize, reopened, labeled, unlabeled] - branches: - - master -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Changelog check - uses: dangoslen/changelog-enforcer@v3 - with: - changeLogPath: 'CHANGES.md' - skipLabels: 'Skip-Changelog' diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml deleted file mode 100644 index 3d31d47..0000000 --- a/.github/workflows/code-analysis.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Code Analysis -on: - push: - -jobs: - black: - name: Black - runs-on: ubuntu-latest - - steps: - - name: Checkout codebase - uses: actions/checkout@v3 - - - name: Run check - uses: plone/code-analysis-action@v2 - with: - check: 'black' - - flake8: - name: flake8 - runs-on: ubuntu-latest - - steps: - - name: Checkout codebase - uses: actions/checkout@v3 - - - name: Run check - uses: plone/code-analysis-action@v2 - with: - check: 'flake8' - - isort: - runs-on: ubuntu-latest - steps: - - name: Checkout codebase - uses: actions/checkout@v3 - - - name: Run check - uses: plone/code-analysis-action@v2 - with: - check: 'isort' - - pyroma: - name: pyroma - runs-on: ubuntu-latest - - steps: - - name: Checkout codebase - uses: actions/checkout@v3 - - - name: Run check - uses: plone/code-analysis-action@v2 - with: - check: 'pyroma' diff --git a/.github/workflows/meta.yml b/.github/workflows/meta.yml new file mode 100644 index 0000000..c9db54b --- /dev/null +++ b/.github/workflows/meta.yml @@ -0,0 +1,66 @@ +# Generated from: +# https://github.com/plone/meta/tree/master/config/default +# See the inline comments on how to expand/tweak this configuration file +name: Meta +on: + push: + branches: + - master + - main + pull_request: + branches: + - master + - main + workflow_dispatch: + +## +# To set environment variables for all jobs, add in .meta.toml: +# [github] +# env = """ +# debug: 1 +# image-name: 'org/image' +# image-tag: 'latest' +# """ +## + +jobs: + qa: + uses: plone/meta/.github/workflows/qa.yml@1.0.0 + test: + uses: plone/meta/.github/workflows/test.yml@1.0.0 + coverage: + uses: plone/meta/.github/workflows/coverage.yml@1.0.0 + dependencies: + uses: plone/meta/.github/workflows/dependencies.yml@1.0.0 + release_ready: + uses: plone/meta/.github/workflows/release_ready.yml@1.0.0 + +## +# To modify the list of default jobs being created add in .meta.toml: +# [github] +# jobs = [ +# "qa", +# "test", +# "coverage", +# "dependencies", +# "release_ready", +# "circular", +# ] +## + +## +# To request that some OS level dependencies get installed +# when running tests/coverage jobs, add in .meta.toml: +# [github] +# os_dependencies = "git libxml2 libxslt" +## + + +## +# Specify additional jobs in .meta.toml: +# [github] +# extra_lines = """ +# another: +# uses: org/repo/.github/workflows/file.yml@main +# """ +## diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 7528e29..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Build and test - -on: [push] - -jobs: - tests: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python: - - 3.8 - - 3.9 - - "3.10" - - "3.11" - plone: - - "6.0-latest" - - steps: - - uses: actions/checkout@v3 - - - name: Setup Plone ${{ matrix.plone }} with Python ${{ matrix.python }} - id: setup - uses: plone/setup-plone@v2.0.0 - with: - python-version: ${{ matrix.python }} - plone-version: ${{ matrix.plone }} - - # Install pytest-plone - - name: Install pytest-plone - run: | - pip install "." - - # test - - name: Test Codebase - run: | - pytest --disable-warnings diff --git a/.gitignore b/.gitignore index b160b41..503e47c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,55 @@ -.coverage +# Generated from: +# https://github.com/plone/meta/tree/master/config/default +# See the inline comments on how to expand/tweak this configuration file +# python related *.egg-info -*.py? -*.swp -# dirs +*.pyc +*.pyo + +# translation related +*.mo + +# tools related +build/ +.coverage +.*project +coverage.xml +dist/ +docs/_build +__pycache__/ +.tox +.vscode/ +node_modules/ + +# venv / buildout related bin/ +develop-eggs/ +eggs/ +.eggs/ +etc/ +.installed.cfg include/ lib/ -lib64/ -etc/ -src/* -var/ -__pycache__ -.pytest_cache -# files -.python-version +lib64 +.mr.developer.cfg +parts/ pyvenv.cfg -inituser -# excludes -!.coveragerc -!.editorconfig -!.gitattributes -!.gitignore -!.gitkeep -!src/pytest_plone +var/ + +# mxdev +/instance/ +/.make-sentinels/ +/*-mxdev.txt +/reports/ +/sources/ +/venv/ +.installed.txt + + +## +# Add extra configuration options in .meta.toml: +# [gitignore] +# extra_lines = """ +# _your own configuration lines_ +# """ +## diff --git a/.meta.toml b/.meta.toml new file mode 100644 index 0000000..3af68cd --- /dev/null +++ b/.meta.toml @@ -0,0 +1,29 @@ +# Generated from: +# https://github.com/plone/meta/tree/master/config/default +# See the inline comments on how to expand/tweak this configuration file +[meta] +template = "default" +commit-id = "8c30aa23" + +[pyproject] +codespell_skip = "*.min.js" +codespell_ignores = "vew" +dependencies_ignores = "['plone.volto', 'zestreleaser.towncrier', 'zest.releaser', 'pytest', 'pytest-cov', 'plone.app.testing']" +dependencies_mappings = [ + "Plone = ['Products.CMFPlone', 'Products.CMFCore', 'Products.GenericSetup', 'Products.ZCatalog', 'z3c.form']", + ] + +[tox] +use_mxdev = true +test_runner = "pytest" +test_path = "/tests" + +[github] +ref = "1.0.0" +jobs = [ + "qa", + "test", + "coverage", + "dependencies", + "release_ready", + ] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f13d059 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,94 @@ +# Generated from: +# https://github.com/plone/meta/tree/master/config/default +# See the inline comments on how to expand/tweak this configuration file +ci: + autofix_prs: false + autoupdate_schedule: monthly + +repos: +- repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [--py38-plus] +- repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort +- repo: https://github.com/psf/black + rev: 23.10.1 + hooks: + - id: black +- repo: https://github.com/collective/zpretty + rev: 3.1.0 + hooks: + - id: zpretty + +## +# Add extra configuration options in .meta.toml: +# [pre_commit] +# zpretty_extra_lines = """ +# _your own configuration lines_ +# """ +## +- repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + +## +# Add extra configuration options in .meta.toml: +# [pre_commit] +# flake8_extra_lines = """ +# _your own configuration lines_ +# """ +## +- repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + additional_dependencies: + - tomli + +## +# Add extra configuration options in .meta.toml: +# [pre_commit] +# codespell_extra_lines = """ +# _your own configuration lines_ +# """ +## +- repo: https://github.com/mgedmin/check-manifest + rev: "0.49" + hooks: + - id: check-manifest +- repo: https://github.com/regebro/pyroma + rev: "4.2" + hooks: + - id: pyroma +- repo: https://github.com/mgedmin/check-python-versions + rev: "0.22.0" + hooks: + - id: check-python-versions + args: ['--only', 'setup.py,pyproject.toml'] +- repo: https://github.com/collective/i18ndude + rev: "6.1.0" + hooks: + - id: i18ndude + + +## +# Add extra configuration options in .meta.toml: +# [pre_commit] +# i18ndude_extra_lines = """ +# _your own configuration lines_ +# """ +## + + +## +# Add extra configuration options in .meta.toml: +# [pre_commit] +# extra_lines = """ +# _your own configuration lines_ +# """ +## diff --git a/CHANGES.md b/CHANGES.md index 9294319..4a9f7f8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,14 +1,16 @@ # Changelog -## 0.2.1 (unreleased) - - -- Nothing changed yet. + + ## 0.2.0 (2023-01-05) - - Add `app` fixture. [ericof] diff --git a/MANIFEST.in b/MANIFEST.in index 9e106a8..6c7de90 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,16 @@ graft src/pytest_plone graft docs +graft news graft tests -include *.in *.md *.png *.svg *.GPL Makefile +include .coveragerc +include .dockerignore include .editorconfig +include *.txt +include *.yml +include *.md +exclude *-mxdev.txt exclude pyvenv.cfg +exclude instance.yaml +exclude Makefile global-exclude *.py[cod] +global-exclude .DS_Store diff --git a/Makefile b/Makefile index 9257ef6..82c49f2 100644 --- a/Makefile +++ b/Makefile @@ -15,20 +15,29 @@ GREEN=`tput setaf 2` RESET=`tput sgr0` YELLOW=`tput setaf 3` + PLONE6=6.0-latest -BACKEND_FOLDER=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +# Python checks +PYTHON?=python3 + +# installed? +ifeq (, $(shell which $(PYTHON) )) + $(error "PYTHON=$(PYTHON) not found in $(PATH)") +endif -CODE_QUALITY_VERSION=2.0.2 -ifndef LOG_LEVEL - LOG_LEVEL=INFO +# version ok? +PYTHON_VERSION_MIN=3.8 +PYTHON_VERSION_OK=$(shell $(PYTHON) -c "import sys; print((int(sys.version_info[0]), int(sys.version_info[1])) >= tuple(map(int, '$(PYTHON_VERSION_MIN)'.split('.'))))") +ifeq ($(PYTHON_VERSION_OK),0) + $(error "Need python $(PYTHON_VERSION) >= $(PYTHON_VERSION_MIN)") endif -CURRENT_USER=$$(whoami) -USER_INFO=$$(id -u ${CURRENT_USER}):$$(getent group ${CURRENT_USER}|cut -d: -f3) -LINT=docker run --rm -e LOG_LEVEL="${LOG_LEVEL}" -v "${BACKEND_FOLDER}":/github/workspace plone/code-quality:${CODE_QUALITY_VERSION} check -FORMAT=docker run --rm --user="${USER_INFO}" -e LOG_LEVEL="${LOG_LEVEL}" -v "${BACKEND_FOLDER}":/github/workspace plone/code-quality:${CODE_QUALITY_VERSION} format -all: build +BACKEND_FOLDER=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) + +GIT_FOLDER=$(BACKEND_FOLDER)/.git + +all: install # Add the following 'help' target to your Makefile # And add help text after each target name starting with '\#\#' @@ -36,62 +45,44 @@ all: build help: ## This help message @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -bin/pip: +bin/pip bin/tox bin/mxdev: @echo "$(GREEN)==> Setup Virtual Env$(RESET)" - python3 -m venv . - bin/pip install -U pip wheel + $(PYTHON) -m venv . + bin/pip install -U "pip" "wheel" "pipx" "mxdev" "tox" "pre-commit" + if [ -d $(GIT_FOLDER) ]; then bin/pre-commit install; else echo "$(RED) Not installing pre-commit$(RESET)";fi + +.PHONY: config +config: bin/pip ## Create instance configuration + @echo "$(GREEN)==> Create instance configuration$(RESET)" + pipx run cookiecutter -f --no-input --config-file instance.yaml gh:plone/cookiecutter-zope-instance -.PHONY: build-plone-6.0 -build-plone-6.0: bin/pip ## Build Plone 6.0 - @echo "$(GREEN)==> Build with Plone 6.0$(RESET)" - bin/pip install Plone -c https://dist.plone.org/release/$(PLONE6)/constraints.txt - bin/pip install -e ".[test]" - bin/mkwsgiinstance -d . -u admin:admin +.PHONY: install +install: build-dev ## Install Plone 6.0 -.PHONY: build -build: build-plone-6.0 ## Build Plone 6.0 +.PHONY: build-dev +build-dev: config ## pip install Plone packages + @echo "$(GREEN)==> Setup Build$(RESET)" + bin/mxdev -c mx.ini + bin/pip install -r requirements-mxdev.txt .PHONY: clean clean: ## Remove old virtualenv and creates a new one @echo "$(RED)==> Cleaning environment and build$(RESET)" - rm -rf bin lib lib64 include share etc var inituser pyvenv.cfg .installed.cfg - + rm -rf bin lib lib64 include share etc var inituser pyvenv.cfg .installed.cfg instance .tox .pytest_cache .PHONY: format -format: ## Format the codebase according to our standards +format: bin/tox ## Format the codebase according to our standards @echo "$(GREEN)==> Format codebase$(RESET)" - $(FORMAT) + bin/tox -e format .PHONY: lint lint: ## check code style - $(LINT) - -.PHONY: lint-black -lint-black: ## validate black formating - $(LINT) black - -.PHONY: lint-flake8 -lint-flake8: ## validate black formating - $(LINT) flake8 - -.PHONY: lint-isort -lint-isort: ## validate using isort - $(LINT) isort - -.PHONY: lint-pyroma -lint-pyroma: ## validate using pyroma - $(LINT) pyroma - -# Release -bin/fullrelease: bin/pip - @echo "$(GREEN)==> Install zest.releaser$(RESET)" - bin/pip install "zest.releaser[recommended]" - -.PHONY: release -release: bin/fullrelease ## Release the package with zest.releaser - @echo "$(GREEN)==> Release the package$(RESET)" - bin/fullrelease + bin/tox -e lint # Tests .PHONY: test -test: ## run tests - bin/pytest --disable-warnings +test: bin/tox ## run tests + bin/tox -e test + +.PHONY: test-coverage +test-coverage: bin/tox ## run tests with coverage + bin/tox -e coverage diff --git a/README.md b/README.md index 18f7a3d..a7cb0f7 100644 --- a/README.md +++ b/README.md @@ -308,7 +308,7 @@ You need a working `python` environment (system, virtualenv, pyenv, etc) version Then install the dependencies and a development instance using: ```bash -make build +make install ``` To run tests for this package: diff --git a/constraints.txt b/constraints.txt new file mode 100644 index 0000000..228b6cc --- /dev/null +++ b/constraints.txt @@ -0,0 +1 @@ +-c https://dist.plone.org/release/6.0-latest/constraints.txt diff --git a/instance.yaml b/instance.yaml new file mode 100644 index 0000000..1c5cd18 --- /dev/null +++ b/instance.yaml @@ -0,0 +1,10 @@ +default_context: + initial_user_name: 'admin' + initial_user_password: 'admin' + + dos_protection_form_disk_limit: "10Mb" + + load_zcml: + package_includes: [] + + db_storage: direct diff --git a/mx.ini b/mx.ini new file mode 100644 index 0000000..3629ad6 --- /dev/null +++ b/mx.ini @@ -0,0 +1,16 @@ +; This is a mxdev configuration file +; it can be used to override versions of packages already defined in the +; constraints files and to add new packages from VCS like git. +; to learn more about mxdev visit https://pypi.org/project/mxdev/ + +[settings] +; example how to override a package version +; version-overrides = +; example.package==2.1.0a2 + +; example section to use packages from git +; [example.contenttype] +; url = https://github.com/collective/example.contenttype.git +; pushurl = git@github.com:collective/example.contenttype.git +; extras = test +; branch = feature-7 diff --git a/news/.changelog_template.jinja b/news/.changelog_template.jinja new file mode 100644 index 0000000..b35bff3 --- /dev/null +++ b/news/.changelog_template.jinja @@ -0,0 +1,15 @@ +{% if sections[""] %} +{% for category, val in definitions.items() if category in sections[""] %} + +### {{ definitions[category]['name'] }} + +{% for text, values in sections[""][category].items() %} +- {{ text }} {{ values|join(', ') }} +{% endfor %} + +{% endfor %} +{% else %} +No significant changes. + + +{% endif %} \ No newline at end of file diff --git a/news/.gitkeep b/news/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/news/.gitkeep @@ -0,0 +1 @@ + diff --git a/news/6.internal b/news/6.internal new file mode 100644 index 0000000..c337bc3 --- /dev/null +++ b/news/6.internal @@ -0,0 +1 @@ +Implement plone/meta [@ericof] diff --git a/pyproject.toml b/pyproject.toml index 39eb1c9..549353b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,48 +1,163 @@ -[tool.pytest.ini_options] -testpaths = [ - "tests", -] +# Generated from: +# https://github.com/plone/meta/tree/master/config/default +# See the inline comments on how to expand/tweak this configuration file +[build-system] +requires = ["setuptools>=68.2"] -[tool.black] -line-length = 88 -target-version = ['py38'] -include = '\.pyi?$' -exclude = ''' -( - /( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - )/ -) -''' +[tool.towncrier] +directory = "news/" +filename = "CHANGES.md" +start_string = "\n" +title_format = "## {version} ({project_date})" +template = "news/.changelog_template.jinja" +underlines = ["", "", ""] + +[[tool.towncrier.type]] +directory = "breaking" +name = "Breaking changes:" +showcontent = true + +[[tool.towncrier.type]] +directory = "feature" +name = "New features:" +showcontent = true + +[[tool.towncrier.type]] +directory = "bugfix" +name = "Bug fixes:" +showcontent = true + +[[tool.towncrier.type]] +directory = "internal" +name = "Internal:" +showcontent = true + +[[tool.towncrier.type]] +directory = "documentation" +name = "Documentation:" +showcontent = true + +[[tool.towncrier.type]] +directory = "tests" +name = "Tests" +showcontent = true + +## +# Add extra configuration options in .meta.toml: +# [pyproject] +# towncrier_extra_lines = """ +# extra_configuration +# """ +## [tool.isort] -profile = "black" -force_alphabetical_sort = true -force_single_line = true -lines_after_imports = 2 -line_length = 120 - -[tool.flakeheaven] -format="grouped" -max_line_length=88 -show_source=true -max-complexity=25 - -[tool.flakeheaven.plugins] -pycodestyle = ["+*"] -pyflakes = ["+*"] -"flake8-*" = ["+*"] - -[tool.plone-code-analysis] -paths = "setup.py src/ tests/" -checkers = ["black", "flake8", "isort", "pyroma", ] -formatters = ["black", "isort",] +profile = "plone" + +## +# Add extra configuration options in .meta.toml: +# [pyproject] +# isort_extra_lines = """ +# extra_configuration +# """ +## + +[tool.black] +target-version = ["py38"] + +## +# Add extra configuration options in .meta.toml: +# [pyproject] +# black_extra_lines = """ +# extra_configuration +# """ +## + +[tool.codespell] +ignore-words-list = "discreet,vew" +skip = "*.po,*.min.js" +## +# Add extra configuration options in .meta.toml: +# [pyproject] +# codespell_ignores = "foo,bar" +# codespell_skip = "*.po,*.map,package-lock.json" +## + +[tool.dependencychecker] +Zope = [ + # Zope own provided namespaces + 'App', 'OFS', 'Products.Five', 'Products.OFSP', 'Products.PageTemplates', + 'Products.SiteAccess', 'Shared', 'Testing', 'ZPublisher', 'ZTUtils', + 'Zope2', 'webdav', 'zmi', + # ExtensionClass own provided namespaces + 'ExtensionClass', 'ComputedAttribute', 'MethodObject', + # Zope dependencies + 'AccessControl', 'Acquisition', 'AuthEncoding', 'beautifulsoup4', 'BTrees', + 'cffi', 'Chameleon', 'DateTime', 'DocumentTemplate', + 'MultiMapping', 'multipart', 'PasteDeploy', 'Persistence', 'persistent', + 'pycparser', 'python-gettext', 'pytz', 'RestrictedPython', 'roman', + 'soupsieve', 'transaction', 'waitress', 'WebOb', 'WebTest', 'WSGIProxy2', + 'z3c.pt', 'zc.lockfile', 'ZConfig', 'zExceptions', 'ZODB', 'zodbpickle', + 'zope.annotation', 'zope.browser', 'zope.browsermenu', 'zope.browserpage', + 'zope.browserresource', 'zope.cachedescriptors', 'zope.component', + 'zope.configuration', 'zope.container', 'zope.contentprovider', + 'zope.contenttype', 'zope.datetime', 'zope.deferredimport', + 'zope.deprecation', 'zope.dottedname', 'zope.event', 'zope.exceptions', + 'zope.filerepresentation', 'zope.globalrequest', 'zope.hookable', + 'zope.i18n', 'zope.i18nmessageid', 'zope.interface', 'zope.lifecycleevent', + 'zope.location', 'zope.pagetemplate', 'zope.processlifetime', 'zope.proxy', + 'zope.ptresource', 'zope.publisher', 'zope.schema', 'zope.security', + 'zope.sequencesort', 'zope.site', 'zope.size', 'zope.structuredtext', + 'zope.tal', 'zope.tales', 'zope.testbrowser', 'zope.testing', + 'zope.traversing', 'zope.viewlet' +] +'Products.CMFCore' = [ + 'docutils', 'five.localsitemanager', 'Missing', 'Products.BTreeFolder2', + 'Products.GenericSetup', 'Products.MailHost', 'Products.PythonScripts', + 'Products.StandardCacheManagers', 'Products.ZCatalog', 'Record', + 'zope.sendmail', 'Zope' +] +'plone.base' = [ + 'plone.batching', 'plone.registry', 'plone.schema','plone.z3cform', + 'Products.CMFCore', 'Products.CMFDynamicViewFTI', +] +python-dateutil = ['dateutil'] +ignore-packages = ['plone.volto', 'zestreleaser.towncrier', 'zest.releaser', 'pytest', 'pytest-cov', 'plone.app.testing'] +Plone = ['Products.CMFPlone', 'Products.CMFCore', 'Products.GenericSetup', 'Products.ZCatalog', 'z3c.form'] + +## +# Add extra configuration options in .meta.toml: +# [pyproject] +# dependencies_ignores = "['zestreleaser.towncrier']" +# dependencies_mappings = [ +# "gitpython = ['git']", +# "pygithub = ['github']", +# ] +## + +[tool.check-manifest] +ignore = [ + ".editorconfig", + ".meta.toml", + ".pre-commit-config.yaml", + "tox.ini", + ".flake8", + "mx.ini", + +] +## +# Add extra configuration options in .meta.toml: +# [pyproject] +# check_manifest_ignores = """ +# "*.map.js", +# "*.pyc", +# """ +## + + +## +# Add extra configuration options in .meta.toml: +# [pyproject] +# extra_lines = """ +# _your own configuration lines_ +# """ +## diff --git a/requirements.txt b/requirements.txt index 3d3bb24..9dd6dd4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -"." +-c constraints.txt +-e ".[test]" diff --git a/setup.py b/setup.py index e2d8d01..7a1dbd4 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,7 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3", "Programming Language :: Python", "Topic :: Software Development :: Testing", @@ -38,6 +39,11 @@ author="Plone", author_email="test@plone.org", url="http://pypi.python.org/pypi/pytest-plone", + project_urls={ + "PyPI": "https://pypi.python.org/pypi/pytest-plone", + "Source": "https://github.com/collective/pytest-plone", + "Tracker": "https://github.com/collective/pytest-plone/issues", + }, license="GPL", packages=find_packages("src", exclude=["ez_setup"]), package_dir={"": "src"}, @@ -49,9 +55,14 @@ "setuptools", "gocept.pytestlayer", "plone.app.testing", - "plone.app.robotframework", "pytest", ], - extras_require={}, + extras_require={ + "test": [ + "zest.releaser[recommended]", + "zestreleaser.towncrier", + "pytest-cov", + ], + }, entry_points={"pytest11": ["plone = pytest_plone.fixtures"]}, ) diff --git a/tests/conftest.py b/tests/conftest.py index d96bab3..f9fc661 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,31 +9,19 @@ def testdir(pytester): # create a temporary conftest.py file pytester.makeconftest( """ - import gocept.pytestlayer.fixture from Products.CMFPlone.testing import PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING from Products.CMFPlone.testing import PRODUCTS_CMFPLONE_INTEGRATION_TESTING - - - _FIXTURES = ( - (PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING, "functional"), - (PRODUCTS_CMFPLONE_INTEGRATION_TESTING, "integration"), - ) - - - def fixtures(): - fixtures = {} - for item, prefix in _FIXTURES: - fixtures.update( - gocept.pytestlayer.fixture.create( - item, - session_fixture_name=f"{prefix}_session", - class_fixture_name=f"{prefix}_class", - function_fixture_name=prefix, - ) + from pytest_plone import fixtures_factory + + pytest_plugins = ["pytest_plone"] + globals().update( + fixtures_factory( + ( + (PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING, "functional"), + (PRODUCTS_CMFPLONE_INTEGRATION_TESTING, "integration"), ) - return fixtures - - globals().update(fixtures()) - """ + ) + ) + """ ) return pytester diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index d1bf718..518e291 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -1,6 +1,5 @@ def test_all_fixtures(testdir): """Test pytest-plone fixtures exist.""" - fixtures = [ "app", "browser_layers", diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..b5bc0f6 --- /dev/null +++ b/tox.ini @@ -0,0 +1,220 @@ +# Generated from: +# https://github.com/plone/meta/tree/master/config/default +# See the inline comments on how to expand/tweak this configuration file +[tox] +# We need 4.4.0 for constrain_package_deps. +min_version = 4.4.0 +envlist = + lint + test + dependencies + + +## +# Add extra configuration options in .meta.toml: +# [tox] +# envlist_lines = """ +# my_other_environment +# """ +# config_lines = """ +# my_extra_top_level_tox_configuration_lines +# """ +## + +[testenv] +skip_install = true +allowlist_externals = + echo + false +# Make sure typos like `tox -e formaat` are caught instead of silently doing nothing. +# See https://github.com/tox-dev/tox/issues/2858. +commands = + echo "Unrecognized environment name {envname}" + false + +## +# Add extra configuration options in .meta.toml: +# [tox] +# testenv_options = """ +# basepython = /usr/bin/python3.8 +# """ +## + +[testenv:init] +description = Prepare environment +skip_install = true +deps = + mxdev +commands = + mxdev -c mx.ini + echo "Initial setup for mxdev" + + +[testenv:format] +description = automatically reformat code +skip_install = true +deps = + pre-commit +commands = + pre-commit run -a pyupgrade + pre-commit run -a isort + pre-commit run -a black + pre-commit run -a zpretty + +[testenv:lint] +description = run linters that will help improve the code style +skip_install = true +deps = + pre-commit +commands = + pre-commit run -a + +[testenv:dependencies] +description = check if the package defines all its dependencies +skip_install = true +deps = + build + z3c.dependencychecker==2.11 +commands = + python -m build --sdist + dependencychecker + +[testenv:dependencies-graph] +description = generate a graph out of the dependencies of the package +skip_install = false +allowlist_externals = + sh +deps = + pipdeptree==2.5.1 + graphviz # optional dependency of pipdeptree +commands = + sh -c 'pipdeptree --exclude setuptools,wheel,pipdeptree,zope.interface,zope.component --graph-output svg > dependencies.svg' + +[testenv:test] +description = run the distribution tests +use_develop = true +skip_install = false +constrain_package_deps = false +set_env = + ROBOT_BROWSER=headlesschrome + +## +# Specify extra test environment variables in .meta.toml: +# [tox] +# test_environment_variables = """ +# PIP_EXTRA_INDEX_URL=https://my-pypi.my-server.com/ +# """ +# +# Set constrain_package_deps .meta.toml: +# [tox] +# constrain_package_deps = false +## +deps = + pytest-plone + pytest + -c constraints-mxdev.txt + + +## +# Specify additional deps in .meta.toml: +# [tox] +# test_deps_additional = """ +# -esources/plonegovbr.portal_base[test] +# """ +# +# Specify a custom constraints file in .meta.toml: +# [tox] +# constraints_file = "https://my-server.com/constraints.txt" +## +commands = + pytest --disable-warnings {posargs} {toxinidir}/tests +extras = + test + + +[testenv:coverage] +description = get a test coverage report +use_develop = true +skip_install = false +constrain_package_deps = false +set_env = + ROBOT_BROWSER=headlesschrome + +## +# Specify extra test environment variables in .meta.toml: +# [tox] +# test_environment_variables = """ +# PIP_EXTRA_INDEX_URL=https://my-pypi.my-server.com/ +# """ +# +# Set constrain_package_deps .meta.toml: +# [tox] +# constrain_package_deps = "false" +## +deps = + pytest-plone + pytest + coverage + -c constraints-mxdev.txt + +commands = + coverage run --source pytest_plone -m pytest {posargs} --disable-warnings {toxinidir}/tests + coverage report -m --format markdown + coverage xml +extras = + test + + +[testenv:release-check] +description = ensure that the distribution is ready to release +skip_install = true +deps = + twine + build + towncrier + -c constraints-mxdev.txt + +commands = + # fake version to not have to install the package + # we build the change log as news entries might break + # the README that is displayed on PyPI + towncrier build --version=100.0.0 --yes + python -m build --sdist + twine check dist/* + +[testenv:circular] +description = ensure there are no cyclic dependencies +use_develop = true +skip_install = false +set_env = + +## +# Specify extra test environment variables in .meta.toml: +# [tox] +# test_environment_variables = """ +# PIP_EXTRA_INDEX_URL=https://my-pypi.my-server.com/ +# """ +## +allowlist_externals = + sh +deps = + pipdeptree + pipforester + -c constraints-mxdev.txt + +commands = + # Generate the full dependency tree + sh -c 'pipdeptree -j > forest.json' + # Generate a DOT graph with the circular dependencies, if any + pipforester -i forest.json -o forest.dot --cycles + # Report if there are any circular dependencies, i.e. error if there are any + pipforester -i forest.json --check-cycles -o /dev/null + + +## +# Add extra configuration options in .meta.toml: +# [tox] +# extra_lines = """ +# _your own configuration lines_ +# """ +##