From 37cf398b9da85f6121aaaeac374ae01f2ab2f858 Mon Sep 17 00:00:00 2001 From: ndparker Date: Sun, 2 Nov 2014 00:14:32 +0100 Subject: [PATCH 1/9] try fixing the issue presented in https://github.com/ndparker/rjsmin/pull/2 --- py3/dev/apidoc.py | 4 ++-- py3/ext.py | 2 +- py3/make/default_targets.py | 2 +- py3/make/targets.py | 8 ++++---- py3/setup.py | 12 ++++++------ py3/shell.py | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/py3/dev/apidoc.py b/py3/dev/apidoc.py index c1057eb..ef4d62f 100644 --- a/py3/dev/apidoc.py +++ b/py3/dev/apidoc.py @@ -41,7 +41,7 @@ def _cleanup_epydoc(target): """ search = _re.compile(r']+width="100%%"').search for filename in _shell.files(target, '*.html'): - fp = open(filename, 'r') + fp = open(filename, 'r', encoding='latin-1') try: html = fp.read() finally: @@ -53,7 +53,7 @@ def _cleanup_epydoc(target): if end >= 0: end += len('') + 1 html = html[:start] + html[end:] - fp = open(filename, 'w') + fp = open(filename, 'w', encoding='latin-1') try: fp.write(html) finally: diff --git a/py3/ext.py b/py3/ext.py index c54c845..852c466 100644 --- a/py3/ext.py +++ b/py3/ext.py @@ -179,7 +179,7 @@ class ConfTest(object): """ self._tempdir = tempdir = _tempfile.mkdtemp() src = _os.path.join(tempdir, 'conftest.c') - fp = open(src, 'w') + fp = open(src, 'w', encoding='utf-8') try: fp.write(source) finally: diff --git a/py3/make/default_targets.py b/py3/make/default_targets.py index 16c95ee..9c74aa9 100644 --- a/py3/make/default_targets.py +++ b/py3/make/default_targets.py @@ -63,7 +63,7 @@ class MakefileTarget(_make.Target): names.append(name) names.sort() - fp = open(_shell.native('Makefile'), 'w') + fp = open(_shell.native('Makefile'), 'w', encoding='utf-8') print(decorate("Generated Makefile, DO NOT EDIT"), file=fp) print(decorate("python %s %s" % ( _os.path.basename(script), self.NAME diff --git a/py3/make/targets.py b/py3/make/targets.py index eca4d02..4620e2f 100644 --- a/py3/make/targets.py +++ b/py3/make/targets.py @@ -187,7 +187,7 @@ class Distribution(_make.Target): return sig.hexdigest() param = {'sig': sig.hexdigest(), 'file': _os.path.basename(filename)} - fp = open("%s.%s" % (filename, name), "w") + fp = open("%s.%s" % (filename, name), "w", encoding='utf-8') fp.write("%(sig)s *%(file)s\n" % param) fp.close() @@ -265,9 +265,9 @@ class Distribution(_make.Target): sig.seek(0, 0) if detach: - open("%s.asc" % filename, "w").write(sig.read()) + open("%s.asc" % filename, "w", encoding='utf-8').write(sig.read()) else: - open(filename, "w").write(sig.read()) + open(filename, "w", encoding='utf-8').write(sig.read()) return True @@ -309,7 +309,7 @@ class Manifest(_make.Target): def run(self): _term.green("Creating %(name)s...", name=self.NAME) dest = _shell.native(self.NAME) - dest = open(dest, 'w') + dest = open(dest, 'w', encoding='utf-8') for name in self.manifest_names(): dest.write("%s\n" % name) dest.close() diff --git a/py3/setup.py b/py3/setup.py index e28f000..83f1c21 100644 --- a/py3/setup.py +++ b/py3/setup.py @@ -88,7 +88,7 @@ def find_description(docs): summary = None filename = docs.get('meta.summary', 'SUMMARY').strip() if filename and _os.path.isfile(filename): - fp = open(filename) + fp = open(filename, encoding='utf-8') try: try: summary = fp.read().strip().splitlines()[0].rstrip() @@ -100,7 +100,7 @@ def find_description(docs): description = None filename = docs.get('meta.description', 'DESCRIPTION').strip() if filename and _os.path.isfile(filename): - fp = open(filename) + fp = open(filename, encoding='utf-8') try: description = fp.read().rstrip() finally: @@ -126,7 +126,7 @@ def find_classifiers(docs): """ filename = docs.get('meta.classifiers', 'CLASSIFIERS').strip() if filename and _os.path.isfile(filename): - fp = open(filename) + fp = open(filename, encoding='utf-8') try: content = fp.read() finally: @@ -145,7 +145,7 @@ def find_provides(docs): """ filename = docs.get('meta.provides', 'PROVIDES').strip() if filename and _os.path.isfile(filename): - fp = open(filename) + fp = open(filename, encoding='utf-8') try: content = fp.read() finally: @@ -164,7 +164,7 @@ def find_license(docs): """ filename = docs.get('meta.license', 'LICENSE').strip() if filename and _os.path.isfile(filename): - fp = open(filename) + fp = open(filename, encoding='utf-8') try: return fp.read().rstrip() finally: @@ -339,7 +339,7 @@ def run(config=('package.cfg',), ext=None, script_args=None, manifest_only=0): ext = [] cfg = _util.SafeConfigParser() - cfg.read(config) + cfg.read(config, encoding='utf-8') pkg = dict(cfg.items('package')) python_min = pkg.get('python.min') or None python_max = pkg.get('python.max') or None diff --git a/py3/shell.py b/py3/shell.py index a40c85c..91f2ebc 100644 --- a/py3/shell.py +++ b/py3/shell.py @@ -204,7 +204,7 @@ sys.exit(result & 7) 'outfile': repr(_pickle.dumps(_os.path.abspath(outfile))), 'argv': repr(_pickle.dumps(argv)), 'env': repr(_pickle.dumps(env)), - })) + }).encode('utf-8')) fd, _ = None, _os.close(fd) if _sys.platform == 'win32': argv = [] From 218097ede6dcd4b3435e862c114be3f58ff506b3 Mon Sep 17 00:00:00 2001 From: ndparker Date: Sun, 16 Nov 2014 15:33:53 +0100 Subject: [PATCH 2/9] add pypy3 support --- py3/setup.py | 10 +++++----- py3/term/_term.py | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/py3/setup.py b/py3/setup.py index 83f1c21..a759e16 100644 --- a/py3/setup.py +++ b/py3/setup.py @@ -41,7 +41,7 @@ def check_python_version(impl, version_min, version_max): """ Check python version """ if impl == 'python': version_info = _sys.version_info - elif impl == 'pypy': + elif impl == 'pypy3': version_info = getattr(_sys, 'pypy_version_info', None) if not version_info: return @@ -50,7 +50,7 @@ def check_python_version(impl, version_min, version_max): return version_info = _sys.version_info else: - raise AssertionError("impl not in ('python', 'pypy', 'jython')") + raise AssertionError("impl not in ('python', 'pypy3', 'jython')") pyversion = list(map(int, version_info[:3])) if version_min: @@ -344,9 +344,9 @@ def run(config=('package.cfg',), ext=None, script_args=None, manifest_only=0): python_min = pkg.get('python.min') or None python_max = pkg.get('python.max') or None check_python_version('python', python_min, python_max) - pypy_min = pkg.get('pypy.min') or None - pypy_max = pkg.get('pypy.max') or None - check_python_version('pypy', pypy_min, pypy_max) + pypy_min = pkg.get('pypy3.min') or None + pypy_max = pkg.get('pypy3.max') or None + check_python_version('pypy3', pypy_min, pypy_max) jython_min = pkg.get('jython.min') or None jython_max = pkg.get('jython.max') or None check_python_version('jython', jython_min, jython_max) diff --git a/py3/term/_term.py b/py3/term/_term.py index b94f58e..4d70d1e 100644 --- a/py3/term/_term.py +++ b/py3/term/_term.py @@ -50,21 +50,28 @@ class _INFO(dict): except (TypeError, _curses.error): pass else: + try: + _curses.tigetstr('sgr0') + except TypeError: # pypy3 + bc = lambda val: val.encode('ascii') + else: + bc = lambda val: val + def make_color(color): """ Make color control string """ - seq = _curses.tigetstr('setaf').decode('ascii') + seq = _curses.tigetstr(bc('setaf')).decode('ascii') if seq is not None: # XXX may fail - need better logic seq = seq.replace("%p1", "") % color return seq - self['NORMAL'] = _curses.tigetstr('sgr0').decode('ascii') - self['BOLD'] = _curses.tigetstr('bold').decode('ascii') + self['NORMAL'] = _curses.tigetstr(bc('sgr0')).decode('ascii') + self['BOLD'] = _curses.tigetstr(bc('bold')).decode('ascii') - erase = _curses.tigetstr('el1').decode('ascii') + erase = _curses.tigetstr(bc('el1')).decode('ascii') if erase is not None: self['ERASE'] = erase + \ - _curses.tigetstr('cr').decode('ascii') + _curses.tigetstr(bc('cr')).decode('ascii') self['RED'] = make_color(_curses.COLOR_RED) self['YELLOW'] = make_color(_curses.COLOR_YELLOW) From fea207ca7f96ca00aa58089c68c47b77fecb739c Mon Sep 17 00:00:00 2001 From: ndparker Date: Tue, 3 Mar 2015 18:26:49 +0100 Subject: [PATCH 3/9] adjust versioning scheme --- py2/setup.py | 4 ++-- py3/setup.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/py2/setup.py b/py2/setup.py index fd86f62..b2fcde8 100644 --- a/py2/setup.py +++ b/py2/setup.py @@ -368,13 +368,13 @@ def run(config=('package.cfg',), ext=None, script_args=None, manifest_only=0): keywords = keywords.split() revision = pkg.get('version.revision', '').strip() if revision: - revision = "-r%s" % (revision,) + revision = int(revision) kwargs = { 'name': pkg['name'], 'version': "%s%s" % ( pkg['version.number'], - ["", "-dev%s" % (revision,)][_util.humanbool( + ["", ".dev%d" % (revision,)][_util.humanbool( 'version.dev', pkg.get('version.dev', 'false') )], ), diff --git a/py3/setup.py b/py3/setup.py index a759e16..6391ef5 100644 --- a/py3/setup.py +++ b/py3/setup.py @@ -369,13 +369,13 @@ def run(config=('package.cfg',), ext=None, script_args=None, manifest_only=0): keywords = keywords.split() revision = pkg.get('version.revision', '').strip() if revision: - revision = "-r%s" % (revision,) + revision = int(revision) kwargs = { 'name': pkg['name'], 'version': "%s%s" % ( pkg['version.number'], - ["", "-dev%s" % (revision,)][_util.humanbool( + ["", ".dev%d" % (revision,)][_util.humanbool( 'version.dev', pkg.get('version.dev', 'false') )], ), From fe73619660df3daaefdaeb65c4a7437b26b135df Mon Sep 17 00:00:00 2001 From: ndparker Date: Fri, 6 Mar 2015 19:47:50 +0100 Subject: [PATCH 4/9] a few py3 adjustments --- include/cext.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/cext.h b/include/cext.h index 47b6f5b..0ae2b07 100644 --- a/include/cext.h +++ b/include/cext.h @@ -62,6 +62,10 @@ #define EXT3 +#define Py_TPFLAGS_HAVE_CLASS (0) +#define Py_TPFLAGS_HAVE_WEAKREFS (0) +#define Py_TPFLAGS_HAVE_ITER (0) + #ifndef PyMODINIT_FUNC #define EXT_INIT_FUNC PyObject *CONCATENATE(PyInit_, EXT_MODULE)(void) #else @@ -89,6 +93,11 @@ static struct PyModuleDef EXT_DEFINE_VAR = { \ #define EXT2 +#ifndef PyVarObject_HEAD_INIT + #define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, +#endif + #ifndef PyMODINIT_FUNC #define EXT_INIT_FUNC void CONCATENATE(init, EXT_MODULE)(void) #else From 575aecc254d63153875b277bf667bc246c2081a3 Mon Sep 17 00:00:00 2001 From: ndparker Date: Sun, 8 Mar 2015 23:30:54 +0100 Subject: [PATCH 5/9] more python3 adjustments --- include/cext.h | 8 ++++++++ py3/setup.py | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/cext.h b/include/cext.h index 0ae2b07..093c61d 100644 --- a/include/cext.h +++ b/include/cext.h @@ -62,9 +62,17 @@ #define EXT3 +#ifndef Py_TPFLAGS_HAVE_CLASS #define Py_TPFLAGS_HAVE_CLASS (0) +#endif + +#ifndef Py_TPFLAGS_HAVE_WEAKREFS #define Py_TPFLAGS_HAVE_WEAKREFS (0) +#endif + +#ifndef Py_TPFLAGS_HAVE_ITER #define Py_TPFLAGS_HAVE_ITER (0) +#endif #ifndef PyMODINIT_FUNC #define EXT_INIT_FUNC PyObject *CONCATENATE(PyInit_, EXT_MODULE)(void) diff --git a/py3/setup.py b/py3/setup.py index 6391ef5..8a30540 100644 --- a/py3/setup.py +++ b/py3/setup.py @@ -250,14 +250,14 @@ def make_manifest(manifest, config, docs, kwargs): kwargs['packages'] = list(kwargs.get('packages') or ()) + [ '_setup', '_setup.py2', '_setup.py3', ] + list(manifest.get('packages.extra', '').split() or ()) - _core._setup_stop_after = "commandline" + _core._setup_stop_after = "commandline" # noqa pylint: disable = protected-access try: dist = _core.setup(**kwargs) finally: - _core._setup_stop_after = None + _core._setup_stop_after = None # pylint: disable = protected-access result = ['MANIFEST', 'PKG-INFO', 'setup.py'] + list(config) - # TODO: work with default values: + # xx: work with default values? for key in ('classifiers', 'description', 'summary', 'provides', 'license'): filename = docs.get('meta.' + key, '').strip() @@ -266,7 +266,7 @@ def make_manifest(manifest, config, docs, kwargs): cmd = dist.get_command_obj("build_py") cmd.ensure_finalized() - #from pprint import pprint; pprint(("build_py", cmd.get_source_files())) + # from pprint import pprint; pprint(("build_py", cmd.get_source_files())) for item in cmd.get_source_files(): result.append(_posixpath.sep.join( _os.path.normpath(item).split(_os.path.sep) @@ -274,7 +274,7 @@ def make_manifest(manifest, config, docs, kwargs): cmd = dist.get_command_obj("build_ext") cmd.ensure_finalized() - #from pprint import pprint; pprint(("build_ext", cmd.get_source_files())) + # from pprint import pprint; pprint(("build_ext", cmd.get_source_files())) for item in cmd.get_source_files(): result.append(_posixpath.sep.join( _os.path.normpath(item).split(_os.path.sep) @@ -288,7 +288,7 @@ def make_manifest(manifest, config, docs, kwargs): cmd = dist.get_command_obj("build_clib") cmd.ensure_finalized() if cmd.libraries: - #import pprint; pprint.pprint(("build_clib", cmd.get_source_files())) + # import pprint; pprint.pprint(("build_clib", cmd.get_source_files())) for item in cmd.get_source_files(): result.append(_posixpath.sep.join( _os.path.normpath(item).split(_os.path.sep) @@ -301,7 +301,7 @@ def make_manifest(manifest, config, docs, kwargs): cmd = dist.get_command_obj("build_scripts") cmd.ensure_finalized() - #import pprint; pprint.pprint(("build_scripts", cmd.get_source_files())) + # import pprint; pprint.pprint(("build_scripts", cmd.get_source_files())) if cmd.get_source_files(): for item in cmd.get_source_files(): result.append(_posixpath.sep.join( @@ -310,7 +310,7 @@ def make_manifest(manifest, config, docs, kwargs): cmd = dist.get_command_obj("install_data") cmd.ensure_finalized() - #from pprint import pprint; pprint(("install_data", cmd.get_inputs())) + # from pprint import pprint; pprint(("install_data", cmd.get_inputs())) try: strings = str except NameError: @@ -335,11 +335,15 @@ def make_manifest(manifest, config, docs, kwargs): def run(config=('package.cfg',), ext=None, script_args=None, manifest_only=0): """ Main runner """ + # pylint: disable = too-many-locals if ext is None: ext = [] cfg = _util.SafeConfigParser() - cfg.read(config, encoding='utf-8') + if (3, 0, 0) <= _sys.version_info < (3, 2, 0): + cfg.read(config) + else: + cfg.read(config, encoding='utf-8') pkg = dict(cfg.items('package')) python_min = pkg.get('python.min') or None python_max = pkg.get('python.max') or None From 8d30069caf0974cd2c4efd97ab3c29e31f4a9d16 Mon Sep 17 00:00:00 2001 From: ndparker Date: Sun, 15 Mar 2015 13:04:49 +0100 Subject: [PATCH 6/9] use curses APIs as intended --- py2/term/_term.py | 9 +++------ py3/term/_term.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/py2/term/_term.py b/py2/term/_term.py index 72b727c..ad3ca95 100644 --- a/py2/term/_term.py +++ b/py2/term/_term.py @@ -1,6 +1,6 @@ # -*- coding: ascii -*- # -# Copyright 2007, 2008, 2009, 2010, 2011 +# Copyright 2007 - 2015 # Andr\xe9 Malo or his licensors, as applicable # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -54,8 +54,7 @@ class _INFO(dict): """ Make color control string """ seq = _curses.tigetstr('setaf') if seq is not None: - # XXX may fail - need better logic - seq = seq.replace("%p1", "") % color + seq = _curses.tparm(seq, color) return seq self['NORMAL'] = _curses.tigetstr('sgr0') @@ -71,7 +70,7 @@ class _INFO(dict): def __getitem__(self, key): """ Deliver always """ - dict.get(self, key) or "" + return dict.get(self, key) or "" def terminfo(): @@ -111,5 +110,3 @@ def announce(fmt, **kwargs): write(fmt, **kwargs) _sys.stdout.write("\n") _sys.stdout.flush() - - diff --git a/py3/term/_term.py b/py3/term/_term.py index 4d70d1e..03f5acb 100644 --- a/py3/term/_term.py +++ b/py3/term/_term.py @@ -1,6 +1,6 @@ # -*- coding: ascii -*- # -# Copyright 2007, 2008, 2009, 2010, 2011 +# Copyright 2007 - 2015 # Andr\xe9 Malo or his licensors, as applicable # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -53,16 +53,16 @@ class _INFO(dict): try: _curses.tigetstr('sgr0') except TypeError: # pypy3 + # pylint: disable = invalid-name bc = lambda val: val.encode('ascii') else: - bc = lambda val: val + bc = lambda val: val # pylint: disable = invalid-name def make_color(color): """ Make color control string """ - seq = _curses.tigetstr(bc('setaf')).decode('ascii') + seq = _curses.tigetstr(bc('setaf')) if seq is not None: - # XXX may fail - need better logic - seq = seq.replace("%p1", "") % color + seq = _curses.tparm(seq, color).decode('ascii') return seq self['NORMAL'] = _curses.tigetstr(bc('sgr0')).decode('ascii') @@ -79,7 +79,7 @@ class _INFO(dict): def __getitem__(self, key): """ Deliver always """ - dict.get(self, key) or "" + return dict.get(self, key) or "" def terminfo(): @@ -119,5 +119,3 @@ def announce(fmt, **kwargs): write(fmt, **kwargs) _sys.stdout.write("\n") _sys.stdout.flush() - - From ab5b3a12bcebf87a0199c2f8102bde32a1a9f9e6 Mon Sep 17 00:00:00 2001 From: ndparker Date: Sun, 15 Mar 2015 18:30:05 +0100 Subject: [PATCH 7/9] some cleanup, some docs --- include/cext.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/cext.h b/include/cext.h index 093c61d..2de5bc0 100644 --- a/include/cext.h +++ b/include/cext.h @@ -249,13 +249,17 @@ typedef int Py_ssize_t; #define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC) #endif -#define DEFINE_GENERIC_DEALLOC(prefix) \ -static void prefix##_dealloc(void *self) \ -{ \ - if (PyType_IS_GC(((PyObject *)self)->ob_type)) \ - PyObject_GC_UnTrack(self); \ - (void)prefix##_clear(self); \ - ((PyObject *)self)->ob_type->tp_free((PyObject *)self); \ +#ifndef Py_TYPE +#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) +#endif + +#define DEFINE_GENERIC_DEALLOC(prefix) \ +static void prefix##_dealloc(void *self) \ +{ \ + if (PyType_IS_GC(Py_TYPE(self))) \ + PyObject_GC_UnTrack(self); \ + (void)prefix##_clear(self); \ + (Py_TYPE(self))->tp_free((PyObject *)self); \ } #endif /* SETUP_CEXT_H */ From 5f18f79207bb0b3a6557ba36bf00c1b84c381a4f Mon Sep 17 00:00:00 2001 From: ndparker Date: Thu, 19 Mar 2015 14:10:37 +0100 Subject: [PATCH 8/9] use unicode docstring --- include/cext.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/cext.h b/include/cext.h index 2de5bc0..78fa7f5 100644 --- a/include/cext.h +++ b/include/cext.h @@ -97,6 +97,8 @@ static struct PyModuleDef EXT_DEFINE_VAR = { \ #define EXT_INIT_ERROR(module) do {Py_XDECREF(module); return NULL;} while(0) #define EXT_INIT_RETURN(module) return module +#define EXT_DOC_UNICODE(m) + #else /* end py3k */ #define EXT2 @@ -134,6 +136,25 @@ static struct EXT_DEFINE__STRUCT EXT_DEFINE_VAR = { \ #define EXT_INIT_ERROR(module) return #define EXT_INIT_RETURN(module) return +#define EXT_DOC_UNICODE(m) do { \ + PyObject *doc__, *uni__; \ + int res__; \ + \ + if ((doc__ = PyObject_GetAttrString(m, "__doc__"))) { \ + uni__ = PyUnicode_FromEncodedObject(doc__, "utf-8", "strict"); \ + Py_DECREF(doc__); \ + if (!uni__) \ + EXT_INIT_ERROR(m); \ + res__ = PyObject_SetAttrString(m, "__doc__", uni__); \ + Py_DECREF(uni__); \ + if (res__ == -1) \ + EXT_INIT_ERROR(m); \ + } \ + else if (!(PyErr_Occurred() \ + && PyErr_ExceptionMatches(PyExc_AttributeError))) \ + EXT_INIT_ERROR(m); \ +} while(0) + #endif /* end py2K */ #define EXT_INIT_TYPE(module, type) do { \ From c7ec74ca0a95014daaa3d8dafea308b958031537 Mon Sep 17 00:00:00 2001 From: ndparker Date: Sun, 11 Oct 2015 15:19:51 +0200 Subject: [PATCH 9/9] fix handling of packages without dev revisions --- py2/setup.py | 2 ++ py3/setup.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/py2/setup.py b/py2/setup.py index b2fcde8..8b15d49 100644 --- a/py2/setup.py +++ b/py2/setup.py @@ -369,6 +369,8 @@ def run(config=('package.cfg',), ext=None, script_args=None, manifest_only=0): revision = pkg.get('version.revision', '').strip() if revision: revision = int(revision) + else: + revision = 0 kwargs = { 'name': pkg['name'], diff --git a/py3/setup.py b/py3/setup.py index 8a30540..bb1e2ee 100644 --- a/py3/setup.py +++ b/py3/setup.py @@ -374,6 +374,8 @@ def run(config=('package.cfg',), ext=None, script_args=None, manifest_only=0): revision = pkg.get('version.revision', '').strip() if revision: revision = int(revision) + else: + revision = 0 kwargs = { 'name': pkg['name'],