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

"SetuptoolsDeprecationWarning: Invalid version" error #2413

Closed
jcarnat opened this issue May 9, 2023 · 5 comments · Fixed by #2416
Closed

"SetuptoolsDeprecationWarning: Invalid version" error #2413

jcarnat opened this issue May 9, 2023 · 5 comments · Fixed by #2416
Labels
bug Something isn't working

Comments

@jcarnat
Copy link

jcarnat commented May 9, 2023

Hello,

I'm compiling searxng, from this repo, using the master branch.
I do it on OpenBSD if that matters.
I'm following the directions from https://docs.searxng.org/admin/installation-searxng.html.

At the "$ pip install -U -e ." step, I get loads of following errors:

Obtaining file:///home/searx/searxng-src                                                            
  Preparing metadata (setup.py) ... error                                                           
  error: subprocess-exited-with-error                                                               
                                                                                                    
  × python setup.py egg_info did not run successfully.                                              
  │ exit code: 1                                                                                    
  ╰─> [59 lines of output]                                                                          
      /home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/dist.py:520: SetuptoolsDepre
cationWarning: Invalid version: '-Y.-m.-d+0aade75e'.                                                
      !!                                                                                            
                                                                                                                  ********************************************************************************      
              The version specified is not a valid version according to PEP 440.                    
              This may not work as expected with newer versions of                                                setuptools, pip, and PyPI.                                                            
                                                                                                    
              By 2023-Sep-26, you need to update your project and remove deprecated calls                         or your builds will no longer be supported.
                                                                                                    
              See https://peps.python.org/pep-0440/ for details.                                    
              ********************************************************************************      
                                                                                                    
      !!                                                                                            
        self._validate_version(self.metadata.version)                                               
      2023-05-10 01:07:34,332 INFO:root: running egg_info                                           
      /home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/command/egg_info.py:131: Set
uptoolsDeprecationWarning: Invalid version: '-Y.-m.-d+0aade75e'.                                    
      !!                                                                                            
                                                                                                    
              ********************************************************************************      
              Version '-Y.-m.-d+0aade75e' is not valid according to PEP 440.                        
                                                                                                    
              Please make sure to specify a valid version for your package.                         
              Also note that future releases of setuptools may halt the build process               
              if an invalid version is given.                                                       
                                                                                                    
              By 2023-Sep-26, you need to update your project and remove deprecated calls           
              or your builds will no longer be supported.                                           
                                                                                                    
              See https://peps.python.org/pep-0440/ for details.                                    
              ********************************************************************************      
                                                                                                    
      !!                                                                                            
        return _normalization.best_effort_version(tagged)                                           
      Traceback (most recent call last):                                                            
        File "<string>", line 2, in <module>                                                        
        File "<pip-setuptools-caller>", line 34, in <module>                                        
        File "/home/searx/searxng-src/setup.py", line 19, in <module>                               
          setup(                                                                                    
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/__init__.py", line 1
07, in setup                                                                                        
          return distutils.core.setup(**attrs)                                                      
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/_distutils/core.py",
 line 185, in setup                                                                                 
          return run_commands(dist)                                                                 
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/_distutils/core.py",
 line 201, in run_commands                                                                          
          dist.run_commands()                                                                       
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/_distutils/dist.py",
 line 969, in run_commands                                                                          
          self.run_command(cmd)                                                                     
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/dist.py", line 1244,
 in run_command                                                                                     
          super().run_command(command)                                                              
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/_distutils/dist.py",
 line 987, in run_command                                                                           
          cmd_obj.ensure_finalized()                                                                
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 111, in ensure_finalized                                                                       
          self.finalize_options()                                                                   
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 219, in finalize_options                                                                     
          parsed_version = packaging.version.Version(self.egg_version)                              
        File "/home/searx/searxng-pyenv/lib/python3.10/site-packages/setuptools/_vendor/packaging/version.py", line 197, in __init__                                                                    
          raise InvalidVersion(f"Invalid version: '{version}'")                                     
      setuptools.extern.packaging.version.InvalidVersion: Invalid version: '-Y.-m.-d-0aade75e'      
      [end of output]                                                                               
                                                                                                    
  note: This error originates from a subprocess, and is likely not a problem with pip.              
error: metadata-generation-failed                                                                   
                                                                                                    
× Encountered error while generating package metadata.                                              
╰─> See above for output.                                                                           
                                                                                                    
note: This is an issue with the package mentioned above, not pip.                                   
hint: See above for details.

If I do the same steps using the master.zip archive, it compiles properly.
After a bunch of trial&errors and readings of bug reports, I identified a string format in searx/version.py that seem to be the root cause. If I modify the file as such

$ diff -U2 searxng-src/searx/version.py.orig searxng-src/searx/version.py
--- searxng-src/searx/version.py.orig   Wed May 10 00:52:40 2023
+++ searxng-src/searx/version.py        Wed May 10 01:13:43 2023
@@ -60,5 +60,5 @@
 
 def get_git_version():
-    git_commit_date_hash = subprocess_run(r"git show -s --date='format:%-Y.%-m.%-d' --format='%cd+%h'")
+    git_commit_date_hash = subprocess_run(r"git show -s --date='format:%Y.%m.%d' --format='%cd+%h'")
     tag_version = git_version = git_commit_date_hash

the compilation proceeds properly and python ~/searxng-src/searx/webapp.py runs properly.

I have very little knowledge in git and python so I'm not sure whether this is the proper way to correct the issue or not.

@jcarnat jcarnat added the bug Something isn't working label May 9, 2023
@return42
Copy link
Member

At the "$ pip install -U -e ." step, I get loads of following errors:

The version number is generated by a call of the git command that is installed on your host.
At this point of the installation procedure, what did this command spit out?

 $ git show -s --date='format:%-Y.%-m.%-d' --format='%cd+%h'"
 $ git --version

Related:

@jcarnat
Copy link
Author

jcarnat commented May 10, 2023

Here are the command outputs:

$ git show -s --date='format:%-Y.%-m.%-d' --format='%cd+%h'
-Y.-m.-d+0aade75e
$ git --version
git version 2.40.0

I also tried to following command:

$ git show -s --date='format:%Y.%m.%d' --format='%cd+%h'
2023.05.06+0aade75e

@return42
Copy link
Member

return42 commented May 10, 2023

Wow thats wired, your version is newer but did not support the minus -:

$ git show -s --date='format:%-Y.%-m.%-d' --format='%cd+%h'
2023.5.9+7fec6244a
$ git --version
git version 2.25.1

I also tried to following command:

$ git show -s --date='format:%Y.%m.%d' --format='%cd+%h'
2023.05.06+0aade75e

Sadly pip versioning scheme does not allow leading zeros in the version numbers .. we fixed this by adding the minus - in the format string 'format:%-Y.%-m.%-d'

Last year we had fixed a incompatibility with older git versions

Now we have a incompatibility with newer versions :-(

This needs to be fixed! We need an implementation that deals better with various git versions:

searxng/searx/version.py

Lines 61 to 62 in 0aade75

def get_git_version():
git_commit_date_hash = subprocess_run(r"git show -s --date='format:%-Y.%-m.%-d' --format='%cd+%h'")

One solution could be: we use git show -s --date='format:%Y.%m.%d' --format='%cd+%h' and delete the leading zeros in the minor and patch-level (2023.05.06) by a regular expression.

return42 added a commit to return42/searxng that referenced this issue May 10, 2023
Newer versions of git [1] do no longer support a format string that includes a minus
to remove leading zeros [2].  The format string '%Y.%m.%d'  is more version rod.

stable
[1] searxng#2413 (comment)
[2] https://github.com/searxng/searxng/pull/2122/files

Closes: searxng#2413
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
return42 added a commit to return42/searxng that referenced this issue May 10, 2023
Newer versions of git [1] do no longer support a format string that includes a minus
to remove leading zeros [2].  The format string '%Y.%m.%d'  is more version rod.

[1] searxng#2413 (comment)
[2] https://github.com/searxng/searxng/pull/2122/files

Closes: searxng#2413
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
@return42
Copy link
Member

I send PR

can you test it / thanks 👍

@jcarnat
Copy link
Author

jcarnat commented May 10, 2023

I have done the whole process of "git clone" + building from scratch and now it works!
Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants