Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Pint from PyPi to RPM wrongly resolves version #1771

Open
John-James-Rambo opened this issue Mar 12, 2021 · 8 comments
Open

Building Pint from PyPi to RPM wrongly resolves version #1771

John-James-Rambo opened this issue Mar 12, 2021 · 8 comments

Comments

@John-James-Rambo
Copy link

Since Pint version 1.10 fpm cannot build proper version of this project with distutils. It downloads proper version but in metadata it shows "version"=>"0.0.0". I guess it's not only with RPM, but only tried it with it.

I believe it's because Pint project changed distribution method to something called zest.releaser. They removed version from setup.py and moved it to different file which is used somehow in setup.cfg. I have no idea how it works and I'm not sure if this is solvable here.

I tried to use --version flag but it didn't changed the output package version. Maybe there is some different flag to set the output version so I could use it as a workaround?

{:timestamp=>"2021-03-12T11:18:32.169172+0000", :message=>"Setting workdir", :workdir=>"/tmp", :level=>:info}
{:timestamp=>"2021-03-12T11:18:32.172077+0000", :message=>"Trying to download", :package=>"Pint", :level=>:info}
{:timestamp=>"2021-03-12T11:18:32.550441+0000", :message=>"Collecting Pint", :level=>:info}
{:timestamp=>"2021-03-12T11:18:35.108201+0000", :message=>"  Downloading https://files.pythonhosted.org/packages/2b/d4/18becb51e9e242640010362b38dde187ecc0d5caeb0a689a2a60083b1ca3/Pint-0.16.1.tar.gz (261kB)", :level=>:info}
{:timestamp=>"2021-03-12T11:18:35.510602+0000", :message=>"  Saved ./Pint-0.16.1.tar.gz", :level=>:info}
{:timestamp=>"2021-03-12T11:18:40.601604+0000", :message=>"Successfully downloaded Pint", :level=>:info}
{:timestamp=>"2021-03-12T11:18:41.177734+0000", :message=>"fetching package metadata", :setup_cmd=>"env PYTHONPATH=/usr/local/share/gems/gems/fpm-1.11.0/lib/fpm/package python3.6 setup.py --command-packages=pyfpm get_metadata --output=/tmp/package-python-build-a21e16304cf8d6cbb1c124fa65d0e9643a13abd2114f3e2ccbe40cefdc11/metadata.json", :level=>:info}
{:timestamp=>"2021-03-12T11:18:41.435713+0000", :message=>"running get_metadata", :level=>:info}
{:timestamp=>"2021-03-12T11:18:41.459273+0000", :message=>"object output of get_metadata", :json=>{"name"=>"Pint", "version"=>"0.0.0", "author"=>"Hernan E. Grecco <[email protected]>", "description"=>"Physical quantities module", "license"=>"BSD", "url"=>"https://github.com/hgrecco/pint", "architecture"=>"all", "dependencies"=>["packaging"]}, :level=>:info}
@rooterkyberian
Copy link

packages I have seen affected so far:

importlib-resources 5.3.0
importlib-metadata 4.8.1
zipp

but surprising, the:

importlib-metadata 1.3.0

is not affected. As indicated by original report above it depends how package is defined.

This is not rpm specific as #1824 shows.

@rooterkyberian
Copy link

I have played some time with this, and I believe the issues sprout from using setup.py.

AFAIK #1821 will fix at least the installed PKG_INFO version which breaks runtime.

Something that may/may not be fixed is get_metadata script. For I had some success with following patch:

diff --git a/lib/fpm/package/pyfpm/get_metadata.py b/lib/fpm/package/pyfpm/get_metadata.py
index a88d79e..361ab56 100644
--- a/lib/fpm/package/pyfpm/get_metadata.py
+++ b/lib/fpm/package/pyfpm/get_metadata.py
@@ -29,12 +29,15 @@ class get_metadata(Command):
     user_options = [
         ('load-requirements-txt', 'l',
          "load dependencies from requirements.txt"),
+        ('pep517', None,
+         "Use PEP 517 for metadata"),
         ("output=", "o", "output destination for metadata json")
     ]
-    boolean_options = ['load-requirements-txt']
+    boolean_options = ['load-requirements-txt', "pep517"]
 
     def initialize_options(self):
         self.load_requirements_txt = False
+        self.pep517 = False
         self.cwd = None
         self.output = None
 
@@ -62,6 +65,16 @@ class get_metadata(Command):
         return deps
 
     def run(self):
