diff --git a/Makefile.am b/Makefile.am index 351613f..93279f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,7 +38,7 @@ dist-hook: done run-ipython: all - LD_LIBRARY_PATH=${LIBDIRS} PYTHONPATH=$(PYTHONDIR) ipython3 + LD_LIBRARY_PATH=${LIBDIRS} PYTHONPATH=$(PYTHONDIR) ipython check-requires: @echo "*** Checking if the dependencies required for testing and analysis are available ***" @@ -94,7 +94,6 @@ bumpver: mv dist/libbytesize.spec.in.new dist/libbytesize.spec.in ; rm -f speclog ; \ sed -ri "s/(AC_INIT\(\[$(PACKAGE_NAME)\], \[)[0-9]+\.[0-9]+(\],.*)/\1$$VERSION.$$NEWSUBVERSION\2/" configure.ac ; \ sed -ri "s/Version:(\\s+)[-0-9.]+/Version:\\1$$VERSION.$$NEWSUBVERSION/" dist/libbytesize.spec.in ; - $(MAKE) -C po/ $(PACKAGE_NAME).pot-update archive: po-pull $(MAKE) distcheck diff --git a/configure.ac b/configure.ac index c2306dc..749d929 100644 --- a/configure.ac +++ b/configure.ac @@ -50,6 +50,22 @@ AC_CHECK_HEADERS([langinfo.h gmp.h mpfr.h stdint.h stdbool.h stdarg.h string.h s [LIBBYTESIZE_SOFT_FAILURE([Header file $ac_header not found.])], []) +AC_ARG_WITH([python2], + AS_HELP_STRING([--with-python2], [support python2 @<:@default=check@:>@]), + [], + [with_python2=check]) + +AC_SUBST(WITH_PYTHON2, 0) +if test "x$with_python2" != "xno"; then + AC_PATH_PROG([python2], [python2], [no]) + AS_IF([test "x$python2" == "xno"], + [if test "x$with_python2" = "xyes"; then + LIBBYTESIZE_SOFT_FAILURE([Python2 support requested, but python2 is not available]) + fi], + [AC_SUBST(WITH_PYTHON2, 1)]) +fi +AM_CONDITIONAL(WITH_PYTHON2, test "x$with_python2" != "xno" -a "x$python2" != "xno") + AC_ARG_WITH([python3], AS_HELP_STRING([--with-python3], [support python3 @<:@default=check@:>@]), [], diff --git a/dist/libbytesize.spec.in b/dist/libbytesize.spec.in index 9658a7c..3f306f9 100644 --- a/dist/libbytesize.spec.in +++ b/dist/libbytesize.spec.in @@ -1,4 +1,5 @@ %define realname bytesize +%define with_python2 @WITH_PYTHON2@ %define with_python3 @WITH_PYTHON3@ %define with_gtk_doc @WITH_GTK_DOC@ @@ -7,7 +8,13 @@ %define python3_opts --without-python3 %endif -%define configure_opts %{?python3_opts} +# python2 is not available on RHEL > 7 and not needed on Fedora > 28 +%if 0%{?rhel} > 7 || 0%{?fedora} > 28 || %{with_python2} == 0 +%define with_python2 0 +%define python2_opts --without-python2 +%endif + +%define configure_opts %{?python3_opts} %{?python2_opts} Name: libbytesize Version: 1.4 @@ -22,6 +29,9 @@ BuildRequires: gmp-devel BuildRequires: mpfr-devel BuildRequires: pcre-devel BuildRequires: gettext-devel +%if %{with_python2} +BuildRequires: python2-devel +%endif %if %{with_python3} BuildRequires: python3-devel %endif @@ -43,6 +53,19 @@ Requires: %{name}%{?_isa} = %{version}-%{release} This package contains header files and pkg-config files needed for development with the libbytesize library. +%if %{with_python2} +%package -n python2-%{realname} +Summary: Python 2 bindings for libbytesize +%{?python_provide:%python_provide python2-%{realname}} +%{?python_provide:%python_provide python2-libbytesize} +Requires: %{name}%{?_isa} = %{version}-%{release} +Requires: python2-six + +%description -n python2-%{realname} +This package contains Python 2 bindings for libbytesize making the use of +the library from Python 2 easier and more convenient. +%endif + %if %{with_python3} %package -n python3-%{realname} Summary: Python 3 bindings for libbytesize @@ -85,6 +108,12 @@ find %{buildroot} -type f -name "*.la" | xargs %{__rm} %{_datadir}/gtk-doc/html/libbytesize %endif +%if %{with_python2} +%files -n python2-%{realname} +%dir %{python2_sitearch}/bytesize +%{python2_sitearch}/bytesize/* +%endif + %if %{with_python3} %files -n python3-%{realname} %dir %{python3_sitearch}/bytesize diff --git a/po/Makefile.am b/po/Makefile.am index de4ad7d..5c288ab 100644 --- a/po/Makefile.am +++ b/po/Makefile.am @@ -161,12 +161,12 @@ MSGMERGE_V_OPTIONS_1 = $(MSGMERGE_OPTIONS) --verbose # Actually do stuff: # .po files get distributed but not installed -dist_noinst_DATA = $(POFILES) $(POTFILE) +dist_noinst_DATA = $(POFILES) # Build the .mo files but don't actually do anything with them. The real # install part is in the install-data-local target below. Build the .pot file # as well, even if there are no .mo files to build, so it can be tested. -nodist_noinst_DATA = $(MOFILES) +nodist_noinst_DATA = $(MOFILES) $(POTFILE) # How to build the .pot file. This needs to be regenerated if anything that # goes into it has changed. @@ -181,13 +181,13 @@ $(PACKAGE).pot-update: @$(MAKE) $(POTFILE) # How to build the merged .mpo files from the .po files -$(MERGED_POFILES): $(POFILES) +$(MERGED_POFILES): $(POFILES) $(POTFILE) .po.mpo: - $(GETTEXT_V_MERGE)$(MSGMERGE) $(MSGMERGE_V_OPTIONS) -o $@ $< $(top_srcdir)/po/$(POTFILE) + $(GETTEXT_V_MERGE)$(MSGMERGE) $(MSGMERGE_V_OPTIONS) -o $@ $< $(POTFILE) # How to build the .mo files from the .mpo files -$(MOFILES): $(MERGED_POFILES) $(POTFILE) +$(MOFILES): $(MERGED_POFILES) .mpo.mo: $(GETTEXT_V_FORMAT)$(MSGFMT) $(MSGFMT_V_OPTIONS) -o $@ $< @@ -210,4 +210,4 @@ uninstall-local: rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(PACKAGE).mo ; \ done -CLEANFILES = $(MERGED_POFILES) $(MOFILES) +CLEANFILES = $(MERGED_POFILES) $(MOFILES) $(POTFILE) diff --git a/po/libbytesize.pot b/po/libbytesize.pot deleted file mode 100644 index 5431896..0000000 --- a/po/libbytesize.pot +++ /dev/null @@ -1,103 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR Red Hat, Inc. -# This file is distributed under the same license as the libbytesize package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: libbytesize 2.1\n" -"Report-Msgid-Bugs-To: anaconda-devel-list@redhat.com\n" -"POT-Creation-Date: 2019-10-29 12:28+0100\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=CHARSET\n" -"Content-Transfer-Encoding: 8bit\n" - -#. TRANSLATORS: 'B' for bytes -#: src/bs_size.c:52 src/bs_size.c:73 -msgid "B" -msgstr "" - -#. TRANSLATORS: abbreviation for kibibyte, 2**10 bytes -#: src/bs_size.c:54 -msgid "KiB" -msgstr "" - -#. TRANSLATORS: abbreviation for mebibyte, 2**20 bytes -#: src/bs_size.c:56 -msgid "MiB" -msgstr "" - -#. TRANSLATORS: abbreviation for gibibyte, 2**30 bytes -#: src/bs_size.c:58 -msgid "GiB" -msgstr "" - -#. TRANSLATORS: abbreviation for tebibyte, 2**40 bytes -#: src/bs_size.c:60 -msgid "TiB" -msgstr "" - -#. TRANSLATORS: abbreviation for pebibyte, 2**50 bytes -#: src/bs_size.c:62 -msgid "PiB" -msgstr "" - -#. TRANSLATORS: abbreviation for exbibyte, 2**60 bytes -#: src/bs_size.c:64 -msgid "EiB" -msgstr "" - -#. TRANSLATORS: abbreviation for zebibyte, 2**70 bytes -#: src/bs_size.c:66 -msgid "ZiB" -msgstr "" - -#. TRANSLATORS: abbreviation for yobibyte, 2**80 bytes -#: src/bs_size.c:68 -msgid "YiB" -msgstr "" - -#. TRANSLATORS: abbreviation for kilobyte, 10**3 bytes -#: src/bs_size.c:75 -msgid "KB" -msgstr "" - -#. TRANSLATORS: abbreviation for megabyte, 10**6 bytes -#: src/bs_size.c:77 -msgid "MB" -msgstr "" - -#. TRANSLATORS: abbreviation for gigabyte, 10**9 bytes -#: src/bs_size.c:79 -msgid "GB" -msgstr "" - -#. TRANSLATORS: abbreviation for terabyte, 10**12 bytes -#: src/bs_size.c:81 -msgid "TB" -msgstr "" - -#. TRANSLATORS: abbreviation for petabyte, 10**15 bytes -#: src/bs_size.c:83 -msgid "PB" -msgstr "" - -#. TRANSLATORS: abbreviation for exabyte, 10**18 bytes -#: src/bs_size.c:85 -msgid "EB" -msgstr "" - -#. TRANSLATORS: abbreviation for zettabyte, 10**21 bytes -#: src/bs_size.c:87 -msgid "ZB" -msgstr "" - -#. TRANSLATORS: abbreviation for yottabyte, 10**24 bytes -#: src/bs_size.c:89 -msgid "YB" -msgstr "" diff --git a/src/python/Makefile.am b/src/python/Makefile.am index cb2b197..e0261a6 100644 --- a/src/python/Makefile.am +++ b/src/python/Makefile.am @@ -1,7 +1,14 @@ +if WITH_PYTHON2 +pylibdir = $(shell python -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(1,0,prefix='${exec_prefix}'))") + +pybytesizedir = $(pylibdir)/bytesize +dist_pybytesize_DATA = bytesize.py __init__.py +endif + if WITH_PYTHON3 py3libdir = $(shell python3 -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(1,0,prefix='${exec_prefix}'))") py3bytesizedir = $(py3libdir)/bytesize -dist_py3bytesize_DATA = bytesize.py __init__.py +nodist_py3bytesize_DATA = bytesize.py __init__.py endif MAINTAINERCLEANFILES = Makefile.in diff --git a/src/python/__init__.py b/src/python/__init__.py index 57403d5..6ab80dc 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -1,4 +1 @@ from .bytesize import Size -from .bytesize import B, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB, KB, MB, GB, TB, PB, EB, ZB, YB -from .bytesize import ROUND_UP, ROUND_DOWN, ROUND_HALF_UP -from .bytesize import SizeError, InvalidSpecError, OverflowError, ZeroDivisionError diff --git a/tests/Makefile.am b/tests/Makefile.am index 1e51834..1f59f64 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,7 @@ AM_TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)" top_builddir="$(top_builddir)" dist_noinst_SCRIPTS = libbytesize_unittest.sh libbytesize_unittest.py lbs_py_override_unittest.py locale_utils.py testenv.sh canary_tests.sh -TESTS = libbytesize_unittest.sh canary_tests.sh +TESTS = libbytesize_unittest.sh lbs_py_override_unittest.py canary_tests.sh # Add the translation-canary source files to the tarball EXTRA_DIST = $(top_srcdir)/translation-canary/translation_canary/*.py \ diff --git a/tests/canary_tests.sh.in b/tests/canary_tests.sh.in index d5a5815..13357e8 100644 --- a/tests/canary_tests.sh.in +++ b/tests/canary_tests.sh.in @@ -17,8 +17,15 @@ if [ -z "$top_srcdir" ]; then top_srcdir="$(dirname "$0")/.." fi +if [ -z "$top_builddir" ] ; then + top_builddir="$(dirname "$0")/.." +fi + +# Make sure libbytesize.pot is up to date +make -C ${top_builddir}/po libbytesize.pot-update >/dev/null 2>&1 + PYTHONPATH="${PYTHONPATH}:${top_srcdir}/translation-canary" export PYTHONPATH # Run the translatable tests on the POT file -python3 -m translation_canary.translatable "${top_srcdir}/po/libbytesize.pot" +python3 -m translation_canary.translatable "${top_builddir}/po/libbytesize.pot" diff --git a/tests/lbs_py_override_unittest.py b/tests/lbs_py_override_unittest.py index 9a219f2..c5f3cb2 100755 --- a/tests/lbs_py_override_unittest.py +++ b/tests/lbs_py_override_unittest.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- import unittest @@ -306,3 +306,5 @@ class SizeTestCase(unittest.TestCase): if __name__=='__main__': unittest.main() #endif + + diff --git a/tests/libbytesize_unittest.py b/tests/libbytesize_unittest.py index 1c57d2a..5e63778 100755 --- a/tests/libbytesize_unittest.py +++ b/tests/libbytesize_unittest.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python2 # -*- coding: utf-8 -*- import locale @@ -8,14 +8,7 @@ import ctypes from locale_utils import get_avail_locales, requires_locales -from bytesize import KiB, GiB, ROUND_UP, ROUND_DOWN, ROUND_HALF_UP, OverflowError - -# SizeStruct is part of the 'private' API and needs to be imported differently -# when running from locally build tree and when using installed library -try: - from bytesize import SizeStruct -except ImportError: - from bytesize.bytesize import SizeStruct +from bytesize import SizeStruct, KiB, GiB, ROUND_UP, ROUND_DOWN, ROUND_HALF_UP, OverflowError DEFAULT_LOCALE = "en_US.utf8" @@ -766,3 +759,4 @@ if __name__=='__main__': sys.argv = [sys.argv[0]] unittest.main() #endif + diff --git a/tests/libbytesize_unittest.sh b/tests/libbytesize_unittest.sh index acb4f94..43b99e3 100755 --- a/tests/libbytesize_unittest.sh +++ b/tests/libbytesize_unittest.sh @@ -8,8 +8,15 @@ if [ -z "$srcdir" ]; then fi if [ 1 = 1 ]; then + python2 ${srcdir}/libbytesize_unittest.py || status=1 +fi + +if [ 1 = 1 ]; then python3 ${srcdir}/libbytesize_unittest.py || status=1 - python3 ${srcdir}/lbs_py_override_unittest.py || status=1 +fi + +if [ 1 = 1 ]; then + python2 ${srcdir}/libbytesize_unittest.py fr_FR.UTF8 || status=1 fi if [ 1 = 1 ]; then diff --git a/tests/libbytesize_unittest.sh.in b/tests/libbytesize_unittest.sh.in index 816bc28..7896675 100644 --- a/tests/libbytesize_unittest.sh.in +++ b/tests/libbytesize_unittest.sh.in @@ -7,9 +7,16 @@ if [ -z "$srcdir" ]; then srcdir="$(dirname "$0")" fi +if [ @WITH_PYTHON2@ = 1 ]; then + python2 ${srcdir}/libbytesize_unittest.py || status=1 +fi + if [ @WITH_PYTHON3@ = 1 ]; then python3 ${srcdir}/libbytesize_unittest.py || status=1 - python3 ${srcdir}/lbs_py_override_unittest.py || status=1 +fi + +if [ @WITH_PYTHON2@ = 1 ]; then + python2 ${srcdir}/libbytesize_unittest.py fr_FR.UTF8 || status=1 fi if [ @WITH_PYTHON3@ = 1 ]; then