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

convert '~=' requirements specifier #184

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

M0ses
Copy link
Contributor

@M0ses M0ses commented Nov 17, 2023

As described in #183 '~=' is not a valid version specifier for rpm and
deb packages.

This patch converts the specifier to valid version specifiers for
rpm/deb.

Examples:

abc ~= 1.1.1

  • in rpm:
BuildRequires: %{python_module abc >= 1.1.1} # Only for suse
Requires: python-abc >= 1.1.1, python-abc < 1.2
  • in deb:
Depends: python-abc (>= 1.1.1), python-abc (<< 1.2)

FIXES: #183
An schould also fix
FIXES: #93

@s-t-e-v-e-n-k
Copy link

Debian also has BuildDepends like BuildRequires, so you should extend this.

@M0ses
Copy link
Contributor Author

M0ses commented Nov 17, 2023

Debian Build-Depends should be fixed now by

20a8be8#diff-e1680efd70b630a38d8132340a9f77468b13b34f3b4162ceb1a8749bc1267665R8

@s-t-e-v-e-n-k
Copy link

@M0ses Hi, do you have time to rebase this to fix the conflicts?

M0ses added 6 commits August 8, 2024 08:22
As described in openSUSE#183 '~=' is not a valid version specifier for rpm and
deb packages.

This patch converts the specifier to valid version specifiers for
rpm/deb.

Examples:

`abc ~= 1.1.1`

* in rpm:

```
BuildRequires: %{python_module abc >= 1.1.1} # Only for suse
Requires: python-abc >= 1.1.1, python-abc < 1.2
```

* in deb:

```
Depends: python-abc (>= 1.1.1), python-abc (<< 1.2)
```

FIXES: openSUSE#183
An schould also fix
FIXES: openSUSE#93
@M0ses M0ses force-pushed the convert_requires branch from ee62f7b to 664f317 Compare August 8, 2024 06:34
Copy link
Contributor

@danigm danigm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me, I've left some comments to try to simplify the code, but the new functionality looks good.

The change of the requires list to a list of list with a [PACKAGE, OP, VERSION] is asking for a change to create a new class to define a requirement and move all the operations to that class, but that's something that can be done after merging, just OOP stuff.

Comment on lines +132 to +136
if "entry_points" not in data or not data['entry_points']:
return []
if isinstance(data["entry_points"], str):
eps = EntryPoints(EntryPoints._from_text(data["entry_points"]))
elif isinstance(data["entry_points"], dict):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change break the following code, because entry_points is not defined and it's used below.

And I think this change is not needed, it's doing the same. If data['entry_points'] is None the if isinstance(data["entry_points"], str): and elif isinstance(data["entry_points"], dict): will be false so it'll go to the else clause and will return []

req += [req[0], '<', ".".join(v)]
out_list.append(req)

return out_list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding this code correctly, the return now is a list of lists, so we should update the documentation of this method to match the new way of producing the output.

Comment on lines +115 to +116
v = req[2].split('.')
v.pop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version in a ~= requirement could be something without dots (abc ~= 3)? In that case, this can remove the version completely and will crash in the following line. But I'm not sure if that case is something that makes sense.

data['build_requires'] += ['wheel']

data["build_requires"] = [['setuptools']]
if _search_requires(data['build_requires'], 'setuptools') and not _search_requires(data['build_requires'], 'wheel'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search_requires function is not needed, this can be done with a list comprehension in a more pythonic way:

# Just the list of requires packages, without version information
require_names = [r[0] for r in data['build_requires']]
if 'setuptools' in require_names and 'wheel' not in require_names:

@@ -336,10 +341,51 @@ def _normalize_license(data):
def _prepare_template_env(template_dir):
# setup jinja2 environment with custom filters
env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))

def _rpm_format_requires(req):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This function does complex require formatting, it could be great to have some comment with examples of what it does, input -> output so it will be easier to understand in the future.

part2 = ", " + " ".join(req[3:])
return part1 + part2

def _parenthesize_version(req):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This function does complex require formatting, it could be great to have some comment with examples of what it does, input -> output so it will be easier to understand in the future.

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 this pull request may close these issues.

requires containing '~=' result in broken spec file Support for wheels
3 participants