wjasper / Linux_Drivers

Open source Linux device drivers
GNU General Public License v3.0
110 stars 64 forks source link

Make an attempt at packaging these drivers on PyPi for general availability. #36

Closed mdwheele closed 2 years ago

mdwheele commented 4 years ago

Hey @wjasper!

:tipping_hand_woman: This PR makes structural changes to the project to allow for packaging of your Python drivers on PyPi.

Related: https://pypi.org/project/linux-drivers Project Layout: https://github.com/mdwheele/Linux_Drivers/tree/pypi-packaging

Please consider this an initial iteration or proof-of-concept. There is certainly more work to be done to really wrap this up and make it something maintainable. Before we move forward with this, it would probably be a good idea for us to get together (mdwheele@ncsu.edu) to make sure this actually works. I don't have any hardware to test this on and you're the best judge of whether or not things are working as intended.

I need to write a Makefile you can use to build and upload archives to PyPi, but here's the gist:

# See: https://packaging.python.org/tutorials/packaging-projects
# Once you've installed all dependencies above and 
# registered an account with pypi.org...

# Build distributed archive...
$ python3 setup.py sdist bdist_wheel

# Upload to PyPi using twine...
$ python3 -m twine upload dist/*

Enter your username: mdwheele
Enter your password: 
Uploading distributions to https://upload.pypi.org/legacy/
Uploading linux_drivers-0.0.3-py3-none-any.whl

View at:
https://pypi.org/project/linux-drivers/0.0.3/

I picked a name arbitrarily, but we can change that to whatever you like. If we change it, we'll just destroy what's already on PyPi.

The work basically boils down to these requirements:

  1. Restructure the project to separate C from Python. Python packages are expected to follow a standard structure. Because the project was organized by function, rather than language, it made it difficult to apply normal packaging procedures.
  2. The project needed a setup.py configuration. The setup.py configuration calls setuptools.setup to define details about your package including: package name, description, version, where to find packages within the source code and dependencies. It is used during the build process to produce a distributed archive that is uploaded to PyPi.
  3. Once project was restructured, module references needed to be updated.. When you run Python code interactively, you can reference modules relative to the current script. When you package code into modules that are expected to be run from anywhere, you have to take care to reference the full module path.

Things left to do: