Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
u committed Jan 12, 2025
1 parent 66d7a85 commit 288c2c1
Show file tree
Hide file tree
Showing 23 changed files with 990 additions and 105 deletions.
33 changes: 17 additions & 16 deletions py2pack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@
from py2pack.utils import (_get_archive_filelist, get_pyproject_table,
parse_pyproject, get_setuptools_scripts,
get_metadata)
import io
from email import parser
from packaging.requirements import Requirement

try:
import libarchive
except ModuleNotFoundError:
libarchive = None
import tarfile
import zipfile

try:
import distro
Expand Down Expand Up @@ -117,18 +113,20 @@ def pypi_json_stream(json_stream):


def pypi_archive_file(file_path):
if libarchive is None:
return None
is_tar = True
try:
with libarchive.file_reader(file_path) as archive:
for entry in archive:
# Check if the entry's pathname matches the target filename
if entry.pathname == 'PKG-INFO':
return pypi_text_stream(io.StringIO(entry.read().decode()))
else:
return None
archive = tarfile.open(file_path)
member = archive.getmember('PKG-INFO')
if member.isfile():
return pypi_text_stream(archive.extractfile(member))
except tarfile.ReadError:
archive = zipfile.ZipFile(file_path)
member = arcihve.getinfo('PKG-INFO')
if not member.is_dir():
return pypi_text_stream(archive.open(member))
except Exception:
return None
pass
return None


def _get_template_dirs():
Expand Down Expand Up @@ -444,6 +442,9 @@ def generate(args):

_normalize_license(data)

for i in ['license', 'source_url', 'home_page', 'summary_no_ending_dot', 'summary']:
data[i + '_singleline'] = str(data[i]).replace('\n', '')

env = _prepare_template_env(_get_template_dirs())
template = env.get_template(args.template)
result = template.render(data).encode('utf-8') # render template and encode properly
Expand Down
70 changes: 23 additions & 47 deletions py2pack/templates/fedora.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,21 @@
Name: python-%{pypi_name}
Version: {{ version }}
Release: %autorelease
Summary: {{ summary|replace('\n','') }}
Summary: {{ summary_singleline }}

# Check if the automatically generated License and its spelling is correct for Fedora
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
License: {{ license|replace('\n','') }}
URL: {{ home_page|replace('\n','') }}
Source: {{ source_url|replace(version, '%{version}')|replace('\n','') }}
License: {{ license_singleline }}
URL: {{ home_page_singleline }}
Source: {{ source_url_sinleline|replace(version, '%{version}') }}

BuildRequires: pyproject-rpm-macros
BuildRequires: python-devel
%if %{undefined python_module}
%define python_module() python3dist(%1)
%endif
BuildRequires: fdupes

{%- set build_requires_plus_pip = ((build_requires if build_requires and build_requires is not none else []) +
['pip']) %}
{%- for req in build_requires_plus_pip |sort %}
BuildRequires: %{python_module {{ req }}}
{%- endfor %}
{%- if (install_requires and install_requires is not none) or (tests_require and tests_require is not none) %}
# SECTION test requirements
%if %{with test}
{%- if install_requires and install_requires is not none %}
{%- for req in install_requires|reject("in",build_requires)|sort %}
BuildRequires: %{python_module {{ req }}}
{%- endfor %}
{%- endif %}
{%- if tests_require and tests_require is not none %}
{%- for req in tests_require|sort|reject("in",build_requires|sort) %}
BuildRequires: %{python_module {{ req }}}
{%- endfor %}
{%- endif %}
%endif
# /SECTION
{%- endif %}
{%- if source_url.endswith('.zip') %}
BuildRequires: unzip
{%- endif %}
BuildRequires: fdupes
{%- if install_requires and install_requires is not none %}
{%- for req in install_requires|sort %}
Requires: %{python_module {{ req }}}
{%- endfor %}
{%- endif %}
{%- if extras_require and extras_require is not none %}
{%- for reqlist in extras_require.values() %}
{%- for req in reqlist %}
Suggests: %{python_module {{ req }}}
{%- endfor %}
{%- endfor %}
{%- endif %}
{%- if not has_ext_modules %}
BuildArch: noarch
{%- endif %}
Expand All @@ -67,24 +31,33 @@ BuildArch: noarch
%package -n %{python_name}
Summary: %{summary}


{%- if provides_extra and provides_extra is not none %}
{%- set provides_extra_string = ','.join(provides_extra) %}
{%- set provides_extra_nonempty = 1 %}
{%- endif %}


%description -n %{python_name} %_description

{%- if provides_extra_nonempty %}
%pyproject_extras_subpkg -n %{python_name} {{ provides_extra_string }}
{%- endif %}

%prep
%autosetup -p1 -n %{pypi_name}-%{version}


%generate_buildrequires
%pyproject_buildrequires {% if provides_extra_nonempty %}-x {{ provides_extra_string }}{% endif %}


%build
%pyproject_wheel


%install
%pyproject_install
{%- set scripts_or_console_scripts = (
(scripts|map('basename')|list if scripts and scripts is not none else []) +
(console_scripts if console_scripts and console_scripts is not none else [])) %}
#{%- for script in scripts_or_console_scripts %}
#%python_clone -a %{buildroot}%{_bindir}/{{ script }}
#{%- endfor %}
# For official Fedora packages, including files with '*' +auto is not allowed
# Replace it with a list of relevant Python modules/globs and list extra files in %%files
%pyproject_save_files '*' +auto
Expand All @@ -93,6 +66,7 @@ Summary: %{summary}
{%- if testsuite or test_suite %}
%if %{with test}
%check
%pyproject_check_import
{%- if has_ext_modules %}
%pytest_arch
{%- else %}
Expand All @@ -101,8 +75,10 @@ Summary: %{summary}
%endif
{%- endif %}


%files -n %{python_name} -f %{pyproject_files}


%changelog
%autochangelog

Expand Down
8 changes: 4 additions & 4 deletions py2pack/templates/mageia.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
Name: python-%{mod_name}
Version: {{ version }}
Release: %mkrel 1
Url: {{ home_page|replace('\n','') }}
Summary: {{ summary|replace('\n','') }}
License: {{ license|replace('\n','') }}
Url: {{ home_page_singleline }}
Summary: {{ summary_singleline }}
License: {{ license_singleline }}
Group: Development/Python
Source: {{ source_url|replace(version, '%{version}')|replace('\n','') }}
Source: {{ source_url_singleline|replace(version, '%{version}') }}
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
BuildRequires: python-devel
{%- for req in requires %}
Expand Down
8 changes: 4 additions & 4 deletions py2pack/templates/opensuse-legacy.spec
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
Name: python-{{ name }}
Version: {{ version }}
Release: 0
Summary: {{ summary_no_ending_dot|default(summary, true)|replace('\n','') }}
License: {{ license|replace('\n','') }}
URL: {{ home_page|replace('\n','') }}
Source: {{ source_url|replace(version, '%{version}')|replace('\n','') }}
Summary: {{ summary_no_ending_dot_singleline|default(summary_singleline, true) }}
License: {{ license_singleline }}
URL: {{ home_page_singleline }}
Source: {{ source_url_singleline|replace(version, '%{version}') }}
BuildRequires: python-setuptools
{%- if install_requires and install_requires is not none %}
{%- for req in install_requires|sort %}
Expand Down
8 changes: 4 additions & 4 deletions py2pack/templates/opensuse.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
Name: python-{{ name }}
Version: {{ version }}
Release: 0
Summary: {{ summary_no_ending_dot|default(summary, true)|replace('\n','') }}
License: {{ license|replace('\n','') }}
URL: {{ home_page|replace('\n','') }}
Source: {{ source_url|replace(version, '%{version}')|replace('\n','') }}
Summary: {{ summary_no_ending_dot_singleline|default(summary_singleline, true) }}
License: {{ license_singleline }}
URL: {{ home_page_singleline }}
Source: {{ source_url_singleline|replace(version, '%{version}') }}
BuildRequires: python-rpm-macros
{%- set build_requires_plus_pip = ((build_requires if build_requires and build_requires is not none else []) +
['pip']) %}
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ homepage = "http://github.com/openSUSE/py2pack"

[project.optional-dependencies]
service = [
"libarchive-c",
"distro",
]

Expand Down
Loading

0 comments on commit 288c2c1

Please sign in to comment.