1

I would like to build a python package, run tests against the build artifact and then upload the python package to a PyPI w/o re-building the package.

We are building a CI/CD pipeline and want to make sure that the exact package we built and tested is what gets published, not a re-built version after the fact.

Currently, if I run the following:

$ python setup.py egg_info -b .$BUILD_NUM sdist bdist_wheel

Then run my tests and run:

$ python setup.py egg_info -b .$BUILD_NUM sdist bdist_wheel upload

Then the timestamp on the files shows the file was re-built the second time.

Is there a way to submit the files without re-building them?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Mark J Miller
  • 4,751
  • 5
  • 44
  • 74
  • Perhaps remove `sdist bdist_wheel` when you do the upload? Those commands sound like you are asking for a rebuild – Mad Physicist Jul 06 '17 at 16:02
  • 1
    You may want to add a tag indicating whether you are using distutils or setuptools. – Mad Physicist Jul 06 '17 at 16:04
  • Returns `error: No dist file created in earlier command`. From what I can tell you are required to specify the distributions you want uploaded as part of the command: https://docs.python.org/2.7/distutils/packageindex.html#the-upload-command – Mark J Miller Jul 06 '17 at 16:08
  • So using distutils? – Mad Physicist Jul 06 '17 at 16:09
  • A simple hack would be to just rerun the tests after uploading to make sure that it's all still kosher. – Mad Physicist Jul 06 '17 at 16:10
  • I assumed it might be something like that. I might also just run the tests w/o packaging/uploading until after I have confirmed tests are passing. – Mark J Miller Jul 06 '17 at 16:11
  • BTW, what does distutils have to do with it? What are my other options? – Mark J Miller Jul 06 '17 at 16:12
  • Your other option is [setuptools](https://setuptools.readthedocs.io/en/latest/) and also [distutils2](https://wiki.python.org/moin/Distutils2). See https://stackoverflow.com/q/6344076/2988730 – Mad Physicist Jul 06 '17 at 16:18

1 Answers1

2

By using sdist and bdist_wheel in your command you explicitly order setup.py to rebuild packages. If you want to upload without rebuilding just use python setup.py upload. Or even better, use twine; it's the recommended way to upload to PyPI.

twine upload dist/*

twine looks into dist, gets the package name and version and uploads packages.

phd
  • 82,685
  • 13
  • 120
  • 165