-
Notifications
You must be signed in to change notification settings - Fork 41
convert '~=' requirements specifier #184
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
c73c5bf
05ea1af
8480b03
b6ddbfa
c453612
664f317
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,12 @@ def fetch(args): | |
|
|
||
| def _canonicalize_setup_data(data): | ||
|
|
||
| def _search_requires(req, pat): | ||
| for arr in req: | ||
| if arr[0] == pat: | ||
| return 1 | ||
| return 0 | ||
|
|
||
| if data.get('build-system', None): | ||
| # PEP 518: 'requires' field is mandatory | ||
| data['build_requires'] = py2pack.requires._requirements_sanitize( | ||
|
|
@@ -160,14 +166,13 @@ def _canonicalize_setup_data(data): | |
| if isinstance(setup_requires, str): | ||
| setup_requires = setup_requires.splitlines() | ||
| # canonicalize to build_requires | ||
| data["build_requires"] = ['setuptools', 'wheel'] + \ | ||
| data["build_requires"] = [['setuptools'], ['wheel']] + \ | ||
| py2pack.requires._requirements_sanitize(setup_requires) | ||
| else: | ||
| # no build_requires means most probably legacy setuptools | ||
| data["build_requires"] = ['setuptools'] | ||
| if 'setuptools' in data['build_requires'] and 'wheel' not in data['build_requires']: | ||
| data['build_requires'] += ['wheel'] | ||
|
|
||
| data["build_requires"] = [['setuptools']] | ||
| if _search_requires(data['build_requires'], 'setuptools') and not _search_requires(data['build_requires'], 'wheel'): | ||
| data['build_requires'] += [['wheel']] | ||
| install_requires = ( | ||
| get_pyproject_table(data, "project.dependencies") or | ||
| get_pyproject_table(data, "tool.flit.metadata.requires") or | ||
|
|
@@ -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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| req[0] = "python-" + req[0] | ||
| part1 = " ".join(req[0:3]) | ||
| part2 = "" | ||
| if len(req) > 3: | ||
| req[3] = "python-" + req[3] | ||
| part2 = ", " + " ".join(req[3:]) | ||
| return part1 + part2 | ||
|
|
||
| def _parenthesize_version(req): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| print(req) | ||
| ret = req[0].lower() | ||
| ver = [] | ||
| if len(req) > 1: | ||
| print(req[1:2]) | ||
| if req[1] == '<': | ||
| req[1] = '<<' | ||
| if req[1] == '>': | ||
| req[1] = '>>' | ||
| ver.append(" (" + " ".join(req[1:3]) + ")") | ||
| if len(req) > 3: | ||
| if req[4] == '<': | ||
| req[4] = '<<' | ||
| if req[4] == '>': | ||
| req[4] = '>>' | ||
| ver.append(req[3].lower() + " (" + " ".join(req[4:6]) + ")") | ||
|
|
||
| if ver: | ||
| print(ver) | ||
| ret += ", ".join(ver) | ||
| return ret | ||
|
|
||
| env.filters['parenthesize_version'] = \ | ||
| lambda s: re.sub('([=<>]+)(.+)', r' (\1 \2)', s) | ||
| lambda s: _parenthesize_version(s) | ||
| env.filters['basename'] = \ | ||
| lambda s: s[s.rfind('/') + 1:] | ||
| env.filters['rpm_format_buildrequires'] = \ | ||
| lambda s: " ".join(s[0:3]) | ||
| env.filters['rpm_format_requires'] = \ | ||
| lambda s: _rpm_format_requires(s) | ||
| env.filters['sort_requires'] = \ | ||
| lambda s: sorted(s, key=lambda k: k[0].lower()) | ||
| env.filters['reject_pkg'] = \ | ||
| lambda s, req: s if not any(s[0] in sl for sl in req) else None | ||
| return env | ||
|
|
||
|
|
||
|
|
@@ -361,7 +407,7 @@ def generate(args): | |
| args.template = file_template_list()[0] | ||
| if not args.filename: | ||
| args.filename = "python-" + args.name + '.' + args.template.rsplit('.', 1)[1] # take template file ending | ||
| print('generating spec file for {0}...'.format(args.name)) | ||
| print('generating spec file for {0} using {1}...'.format(args.name, args.template)) | ||
| data = args.fetched_data['info'] | ||
| durl = newest_download_url(args) | ||
| source_url = data['source_url'] = (args.source_url or (durl and durl['url'])) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,4 +102,20 @@ def _requirements_sanitize(req_list): | |
| (Requirement(s.split("#", maxsplit=1)[0]) for s in req_list) | ||
| if _requirement_filter_by_marker(req) | ||
| ) | ||
| return [" ".join(req) for req in filtered_req_list] | ||
| out_list = [] | ||
| for req in filtered_req_list: | ||
| # Convert '~=' operator to something rpm and deb can understand | ||
| # abc ~= 1.1.1 | ||
| # should be converted into something like (for rpm) | ||
| # | ||
| # Requires: python-abc >= 1.1.1, python-abc < 1.2 | ||
| # BuildRequires: %{python_module abc >= 1.1.1} | ||
| if len(req) > 1 and req[1] == '~=': | ||
| req[1] = '>=' | ||
| v = req[2].split('.') | ||
| v.pop() | ||
|
Comment on lines
+115
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version in a |
||
| v[-1] = str(int(v[-1]) + 1) | ||
| req += [req[0], '<', ".".join(v)] | ||
| out_list.append(req) | ||
|
|
||
| return out_list | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
search_requiresfunction is not needed, this can be done with a list comprehension in a more pythonic way: