pypa/build

Do not add trailing whitespaces to / preserve whitespaces in setup.cfg

Closed this issue · 1 comments

Steps to reproduce:

git clone --depth=1 https://github.com/mxmlnkn/ratarmount
cd ratarmount/
python3 -m build .
tar -xf dist/ratarmount-*.tar.gz
diff -u setup.cfg ratarmount-*/setup.cfg

Output:

--- setup.cfg	2024-02-24 11:56:51.478616130 +0100
+++ ratarmount-0.14.1/setup.cfg	2024-02-24 11:57:12.362687000 +0100
@@ -1,57 +1,60 @@
 [metadata]
-name    = ratarmount
+name = ratarmount
 version = 0.14.1
-
-description   = Random Access Read-Only Tar Mount
-url           = https://github.com/mxmlnkn/ratarmount
-author        = Maximilian Knespel
-author_email  = mxmlnkn@github.de
-license       = MIT
+description = Random Access Read-Only Tar Mount
+url = https://github.com/mxmlnkn/ratarmount
+author = Maximilian Knespel
+author_email = mxmlnkn@github.de
+license = MIT
 license_files = LICENSE
-classifiers   =
-    License :: OSI Approved :: MIT License
-    Development Status :: 4 - Beta
-    Natural Language :: English
-    Operating System :: MacOS
-    Operating System :: Unix
-    Programming Language :: Python :: 3
-    Programming Language :: Python :: 3.6
-    Programming Language :: Python :: 3.7
-    Programming Language :: Python :: 3.8
-    Programming Language :: Python :: 3.9
-    Programming Language :: Python :: 3.10
-    Programming Language :: Python :: 3.11
-    Programming Language :: Python :: 3.12
-    Topic :: System :: Archiving
-    Topic :: System :: Archiving :: Compression
-    Topic :: System :: Filesystems
-    Topic :: Utilities
-
+classifiers = 
+	License :: OSI Approved :: MIT License
+	Development Status :: 4 - Beta
+	Natural Language :: English
+	Operating System :: MacOS
+	Operating System :: Unix
+	Programming Language :: Python :: 3
+	Programming Language :: Python :: 3.6
+	Programming Language :: Python :: 3.7
+	Programming Language :: Python :: 3.8
+	Programming Language :: Python :: 3.9
+	Programming Language :: Python :: 3.10
+	Programming Language :: Python :: 3.11
+	Programming Language :: Python :: 3.12
+	Topic :: System :: Archiving
+	Topic :: System :: Archiving :: Compression
+	Topic :: System :: Filesystems
+	Topic :: Utilities
 long_description = file: README.md,
 long_description_content_type = text/markdown
 
 [options]
 py_modules = ratarmount
-install_requires =
-    ratarmountcore ~= 0.6.0
-    fusepy
-    indexed_bzip2 >= 1.3.1, < 2.0
-    indexed_gzip >= 1.6.3, < 2.0
-    indexed_zstd >= 1.3.1, < 2.0; sys_platform=="darwin"
-    indexed_zstd >= 1.2.2, < 2.0; platform_system!="Windows"
-    dataclasses; python_version < "3.7.0"
-    python-xz ~= 0.4.0
-    rapidgzip ~= 0.10.0
-    rarfile ~= 4.0
+install_requires = 
+	ratarmountcore ~= 0.6.0
+	fusepy
+	indexed_bzip2 >= 1.3.1, < 2.0
+	indexed_gzip >= 1.6.3, < 2.0
+	indexed_zstd >= 1.3.1, < 2.0; sys_platform=="darwin"
+	indexed_zstd >= 1.2.2, < 2.0; platform_system!="Windows"
+	dataclasses; python_version < "3.7.0"
+	python-xz ~= 0.4.0
+	rapidgzip ~= 0.10.0
+	rarfile ~= 4.0
 
 [options.extras_require]
-full  =
-bzip2 =
-gzip  =
-rar   =
-xz    =
-zip   =
-zstd  =
+full = 
+bzip2 = 
+gzip = 
+rar = 
+xz = 
+zip = 
+zstd = 
 
 [options.entry_points]
 console_scripts = ratarmount=ratarmount:cli
+
+[egg_info]
+tag_build = 
+tag_date = 0
+

And with diff -w setup.cfg ratarmount-*/setup.cfg:

--- setup.cfg	2024-02-24 11:56:51.478616130 +0100
+++ ratarmount-0.14.1/setup.cfg	2024-02-24 11:57:12.362687000 +0100
@@ -1,7 +1,6 @@
 [metadata]
 name    = ratarmount
 version = 0.14.1
-
 description   = Random Access Read-Only Tar Mount
 url           = https://github.com/mxmlnkn/ratarmount
 author        = Maximilian Knespel
@@ -26,7 +25,6 @@
     Topic :: System :: Archiving :: Compression
     Topic :: System :: Filesystems
     Topic :: Utilities
-
 long_description = file: README.md,
 long_description_content_type = text/markdown
 
@@ -55,3 +53,8 @@
 
 [options.entry_points]
 console_scripts = ratarmount=ratarmount:cli
+
+[egg_info]
+tag_build = 
+tag_date = 0
+

There are multiple similar issues in other projects: bumpversion, setuptools

The reasons why this is a problem stated in those issues are the same as mine: I noticed this after losing my sanity because I tried to generate a patch from the Github repository and it didn't work with Conda:

Found source in cache: ratarmount-0.14.1_4eb3987fd9.tar.gz
Extracting download
Applying patch: /ratarmount-feedstock/recipe/remove-rapidgzip.patch
Applying patch: /ratarmount-feedstock/recipe/remove-rapidgzip.patch with args:
['-Np0', '-i', '/tmp/tmpt8csnys_/remove-rapidgzip.patch.native', '--binary']
checking file setup.cfg
Hunk #1 FAILED at 41.
1 out of 1 hunk FAILED
Warning: failed to download source.  If building, will try again after downloading recipe dependencies.
Error was: 
Command '['/opt/miniconda3/bin/patch', '--no-backup-if-mismatch', '--batch', '-Np0', '-i', '/tmp/tmpt8csnys_/remove-rapidgzip.patch.native', '--binary', '--dry-run']' returned non-zero exit status 1.

I'm not sure whether this applies to build, but it seems to be a ConfigParser problem for the other linked issues. This is documented behavior of ConfigParser and therefore unlikely to change. I think the easiest workaround, as already implied by the above diff commands, would be these steps:

  1. Generate new setup.cfg with ConfigParser
  2. Generate a diff ignoring whitespace changes with diff -w or an equivalent Python library.
  3. Apply the minimal non-whitespace-changing diff to the original setup.cfg.

(Removing the whitespaces I used for alignment might be contestable. But I think adding trailing whitespaces is unequivocally a worse style and I also have not seen tabs being used for indentation for quite a while and didn't expect that change.)

This belongs to setuptools. Please open an issue there.