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

fix bug: AttributeError: 'Namespace' object has no attribute 'localfile' for fetch command #196

Closed
wants to merge 7 commits into from
Closed
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
10 changes: 7 additions & 3 deletions py2pack/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def generate(args):
warnings.warn("the '--run' switch is deprecated and a noop",
DeprecationWarning)

fetch_data(args)
fetch_local_data(args)
if not args.template:
args.template = file_template_list()[0]
if not args.filename:
Expand Down Expand Up @@ -405,12 +405,12 @@ def generate(args):
outfile.close()


def fetch_data(args):
def fetch_local_data(args):
localfile = args.localfile
local = args.local

if not localfile and local:
localfile = f'{args.name}.egg-info/PKG-INFO'
localfile = os.path.join(f'{args.name}.egg-info', 'PKG-INFO')
if os.path.isfile(localfile):
try:
data = pypi_json_file(localfile)
Expand All @@ -419,6 +419,10 @@ def fetch_data(args):
args.fetched_data = data
args.version = args.fetched_data['info']['version']
return
fetch_data(args)


def fetch_data(args):
args.fetched_data = pypi_json(args.name, args.version)
urls = args.fetched_data['urls']
if len(urls) == 0:
Expand Down
120 changes: 84 additions & 36 deletions py2pack/templates/fedora.spec
Original file line number Diff line number Diff line change
@@ -1,61 +1,109 @@
#
# spec file for package python-{{ name }}
#
# Copyright (c) {{ year }} {{ user_name }}.
#

Name: python-{{ name }}
%define pypi_name {{ name }}
%define python_name python3-%{pypi_name}
Name: python-%{pypi_name}
Version: {{ version }}
Release: 0
Release: %autorelease
Summary: {{ summary }}

# Check if the automatically generated License and its spelling is correct for Fedora
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
License: {{ license }}
URL: {{ home_page }}
Source: {{ source_url|replace(version, '%{version}') }}
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: python-devel {%- if requires_python %} = {{ requires_python }} {% endif %}
{%- for req in requires %}
BuildRequires: python-{{ req|replace('(','')|replace(')','') }}
Requires: python-{{ req|replace('(','')|replace(')','') }}

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

{%- 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 %}
{%- for req in install_requires %}
BuildRequires: python-{{ req|replace('(','')|replace(')','') }}
Requires: python-{{ req|replace('(','')|replace(')','') }}
{%- 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 %}
{%- if extras_require %}
{%- 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-{{ req|replace('(','')|replace(')','') }}
Suggests: %{python_module {{ req }}}
{%- endfor %}
{%- endfor %}
{%- endif %}
{%- if not has_ext_modules %}
BuildArch: noarch
{%- endif %}

# Fill in the actual package description to submit package to Fedora
%global _description %{expand:
{{ description }}}

%description %_description

%package -n %{python_name}
Summary: %{summary}

%description -n %{python_name} %_description

%description
{{ description }}

%prep
%setup -q -n {{ name }}-%{version}
%autosetup -p1 -n %{pypi_name}-%{version}

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


%install
python setup.py install --prefix=%{_prefix} --root=%{buildroot}
%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

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root,-)
{%- if doc_files %}
%doc {{ doc_files|join(" ") }}
{%- if testsuite or test_suite %}
%if %{with test}
%check
{%- if has_ext_modules %}
%pytest_arch
{%- else %}
%pytest
{%- endif %}
%endif
{%- endif %}
{%- for script in scripts|default([], true) %}
%{_bindir}/{{ script }}
{%- endfor %}
%{python_sitelib}/*

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

%changelog
%autochangelog


80 changes: 80 additions & 0 deletions test/examples/py2pack-fedora-augmented.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
%define pypi_name py2pack
%define python_name python3-%{pypi_name}
Name: python-%{pypi_name}
Version: 0.8.5
Release: %autorelease
Summary: Generate distribution packages from PyPI

# Check if the automatically generated License and its spelling is correct for Fedora
# https://docs.fedoraproject.org/en-US/packaging-guidelines/LicensingGuidelines/
License: Apache-2.0
URL: http://github.com/openSUSE/py2pack
Source: https://files.pythonhosted.org/packages/source/p/py2pack/py2pack-%{version}.tar.gz

BuildRequires: pyproject-rpm-macros
BuildRequires: python-devel
%if %{undefined python_module}
%define python_module() python3dist(%1)
%endif
BuildRequires: %{python_module pbr >= 1.8}
BuildRequires: %{python_module pip}
BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module wheel}
# SECTION test requirements
%if %{with test}
BuildRequires: %{python_module Jinja2}
BuildRequires: %{python_module metaextract}
BuildRequires: %{python_module six}
BuildRequires: %{python_module coverage}
BuildRequires: %{python_module ddt}
BuildRequires: %{python_module flake8}
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module Sphinx >= 1.2.1}
BuildRequires: %{python_module sphinxcontrib.programoutput}
%endif
# /SECTION
BuildRequires: fdupes
Requires: %{python_module Jinja2}
Requires: %{python_module metaextract}
Requires: %{python_module setuptools}
Requires: %{python_module six}
Suggests: %{python_module typing}
BuildArch: noarch

# Fill in the actual package description to submit package to Fedora
%global _description %{expand:
Generate distribution packages from PyPI}

%description %_description

%package -n %{python_name}
Summary: %{summary}

%description -n %{python_name} %_description


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

%build
%pyproject_wheel


%install
%pyproject_install
#
#%python_clone -a %{buildroot}%{_bindir}/py2pack
#
# 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
%if %{with test}
%check
%pytest
%endif

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

%changelog
%autochangelog

Loading
Loading