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

Fix DIP Parts to run with FreeCAD 0.18 and Python 3 #372

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix DIP Parts to run with FreeCAD 0.18 and Python 3 #372

wants to merge 2 commits into from

Conversation

acisternino
Copy link
Contributor

Fixes issue running the DIP Parts scripts with FreeCAD 0.18 and Python 3.

Mostly float division and import issues.

@easyw
Copy link
Owner

easyw commented Jun 14, 2020

@acisternino
does your fix work both with py3 & py2 (i.e. FC 0.18 & FC0.17)?

@acisternino
Copy link
Contributor Author

@easyw
I am sorry, I have tested it only with FC 0.18/Py3. I'll give it a try as soon as possible but I don't think it is compatible.

The integer division fixes probably are but the use of importlib.reload and other changes surely not.

Feel free to close this if you don't want to wait.

@easyw
Copy link
Owner

easyw commented Jun 16, 2020

@acisternino
I can wait .. no hurry at all
If possible I would like to have it back compatible, but the need is not so important considering that the actual stable release is 0.18.4 and from now on all will be py3 only.

@Qbort
Copy link
Contributor

Qbort commented Jun 17, 2020

the use of importlib.reload

The only alternative that works in python2 and python3 is imp.reload. However "imp" package is deprecated in Python3...

Shouldn't this repository move away from supporting python 2 anyway? See #315

I ask because I'm working on similar fixes for BGA packages and others that do not work with FC 0.18.

@easyw
Copy link
Owner

easyw commented Jun 17, 2020

@Qbort

The only alternative that works in python2 and python3 is imp.reload.

a solution is already adopted here:

def reload_lib(lib):
if (sys.version_info > (3, 0)):
import importlib
importlib.reload(lib)
else:
reload (lib)

@acisternino
Copy link
Contributor Author

Another solution could be using something like this:

try:
    reload          # Python 2.7
except NameError:
    from importlib import reload   # Python 3.4+

I'll try to find solutions for the other features.

@Qbort
Copy link
Contributor

Qbort commented Jun 18, 2020

It would be good if we can agree the "best method" to do this. I am already in process of fixing all modules (see my PR #374) and what I have done is define the below function in cq_cad_tools.py

def reload_lib(lib):
if (sys.version_info > (3, 0)):
import importlib
importlib.reload(lib)
else:
reload (lib)

Then at the top of all files that use import, I added below 3 lines of code:

https://github.com/Qbort/kicad-3d-models-in-freecad/blob/python3_support/cadquery/FCAD_script_generator/4UCON_17809/main_generator.py#L109-L111

I'd rather agree this before I go too far with my changes on my PR #374 ...

@easyw
Copy link
Owner

easyw commented Jun 19, 2020

I'd rather agree this before I go too far with my changes on PR

@Qbort this approach seems fine.. adding the code in a common module is requiring to check and fix all the generators... is what you are you going to do? If so I'm fine with this approach 😄

@easyw
Copy link
Owner

easyw commented Sep 10, 2020

Another solution could be using something like this:

@acisternino in general I try to use [try excet] as little as possible inside the code... I would prefer to keep the first solution suggested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants