to_pypi.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # Script to release FlexMeasures to PyPi.
  3. #
  4. # Cleans up build and dist dirs, checks for python files which are not in git, installs dependencies
  5. # and finally uploads tar and wheel packages to Pypi.
  6. #
  7. #
  8. # Usage
  9. # ------------
  10. #
  11. # ./to_pypi [--dry-run]
  12. #
  13. # If the --dry-run flag is present, this script will do all steps, but skip the upload to Pypi.
  14. #
  15. #
  16. # Required packages (install/upgrade with pip into your environment, or `make install-for-dev`):
  17. # - build
  18. # - packaging>=24.2
  19. #
  20. #
  21. # Where does the FlexMeasures version come from?
  22. # ----------------------------------------------
  23. # The version comes from setuptools_scm. See `python setup.py --version`.
  24. # setuptools_scm works via git tags that should implement a semantic versioning scheme, e.g. v0.2.3
  25. #
  26. # If there were zero commits since the most recent tag, we have a real release and the version basically *is* what the tag says.
  27. # Otherwise, the version also includes a .devN identifier, where N is the number of commits since the last version tag.
  28. #
  29. #
  30. # More information on creating a dev release
  31. # -------------------------------------------
  32. # Note that the only way to create a new dev release is to add another commit on your development branch.
  33. # It might have been convenient to not have to commit to do that (for experimenting with very small changes),
  34. # but we decided against that. Let's explore why for a bit:
  35. #
  36. # First, setuptools_scm has the ability to add a local scheme (git commit and date/time) to the version,
  37. # but we've disabled that, as that extra part isn't formatted in a way that Pypi accepts it.
  38. # Another way would have been to add a local version identifier ("+M", note the plus sign),
  39. # which is allowed in PEP 440 but explicitly disallowed by Pypi.
  40. # Finally, if we simply add a number to .devN (-> .devNM), the ordering of dev versions would be
  41. # disturbed after the next local commit (e.g. we add 1 to .dev4, making it .dev41, and then the next version, .dev5,
  42. # is not the highest version chosen by PyPi).
  43. #
  44. # So we'll use these tools as the experts intended.
  45. # If you want, you can read more about acceptable versions in PEP 440: https://www.python.org/dev/peps/pep-0440/
  46. NUM_PY_FILES_IN_FM=$(git status --porcelain flexmeasures | grep '??.*\.py' | wc -l)
  47. if [ $NUM_PY_FILES_IN_FM -gt 0 ]; then
  48. PY_FILES_IN_FM=$(git status --porcelain flexmeasures | grep '??.*\.py')
  49. echo """[TO_PYPI] The following python files are not under git control but would be packaged anyways (unless explicitly excluded, e.g. in MANIFEST.in):
  50. $PY_FILES_IN_FM
  51. You probably want to remove any files with sensitive data; or add a MANIFEST.in file with 'exclude flexmeasures/path/to/filename' ...
  52. """
  53. read -p "Continue (y/n)? " choice
  54. case "$choice" in
  55. y|Y ) echo "If you say so. Continuing ...";;
  56. n|N ) echo "Aborting ..."; exit 2;;
  57. * ) echo "invalid choice";;
  58. esac
  59. fi
  60. echo "[TO_PYPI] Cleaning ..."
  61. rm -rf build/* dist/*
  62. echo "[TO_PYPI] Installing dependencies ..."
  63. pip -q install twine
  64. pip -q install wheel
  65. echo "[TO_PYPI] Packaging ..."
  66. python -m build
  67. if [ "$1" == "--dry-run" ]; then
  68. echo "[TO_PYPI] Not uploading to Pypi (--dry-run active) ..."
  69. else
  70. echo "[TO_PYPI] Uploading to Pypi ..."
  71. twine upload dist/*
  72. fi