Skip to content

Commit

Permalink
Add pre-commit config and apply it
Browse files Browse the repository at this point in the history
Add `.pre-commit-config.yaml` and commit the modifications to respect
it.
Remove compatibility with Python < 3.8.
  • Loading branch information
Gaël Écorchard committed Jan 23, 2025
1 parent 920a059 commit 5969cdf
Show file tree
Hide file tree
Showing 35 changed files with 335 additions and 311 deletions.
22 changes: 11 additions & 11 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Thank you for creating a pull request to contribute to FreeCAD-macros!
To integrate your macro please make sure the following steps are complete:

- [ ] Please check this box if you're not submitting a new macro.
- [ ] Are you submitting a new macro ?
- [ ] Have you followed the ['How to submit a macro'](../README.md#how-to-submit-a-macro) section of the README.md ?
- [ ] Your macro has a [Description](../README.md#macro-description) in its header.
- [ ] Your macro has a [CamelCase name](../README.md#camelcase-macro-name).
- [ ] Your macro is named [appropriately](../README.md#macro-name-specifics).
- [ ] Your macro contains a [Metadata section](../README.md#macro-metadata) that immediately follows the header description.
- [ ] Your macro is Python3/Qt5 compliant and tested on the latest FreeCAD stable and development releases.
- [ ] You're including documentation on how your macro works (bonus: screenshots and/or video on the Wiki)
- [ ] Commit message is [well-written](https://chris.beams.io/posts/git-commit/)
- [ ] Please check this box if you're not submitting a new macro.
- [ ] Are you submitting a new macro ?
- [ ] Have you followed the ['How to submit a macro'](../README.md#how-to-submit-a-macro) section of the README.md ?
- [ ] Your macro has a [Description](../README.md#macro-description) in its header.
- [ ] Your macro has a [CamelCase name](../README.md#camelcase-macro-name).
- [ ] Your macro is named [appropriately](../README.md#macro-name-specifics).
- [ ] Your macro contains a [Metadata section](../README.md#macro-metadata) that immediately follows the header description.
- [ ] Your macro is Python3/Qt5 compliant and tested on the latest FreeCAD stable and development releases.
- [ ] You're including documentation on how your macro works (bonus: screenshots and/or video on the Wiki)
- [ ] Commit message is [well-written](https://chris.beams.io/posts/git-commit/)
- [ ] Commit message is titled in the following way `[MacroName] Short description`.
- [ ] Optional, write or update the changelog in the macro, from latest to oldest.

And please remember to update the Wiki with the features added or changed once this PR is merged.
And please remember to update the Wiki with the features added or changed once this PR is merged.
**Note**: If you don't have wiki access, then please mention your contribution on the [0.19 Changelog Forum Thread](https://forum.freecadweb.org/viewtopic.php?f=10&t=34586).

---
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# To use:
#
# pre-commit run -a
#
# Or:
#
# pre-commit install # (runs every time you commit in git)
#
# To update this file:
#
# pre-commit autoupdate
#
# See https://github.com/pre-commit/pre-commit for more information.
# See https://pre-commit.com/hooks.html for more hooks.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
# - id: check-illegal-windows-names
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: fix-byte-order-marker
- id: forbid-submodules
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py38-plus]
22 changes: 11 additions & 11 deletions Conversion/DxfToSketchLayers.FCMacro
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import FreeCADGui


#
# DXF unwrapping and colour converting.
# DXF unwrapping and colour converting.
# TODO: Would like this in a separate file.)
dxfcolors = ['#000000', '#FF0000', '#FFFF00', '#00FF00',
'#00FFFF', '#0000FF', '#FF00FF', '#000000',
Expand Down Expand Up @@ -170,7 +170,7 @@ def arcextrusionfac(e):


#
# Function to create sketches and inject dxf geometry directly into it
# Function to create sketches and inject dxf geometry directly into it
#

def MakeSketches(addObjectFunc, entitygroups):
Expand All @@ -193,12 +193,12 @@ def MakeSketches(addObjectFunc, entitygroups):
p0 = Vector(e.dxf.start[0], e.dxf.start[1])
p1 = Vector(e.dxf.end[0], e.dxf.end[1])
sketch.addGeometry(Part.LineSegment(p0, p1))

elif e.dxftype() == "CIRCLE":
exfac = arcextrusionfac(e)
cen = Vector(e.dxf.center[0]*exfac, e.dxf.center[1])
sketch.addGeometry(Part.Circle(cen, cnorm, e.dxf.radius))

elif e.dxftype() == "ARC":
exfac = arcextrusionfac(e)
cen = Vector(e.dxf.center[0]*exfac, e.dxf.center[1])
Expand All @@ -212,7 +212,7 @@ def MakeSketches(addObjectFunc, entitygroups):
cps = [Vector(x[0], x[1]) for x in list(e.control_points)]
bspl = Part.BSplineCurve(cps,None,None,False,e.dxf.degree,None,e.closed)
sketch.addGeometry(bspl)

elif e.dxftype() == "LWPOLYLINE":
def lwpgeo(p0, p1, bulge):
if bulge != 0:
Expand All @@ -232,16 +232,16 @@ def MakeSketches(addObjectFunc, entitygroups):
return(Part.ArcOfCircle(circ, mang-th2, mang+th2))
else:
return Part.LineSegment(p0, p1)

p0 = Vector(e[0][0], e[0][1])
for i in range(1, len(e)):
p1 = Vector(e[i][0], e[i][1])
sketch.addGeometry(lwpgeo(p0, p1, e[i-1][4]))
p0 = p1
if e.closed:
sketch.addGeometry(lwpgeo(p0, Vector(e[0][0], e[0][1]), e[-1][4]))
elif e.dxftype() == "POLYLINE":

elif e.dxftype() == "POLYLINE":
p0s = Vector(e[0].dxf.location[0], e[0].dxf.location[1])
p0 = p0s
for i in range(1, len(e)):
Expand All @@ -251,10 +251,10 @@ def MakeSketches(addObjectFunc, entitygroups):
p0 = p1
if e.is_closed and p0s != p0:
sketch.addGeometry(Part.LineSegment(p0, p0s))

else:
print("unknown", e.dxftype())

except Part.OCCError as err:
print(e, err)
return sketches
Expand All @@ -272,7 +272,7 @@ def main():
dfile = ezdxf.readfile(fname)

unitfacmap = {4:1.0} # 4->mm
unitfac = unitfacmap[dfile.header['$INSUNITS']]
unitfac = unitfacmap[dfile.header['$INSUNITS']]
fac = dfile.header['$DIMALTF']
print("Factor multiply requested (not implemented)", fac, unitfac)

Expand Down
12 changes: 6 additions & 6 deletions Conversion/MultiCopy.FCMacro
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# as the successor of the GNU Library Public License, version 2, hence
# the version number 2.1.]
#
# 'MultiCopy' is a FreeCAD macro package. MultiCopy allows the duplication
# (copy and paste) of multiple FreeCAD objects that can be labelled
# 'MultiCopy' is a FreeCAD macro package. MultiCopy allows the duplication
# (copy and paste) of multiple FreeCAD objects that can be labelled
# sequentially and in a custom manner.
#
# Copyright (C) 2021 Melwyn Francis Carlo
Expand Down Expand Up @@ -46,8 +46,8 @@
#
#
#
# The MultiCopy macro was developed and tested on a platform containing the
# following system and FreeCAD software specifications :
# The MultiCopy macro was developed and tested on a platform containing the
# following system and FreeCAD software specifications :
#
# - OS : Ubuntu 18.04.5 LTS (LXDE/Lubuntu)
# - Word size of OS : 64-bit
Expand All @@ -67,10 +67,10 @@
"""
To use this macro, the steps to be followed are simple and straightforward :
select one or more FreeCAD objects from the Tree view, and then select 'MultiCopy'.
In the dialog box that pops up, choose the copy method, select and input the relevant
In the dialog box that pops up, choose the copy method, select and input the relevant
paste parameters and commands, and then click on 'Paste'.
Note (1) The single underscore prefix (e.g. _name) denotes a private
Note (1) The single underscore prefix (e.g. _name) denotes a private
function or a private variable.
Note (2) Some of the short forms used in this script are as follows:
'mc' stands for MultiCopy
Expand Down
1 change: 0 additions & 1 deletion Conversion/MultiCopy/MultiCopyAuxFunc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


##########################################################################################
Expand Down
5 changes: 2 additions & 3 deletions Conversion/MultiCopy/MultiCopyCore.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


##########################################################################################
Expand Down Expand Up @@ -503,9 +502,9 @@ def __validate_check_assignment(lineOfText, tags_list, tabs_n):
.replace('\r', '')
.strip()
)
if input_label_text.count('\{') != input_label_text.count('\}'):
if input_label_text.count(r'\{') != input_label_text.count(r'\}'):
return False
input_label_text = input_label_text.replace('\{', '').replace('\}', '')
input_label_text = input_label_text.replace(r'\{', '').replace(r'\}', '')
if input_label_text.count('{') != input_label_text.count('}'):
return False
while input_label_text.count('{') > 0:
Expand Down
1 change: 0 additions & 1 deletion Conversion/MultiCopy/MultiCopyGui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


##########################################################################################
Expand Down
9 changes: 4 additions & 5 deletions Conversion/MultiCopy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-


##########################################################################################
Expand Down Expand Up @@ -59,8 +58,8 @@
DESCRIPTION
--------------------
'MultiCopy' is a user-created macro to be used within the FreeCAD application.
MultiCopy allows the duplication (copy and paste) of multiple FreeCAD objects
'MultiCopy' is a user-created macro to be used within the FreeCAD application.
MultiCopy allows the duplication (copy and paste) of multiple FreeCAD objects
that can be labelled sequentially and in a custom manner.
Key features include:
Expand All @@ -71,9 +70,9 @@
> Duplicate with or without dependencies
> Add custom label separators
> Add padded numbering to labels
> Numbering types: Ordinary numerals, upper/lower-case roman numerals and
> Numbering types: Ordinary numerals, upper/lower-case roman numerals and
upper/lower-case alphabetic characters
> Unique 'Paste Code Commands' that allow multiple duplication procedurally
> Unique 'Paste Code Commands' that allow multiple duplication procedurally
as well as in nested loops
> Both CUI and GUI methods available
Expand Down
9 changes: 4 additions & 5 deletions GenevaWheelGUI.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# see http://www.freecadweb.org/wiki/Macro_Geneva_Wheel_GUI

#Creation of a Geneva Wheel with Parametric values By: Isaac Ayala (drei) & Mark Stephen (quick61)
#This Macro creates the main parts of a Geneva Wheel Mechanism
#This Macro creates the main parts of a Geneva Wheel Mechanism

#It depends on six values that must be altered in the following code
#The variables are a, b, n, p, t and h.
Expand All @@ -12,7 +12,7 @@
#b = Geneva Wheel Radius
#p = Drive Pin Radius
#t = Geneva Wheel Tolerance
#h = Geneva Wheel Height
#h = Geneva Wheel Height
#n = Driven Slot Quantity
# Output
#c = Distance Between Centers
Expand All @@ -31,7 +31,6 @@
#c = b/math.cos(math.pi/n)
#a = math.sqrt((math.pow(c,2))-(math.pow(b,2)))

from __future__ import division
import math
from FreeCAD import Base
from PySide import QtGui, QtCore
Expand Down Expand Up @@ -161,7 +160,7 @@ def __init__(self):
la.addWidget(self.gWn)

#
# - Include graphic image in dialog window -
# - Include graphic image in dialog window -
#
# Insure that image is in the same directory as this Macro.
# Image should be available from same source as Macro.
Expand All @@ -180,7 +179,7 @@ def __init__(self):
hbox.addStretch()
hbox.addWidget(self.PiX)
hbox.addStretch()

la.addSpacing(15)
la.addLayout(hbox)
la.addSpacing(15)
Expand Down
2 changes: 1 addition & 1 deletion ImportExport/FabricationCutlist.FCMacro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This macro aims to make it easy to create an accurate cutlist when you are going to fabricate something made out of rectangles and round bar.
# This macro aims to make it easy to create an accurate cutlist when you are going to fabricate something made out of rectangles and round bar.
# For example, if you're welding together a gate from commercial mild steel, you are probably using square tubing, round bar and / or angle iron.
# For all of these you can use Part WB's *Box* and *Cylinder* types.
# Having done so, this macro will create a comma-separated set of values that make up your cutlist. The collumns are as follows:
Expand Down
2 changes: 1 addition & 1 deletion ImportExport/ObjectsToPython.FCMacro
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def addProperties(obj, objname, refobj, objectlist):
'Immutable', 1,
'ReadOnly', 2,
'PropReadOnly', 24,
'PropOutput', 27,
'PropOutput', 27,
]

def propIsReadonly(obj, propname):
Expand Down
10 changes: 5 additions & 5 deletions ImportExport/ObjectsToPython/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Objects To Python
Exports existing objects from a FreeCAD project to a python script

This macro should create clean, human readable python code from already existing FreeCAD objects.
This macro should create clean, human readable python code from already existing FreeCAD objects.
When the generated code is executed, it should create all objects from scratch.

ATTENTION: It does not work for all objects in FreeCAD. Especially objects created by built in python scripts like everything in the Draft workbench will not work correctly.
ATTENTION: It does not work for all objects in FreeCAD. Especially objects created by built in python scripts like everything in the Draft workbench will not work correctly.

## How it works
The macro is quite simple. It loops through the properties of all selected objects, compares then to a default object, and generates script lines for object creation and changed properties. For some objects (Sketcher or Spreadsheet objects), special handling in the macro is needed. It may not be complete.

## Usage
This macro generates python code from all selected objects in a FreeCAD project.
If no object is selected, all objects in the project will be selected.
This macro generates python code from all selected objects in a FreeCAD project.
If no object is selected, all objects in the project will be selected.

A dialog will open and the output will be written into it. Press CTRL-a and CTRL-c to copy the code.
A dialog will open and the output will be written into it. Press CTRL-a and CTRL-c to copy the code.

Loading

0 comments on commit 5969cdf

Please sign in to comment.