+        if self.pep517:
+            from pep517 import meta
+            import io
+            
+            distribution = meta.load(self.cwd)
+            with io.StringIO() as buf:
+                buf.write(distribution.metadata.as_string())
+                buf.seek(0)
+                self.distribution.metadata.read_pkg_file(buf)
+
         data = {
             "name": self.distribution.get_name(),
             "version": self.distribution.get_version(),

@rooterkyberian
Copy link

in the mean time, my workaround for rpm packages:

mkdir rpmrebuild && wget -nv https://sourceforge.net/projects/rpmrebuild/files/rpmrebuild/2.16/rpmrebuild-2.16.tar.gz/download -O- | tar xvz  -C rpmrebuild
./rpmrebuild/rpmrebuild.sh --package --change-files='find "$RPM_BUILD_ROOT" -type f -name PKG-INFO -exec sed -i "s/^Version: 0\.0\.0$/Version: '$VERSION'/" {} +' -d ./new_pkg/ ./FPM_GENERATED_FPM_I_WANT_FIXED.rpm
cp ./new_pkg/*/*.rpm *.rpm

Please note, I suspect not only Version is invalid, but dependencies as well, so this is a very crude workaround.

@jordansissel
Copy link
Owner

in the mean time, my workaround for rpm packages:

fpm has a built-in way to do this: fpm -s rpm -t rpm -v 1.2.3 whatever.rpm will read whatever.rpm and set the version to 1.2.3 and write a new rpm output.

@jordansissel
Copy link
Owner

jordansissel commented Nov 9, 2021

I'm trying to find a solution for this but I can't even get Pint downloaded to even try packaging. If I use the same pip command that fpm (on a branch #1820) uses, it fails:

% python3 -m pip download --no-clean --no-deps --no-binary :all: -i https://pypi.python.org/simple --build /tmp/z Pint
Looking in indexes: https://pypi.python.org/simple
Collecting Pint
  Using cached Pint-0.18.tar.gz (272 kB)
  Installing build dependencies ... error
...
      LookupError: https://files.pythonhosted.org/packages/aa/5b/62165da80cbc6e1779f342234c7ddc6c6bc9e64cef149046a9c0456f912b/tomli-1.2.2.tar.gz#sha256=c6ce0015eb38820eaf32b5db832dbc26deb3dd427bd5f6556cf0acac2c214fee (from https://pypi.org/simple/tomli/) (requires-python:>=3.6) is already being built: tomli>=1.0 from https://files.pythonhosted.org/packages/aa/5b/62165da80cbc6e1779f342234c7ddc6c6bc9e64cef149046a9c0456f912b/tomli-1.2.2.tar.gz#sha256=c6ce0015eb38820eaf32b5db832dbc26deb3dd427bd5f6556cf0acac2c214fee
      ----------------------------------------
    ERROR: Command errored out with exit status 2: /usr/bin/python3 /usr/lib/python3/dist-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-smkwza9y/overlay --no-warn-script-location --no-binary :all: --only-binary :none: -i https://pypi.python.org/simple -- 'flit_core>=3.2.0,<4' Check the logs for full command output.
    ----------------------------------------
  ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/lib/python3/dist-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-f7jydubf/overlay --no-warn-script-location --no-binary :all: --only-binary :none: -i https://pypi.python.org/simple -- 'setuptools>=45' wheel 'tomli>=1.0' 'packaging>=20.0' Check the logs for full command output.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/lib/python3/dist-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-oqzrghqx/overlay --no-warn-script-location --no-binary :all: --only-binary :none: -i https://pypi.python.org/simple -- 'setuptools>=41' wheel 'setuptools_scm[toml]>=3.4.3' Check the logs for full command output.

@jordansissel
Copy link
Owner

Attempting to install a source package fails with pip:

%python3 -m pip install --no-binary :all: Pint
...
      LookupError: https://files.pythonhosted.org/packages/aa/5b/62165da80cbc6e1779f342234c7ddc6c6bc9e64cef149046a9c0456f912b/tomli-1.2.2.tar.gz#sha256=c6ce0015eb38820eaf32b5db832dbc26deb3dd427bd5f6556cf0acac2c214fee (from https://pypi.org/simple/tomli/) (requires-python:>=3.6) is already being built: tomli>=1.0 from https://files.pythonhosted.org/packages/aa/5b/62165da80cbc6e1779f342234c7ddc6c6bc9e64cef149046a9c0456f912b/tomli-1.2.2.tar.gz#sha256=c6ce0015eb38820eaf32b5db832dbc26deb3dd427bd5f6556cf0acac2c214fee

I confess I"m not sure exactly how to resolve this right now. Until I can get pip to download/install this package without crashing, I'm probably stuck.

@rooterkyberian
Copy link

in the mean time, my workaround for rpm packages:

fpm has a built-in way to do this: fpm -s rpm -t rpm -v 1.2.3 whatever.rpm will read whatever.rpm and set the version to 1.2.3 and write a new rpm output.

it doesn't change what is important for python runtime, i.e. PKG-INFO version.

The problem is that Python will check at runtime if dependencies are matching by checking PKG-INFO
If not, error like this can be returned:

pkg_resources.DistributionNotFound: The 'importlib-resources>=5' distribution was not found and is required by ocrmypdf

So I modify importlib_resources-0.0.0-py3.6.egg-info/PKG-INFO with the version I know was requested in the first place.

@jordansissel
Copy link
Owner

jordansissel commented Nov 10, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants