bepasty-server icon indicating copy to clipboard operation
bepasty-server copied to clipboard

Use setup.cfg instead of setup.py

Open augustfengd opened this issue 3 years ago • 11 comments

Use setup.cfg instead of setup.py

Besides fully migrating to setup.cfg, the versioning system is also changed from setuptools_scm to a simple attribute in bepasty/__init__.py.

This would require manual editing of the bepasty/__init__.py in order to control the versioning from now on.

Removing setuptools_scm as a dependency will allow the package to be built without a .git folder present, which is favorable for packaging a docker image, otherwise pip install -e . would fail.

augustfengd avatar Jul 08 '21 04:07 augustfengd

I don't want to drop setuptools_scm.

Besides the automated versioning (at release time and also computing reasonable versions in between of releases), it also manages the MANIFEST (which also is a frequent pain point for projects).

ThomasWaldmann avatar Jul 09 '21 09:07 ThomasWaldmann

with a manual MANIFEST.in as:

include AUTHORS
include LICENSE
include MANIFEST.in
include *.rst
include tox.ini
graft src
graft scripts
graft requirements.d
global-exclude __pycache__
global-exclude *.py[co]

It retains the the same files, but also duplicates some metadata files into bepasty.egg-info. I'm not too sure why but I could investigate and look for a way to avoid this.

In my opinion, there are some files/folders being captured by setuptools_scm, which aren't really necessary in the package source distribution. The MANIFEST.in list would be pretty short and manageable otherwise without these:

  • requirements.d/
  • scripts/
  • tox.ini

The loss of auto versioning feature is not too convenient though, I agree. However the advantage for a Dockerfile is that it wouldn't need to install git or include the .git folder into order to build an image.

This is the Dockerfile that I have in mind:

FROM python:3.9-slim

WORKDIR /app

# copy the minimum files necessary to install dependencies.
COPY setup.py setup.cfg /app/
COPY bepasty/__init__.py bepasty/
RUN pip install -e . gunicorn

# copy the content of bepasty now.
COPY . .

ENTRYPOINT exec /usr/local/bin/gunicorn -b 0.0.0.0:5000 --workers=${WORKERS:-4} bepasty.wsgi

augustfengd avatar Jul 10 '21 04:07 augustfengd

I you use a release from pypi, does that still need git?

ThomasWaldmann avatar Jul 10 '21 15:07 ThomasWaldmann

In that case no, I don't think so. I think a simple pip install bepasty which references a release on PyPi would suffice.

Even something as simple this would work.

FROM python:3.9-slim

RUN pip install bepasty gunicorn

ENTRYPOINT exec /usr/local/bin/gunicorn -b 0.0.0.0:5000 --workers=${WORKERS:-4} bepasty.wsgi

The docker release would kind of be second-class, though. The PyPi would need to be released and available on PyPI before building and releasing a docker image.

augustfengd avatar Jul 10 '21 15:07 augustfengd

Releases are made via putting a git tag on the repo, so that is always the "first class". But when doing a release, I also publish the corresponding pypi package, so it is available at the same time.

All other packages are made whenever the respective package maintainer does it, so it can be quick or take some time.

ThomasWaldmann avatar Jul 11 '21 11:07 ThomasWaldmann

Ah about the git tag, I acknowledge that now. However my point remains that that docker images based on what's already on the pypi is kind of third-party ish.

Would there be an interest for this project to adopt docker releases flow that would be done alongside the pypi one ?

augustfengd avatar Jul 11 '21 14:07 augustfengd

I don't use docker, so I would not like to care for docker stuff.

Also, as I said, I'ld like to keep setuptools_scm for 2 reasons.

ThomasWaldmann avatar Jul 12 '21 11:07 ThomasWaldmann

Just an update, I just reverted the removal of the setuptools_scm.

When I git tag and then run python setup.py sdist, it seems to produce a package nearly the same way as it had been done with the latest release on PyPI. The differences may be due to us not having the same setuptools version.

I'll consider alternative solutions for having creating docker images, but the refactoring to setup.cfg may still valuable.

Let me know if there's anything I else I can do for this PR.

Thanks !

augustfengd avatar Aug 20 '21 03:08 augustfengd

You talk about differences, what precisely were the differences?

ThomasWaldmann avatar Aug 20 '21 13:08 ThomasWaldmann

Codecov Report

Merging #276 (58f33e7) into master (c40d55d) will decrease coverage by 0.52%. The diff coverage is 46.31%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #276      +/-   ##
==========================================
- Coverage   71.38%   70.85%   -0.53%     
==========================================
  Files          44       44              
  Lines        2558     2594      +36     
==========================================
+ Hits         1826     1838      +12     
- Misses        732      756      +24     
Impacted Files Coverage Δ
src/bepasty/cli/object.py 0.00% <0.00%> (ø)
src/bepasty/cli/server.py 0.00% <ø> (ø)
src/bepasty/tests/screenshots.py 0.00% <0.00%> (ø)
src/bepasty/utils/formatters.py 15.15% <0.00%> (ø)
src/bepasty/views/display.py 16.83% <0.00%> (ø)
src/bepasty/views/upload.py 20.95% <0.00%> (ø)
src/bepasty/wsgi.py 0.00% <ø> (ø)
src/bepasty/views/download.py 59.13% <32.50%> (-19.05%) :arrow_down:
src/bepasty/storage/filesystem/__init__.py 91.81% <66.66%> (-0.08%) :arrow_down:
src/bepasty/utils/date_funcs.py 93.33% <66.66%> (ø)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8f4c23f...58f33e7. Read the comment docs.

codecov-commenter avatar Aug 20 '21 13:08 codecov-commenter

At a quick glance, I saw some differences in quotes and also an added tuple for the versioning. I'm pretty sure the version_tuple is attributed to me having a newer setuptools_scm since it's a feature introduced in v5.0.0.

I just did a more thorough study by checking out the repository at release 1.0.0, and doing a python3 setup.py sdist with a back-porting of two commits from this PR. Then I compared the output against the archive on PyPI.

The setup.cfg and setup.py were excluded from the diff, because they would obviously be different. But besides that, there are still some differences other than the previously mentioned quotes and version_tuple.

These differences look to be simply because the back-port included more recent iterations of the setup.cfg/setup.py, which included Pillow in the manifests, for example.

(.env) $ diff --color -r --exclude="setup.py" --exclude="setup.cfg" bepasty-1.0.0.pypi bepasty-1.0.0.setup.cfg/
diff --color -r '--exclude=setup.py' '--exclude=setup.cfg' bepasty-1.0.0.pypi/PKG-INFO bepasty-1.0.0.setup.cfg/PKG-INFO
5c5
< Home-page: https://github.com/bepasty/bepasty-server/
---
> Home-page: 'https://github.com/bepasty/bepasty-server/'
7c7
< Author-email:
---
> Author-email: ''
78c78
< Keywords: text image audio video binary pastebin upload download service wsgi flask
---
> Keywords: "text image audio video binary pastebin upload download service wsgi flask"
86d85
< Classifier: Programming Language :: Python :: 3.5
91c90,91
< Requires-Python: >=3.5
---
> Classifier: Programming Language :: Python :: 3.10
> Requires-Python: >=3.6
92a93
> Provides-Extra: pillow
diff --color -r '--exclude=setup.py' '--exclude=setup.cfg' bepasty-1.0.0.pypi/src/bepasty/_version.py bepasty-1.0.0.setup.cfg/src/bepasty/_version.py
4a5
> version_tuple = (1, 0, 0)
diff --color -r '--exclude=setup.py' '--exclude=setup.cfg' bepasty-1.0.0.pypi/src/bepasty.egg-info/PKG-INFO bepasty-1.0.0.setup.cfg/src/bepasty.egg-info/PKG-INFO
5c5
< Home-page: https://github.com/bepasty/bepasty-server/
---
> Home-page: 'https://github.com/bepasty/bepasty-server/'
7c7
< Author-email:
---
> Author-email: ''
78c78
< Keywords: text image audio video binary pastebin upload download service wsgi flask
---
> Keywords: "text image audio video binary pastebin upload download service wsgi flask"
86d85
< Classifier: Programming Language :: Python :: 3.5
91c90,91
< Requires-Python: >=3.5
---
> Classifier: Programming Language :: Python :: 3.10
> Requires-Python: >=3.6
92a93
> Provides-Extra: pillow
diff --color -r '--exclude=setup.py' '--exclude=setup.cfg' bepasty-1.0.0.pypi/src/bepasty.egg-info/SOURCES.txt bepasty-1.0.0.setup.cfg/src/bepasty.egg-info/SOURCES.txt
40d39
< src/bepasty.egg-info/not-zip-safe
Only in bepasty-1.0.0.pypi/src/bepasty.egg-info: not-zip-safe
diff --color -r '--exclude=setup.py' '--exclude=setup.cfg' bepasty-1.0.0.pypi/src/bepasty.egg-info/requires.txt bepasty-1.0.0.setup.cfg/src/bepasty.egg-info/requires.txt
3d2
< xstatic
4a4
> xstatic
9d8
< xstatic-jquery-ui
10a10
> xstatic-jquery-ui
14a15,17
>
> [pillow]
> Pillow

augustfengd avatar Sep 03 '21 02:09 augustfengd

Thanks for the PR, merged!

ThomasWaldmann avatar Jan 21 '23 17:01 ThomasWaldmann