1

I am trying to create a python distribution package following https://packaging.python.org/en/latest/tutorials/packaging-projects/. My source folder contains many irrelevant files and subfolders which should be excluded from the distribution, such as temporary files, auxiliary code, test output files, private notes, etc. The knowledge of which files are relevant and which not, is already represented in the git source control. Instead of replicating all this as inclusion/exclusion rules in the pyproject configuration file (and needing to keep it up to date going forward), I would like my build chain to be based on a git commit/tag. This will also be useful for keeping versioning in sync between my repo history and pypi. I know there is an option to do it with github actions, but my question is how to do it locally, based just on git rather than github.

Edit following comment: I agree that you don't always want the repo and distro trees to be the same, but it would be much simpler to control if the distro starts from the repo tree as a baseline, with a few additional exclusion rules on top of that.

o17t H1H' S'k
  • 2,541
  • 5
  • 31
  • 52
  • 2
    I understand the desire to keep this [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), but I would recommend keeping it separate anyway. The reason is that not everything in source control should necessarily go into the final package (for example, documentation for developers/packagers), and conversely, not everything that goes into the final package is necessarily in source control (for example, generated code or build artifacts). – Thomas Nov 30 '22 at 12:05
  • DRY or die! I get your point. so the way i would do it is create a git branch for the pip. but still it is much easier for me to manage the source tree via git – o17t H1H' S'k Nov 30 '22 at 12:08
  • and in my case the most sensible approach seems to base inclusion/exclusion on main branch + one or two additional exclusion rules (e.g. exclude some media files) – o17t H1H' S'k Nov 30 '22 at 12:14
  • This seems very out of scope for StackOverflow. -- Also I feel like possible solutions are easy to find out in search engines. – sinoroc Dec 02 '22 at 12:26
  • @sinoroc I did not find them – o17t H1H' S'k Dec 02 '22 at 12:57
  • 1
    https://setuptools.pypa.io/en/latest/userguide/miscellaneous.html – sinoroc Dec 02 '22 at 13:44
  • 1
    Maybe provide a [mre], it will be easier to discuss on something concrete and avoid misunderstandings. – sinoroc Dec 02 '22 at 13:46

1 Answers1

2

To automatically include files from a Git or Mercurial repository you can use setuptools_scm. The tool can also automatically set the software version from a repository tag and the amount of changes since the tag.

The tool prepares data for the standard setuptools.