adafruit / circuitpython-build-tools

Build scripts for CircuitPython libraries and the bundle
MIT License
28 stars 17 forks source link

indented `__version__` value not being replaced #94

Closed 2bndy5 closed 1 year ago

2bndy5 commented 2 years ago

I'm trying to figure out how to get setuptools_scm to save the version number in a generate file (named _version.py) when building the wheel for PyPI while still being compliant with this pkg when generating bundles. However, the __version__ value is not getting replaced when I use

# in my __init__.py module

try:  # if pkg was built for PyPI uploads
    from ._version import __version__  # get the version generated by setuptools_scm
except ImportError:  # pkg was built as bundle by circuitpython-build-bundles
    __version__ = "0.0.0-auto.0"

It is possible that I'm overthinking this (see additional context below). As I currently see it, my limitation is here: https://github.com/adafruit/circuitpython-build-tools/blob/687af8c22b41b17f2e25d2389f495f7a9b8f454c/circuitpython_build_tools/build.py#L141-L143

I think a lstrip() would fix my predicament:

 if line.lstrip().startswith("__version__"): 
     line = re.sub(r"0\.0\.0[-+]auto\.0", library_version, line) 

I added a little regex to reduce the somewhat duplicated code.

Additional CI context

If I build the wheel and bundles in the same CI job, then I risk bundling the generated _version.py (which seems unnecessary for CircuitPython's small file storage capacity).

If I don't generate the _version.py file then the following code resolves differently depending on the platform:

>>> # on CPython
>>> from my_lib import __version__
>>> print(__version__)
0.0.0-auto.0
>>> # on CircuitPython firmware
>>> from my_lib import __version__
>>> print(__version__)
1.0.0
tekktrik commented 1 year ago

The current release process sidesteps requiring this package to do so by using sed in the release workflow.

2bndy5 commented 1 year ago

Yes, that works when building the bundles, but the __version__ attr remains 0.0.0-auto.0 when building dists for pypi (even with setuptools_scm).

tekktrik commented 1 year ago

The workflow now looks for 0.0.0+auto.0 and changes it before building wheels and uploading them and the source distribution. Anywhere that uses 0.0.0-auto.0 should be changed to 0.0.0+auto.0 and use the new release workflows, and it should modify and upload them to PyPI appropriately.

2bndy5 commented 1 year ago

Oh I see. This issue still stands if not using adafruit CI actions, but I guess we can call it solved since this is the only feedback for nearly 5 months.