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

Python 3 support and command line fixes #6

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

Python 3 support and command line fixes #6

wants to merge 6 commits into from

Conversation

rohieb
Copy link

@rohieb rohieb commented Apr 29, 2019

Python 3 has been out for over ten years, and end-of-life for Python 2 is very near. This pull-request ports the project to Python 3, fixes some problems with command line usage (maybe related to Python 3 support), and also fixes the problems addressed in #1 and #4.

Python 2 is EOL, and Python 3 has been out for about ten years now.

Implicit relative imports are deprecated in Python 3, make it an
explicit relative import.

StringIO has moved to the io package.
The lxml bindings generates bytes, not strings. However, file primitives
are Unicode-aware by default in Python 3, so write() will expect strings
unless the file was opened in raw mode (by adding 'b' to the flags):

    Traceback (most recent call last):
      [...]
      File ".../geometry/svg_utils.py", line 49, in write_svg
        f.write(xml_str);
    TypeError: write() argument must be str, not bytes
array.has_key() was deprecated in Python 3 and will now throw errors:

    Traceback (most recent call last):
      [...]
      File ".../geometry/primitives.py", line 130, in append_to_svg
        if style.has_key('stroke'):
    AttributeError: 'dict' object has no attribute 'has_key'
The type of this parameter is a positive float, so we should assign a
float to it. Otherwise, get_geometry() will complain when passed None:

    Traceback (most recent call last):
      File "./gear.py", line 318, in <module>
        run_with_args()
      File "./gear.py", line 302, in run_with_args
        geom = g.get_geometry(args.r, args.k, args.b)
      File "./gear.py", line 232, in get_geometry
        if bore > 0:
    TypeError: '>' not supported between instances of 'NoneType' and 'int'
Having a shebang in gear.py also removes ambiguity about which python
version to use.
We don't need to pass any parameters to argparse, it figures them out by
itself. Furthermore, if we pass it the whole sys.argv array, it will
complain about "error: unrecognized arguments: ./gear.py".

Fixes #1, #4
@rohieb
Copy link
Author

rohieb commented Apr 29, 2019

Mmmh. The setup.py needs some deeper changes in directory structure in order to install everything to the correct paths. I'll leave it out for now.

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.

1 participant