0

I'm currently working on publishing a python package (I've already ran installation tests on test pypi and am able to pip install and run my code cleanly in a clean environment).

Context

I currently have a working directory that contains 1) source distribution 2) build distribution 3) src folder containing my package which contains all my code for my library 4) README, LICENSE, pyproject.toml file utilizing setuptools. This working directory has a local git repository which is hooked up to a remote repository (on github).

Problem and My Attempt to Fix It

However, I'm confused about one thing that I couldn't find a clear answer on, even after looking through documentation. I have .py files, in my git repository and working directory, that I DO NOT want to include in my ACTUAL release to pypi. I attempted to use a MANIFEST.in file and used the exclude command to take these files out, but I found out that MANIFEST.in doesn't exclude python modules (.py files) in the build distributions (wheels), so when I pip install my package, the modules that I wanted gone are still included in the package on the user end. So tldr; How can I keep all my files in the working directory, but exclude certain .py files in the build distribution (before I publish to pypi)?

If I have any mistakes in my terminology/understanding of this, please correct me as I am new to this workflow of publishing packages.

Edit: I figured out a workaround, but still haven't solved this issue.

I originally wanted to exclude a single python module (a .py file) from the bdist because I didn't want the module to be accessible on the user end (i.e. if someone writes from library_name import *, I didn't want my file to be imported for them to use), however, I still wanted this file to be tracked on my git repository so that it would show up on my github repo for this project.

Instead of excluding the file from my bdist, I just included it in the bdist, but I made sure to not import it in the __init__.py so that the user couldn't access it by importing. Not the most elegant solution but it is sufficient for my situation. I will leave this question open because I am open to suggestions on how to address this.

AndrewJaeyoung
  • 368
  • 3
  • 10
  • do you have a .gitignore file on github ? – Devyl Jul 13 '22 at 10:46
  • How do you identify packages in your setup.py? with find_packages? You could exclude packages there. – Felix Kleine Bösing Jul 13 '22 at 11:50
  • @FelixKleineBösing I don't use a setup.py (I only use a pyproject.toml file as specified in this packaging documentation: https://packaging.python.org/en/latest/tutorials/packaging-projects/), but even with a setup.py, it doesn't seem to be possible (see: https://stackoverflow.com/questions/26911045/is-it-possible-to-exclude-certain-files-when-building-a-wheel-with-setup-py). I am trying to exclude a single .py file from my bdist, not necessarily a whole package or directory. – AndrewJaeyoung Jul 13 '22 at 16:18
  • @Devyl I do use a gitignore file, but how will that help me exclude a .py file from the bdist (.whl) for my package? To my knowledge, .gitignore only ignores tracking of certain files on git repositories. You can't track a file on your git repository, but not have it in the local directory. What were you hinting at? – AndrewJaeyoung Jul 13 '22 at 16:35

0 Answers0