Skip to content

Commit

Permalink
pyupgrade formatter added
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Feb 13, 2024
1 parent 25e282d commit 54f8f5a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

- Add `wtr` (Web test runner) domain to `js` topic.

- Add pyupgrade based code formatter, see https://pypi.org/project/pyupgrade/.

## 1.0a3 (2024-02-06)

- Add `typecheck` target and use it for mypy instead of `check` target.
Expand Down
50 changes: 50 additions & 0 deletions src/mxmake/topics/qa/pyupgrade.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#:[pyupgrade]
#:title = pyupgrade
#:description = Automatically upgrade syntax for newer versions of the language.
#:depends = core.mxenv
#:
#:[target.pyupgrade]
#:description = Run pyupgrade.
#:
#:[setting.PYUPGRADE_SRC]
#:description = Source folder to scan for XML and ZCML files.
#:default = src
#:
#:[setting.PYUPGRADE_PARAMETERS]
#:description = Additional parameters for pyupgrade, see https://github.com/asottile/pyupgrade for details.
#:default = --py38-plus
#:
#:[target.pyupgrade-dirty]
#:description = Marks pyupgrade dirty
#:
#:[target.pyupgrade-clean]
#:description = Uninstall pyupgrade.

##############################################################################
# pyupgrade
##############################################################################

PYUPGRADE_PARAMETERS?=
PYUPGRADE_TARGET:=$(SENTINEL_FOLDER)/pyupgrade.sentinel
$(PYUPGRADE_TARGET): $(MXENV_TARGET)
@echo "Install pyupgrade"
@$(MXENV_PYTHON) -m pip install pyupgrade
@touch $(PYUPGRADE_TARGET)

.PHONY: pyupgrade-format
pyupgrade-format: $(PYUPGRADE_TARGET)
@echo "Run pyupgrade format in: $(PYUPGRADE_SRC)"
@find $(PYUPGRADE_SRC) -name '*.py' -exec $(MXENV_PATH)pyupgrade $(PYUPGRADE_PARAMETERS) {} +

.PHONY: pyupgrade-dirty
pyupgrade-dirty:
@rm -f $(PYUPGRADE_TARGET)

.PHONY: pyupgrade-clean
pyupgrade-clean: pyupgrade-dirty
@test -e $(MXENV_PYTHON) && $(MXENV_PYTHON) -m pip uninstall -y pyupgrade || :

INSTALL_TARGETS+=$(PYUPGRADE_TARGET)
FORMAT_TARGETS+=pyupgrade-format
DIRTY_TARGETS+=pyupgrade-dirty
CLEAN_TARGETS+=pyupgrade-clean

0 comments on commit 54f8f5a

Please sign in to comment.