File python-story.spec of Package python-story

# spec file for package python-story
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

%bcond_without check

%define use_nuitka3_standalone 1

%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
Name:           python-story
Version:        0.20.4
# Exports in check section can be removed in next release
Release:        0
Summary:        Storyscript Cloud CLI
License:        Apache-2.0
Group:          Development/Languages/Python
BuildRequires:  %{python_module setuptools_scm}
BuildRequires:  %{python_module setuptools}
BuildRequires:  clang
BuildRequires:  fdupes
BuildRequires:  python-rpm-macros
Requires:       python-PyYAML >= 4.2
Requires:       python-appdirs
Requires:       python-blindspin
Requires:       python-click >= 7.0
Requires:       python-click-completion >= 0.5.1
Requires:       python-click-help-colors >= 0.5
Requires:       python-click-spinner >= 0.1.8
Requires:       python-emoji >= 0.5.0
Requires:       python-pytz >= 2018.5
Requires:       python-raven >= 6.9.0
Requires:       python-requests >= 2.20.0
Requires:       python-semver
Requires:       python-storyscript >= 0.20.1
Requires:       python-texttable >= 1.4.0
Requires:       python-websockets >= 7.0
Requires:       python-xerox
Requires:       python3-story-stories = %{version}
#BuildArch:      noarch
# SECTION test requirements
BuildRequires:  %{python_module PyYAML >= 4.2}
BuildRequires:  %{python_module appdirs}
BuildRequires:  %{python_module blindspin}
BuildRequires:  %{python_module click >= 7.0}
BuildRequires:  %{python_module click-completion >= 0.5.1}
BuildRequires:  %{python_module click-help-colors >= 0.5}
BuildRequires:  %{python_module click-spinner >= 0.1.8}
BuildRequires:  %{python_module}
BuildRequires:  %{python_module emoji >= 0.5.0}
BuildRequires:  %{python_module pytest-asyncio}
BuildRequires:  %{python_module pytest-mock}
BuildRequires:  %{python_module pytest-runner}
BuildRequires:  %{python_module pytest}
BuildRequires:  %{python_module pytz >= 2018.5}
BuildRequires:  %{python_module raven >= 6.9.0}
BuildRequires:  %{python_module requests >= 2.20.0}
BuildRequires:  %{python_module semver}
BuildRequires:  %{python_module storyscript >= 0.23.4}
BuildRequires:  %{python_module texttable >= 1.4.0}
BuildRequires:  %{python_module websockets >= 7.0}
BuildRequires:  %{python_module xerox}
#BuildRequires:  gdb
BuildRequires:  zlib-devel
BuildRequires:  zlib-devel-static
BuildRequires:  libxcrypt-devel
BuildRequires:  libxcrypt-devel-static
#BuildRequires:  libopenssl-1_1-devel
BuildRequires:  libopenssl-1_1-devel-static
BuildRequires:  libffi-devel
BuildRequires:  libbz2-devel
BuildRequires:  uuid-devel
BuildRequires:  xz-devel
BuildRequires:  xz-static-devel


Storyscript Cloud CLI module.

%package -n story-cli-static
Summary:        Storyscript Cloud CLI binary
Group:          Development/Tools/Other

%description -n story-cli-static
Storyscript Cloud CLI binary.

%if 0
%package stories
Summary:        Stories for Storyscript Cloud CLI
Group:          Development/Tools/Other

%description stories
Stories for Storyscript Cloud CLI.

%setup -q -n story-%{version}
#sed -i '/asyncio/d'
sed -i 's/==/>=/g;s/~=/>=/g'

# Nuitka uses the standard for its entry point
cp story/ story/
sed -i 's/^from \. /from story /;s/from \./from story./' ./story/

python3 -c 'import _ctypes'
python3 -c 'import _ctypes; print(_ctypes.__file__)' ||:

python3 -c 'import sys; print(sys.builtin_module_names)'

%if 0%{?have_nuitka3} && ! 0%{?skip_nuitka3}
# Show that most of the packages are already pre-compiled, and the resources of them are prominent here for debugging
%python_expand find %{$python_sitelib} -not -name __pycache__ -and -not -name '*.pyi' | sort

export CFLAGS="%{optflags}"
# Ideally standalone build shouldnt need to have 'story' built and installed already, but I havent worked that out yet
# `install` fails without `build`, so need to build here.


# build standalone
%if 0%{?use_nuitka3_standalone}

