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

Ensure pure-Python implementations **do not** invoke code from the binary extension. #160

Merged
merged 39 commits into from
Jan 6, 2020

Conversation

dhermes
Copy link
Owner

@dhermes dhermes commented Jan 6, 2020

Fixes #159.

This was way more work than I thought it would be, but I think long-term it will be worth it.

The goal is to replace the original names with a wrapper that
**only** exports the parts needed elsewhere and put the pure Python
implementations by themselves.

Done via:

```
git mv _curve_helpers.py _py_curve_helpers.py
git mv _geometric_intersection.py _py_geometric_intersection.py
git mv _helpers.py _py_helpers.py
git mv _intersection_helpers.py _py_intersection_helpers.py
git mv _surface_helpers.py _py_surface_helpers.py
git mv _surface_intersection.py _py_surface_intersection.py
```

Found these modules via:

```
git grep -l 'if _speedup is None'
```
These are intended to stand in for the previous modules, and the rename
is intentional (and temporary) to suss out places where the imports
are relying on pure Python parts vs. parts that could either by
Python or speedup.
Done via:

```
git mv test__curve_helpers.py test_py_curve_helpers.py
git mv test__geometric_intersection.py test_py_geometric_intersection.py
git mv test__helpers.py test_py_helpers.py
git mv test__intersection_helpers.py test_py_intersection_helpers.py
git mv test__surface_helpers.py test_py_surface_helpers.py
git mv test__surface_intersection.py test_py_surface_intersection.py
```

No code edits were made in this commit, but some will need to be
done to fix imports and split out the "wrap" portions.
Done via:

```
cd test/unit/
git mv test_py_curve_helpers.py test__py_curve_helpers.py
git mv test_py_geometric_intersection.py test__py_geometric_intersection.py
git mv test_py_helpers.py test__py_helpers.py
git mv test_py_intersection_helpers.py test__py_intersection_helpers.py
git mv test_py_surface_helpers.py test__py_surface_helpers.py
git mv test_py_surface_intersection.py test__py_surface_intersection.py
```
In the process had to fix a runtime import of a Python
module within `_speedup.pyx`.
This was for functions that also occurred as `_speedup.{name}` that
have now been renamed (from `_{name}`) to `{name}`.

Also cleaned up the `_{name}` references in documentation wherever
I could find references.
This was only temporary to ensure all the old names had been properly
moved.

Done via:

```
git mv src/python/bezier/_wrap_curve_helpers.py src/python/bezier/_curve_helpers.py
git mv src/python/bezier/_wrap_geometric_intersection.py src/python/bezier/_geometric_intersection.py
git mv src/python/bezier/_wrap_helpers.py src/python/bezier/_helpers.py
git mv src/python/bezier/_wrap_intersection_helpers.py src/python/bezier/_intersection_helpers.py
git mv src/python/bezier/_wrap_surface_helpers.py src/python/bezier/_surface_helpers.py
git mv src/python/bezier/_wrap_surface_intersection.py src/python/bezier/_surface_intersection.py
git mv tests/unit/test__wrap_curve_helpers.py tests/unit/test__curve_helpers.py
git mv tests/unit/test__wrap_geometric_intersection.py tests/unit/test__geometric_intersection.py
git mv tests/unit/test__wrap_helpers.py tests/unit/test__helpers.py
git mv tests/unit/test__wrap_intersection_helpers.py tests/unit/test__intersection_helpers.py
git mv tests/unit/test__wrap_surface_helpers.py tests/unit/test__surface_helpers.py
git mv tests/unit/test__wrap_surface_intersection.py tests/unit/test__surface_intersection.py
```

A subsequent commit will update the **references** to these files.
Done via:

```
git grep -l _wrap -- ':(exclude)*.c' | xargs sed -i s/_wrap/''/g
```

Still need to follow-up to:

- Resolve lint errors due to alphabetical ordering of imports
- Re-generate `*.c` files with Cython
Slipped in some changes where `black` does not have an "opinion".
In particular, tried to make sure there is an empty line after the
LICENSE header and make sure there are 2 empty lines between imports
and constants.
- Removing the `HAS_SPEEDUP` check since the tests for the pure Python
  implementations now eschew usage of speedups (even if present)
- Explicitly re-defining the marked methods in the subclass to
  avoid marking them as slow
Pylint (correctly) flagged them as `useless-super-delegation`
and so I disabled the rule for the few methods where I re-defined
methods to drop the `slow` mark in pytest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All pure-Python implementations should invoke the other pure-Python implementations
1 participant