Skip to content

Commit

Permalink
Merge pull request #168 from plone/maurits-modernize
Browse files Browse the repository at this point in the history
Modernize, remove outdated code, add code-analysis checks
  • Loading branch information
mauritsvanrees authored Jul 1, 2022
2 parents f24fa8c + fca366d commit 6ab1f7e
Show file tree
Hide file tree
Showing 50 changed files with 1,908 additions and 2,083 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Code Analysis
on:
push:

jobs:
code-analysis:
name: Code analysis
runs-on: ubuntu-latest

steps:
- name: Checkout codebase
uses: actions/checkout@v2

- name: Run check isort
uses: plone/code-analysis-action@v1
with:
check: 'isort'
path: |
plone
setup.py
- name: Run check black
uses: plone/code-analysis-action@v1
with:
check: 'black'
path: |
plone
setup.py
- name: Run check flake8
uses: plone/code-analysis-action@v1
with:
check: 'flake8'
path: |
plone
setup.py
- name: Run check pyroma
uses: plone/code-analysis-action@v1
with:
check: 'pyroma'
path: |
./
- name: Run check zpretty
uses: plone/code-analysis-action@v1
with:
check: 'zpretty'
path: |
plone
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-xeu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules

# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

CODE_QUALITY_VERSION=1.0.1
LINT=docker run --rm -v "$(PWD)":/github/workspace plone/code-quality:${CODE_QUALITY_VERSION} check
FORMAT=docker run --rm -v "$(PWD)":/github/workspace plone/code-quality:${CODE_QUALITY_VERSION} format

PACKAGE_NAME=plone.dexterity
PACKAGE_PATH=plone/
CHECK_PATH=setup.py $(PACKAGE_PATH)

# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
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}'

.PHONY: format
format: ## Format the codebase according to our standards
$(FORMAT) "$(CHECK_PATH)"

.PHONY: lint
lint: ## validate with isort, black, flake8, pyroma, zpretty
# Would be nice to have a way to run all available checks, instead of specifying them here.
$(LINT) isort "$(CHECK_PATH)"
$(LINT) black "$(CHECK_PATH)"
$(LINT) flake8 "$(CHECK_PATH)"
$(LINT) pyroma .
$(LINT) zpretty "$(PACKAGE_PATH)"
2 changes: 2 additions & 0 deletions news/161.breaking.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Python 3.7+ only, drop Python 2 support.
[jensens, maurits]
2 changes: 2 additions & 0 deletions news/161.breaking.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove long deprecated imports and fallbacks.
[jensens, maurits]
2 changes: 2 additions & 0 deletions news/161.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use Bootstrap 5 classes for buttons.
[jensens]
1 change: 0 additions & 1 deletion plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__import__("pkg_resources").declare_namespace(__name__)
1 change: 0 additions & 1 deletion plone/dexterity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
# Kick dynamic module factory
from . import schema # noqa
33 changes: 0 additions & 33 deletions plone/dexterity/bbb.py

This file was deleted.

6 changes: 2 additions & 4 deletions plone/dexterity/behavior.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.behavior.interfaces import IBehaviorAssignable
from plone.dexterity.interfaces import IDexterityContent
from plone.dexterity.schema import SCHEMA_CACHE
Expand All @@ -8,7 +7,7 @@

@implementer(IBehaviorAssignable)
@adapter(IDexterityContent)
class DexterityBehaviorAssignable(object):
class DexterityBehaviorAssignable:
"""Support plone.behavior behaviors stored in the FTI"""

def __init__(self, context):
Expand All @@ -21,5 +20,4 @@ def supports(self, behavior_interface):
return False

def enumerateBehaviors(self):
for behavior in SCHEMA_CACHE.behavior_registrations(self.context.portal_type):
yield behavior
yield from SCHEMA_CACHE.behavior_registrations(self.context.portal_type)
1 change: 0 additions & 1 deletion plone/dexterity/browser/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
21 changes: 10 additions & 11 deletions plone/dexterity/browser/add.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from Acquisition import aq_inner
from Acquisition.interfaces import IAcquirer
Expand Down Expand Up @@ -37,10 +36,10 @@ class DefaultAddForm(DexterityExtensibleForm, form.AddForm):

portal_type = None
immediate_view = None
success_message = _(u"Item created")
success_message = _("Item created")

def __init__(self, context, request, ti=None):
super(DefaultAddForm, self).__init__(context, request)
super().__init__(context, request)
if ti is not None:
self.ti = ti
self.portal_type = ti.getId()
Expand Down Expand Up @@ -119,10 +118,10 @@ def handleAdd(self, action):
self._finishedAdd = True
IStatusMessage(self.request).addStatusMessage(self.success_message, "info")

@button.buttonAndHandler(_(u"Cancel"), name="cancel")
@button.buttonAndHandler(_("Cancel"), name="cancel")
def handleCancel(self, action):
IStatusMessage(self.request).addStatusMessage(
_(u"Add New Item operation cancelled"), "info"
_("Add New Item operation cancelled"), "info"
)
self.request.response.redirect(self.nextURL())
notify(AddCancelledEvent(self.context))
Expand All @@ -135,25 +134,25 @@ def update(self):
"Subobject type disallowed by IConstrainTypes adapter: %s"
% self.portal_type
)
super(DefaultAddForm, self).update()
super().update()
# fire the edit begun only if no action was executed
if len(self.actions.executedActions) == 0:
notify(AddBegunEvent(self.context))

def updateActions(self):
super(DefaultAddForm, self).updateActions()
super().updateActions()
if "save" in self.actions:
self.actions["save"].addClass("context")
self.actions["save"].addClass("success")

if "cancel" in self.actions:
self.actions["cancel"].addClass("standalone")
self.actions["cancel"].addClass("secondary")

@property
def label(self):
portal_type = self.portal_type
fti = getUtility(IDexterityFTI, name=portal_type)
type_name = fti.Title()
return _(u"Add ${name}", mapping={"name": type_name})
return _("Add ${name}", mapping={"name": type_name})


class DefaultAddView(layout.FormWrapper, BrowserPage):
Expand All @@ -168,7 +167,7 @@ class DefaultAddView(layout.FormWrapper, BrowserPage):
form = DefaultAddForm

def __init__(self, context, request, ti):
super(DefaultAddView, self).__init__(context, request)
super().__init__(context, request)
self.ti = ti

# Set portal_type name on newly created form instance
Expand Down
3 changes: 1 addition & 2 deletions plone/dexterity/browser/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.autoform.form import AutoExtensibleForm
from plone.dexterity.i18n import MessageFactory as _
from plone.dexterity.interfaces import IDexterityFTI
Expand All @@ -9,7 +8,7 @@
class DexterityExtensibleForm(AutoExtensibleForm):
"""Mixin class for Dexterity forms that support updatable fields"""

default_fieldset_label = _("label_schema_default", default=u"Default")
default_fieldset_label = _("label_schema_default", default="Default")

@property
def description(self):
Expand Down
Loading

0 comments on commit 6ab1f7e

Please sign in to comment.