glederrey / camogen

Generator of random camouflage
MIT License
48 stars 16 forks source link

Python 2.7 support #7

Closed gammalogic closed 3 months ago

gammalogic commented 3 months ago

With reference to issue https://github.com/glederrey/camogen/issues/1 I tried running camogen initially under Python 2.7 as this is the default on my (old) copy of macOS and got the same error messages.

I tried commenting-out every instance of the if type(v).__name__ != 'Vertex': condition and this appears to allow the script to run correctly. I think this is because Python 2.7 can't access the name of the class using that construct. In polygon.py (and other scripts) if I then replace

if type(v).__name__ != 'Vertex':

with

if v.__class__.__name__ != 'Vertex': 

then the check works as expected and the script runs without generating any errors. I have verified that the class name is accessed correctly using print(v.__class__.__name__) and therefore the class name check should work as expected. The replacement code does appear to work fine in Python 3 although I understand that it is not the recommended way to access class type information going forwards. However, if people are stuck with Python 2.7 for some reason then this replacement code may be helpful.

glederrey commented 3 months ago

Hi,

Thanks a lot. I have tried to run it with python3.11 and apply your changes and it worked. I, thus, pushed the update directly. Thank you very much!

(Maybe, one day, I will refactor this code... Maybe...)

gammalogic commented 3 months ago

Thank you. I did consider the possibility (in my copy of the scripts) of checking the Python version number somewhere using sys.version_info[0] and then adding a context check. Maybe if you decide to refactor the code at some point then a context check could be more appropriate provided that it does not clutter up the code and you wanted to keep the type() construct you've previously used.

Also, thank you very much for your work on the software. I've been using it to generate digital camo patterns and it's very easy using the parameters to get exactly what I want. Good job!

glederrey commented 3 months ago

If I decide one day to refactor it, I will definitely make sure it works in both cases. Many things should be improved with this code tbh. =)

Happy to hear that you're using it. For me it's very fun that people are still using since it was a side project of a side project of my master project. =) But I'm glad that it can be of help to people. =D