flit icon indicating copy to clipboard operation
flit copied to clipboard

Only tar.gz format is made with `flit build` when there is `.git`?

Open samuelwhiskeyjohnson opened this issue 1 year ago • 5 comments

flit build normally produces both tar.gz and .whl format

but when I use git init to have .git in the project, only tar.gz is made.

samuelwhiskeyjohnson avatar Jul 05 '24 15:07 samuelwhiskeyjohnson

That's weird, what do the messages say? Most of my projects have a .git folder and Flit generally builds wheels as well.

takluyver avatar Jul 05 '24 16:07 takluyver

The message is a bit different.

Structure

  • pytest_skip_slow_DIY (directory)
    • .git (directory)
    • dist (directory)
    • examples (directory)
    • LICENSE (file)
    • pyproject.toml (file)
    • pytest_skip_slow_module.py (file)

But here this is with .git folder

(venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY> git init
Initialized empty Git repository in C:/Users/SJ/Desktop/Programs/Python/PyTest/code/ch15/pytest_skip_slow_DIY/.git/
(venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY> flit build
Untracked or deleted files in the source directory. Commit, undo or ignore these files in your VCS.
(venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY> 
(venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY> ls dist


    Directory: C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY\dist


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          7/6/2024   2:32 AM             79 pytest_skip_slow_module-0.0.5.tar.gz


(venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY>


This is when I don't have the git folder

(venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY> flit build
Built sdist: dist\pytest_skip_slow_module-0.0.5.tar.gz  I-flit_core.sdist
Copying package file(s) from C:\Users\SJ\AppData\Local\Temp\tmp_9wzr_4r\pytest_skip_slow_module-0.0.5\pytest_skip_slow_module.py  I-flit_core.wheel
Writing metadata files                               I-flit_core.wheel
Writing the record of files                          I-flit_core.wheel
Built wheel: dist\pytest_skip_slow_module-0.0.5-py2.py3-none-any.whl  I-flit_core.wheel
(venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY> ls dist


    Directory: C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY\dist


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          7/6/2024   2:35 AM           5271 pytest_skip_slow_module-0.0.5-py2.py3-none-any.whl
-a----          7/6/2024   2:35 AM           4316 pytest_skip_slow_module-0.0.5.tar.gz


(venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest\code\ch15\pytest_skip_slow_DIY> 



samuelwhiskeyjohnson avatar Jul 05 '24 17:07 samuelwhiskeyjohnson

Aha, OK. So it's by design that it's stopping early, as the message indicates:

Untracked or deleted files in the source directory. Commit, undo or ignore these files in your VCS.

It uses git to decide which files to include in the sdist, but if they're neither checked in nor ignored, it doesn't know what to do, so it refuses until you decide on those files. (This is what it does for now, anyway - we're actually moving away from this).

You can override this with the --no-use-vcs option.

There is a bug, however, in that it's creating the .tar.gz file before doing that check. It's actually giving you an empty archive, that's why the length is only 79 bytes. It shouldn't do this if it's refusing to build.

takluyver avatar Jul 05 '24 17:07 takluyver

1 ok so flit build --no-use-vcs does work. It creates tar.gz and the .whl. 🙂

2

It (Flit) uses git to decide which files to include in the sdist, but if they're neither checked in nor ignored, it doesn't know what to do, so it refuses (to build) until you decide on those files.

I'm not very knowledgeable at Flit. So I'm assuming "it" means "Flit" and "it refuses" mean "it refuses to build" is what you meant for clarity. Anyways, so shouldn't adding .gitignore also fix this problem? Even I add .gitignore so that ignore whatever the files inside the dist folder and do flit build I suffer from the same problem generating only the tar.gz format and not the .whl.

.gitignore

dist
__pycache__

samuelwhiskeyjohnson avatar Jul 06 '24 17:07 samuelwhiskeyjohnson

All the files in your project directory (where pyproject.toml is) need to be either ignored or added (git add blah.txt) to git. If git status shows you any 'Untracked files', Flit will give you this error.

takluyver avatar Jul 08 '24 13:07 takluyver