%{python_expand # export PYTHONPATH=%{buildroot}%{$python_sitelib}

cp story/

echo '' >>
echo 'import storyhub' >>
echo 'import story.commands.apps' >>
echo 'import story.commands.template' >>

mv story .story
export CC=clang
export CXX=clang++
export LDFLAGS="-z nodeflib"
# top level module and 'main' are excluded
$python -m nuitka --explain-imports --standalone --recurse-all --recurse-stdlib --python-flag=no_site --show-progress --show-scons --unstripped --include-plugin-files /usr/lib/python3.7/site-packages/raven/ --verbose

%if 0
  --include-module story.api \
  --include-module story.awesome \
  --include-module story.cli \
  --include-module story.commands \
  --include-module story.commands.apps \
  --include-module story.commands.completion \
  --include-module story.commands.config \
  --include-module story.commands.deploy \
  --include-module \
  --include-module story.commands.login \
  --include-module story.commands.logout \
  --include-module story.commands.logs \
  --include-module story.commands.maintenance \
  --include-module story.commands.releases \
  --include-module story.commands.repl \
  --include-module story.commands.repl.Repl \
  --include-module story.commands.repl.Scope \
  --include-module \
  --include-module story.commands.status \
  --include-module story.commands.template \
  --include-module story.commands.test \
  --include-module story.commands.update \
  --include-module story.ensure \
  --include-module story.environment \
  --include-module story.helpers \
  --include-module story.helpers.aliases \
  --include-module story.helpers.datetime \
  --include-module story.helpers.didyoumean \
  --include-module story.options \
  --include-module \
  --include-module \
  --include-module story.utils \
  --include-module story.version \

mv .story story


find $output_dir

ls $output_dir

file $output_dir/cli
ls -al $output_dir/cli

mkdir -p %{buildroot}%{_libdir}/storyscript/cli
mv $output_dir/* %{buildroot}%{_libdir}/storyscript/cli

#cp -rp %{$python_sitelib}/storyhub* %{buildroot}%{_libdir}/storyscript/cli

mkdir -p %{buildroot}%{_bindir}
(cd %{buildroot}/%{_bindir} && ln -fs ../../%{_libdir}/storyscript/cli/cli story)

LD_LIBRARY_PATH=%{buildroot}%{_libdir}/storyscript/cli ldd %{buildroot}%{_bindir}/story

mkdir -p %{buildroot}/etc/
#echo %{_libdir}/storyscript/cli > %{buildroot}/etc/

# Horrible hack around for
# /home/abuild/rpmbuild/BUILDROOT/python-story-0.20.4-40.1.i386/usr/lib/python3.7/site-packages/story/commands/ in get_stories
# FileNotFoundError: [Errno 2] No such file or directory: '/home/abuild/rpmbuild/BUILDROOT/python-story-0.20.4-40.1.i386/usr/lib/python3.7/site-packages/stories'
# or when standalone cli
# ["FileNotFoundError: [Errno 2] No such file or directory: '/home/abuild/rpmbuild/BUILDROOT/python-story-0.20.4-0.i386/usr/lib/storyscript/cli/story/stories'", '  File "cli/", line 10, in <module>'

mkdir -p %{buildroot}%{_libdir}/storyscript/cli/story
#cp -r %{buildroot}%{$python_sitelib}/story/stories/ %{buildroot}%{$python_sitelib}
cp -r ./story/stories/ %{buildroot}%{_libdir}/storyscript/cli/story
cp -r ./story/stories/ %{buildroot}%{_libdir}/storyscript/cli/
# check it is there
ls %{buildroot}%{_libdir}/storyscript/cli/story/stories/http.story
# end of hack

# core dumped
#LD_LIBRARY_PATH=%{buildroot}%{_libdir}/storyscript/cli %{buildroot}%{_bindir}/story --help

#LD_LIBRARY_PATH=%{buildroot}%{_libdir}/storyscript/cli %{buildroot}%{_bindir}/story apps ||:


#%%python_expand %fdupes %{buildroot}%{$python_sitelib}

# endif standalone install

%if 0%{?use_nuitka3_standalone}




%if %{with check}
export LANG=en_US.UTF-8

# This was necessary, but maybe --ignore tests/integration/commands/ has meant it isnt getting coverage
#export PATH=%{buildroot}%{_bindir}:$PATH

export PYTHONPATH=%{buildroot}%{_libdir}/storyscript/cli/

mv story .story
#%%python_expand py.test-%{$python_bin_suffix} --ignore tests/integration/commands/ -k 'not test_apps_create and not api_throws_an_exception2'
mv .story story

%files %{python_files}
%license LICENSE

%if %{use_nuitka3_standalone}
%files -n story-cli-static
%license LICENSE
%dir %{_libdir}/storyscript/
#%%config /etc/