Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion py2pack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ def generate(args):
data['source_url'] = _get_source_url(args.name, url['filename'])
else:
data['source_url'] = args.name + '-' + args.version + '.zip'
data['year'] = datetime.datetime.now().year # set current year

now = datetime.datetime.now()
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change this? AFAICS you never use it in the fedora template..

Copy link
Author

Choose a reason for hiding this comment

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

I didn't feel like calling now() twice for no particular reason.

The 'year' was already initialized by the existing init ... that is not changed. (there is data['year'] = now.year)

I am adding template of 'changelog_date' in a format suitable for Fedora changes.
The 'changelog_date' is used in the spec file template.

data['year'] = now.year # set current year
data['changelog_date'] = now.strftime("%a %b %d %Y") # set date for RPM changelog
data['user_name'] = pwd.getpwuid(os.getuid())[4] # set system user (packager)
data['summary_no_ending_dot'] = re.sub('(.*)\.', '\g<1>', data.get('summary', ""))

Expand Down
166 changes: 141 additions & 25 deletions py2pack/templates/fedora.spec
Original file line number Diff line number Diff line change
@@ -1,27 +1,76 @@
#
# spec file for package python-{{ name }}
#
# Copyright (c) {{ year }} {{ user_name }}.
#
# specfile autogenerated by py2pack from {{ name }}
# Please delete the unused comments serving just as examples
# template based on
# https://fedoraproject.org/wiki/Packaging:Python#Example_common_spec_file
# https://fedoraproject.org/wiki/Packaging:SourceURL
# https://fedoraproject.org/wiki/Packaging:Guidelines

Name: python-{{ name }}
%global srcname {{ name }}
%global sum {{ summary }}

%global gituser acmegituser
%global gitname {{ name }}
%global commit 40-CHARACTER-HASH-VALUE
%global shortcommit %(c=%{commit}; echo ${c:0:7})

# Set to 0 to disable building of the python3 subpackage
%if 0%{?fedora} || ( 0%{?rhel} && 0%{?rhel} >= 7 )
%global with_python3 1
%endif

%if 0%{?rhel} && 0%{?rhel} <= 6
%{!?__python2: %global __python2 /usr/bin/python2}
%{!?python2_sitelib: %global python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
%{!?python2_sitearch: %global python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
%endif


Name: python-%{srcname}
Version: {{ version }}
Release: 0
Url: {{ home_page }}
Summary: {{ summary }}
License: {{ license }}
#Release: 1.git.%{shortcommit}%{?dist}
Release: 1%{?dist}
Summary: %{sum}
Group: Development/Languages/Python
Source: {{ source_url|replace(version, '%{version}') }}
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: python-devel {%- if requires_python %} = {{ requires_python }} {% endif %}

License: {{ license }}
#URL: https://pypi.python.org/pypi/{{ name }}
#URL: https://pypi.python.org/pypi/%{srcname}
#URL: https://github.com/%{gituser}/{{ name }}
#URL: https://github.com/%{gituser}/%{gitname}
URL: {{ home_page }}
#Source0: https://github.com/%{gituser}/%{srcname}/archive/%{commit}/%{name}-%{version}-%{shortcommit}.tar.gz
#Source0: http://downloads.sourceforge.net/%{name}/%{name}-%{version}.tar.gz
#Source0: https://files.pythonhosted.org/packages/source/e/%{srcname}/%{srcname}-%{version}.tar.gz
Source0: {{ source_url|replace(version, '%{version}')|replace(name, '%{srcname}') }}

{%- if not is_extension %}
BuildArch: noarch
{%- else %}
BuildRequires: gcc
BuildRequires: libtool
BuildRequires: python2-devel
BuildRequires: python-libs
%if 0%{?with_python3}
BuildRequires: python%{python3_pkgversion}-devel
BuildRequires: python%{python3_pkgversion}-libs
%endif # if with_python3
{%- endif %}

BuildRequires: python-setuptools
%if 0%{?with_python3}
BuildRequires: python%{python3_pkgversion}-setuptools
%endif # if with_python3

{%- for req in requires %}
BuildRequires: python-{{ req|replace('(','')|replace(')','') }}
Requires: python-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}

{%- for req in install_requires %}
BuildRequires: python-{{ req|replace('(','')|replace(')','') }}
Requires: python-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}

{%- if extras_require %}
{%- for reqlist in extras_require.values() %}
{%- for req in reqlist %}
Expand All @@ -30,33 +79,100 @@ Suggests: python-{{ req|replace('(','')|replace(')','') }}
{%- endfor %}
{%- endif %}



%description
{{ description }}

%package -n python2-%{srcname}
Summary: %{sum}
%{?python_provide:%python_provide python2-%{srcname}}

%description -n python2-%{srcname}
An python2 module {{ name }}.


%if 0%{?with_python3}
%package -n python3-%{srcname}
Summary: %{sum}
%{?python_provide:%python_provide python3-%{srcname}}

%description -n python3-%{srcname}
An python3 module {{ name }}.
%endif # with_python3


#===============================================================================
%prep
%setup -q -n {{ name }}-%{version}
#setup -q -n %{srcname}-%{version}
#autosetup -n %{gitname}-%{commit}
%autosetup -n %{srcname}-%{version}



#===============================================================================
%build
{%- if is_extension %}
export CFLAGS="%{optflags}"
{%- endif %}
python setup.py build
#python setup.py build
%py2_build

%if 0%{?with_python3}
%py3_build
%endif # with_python3



#===============================================================================
%install
python setup.py install --prefix=%{_prefix} --root=%{buildroot}
#python setup.py install --prefix=%{_prefix} --root=%{buildroot}
# Must do the python2 install first because the scripts in /usr/bin are
# overwritten with every setup.py install, and in general we want the
# python3 version to be the default.
# If, however, we're installing separate executables for python2 and python3,
# the order needs to be reversed so the unversioned executable is the python2 one.
%py2_install

%if 0%{?with_python3}
%py3_install
%endif # with_python3



#===============================================================================
%check
%{__python2} setup.py test

%if 0%{?with_python3}
%{__python3} setup.py test
%endif # with_python3

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root,-)

#===============================================================================
# Note that there is no %%files section for the unversioned python module if we are building for several python runtimes
%files -n python2-%{srcname}
#%license COPYING
{%- if doc_files %}
%doc {{ doc_files|join(" ") }}
{%- endif %}
%{python2_sitelib}/*
{%- for script in scripts %}
%{_bindir}/{{ script }}
{%- endfor %}
%{python_sitelib}/*

%changelog
%if 0%{?with_python3}
%files -n python3-%{srcname}
#%license COPYING
{%- if doc_files %}
%doc {{ doc_files|join(" ") }}
{%- endif %}
%{python3_sitelib}/*
{%- for script in scripts %}
%{_bindir}/{{ script }}
{%- endfor %}
%endif # with_python3


#===============================================================================
%changelog
* {{ changelog_date }} {{ user_name }} <packager@example.com> - {{ version }}-1
- initial {{ name }} package for Fedora generated with py2pack