File osc.spec of Package osc

# spec file for package osc
# Copyright (c) 2024 SUSE LLC
# 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

%define use_python python3
%define use_python_pkg python3

%if 0%{?suse_version} && 0%{?suse_version} < 1500
# use python36 on SLE 12 and older
%define use_python python3.6
%define use_python_pkg python36

%define completion_dir_bash %{_datadir}/bash-completion/completions
%define completion_dir_csh %{_sysconfdir}/profile.d
%define completion_dir_fish %{_datadir}/fish/vendor_completions.d
%define completion_dir_zsh %{_datadir}/zsh/functions/Completion
%define osc_plugin_dir %{_prefix}/lib/osc-plugins
# need to override python_sitelib because it is not set as we would expect on many distros
%define python_sitelib %(RPM_BUILD_ROOT= %{use_python} -Ic "import sysconfig; print(sysconfig.get_path('purelib'))")

# generate manpages on distros where argparse-manpage >= 3 and python3-Sphinx are available
# please note that RHEL build requires packages from CRB and EPEL repositories
%if 0%{?suse_version} > 1500 || 0%{?fedora} >= 37 || 0%{?rhel} >= 9
%bcond_without man
%bcond_with man

# whether to use fdupes to deduplicate python bytecode
%if 0%{?suse_version} || 0%{?fedora} || 0%{?rhel} >= 8 || 0%{?amzn}
%bcond_without fdupes
%bcond_with fdupes

%define argparse_manpage_pkg argparse-manpage
%define obs_build_pkg obs-build
%define ssh_add_pkg openssh-clients
%define ssh_keygen_pkg openssh
%define sphinx_pkg %{use_python_pkg}-sphinx

%if 0%{?suse_version}
%define argparse_manpage_pkg %{use_python_pkg}-argparse-manpage
%define obs_build_pkg build
%define ssh_keygen_pkg openssh-common
%define sphinx_pkg %{use_python_pkg}-Sphinx

Name:           osc
Version:        1.6.2
Release:        0
Summary:        Command-line client for the Open Build Service
License:        GPL-2.0-or-later
Group:          Development/Tools/Other


%if 0%{?debian}
Source1:        debian.dirs

BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%if %{with man}
BuildRequires:  %{argparse_manpage_pkg}
BuildRequires:  %{sphinx_pkg}
BuildRequires:  %{use_python_pkg}-cryptography
BuildRequires:  %{use_python_pkg}-devel >= 3.6
BuildRequires:  %{use_python_pkg}-rpm
BuildRequires:  %{use_python_pkg}-setuptools
BuildRequires:  %{use_python_pkg}-urllib3
BuildRequires:  diffstat
%if %{with fdupes}
BuildRequires:  fdupes
# needed for git scm tests
BuildRequires:  git-core

Requires:       %{use_python_pkg}-cryptography
Requires:       %{use_python_pkg}-rpm
Requires:       %{use_python_pkg}-urllib3

# needed for showing download progressbars
Recommends:     %{use_python_pkg}-progressbar

# needed for setting the default editor by distro
Recommends:     %{use_python_pkg}-distro

# needed for storing credentials in kwallet/gnome-keyring
Recommends:     %{use_python_pkg}-keyring
Recommends:     %{use_python_pkg}-keyring-keyutils

Recommends:     %{obs_build_pkg}
Recommends:     ca-certificates
Recommends:     diffstat
Recommends:     powerpc32
Recommends:     sudo

# needed for building from git
Recommends:     git-core
Recommends:     git-lfs

# needed for `osc add <URL>`
Recommends:     obs-service-recompress
Recommends:     obs-service-download_files
Recommends:     obs-service-format_spec_file
Recommends:     obs-service-obs_scm
Recommends:     obs-service-set_version
Recommends:     obs-service-source_validator
Recommends:     obs-service-tar_scm
Recommends:     obs-service-verify_file

# needed for ssh signature auth
Recommends:     %{ssh_add_pkg}
Recommends:     %{ssh_keygen_pkg}

# needed for `osc browse` that calls xdg-open
Recommends:     xdg-utils

Provides:       %{use_python_pkg}-osc

openSUSE Commander is a command-line client for the Open Build Service.

See, as well as
for a general introduction.

%autosetup -p1

%{use_python} build

# write rpm macros
cat << EOF > macros.osc
%%osc_plugin_dir %{osc_plugin_dir}

# build man pages
%if %{with man}
PYTHONPATH=. argparse-manpage \
    --output=osc.1 \
    --format=single-commands-section \
    --module=osc.commandline \
    --function=get_parser \
    --project-name=osc \
    --prog=osc \
    --description="openSUSE Commander" \
    --author="Contributors to the osc project. See the project's GIT history for the complete list." \

sphinx-build -b man doc .

%{use_python} install -O1 --skip-build --force --root %{buildroot} --prefix %{_prefix}

# create plugin dirs
install -d %{buildroot}%{osc_plugin_dir}
install -d %{buildroot}%{_sharedstatedir}/osc-plugins

# install completions
install -Dm0755 contrib/osc.complete %{buildroot}%{_datadir}/osc/complete
install -Dm0644 contrib/complete.csh %{buildroot}%{completion_dir_csh}/osc.csh
install -Dm0644 contrib/ %{buildroot}%{completion_dir_bash}/osc.bash
install -Dm0644 contrib/ %{buildroot}%{completion_dir_fish}/
install -Dm0644 contrib/osc.zsh %{buildroot}%{completion_dir_zsh}/osc.zsh

# install rpm macros
install -Dm0644 macros.osc %{buildroot}%{_rpmmacrodir}/macros.osc

# install man page
%if %{with man}
install -Dm0644 osc.1 %{buildroot}%{_mandir}/man1/osc.1
install -Dm0644 oscrc.5 %{buildroot}%{_mandir}/man5/oscrc.5

%if %{with fdupes}
%fdupes %buildroot


%{use_python} test


# docs
%license COPYING
%if %{with man}

# executables

# python modules

# rpm macros

# plugins
%dir %{osc_plugin_dir}
%dir %{_sharedstatedir}/osc-plugins

# completions
%dir %{_datadir}/osc
%config %{completion_dir_csh}/*
%dir %{_datadir}/zsh
%dir %{_datadir}/zsh/functions
%dir %{_datadir}/zsh/functions/Completion

# osc owns the dirs to avoid the "directories not owned by a package" build error
%dir %{_datadir}/fish
%dir %{_datadir}/fish/vendor_completions.d

openSUSE Build Service is sponsored by