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

Invalid version string #262

Closed
moubctez opened this issue Jul 5, 2022 · 5 comments · Fixed by #263
Closed

Invalid version string #262

moubctez opened this issue Jul 5, 2022 · 5 comments · Fixed by #263

Comments

@moubctez
Copy link

moubctez commented Jul 5, 2022

Getting Rust version produces incorrect result:

  File "/dist/pkg/lib/python3.10/site-packages/setuptools_rust/rustc_info.py", line 13, in get_rust_version
    return Version(_rust_version_verbose().split(" ")[1])
  File "/dist/pkg/lib/python3.10/site-packages/semantic_version/base.py", line 105, in __init__
    major, minor, patch, prerelease, build = self.parse(version_string, partial)
  File "/dist/pkg/lib/python3.10/site-packages/semantic_version/base.py", line 318, in parse
    raise ValueError('Invalid version string: %r' % version_string)
ValueError: Invalid version string: '1.62.0\nbinary:'

That's because the output of rustc -Vv is being split by a single space (" "), and the new-line character stays.

I had to fix it with this patch:

--- setuptools_rust/rustc_info.py.orig	2022-07-05 06:20:44.000000000 +0000
+++ setuptools_rust/rustc_info.py
@@ -10,7 +10,7 @@ def get_rust_version() -> Optional[Versi
     try:
         # first line of rustc -Vv is something like
         # rustc 1.61.0 (fe5b13d68 2022-05-18)
-        return Version(_rust_version_verbose().split(" ")[1])
+        return Version(_rust_version().split(" ")[1])
     except (subprocess.CalledProcessError, OSError):
         return None
 
@@ -59,5 +59,10 @@ def get_rust_target_list() -> List[str]:
 
 
 @lru_cache()
+def _rust_version() -> str:
+    return subprocess.check_output(["rustc", "-V"], text=True)
+
+
+@lru_cache()
 def _rust_version_verbose() -> str:
     return subprocess.check_output(["rustc", "-Vv"], text=True)
@DerDummePunkt
Copy link

Running into the same issue when trying to install python / cryptography on armv6

#0 150.4       running build_rust
#0 150.4       
#0 150.4           =============================DEBUG ASSISTANCE=============================
#0 150.4           If you are seeing a compilation error please try the following steps to
#0 150.4           successfully install cryptography:
#0 150.4           1) Upgrade to the latest pip and try again. This will fix errors for most
#0 150.4              users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
#0 150.4           2) Read https://cryptography.io/en/latest/installation/ for specific
#0 150.4              instructions for your platform.
#0 150.4           3) Check our frequently asked questions for more information:
#0 150.4              https://cryptography.io/en/latest/faq/
#0 150.4           4) Ensure you have a recent Rust toolchain installed:
#0 150.4              https://cryptography.io/en/latest/installation/#rust
#0 150.4       
#0 150.4           Python: 3.8.13
#0 150.4           platform: Linux-5.18.6-1-MANJARO-armv7l-with-glibc2.4
#0 150.4           pip: n/a
#0 150.4           setuptools: 63.1.0
#0 150.4           setuptools_rust: 1.4.0
#0 150.4           =============================DEBUG ASSISTANCE=============================
#0 150.4       
#0 150.4       Traceback (most recent call last):
#0 150.4         File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
#0 150.4           main()
#0 150.4         File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
#0 150.4           json_out['return_val'] = hook(**hook_input['kwargs'])
#0 150.4         File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel
#0 150.4           return _build_backend().build_wheel(wheel_directory, config_settings,
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 244, in build_wheel
#0 150.4           return self._build_with_temp_dir(['bdist_wheel'], '.whl',
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 229, in _build_with_temp_dir
#0 150.4           self.run_setup()
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 174, in run_setup
#0 150.4           exec(compile(code, __file__, 'exec'), locals())
#0 150.4         File "setup.py", line 39, in <module>
#0 150.4           setup(
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/__init__.py", line 87, in setup
#0 150.4           return distutils.core.setup(**attrs)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 177, in setup
#0 150.4           return run_commands(dist)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 193, in run_commands
#0 150.4           dist.run_commands()
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 968, in run_commands
#0 150.4           self.run_command(cmd)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 1217, in run_command
#0 150.4           super().run_command(command)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
#0 150.4           cmd_obj.run()
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 299, in run
#0 150.4           self.run_command('build')
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 317, in run_command
#0 150.4           self.distribution.run_command(command)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 1217, in run_command
#0 150.4           super().run_command(command)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
#0 150.4           cmd_obj.run()
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/command/build.py", line 24, in run
#0 150.4           super().run()
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/command/build.py", line 131, in run
#0 150.4           self.run_command(cmd_name)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 317, in run_command
#0 150.4           self.distribution.run_command(command)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 1217, in run_command
#0 150.4           super().run_command(command)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
#0 150.4           cmd_obj.run()
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/cffi/setuptools_ext.py", line 144, in run
#0 150.4           base_class.run(self)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools_rust/setuptools_ext.py", line 134, in run
#0 150.4           build_rust.run()
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools_rust/command.py", line 57, in run
#0 150.4           version = get_rust_version()
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/setuptools_rust/rustc_info.py", line 13, in get_rust_version
#0 150.4           return Version(_rust_version_verbose().split(" ")[1])
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/semantic_version/base.py", line 105, in __init__
#0 150.4           major, minor, patch, prerelease, build = self.parse(version_string, partial)
#0 150.4         File "/tmp/pip-build-env-x3h2talf/overlay/lib/python3.8/site-packages/semantic_version/base.py", line 318, in parse
#0 150.4           raise ValueError('Invalid version string: %r' % version_string)
#0 150.4       ValueError: Invalid version string: '1.48.0\nbinary:'
#0 150.4       [end of output]

@shernshiou
Copy link

Getting Rust version produces incorrect result:

  File "/dist/pkg/lib/python3.10/site-packages/setuptools_rust/rustc_info.py", line 13, in get_rust_version
    return Version(_rust_version_verbose().split(" ")[1])
  File "/dist/pkg/lib/python3.10/site-packages/semantic_version/base.py", line 105, in __init__
    major, minor, patch, prerelease, build = self.parse(version_string, partial)
  File "/dist/pkg/lib/python3.10/site-packages/semantic_version/base.py", line 318, in parse
    raise ValueError('Invalid version string: %r' % version_string)
ValueError: Invalid version string: '1.62.0\nbinary:'

That's because the output of rustc -Vv is being split by a single space (" "), and the new-line character stays.

I had to fix it with this patch:

--- setuptools_rust/rustc_info.py.orig	2022-07-05 06:20:44.000000000 +0000
+++ setuptools_rust/rustc_info.py
@@ -10,7 +10,7 @@ def get_rust_version() -> Optional[Versi
     try:
         # first line of rustc -Vv is something like
         # rustc 1.61.0 (fe5b13d68 2022-05-18)
-        return Version(_rust_version_verbose().split(" ")[1])
+        return Version(_rust_version().split(" ")[1])
     except (subprocess.CalledProcessError, OSError):
         return None
 
@@ -59,5 +59,10 @@ def get_rust_target_list() -> List[str]:
 
 
 @lru_cache()
+def _rust_version() -> str:
+    return subprocess.check_output(["rustc", "-V"], text=True)
+
+
+@lru_cache()
 def _rust_version_verbose() -> str:
     return subprocess.check_output(["rustc", "-Vv"], text=True)

I can confirm this patch works. Can you submit a pull request to solve it? Thanks

@ostefano
Copy link

ostefano commented Jul 5, 2022

Fix works here are as well.

New release would be nice because setuptools-rust is used by pipenv at build time (so hot-patching not trivial).

@gaige
Copy link

gaige commented Jul 5, 2022

Running into the same problem on Solaris/Illumos/SmartOS.

For reference, rustc -V output is

rustc 1.60.0

and rustc -Vv output is:

rustc 1.60.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-illumos
release: 1.60.0
LLVM version: 13.0.1

tjwalton added a commit to tjwalton/setuptools-rust that referenced this issue Jul 5, 2022
@davidhewitt
Copy link
Member

Thanks all and sorry about this bug. Will push a patch release as soon as I can get to a computer.

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

Successfully merging a pull request may close this issue.

6 participants