Skip to content

Commit

Permalink
Implement support for specific python versions #16
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMEEE committed Mar 28, 2024
1 parent 39c562f commit 5df10c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
21 changes: 14 additions & 7 deletions pyp2spec/conf2spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def wrap_description(config):
break_long_words=False
)

def fill_in_template(config):
def fill_in_template(config, python_version):
"""Return template rendered with data from config file."""

with (files("pyp2spec") / TEMPLATE_FILENAME).open("r", encoding="utf-8") as f:
Expand All @@ -152,6 +152,7 @@ def fill_in_template(config):
name=config.get_string("pypi_name"),
python_name=config.get_string("python_name"),
pypi_version=config.get_string("pypi_version"),
python_version=python_version,
source=config.get_string("source"),
summary=config.get_string("summary"),
test_method=generate_check(config),
Expand All @@ -163,11 +164,11 @@ def fill_in_template(config):
return result


def save_spec_file(config, output):
def save_spec_file(config, output, python_version):
"""Save the spec file in the current directory if custom output is not set.
Return the saved file name."""

result = fill_in_template(config)
result = fill_in_template(config, python_version)
if output is None:
output = config.get_string("python_name") + ".spec"
with open(output, "w", encoding="utf-8") as spec_file:
Expand All @@ -176,10 +177,10 @@ def save_spec_file(config, output):
return output


def create_spec_file(config_file, spec_output=None):
def create_spec_file(config_file, spec_output=None, python_version=None):
"""Create and save the generate spec file."""
config = ConfigFile(config_file)
return save_spec_file(config, spec_output)
return save_spec_file(config, spec_output, python_version)


@click.command()
Expand All @@ -189,9 +190,15 @@ def create_spec_file(config_file, spec_output=None):
"-o",
help="Provide custom output for spec file",
)
def main(config, spec_output):
@click.option(
"--python-version",
"-p",
help="Specify specific python version to build for, e.g 3.11",
)

def main(config, spec_output, python_version):
try:
create_spec_file(config, spec_output)
create_spec_file(config, spec_output, python_version)
except (Pyp2specError, NotImplementedError) as exc:
click.secho(f"Fatal exception occurred: {exc}", fg="red")
sys.exit(1)
Expand Down
27 changes: 24 additions & 3 deletions pyp2spec/template.spec
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{% if python_version %}
%global python3_pkgversion {{ python_version }}

{% endif -%}
Name: {{python_name}}
Version: {{version}}
Release: %autorelease
Expand All @@ -11,7 +15,11 @@ Source: {{source}}
{% if not archful %}
BuildArch: noarch
{%- endif %}
{% if python_version %}
BuildRequires: python%{python3_pkgversion}-devel
{% else -%}
BuildRequires: python3-devel
{% endif -%}
{% for br in additional_build_requires -%}
BuildRequires: {{br}}
{% endfor %}
Expand All @@ -21,15 +29,25 @@ BuildRequires: {{br}}
{{description}}}

%description %_description

{% if python_version %}
%package -n python%{python3_pkgversion}-{{name}}
{% else %}
%package -n python3-{{name}}
{% endif -%}
Summary: %{summary}

{% if python_version %}
%description -n python%{python3_pkgversion}-{{name}} %_description
{% else %}
%description -n python3-{{name}} %_description
{% endif -%}
{% if extras %}
# For official Fedora packages, review which extras should be actually packaged
# See: https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#Extras
{%- if python_version %}
%pyproject_extras_subpkg -n python%{python3_pkgversion}-{{name}} {{extras}}
{% else %}
%pyproject_extras_subpkg -n python3-{{name}} {{extras}}
{% endif -%}
{% endif %}

%prep
Expand Down Expand Up @@ -59,8 +77,11 @@ Summary: %{summary}
{% if test_method -%}
{{test_method}}
{% endif %}

{% if python_version %}
%files -n python%{python3_pkgversion}-{{name}} -f %{pyproject_files}
{% else %}
%files -n python3-{{name}} -f %{pyproject_files}
{% endif -%}
{% if doc_files -%}
%doc {{doc_files}}
{% endif -%}
Expand Down

0 comments on commit 5df10c0

Please sign in to comment.