diff --git a/jython-cachedir.patch b/jython-cachedir.patch new file mode 100644 index 0000000000000000000000000000000000000000..f639bb037d5ef3793b69908d41f6179cc9faa334 --- /dev/null +++ b/jython-cachedir.patch @@ -0,0 +1,16 @@ +--- src/org/python/core/PySystemState.java.orig 2014-05-28 11:09:26.758604716 +0100 ++++ src/org/python/core/PySystemState.java 2014-05-28 11:16:59.136279132 +0100 +@@ -960,8 +960,11 @@ + } + cachedir = new File(props.getProperty(PYTHON_CACHEDIR, CACHEDIR_DEFAULT_NAME)); + if (!cachedir.isAbsolute()) { +- String prefixString = prefix == null ? null : Py.fileSystemDecode(prefix); +- cachedir = new File(prefixString, cachedir.getPath()); ++ File jythondir = new File(System.getProperty("user.home"), ".jython-cache"); ++ if (!jythondir.isDirectory()) { ++ jythondir.mkdirs(); ++ } ++ cachedir = new File(jythondir, cachedir.getPath()); + } + } + diff --git a/jython-dont-validate-pom.patch b/jython-dont-validate-pom.patch new file mode 100644 index 0000000000000000000000000000000000000000..9f19499806fe0ad63dc9e8dc8358cc8ea75f291c --- /dev/null +++ b/jython-dont-validate-pom.patch @@ -0,0 +1,62 @@ +--- build.xml.orig 2015-04-08 23:42:46.345303431 +0100 ++++ build.xml 2015-04-08 23:44:39.525852992 +0100 +@@ -139,6 +139,9 @@ + + + ++ ++ ++ + + + +--- maven/build.xml.orig 2014-05-30 09:14:45.807566331 +0100 ++++ maven/build.xml 2014-05-30 09:20:08.483159086 +0100 +@@ -107,8 +107,6 @@ + + +- + + + +@@ -159,31 +157,6 @@ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- + + + +@@ -208,5 +181,5 @@ + + + +- ++ + diff --git a/jython-fix-multiprocessing.patch b/jython-fix-multiprocessing.patch new file mode 100644 index 0000000000000000000000000000000000000000..5df40e338ea07cb5a3ffac8639fafb5e92f68ea9 --- /dev/null +++ b/jython-fix-multiprocessing.patch @@ -0,0 +1,41 @@ +--- a/Lib/subprocess.py ++++ b/Lib/subprocess.py +@@ -491,6 +491,38 @@ def _eintr_retry_call(func, *args): + raise + + ++# XXX This function is only used by multiprocessing and the test suite, ++# but it's here so that it can be imported when Python is compiled without ++# threads. ++ ++def _args_from_interpreter_flags(): ++ """Return a list of command-line arguments reproducing the current ++ settings in sys.flags and sys.warnoptions.""" ++ flag_opt_map = { ++ 'debug': 'd', ++ # 'inspect': 'i', ++ # 'interactive': 'i', ++ 'optimize': 'O', ++ 'dont_write_bytecode': 'B', ++ 'no_user_site': 's', ++ 'no_site': 'S', ++ 'ignore_environment': 'E', ++ 'verbose': 'v', ++ 'bytes_warning': 'b', ++ 'py3k_warning': '3', ++ } ++ args = [] ++ for flag, opt in flag_opt_map.items(): ++ v = getattr(sys.flags, flag) ++ if v > 0: ++ args.append('-' + opt * v) ++ if getattr(sys.flags, 'hash_randomization') != 0: ++ args.append('-R') ++ for opt in sys.warnoptions: ++ args.append('-W' + opt) ++ return args ++ ++ + def call(*popenargs, **kwargs): + """Run command with arguments. Wait for command to complete, then + return the returncode attribute. diff --git a/jython-fix-tty-detection.patch b/jython-fix-tty-detection.patch new file mode 100644 index 0000000000000000000000000000000000000000..857e8bece2812b8e368c05d3d801cb7e2acbf750 --- /dev/null +++ b/jython-fix-tty-detection.patch @@ -0,0 +1,14 @@ +--- src/shell/jython.orig 2017-08-11 16:24:32.831309328 +0100 ++++ src/shell/jython 2017-08-11 16:23:55.346726416 +0100 +@@ -242,6 +242,11 @@ + fi + fi + ++# Detect absence of tty ++if ! tty -s; then ++ JAVA_OPTS="$JAVA_OPTS -Dpython.launcher.tty=false" ++fi ++ + if [ -n "$profile_requested" -o -z "$boot_requested" ] ; then + [ -n "$profile_requested" ] && echo "Running with instrumented profiler" + java_args=("${java_args[@]}" -classpath "$CP$CP_DELIMITER$CLASSPATH") diff --git a/jython-launcher.patch b/jython-launcher.patch new file mode 100644 index 0000000000000000000000000000000000000000..51ae598d90a7befe3ab477710577769220e2a495 --- /dev/null +++ b/jython-launcher.patch @@ -0,0 +1,37 @@ +--- src/shell/jython.orig 2017-01-26 12:01:25.475209982 +0000 ++++ src/shell/jython 2017-01-26 12:00:52.178558518 +0000 +@@ -74,17 +74,8 @@ + + CP_DELIMITER=":" + +-CP=$JYTHON_HOME/jython-dev.jar +- +-if [ -f "$CP" ] ; then +- # add necessary jars for command-line execution +- for j in "$JYTHON_HOME"/javalib/*.jar; do +- if [ "$CP" ]; then +- CP="$CP$CP_DELIMITER$j" +- else +- CP="$j" +- fi +- done ++if [ -f "$JYTHON_HOME/jython-dev.jar" ] ; then ++ CP=$JYTHON_HOME/jython-dev.jar + elif [ ! -f "$JYTHON_HOME"/jython.jar ] ; then + echo "$0: $JYTHON_HOME contains neither jython-dev.jar nor jython.jar." >&2 + echo "Try running this script from the 'bin' directory of an installed Jython or " >&2 +@@ -93,6 +84,14 @@ + else + CP=$JYTHON_HOME/jython.jar + fi ++ # add necessary jars for command-line execution ++ for j in "$JYTHON_HOME"/javalib/*.jar; do ++ if [ "$CP" ]; then ++ CP="$CP$CP_DELIMITER$j" ++ else ++ CP="$j" ++ fi ++ done + + if $cygwin; then + # switch delimiter only after building a Unix style $CP diff --git a/jython-no-carrotsearch-sizeof.patch b/jython-no-carrotsearch-sizeof.patch new file mode 100644 index 0000000000000000000000000000000000000000..98e7f0e52603436043a977d551517a785e638712 --- /dev/null +++ b/jython-no-carrotsearch-sizeof.patch @@ -0,0 +1,216 @@ +diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS +index 9c4370e..a435834 100644 +--- a/ACKNOWLEDGMENTS ++++ b/ACKNOWLEDGMENTS +@@ -35,6 +35,7 @@ Jython links the following libraries: + * Mock Runner, licensed under the Apache 1.1 license + * Netty 4, licensed under the Apache 2.0 license from the Netty project + * PyPy datetime module, licensed under the MIT License from the PyPy project ++* Java sizeof, licensed under the Apache 2.0 License from the Apache Software Foundation + + Jython follows closely the Python language and its reference + implementation CPython, as created by Guido van Rossum. +diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py +index fc33854..7d280c5 100644 +--- a/Lib/test/test_support.py ++++ b/Lib/test/test_support.py +@@ -1021,7 +1021,7 @@ def gc_collect(): + gc.collect() + + +-_header = '2P' ++_header = '1P' + if hasattr(sys, "gettotalrefcount"): + _header = '2P' + _header + _vheader = _header + 'P' +diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py +index e88445b..c038a9f 100644 +--- a/Lib/test/test_sys.py ++++ b/Lib/test/test_sys.py +@@ -1,6 +1,8 @@ + # -*- coding: iso-8859-1 -*- + import unittest, test.test_support + import sys, cStringIO ++import struct ++ + + class SysModuleTest(unittest.TestCase): + +@@ -271,12 +273,84 @@ class SysModuleTest(unittest.TestCase): + self.assertEqual(out, '?') + + ++class SizeofTest(unittest.TestCase): ++ """Jython modified version of getsizeof""" ++ ++ def setUp(self): ++ self.P = struct.calcsize('P') ++ self.longdigit = sys.long_info.sizeof_digit ++ self.file = open(test.test_support.TESTFN, 'wb') ++ ++ def tearDown(self): ++ self.file.close() ++ test.test_support.unlink(test.test_support.TESTFN) ++ ++ check_sizeof = test.test_support.check_sizeof ++ ++ def test_default(self): ++ size = test.test_support.calcobjsize ++ self.assertEqual(sys.getsizeof(True, -1), size('l')) ++ ++ def test_objecttypes(self): ++ # check all types defined in Objects/ ++ size = test.test_support.calcobjsize ++ vsize = test.test_support.calcvobjsize ++ check = self.check_sizeof ++ # bool ++ check(True, size('l')) ++ # buffer ++ with test.test_support.check_py3k_warnings(): ++ check(buffer(''), size('1P2Pil')) ++ # builtin_function_or_method ++ check(len, size('3P')) ++ # bytearray_iterator ++ check(iter(bytearray()), size('2PP')) ++ # cell ++ def get_cell(): ++ x = 42 ++ def inner(): ++ return x ++ return inner ++ check(get_cell().func_closure[0], size('2P')) ++ # classobj (old-style class) ++ class class_oldstyle(): ++ def method(): ++ pass ++ check(class_oldstyle, size('6P')) ++ # instance (old-style class) ++ check(class_oldstyle(), size('3P')) ++ # instancemethod (old-style class) ++ check(class_oldstyle().method, size('3P')) ++ # complex ++ check(complex(0,1), size('2P2d')) ++ # code ++ check(get_cell().func_code, size('4i3Pi3P')) ++ # BaseException ++ check(BaseException(), size('3P')) ++ ++ def test_pythontypes(self): ++ # check all types defined in Python/ ++ size = test.test_support.calcobjsize ++ vsize = test.test_support.calcvobjsize ++ check = self.check_sizeof ++ # imp.NullImporter ++ import imp ++ check(imp.NullImporter(self.file.name), size('3P')) ++ try: ++ raise TypeError ++ except TypeError: ++ tb = sys.exc_info()[2] ++ # traceback ++ if tb != None: ++ check(tb, size('2P2i')) ++ ++ + def test_main(): + if test.test_support.is_jython: + del SysModuleTest.test_lost_displayhook + del SysModuleTest.test_refcount + del SysModuleTest.test_setcheckinterval +- test.test_support.run_unittest(SysModuleTest) ++ test.test_support.run_unittest(SysModuleTest, SizeofTest) + + if __name__ == "__main__": + test_main() +diff --git a/build.xml b/build.xml +index 46d288f..0f15f74 100644 +--- a/build.xml ++++ b/build.xml +@@ -155,6 +155,7 @@ oracle.jar=C:/workspace/HEAD/for_development/bisdevsrv28/jboss/server/infra/lib/ + + + ++ + + + +@@ -577,8 +578,10 @@ The readme text for the next release will be like: + + + +- ++ ++ ++ + + + +diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java +index 6ec694c..335a70e 100644 +--- a/src/org/python/core/PySystemState.java ++++ b/src/org/python/core/PySystemState.java +@@ -32,8 +32,8 @@ import java.util.concurrent.ConcurrentMap; + import java.util.concurrent.locks.ReentrantLock; + import java.util.jar.JarEntry; + import java.util.jar.JarFile; +- + import jnr.posix.util.Platform; ++import com.carrotsearch.sizeof.RamUsageEstimator; + + import org.python.Version; + import org.python.core.adapter.ClassicPyObjectAdapter; +@@ -434,6 +434,15 @@ public class PySystemState extends PyObject implements AutoCloseable, + return recursionlimit; + } + ++ @SuppressWarnings("unused") ++ public long getsizeof(Object obj, long defaultVal) { ++ return getsizeof(obj); ++ } ++ ++ public long getsizeof(Object obj) { ++ return RamUsageEstimator.shallowSizeOf(obj); ++ } ++ + public void setrecursionlimit(int recursionlimit) { + if (recursionlimit <= 0) { + throw Py.ValueError("Recursion limit must be positive"); +diff --git a/src/org/python/modules/gc.java b/src/org/python/modules/gc.java +index 633621e..997a97a 100644 +--- a/src/org/python/modules/gc.java ++++ b/src/org/python/modules/gc.java +@@ -2558,13 +2558,30 @@ public class gc { + } + + /** +- * Not supported by Jython. ++ * Only works reliably if {@code monitorGlobal} is active, as it depends on ++ * monitored objects to search for referrers. It only finds referrers that ++ * properly implement the traverseproc mechanism (unless reflection-based ++ * traversion is activated and works stable). + * Throws {@link org.python.core.Py#NotImplementedError}. + * + * @throws org.python.core.Py.NotImplementedError + */ + public static PyObject get_objects() { +- throw Py.NotImplementedError("not applicable to Java GC"); ++ if (!isMonitoring()) { ++ throw Py.NotImplementedError( ++ "not applicable in Jython if gc module is not monitoring PyObjects"); ++ } ++ ArrayList resultList = new ArrayList<>(monitoredObjects.size()); ++ synchronized (monitoredObjects) { ++ for (WeakReferenceGC src: monitoredObjects) { ++ PyObject obj = src.get(); ++ if (isTraversable(obj)) { ++ resultList.add(obj); ++ } ++ } ++ } ++ resultList.trimToSize(); ++ return new PyList(resultList); + } + + /** diff --git a/jython-use-rpm-wheels.patch b/jython-use-rpm-wheels.patch new file mode 100644 index 0000000000000000000000000000000000000000..979eb17f347717407e7323e83ac630e3b3e70af2 --- /dev/null +++ b/jython-use-rpm-wheels.patch @@ -0,0 +1,71 @@ +diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py +index 40ac49d..0c7245d 100644 +--- a/Lib/ensurepip/__init__.py ++++ b/Lib/ensurepip/__init__.py +@@ -1,9 +1,10 @@ + #!/usr/bin/env python2 + from __future__ import print_function + ++import distutils.version ++import glob + import os + import os.path +-import pkgutil + import shutil + import sys + import tempfile +@@ -11,10 +12,20 @@ import tempfile + + __all__ = ["version", "bootstrap"] + ++_WHEEL_DIR = "/usr/share/python-wheels/" + +-_SETUPTOOLS_VERSION = "28.8.0" + +-_PIP_VERSION = "9.0.1" ++def _get_most_recent_wheel_version(pkg): ++ prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg)) ++ suffix = "-py2.py3-none-any.whl" ++ pattern = "{}*{}".format(prefix, suffix) ++ versions = (p[len(prefix):-len(suffix)] for p in glob.glob(pattern)) ++ return str(max(versions, key=distutils.version.LooseVersion)) ++ ++ ++_SETUPTOOLS_VERSION = _get_most_recent_wheel_version("setuptools") ++ ++_PIP_VERSION = _get_most_recent_wheel_version("pip") + + # pip currently requires ssl support, so we try to provide a nicer + # error message when that is missing (http://bugs.python.org/issue19744) +@@ -42,8 +53,13 @@ def _run_pip(args, additional_paths=None): + sys.path = additional_paths + sys.path + + # Install the bundled software +- import pip +- pip.main(args) ++ try: ++ # pip 10 ++ from pip._internal import main ++ except ImportError: ++ # pip 9 ++ from pip import main ++ main(args) + + + def version(): +@@ -100,12 +116,9 @@ def bootstrap(root=None, upgrade=False, user=False, + additional_paths = [] + for project, version in _PROJECTS: + wheel_name = "{}-{}-py2.py3-none-any.whl".format(project, version) +- whl = pkgutil.get_data( +- "ensurepip", +- "_bundled/{}".format(wheel_name), +- ) +- with open(os.path.join(tmpdir, wheel_name), "wb") as fp: +- fp.write(whl) ++ with open(os.path.join(_WHEEL_DIR, wheel_name), "rb") as sfp: ++ with open(os.path.join(tmpdir, wheel_name), "wb") as fp: ++ fp.write(sfp.read()) + + additional_paths.append(os.path.join(tmpdir, wheel_name)) + diff --git a/jython.spec b/jython.spec new file mode 100644 index 0000000000000000000000000000000000000000..f1384730c0fe7cde8c1925252ff773d9d5318d3c --- /dev/null +++ b/jython.spec @@ -0,0 +1,148 @@ +%global scm_tag v2.7.1 +%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g') +Name: jython +Version: 2.7.1 +Release: 1 +Summary: A Java implementation of the Python language +License: ASL 1.1 and BSD +URL: http://www.jython.org/ +%bcond_without rpmwheels +Source0: https://github.com/jython/jython/archive/%{scm_tag}.tar.gz +Patch0: jython-cachedir.patch +Patch1: jython-dont-validate-pom.patch +Patch2: jython-no-carrotsearch-sizeof.patch +Patch3: jython-launcher.patch +Patch4: jython-fix-multiprocessing.patch +Patch5: jython-fix-tty-detection.patch +Patch189: jython-use-rpm-wheels.patch +Requires: antlr32-java apache-commons-compress bouncycastle bouncycastle-pkix guava +Requires: objectweb-asm jctools >= 2.0.2 jnr-constants jnr-ffi jnr-netdb jnr-posix jffi +Requires: jffi-native jline jansi icu4j netty >= 4.1.13 xerces-j2 +BuildRequires: javapackages-local ant ant-junit glassfish-servlet-api antlr32-tool +BuildRequires: apache-commons-compress bouncycastle guava objectweb-asm +BuildRequires: jctools >= 2.0.2 jnr-constants jnr-ffi jnr-netdb jnr-posix jffi jffi-native +BuildRequires: jline jansi icu4j netty >= 4.1.13 xerces-j2 +%if %{with rpmwheels} +BuildRequires: python-setuptools-wheel python-pip-wheel +Requires: python-setuptools-wheel python-pip-wheel +%else +Provides: bundled(python2-pip) = 9.0.1 +Provides: bundled(python2-setuptools) = 28.8.0 +%endif +BuildArch: noarch +%description +Jython is an implementation of the high-level, dynamic, object-oriented +language Python seamlessly integrated with the Java platform. The +predecessor to Jython, JPython, is certified as 100% Pure Java. Jython is +freely available for both commercial and non-commercial use and is +distributed with source code. Jython is complementary to Java and is +especially suited for the following tasks: Embedded scripting - Java +programmers can add the Jython libraries to their system to allow end +users to write simple or complicated scripts that add functionality to the +application. Interactive experimentation - Jython provides an interactive +interpreter that can be used to interact with Java packages or with +running Java applications. This allows programmers to experiment and debug +any Java system using Jython. Rapid application development - Python +programs are typically 2-10X shorter than the equivalent Java program. +This translates directly to increased programmer productivity. The +seamless interaction between Python and Java allows developers to freely +mix the two languages both during development and in shipping products. + +%package javadoc +Summary: Javadoc for %{name} +Obsoletes: %{name}-manual = %{version}-%{release} +Provides: %{name}-manual < %{version}-%{release} +%description javadoc +API documentation for %{name}. + +%package demo +Summary: Demo for %{name} +Requires: %{name} = %{version}-%{release} +%description demo +Demonstrations and samples for %{name}. + +%prep +%setup -q -n jython-%{version} +%patch2 -R -p1 +%patch0 +%patch1 +#%patch3 +%patch4 -p1 +%patch5 + +find . -type f -a -name *.jar -delete +find . -type f -a -name *.exe -delete +find . -type f -a -name *.dll -delete +%if %{with rpmwheels} +%patch189 -p1 +rm Lib/ensurepip/_bundled/*.whl +rmdir Lib/ensurepip/_bundled +%endif +rm -rf extlibs/* +sed -i -e '/ - 2.7.1-1 +- Package init diff --git a/jython.yaml b/jython.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e549f8a0a4d6231170929a41930b7c7158c9d686 --- /dev/null +++ b/jython.yaml @@ -0,0 +1,5 @@ +git_url: https://github.com/jython/jython.git +version_control: github +src_repo: jython/jython +tag_prefix: "^v" +seperator: "." diff --git a/v2.7.1.tar.gz b/v2.7.1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..6703ebecddbc2c15b541227fb59a472abd69f1d1 Binary files /dev/null and b/v2.7.1.tar.gz differ