From 3d220139a60b34bc7da8056e635c45b7d28bdfd1 Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Wed, 22 May 2019 20:12:41 +0300 Subject: [PATCH] Fixed the stuff to use setuptools better. Low-value stuff like inserting versions into README.md and adding a file with metainfo has been removed. If one needs a version info or content of README, he should use pkg_resources. Releases are the versions built from git tags. Development releases have git tags with "-dev" :) Also added some goodies, like .editorconfig and ignores. --- .editorconfig | 8 + .gitignore | 2 + dill/__init__.py | 12 - dill/tools/__init__.py | 0 .../tools/get_objgraph.py | 2 +- scripts/undill => dill/tools/undill.py | 2 +- pyproject.toml | 5 + setup.cfg | 52 ++- setup.py | 318 +----------------- 9 files changed, 68 insertions(+), 333 deletions(-) create mode 100644 .editorconfig create mode 100644 dill/tools/__init__.py rename scripts/get_objgraph => dill/tools/get_objgraph.py (98%) rename scripts/undill => dill/tools/undill.py (95%) create mode 100644 pyproject.toml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..b0d1ce9b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*.py] +charset = utf-8 +indent_style = space +indent_size = 4 +insert_final_newline = true +end_of_line = lf diff --git a/.gitignore b/.gitignore index a1eb9281..b9cf3257 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .cache/ *.egg-info/ *.pyc +/dist +/build diff --git a/dill/__init__.py b/dill/__init__.py index 6e216273..0797d784 100644 --- a/dill/__init__.py +++ b/dill/__init__.py @@ -7,21 +7,9 @@ # - https://github.com/uqfoundation/dill/blob/master/LICENSE # get version numbers, license, and long description -try: - from .info import this_version as __version__ - from .info import readme as __doc__, license as __license__ -except ImportError: - msg = """First run 'python setup.py build' to build dill.""" - raise ImportError(msg) __author__ = 'Mike McKerns' -__doc__ = """ -""" + __doc__ - -__license__ = """ -""" + __license__ - from ._dill import dump, dumps, load, loads, dump_session, load_session, \ Pickler, Unpickler, register, copy, pickle, pickles, check, \ HIGHEST_PROTOCOL, DEFAULT_PROTOCOL, PicklingError, UnpicklingError, \ diff --git a/dill/tools/__init__.py b/dill/tools/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/scripts/get_objgraph b/dill/tools/get_objgraph.py similarity index 98% rename from scripts/get_objgraph rename to dill/tools/get_objgraph.py index 4ff9f765..922fd5f7 100644 --- a/scripts/get_objgraph +++ b/dill/tools/get_objgraph.py @@ -28,7 +28,7 @@ load_types(pickleable=True,unpickleable=True) from dill import objects -if __name__ == "__main__": +def get_objgraph(): import sys if len(sys.argv) != 2: print ("Please provide exactly one file or type name (e.g. 'IntType')") diff --git a/scripts/undill b/dill/tools/undill.py similarity index 95% rename from scripts/undill rename to dill/tools/undill.py index c4e05a14..9e842022 100644 --- a/scripts/undill +++ b/dill/tools/undill.py @@ -14,7 +14,7 @@ ['hello', 'world'] """ -if __name__ == '__main__': +def undill(): import sys import dill for file in sys.argv[1:]: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..66ddafdb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[build-system] +requires = ["setuptools>=44", "wheel", "setuptools_scm[toml]>=3.4.3"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] diff --git a/setup.cfg b/setup.cfg index 46edaabe..a4e1a175 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,48 @@ -[egg_info] -tag_build = .dev0 -#tag_svn_revision = yes -#tag_date = yes +[metadata] +name = dill +author = Mike McKerns +maintainer = Mike McKerns +license = BSD-3-Clause +license_file = LICENSE +description = serialize all of python +long_description = file: README.md +long_description_content_type = text/markdown +url = https://pypi.org/project/dill +homepage = https://github.com/uqfoundation/dill +download_url = https://github.com/uqfoundation/dill +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + Intended Audience :: Science/Research + License :: OSI Approved :: BSD License + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.5 + Programming Language :: Python :: 2.6 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.1 + Programming Language :: Python :: 3.2 + Programming Language :: Python :: 3.3 + Programming Language :: Python :: 3.4 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Topic :: Scientific/Engineering + Topic :: Software Development +platforms = Linux, Windows, Mac + +[options] +packages = dill, dill.tools +zip_safe = False +python_requires = >=2.5, !=3.0.* +setup_requires = setuptools>=44; wheel; setuptools_scm[toml]>=3.4.3 + +[options.extras_require] +readline = pyreadline>=1.7.1 +graph = objgraph>=1.7.2 + +[options.entry_points] +console_scripts = + undill = dill.tools.undill:undill + get_objgraph = dill.tools.get_objgraph:get_objgraph diff --git a/setup.py b/setup.py index c9f7f1cd..5178d666 100644 --- a/setup.py +++ b/setup.py @@ -6,319 +6,7 @@ # License: 3-clause BSD. The full license text is available at: # - https://github.com/uqfoundation/dill/blob/master/LICENSE -import os -import sys -# drop support for older python -unsupported = None -if sys.version_info < (2, 7): - unsupported = 'Versions of Python before 2.7 are not supported' -elif (3, 0) <= sys.version_info < (3, 5): - unsupported = 'Versions of Python before 3.5 are not supported' -if unsupported: - raise ValueError(unsupported) +from setuptools import setup -# set version numbers -stable_version = '0.3.3' -target_version = '0.3.4' -is_release = stable_version == target_version - -# check if easy_install is available -try: -# import __force_distutils__ #XXX: uncomment to force use of distutills - from setuptools import setup - has_setuptools = True -except ImportError: - from distutils.core import setup - has_setuptools = False - -# generate version number -if os.path.exists('dill/info.py'): - # is a source distribution, so use existing version - os.chdir('dill') - with open('info.py','r') as f: - f.readline() # header - this_version = f.readline().split()[-1].strip("'") - os.chdir('..') -elif stable_version == target_version: - # we are building a stable release - this_version = target_version -else: - # we are building a distribution - this_version = target_version + '.dev0' - if is_release: - from datetime import date - today = "".join(date.isoformat(date.today()).split('-')) - this_version += "-" + today - -# get the license info -with open('LICENSE') as file: - license_text = file.read() - -# generate the readme text -long_description = \ -"""----------------------------- -dill: serialize all of python ------------------------------ - -About Dill -========== - -``dill`` extends python's ``pickle`` module for serializing and de-serializing -python objects to the majority of the built-in python types. Serialization -is the process of converting an object to a byte stream, and the inverse -of which is converting a byte stream back to a python object hierarchy. - -``dill`` provides the user the same interface as the ``pickle`` module, and -also includes some additional features. In addition to pickling python -objects, ``dill`` provides the ability to save the state of an interpreter -session in a single command. Hence, it would be feasable to save a -interpreter session, close the interpreter, ship the pickled file to -another computer, open a new interpreter, unpickle the session and -thus continue from the 'saved' state of the original interpreter -session. - -``dill`` can be used to store python objects to a file, but the primary -usage is to send python objects across the network as a byte stream. -``dill`` is quite flexible, and allows arbitrary user defined classes -and functions to be serialized. Thus ``dill`` is not intended to be -secure against erroneously or maliciously constructed data. It is -left to the user to decide whether the data they unpickle is from -a trustworthy source. - -``dill`` is part of ``pathos``, a python framework for heterogeneous computing. -``dill`` is in active development, so any user feedback, bug reports, comments, -or suggestions are highly appreciated. A list of issues is located at https://github.com/uqfoundation/dill/issues, with a legacy list maintained at https://uqfoundation.github.io/pathos-issues.html. - - -Major Features -============== - -``dill`` can pickle the following standard types: - - - none, type, bool, int, long, float, complex, str, unicode, - - tuple, list, dict, file, buffer, builtin, - - both old and new style classes, - - instances of old and new style classes, - - set, frozenset, array, functions, exceptions - -``dill`` can also pickle more 'exotic' standard types: - - - functions with yields, nested functions, lambdas, - - cell, method, unboundmethod, module, code, methodwrapper, - - dictproxy, methoddescriptor, getsetdescriptor, memberdescriptor, - - wrapperdescriptor, xrange, slice, - - notimplemented, ellipsis, quit - -``dill`` cannot yet pickle these standard types: - - - frame, generator, traceback - -``dill`` also provides the capability to: - - - save and load python interpreter sessions - - save and extract the source code from functions and classes - - interactively diagnose pickling errors - - -Current Release -=============== - -This documentation is for version ``dill-%(thisver)s``. - -The latest released version of ``dill`` is available from: - - https://pypi.org/project/dill - -``dill`` is distributed under a 3-clause BSD license. - - >>> import dill - >>> dill.license() - - -Development Version -=================== - -You can get the latest development version with all the shiny new features at: - - https://github.com/uqfoundation - -If you have a new contribution, please submit a pull request. - - -Installation -============ - -``dill`` is packaged to install from source, so you must -download the tarball, unzip, and run the installer:: - - [download] - $ tar -xvzf dill-%(relver)s.tar.gz - $ cd dill-%(relver)s - $ python setup py build - $ python setup py install - -You will be warned of any missing dependencies and/or settings -after you run the "build" step above. - -Alternately, ``dill`` can be installed with ``pip`` or ``easy_install``:: - - $ pip install dill - - -Requirements -============ - -``dill`` requires: - - - ``python``, **version == 2.7** or **version >= 3.5**, or ``pypy`` - -Optional requirements: - - - ``setuptools``, **version >= 0.6** - - ``pyreadline``, **version >= 1.7.1** (on windows) - - ``objgraph``, **version >= 1.7.2** - - -More Information -================ - -Probably the best way to get started is to look at the documentation at -http://dill.rtfd.io. Also see ``dill.tests`` for a set of scripts that -demonstrate how ``dill`` can serialize different python objects. You can -run the test suite with ``python -m dill.tests``. The contents of any -pickle file can be examined with ``undill``. As ``dill`` conforms to -the ``pickle`` interface, the examples and documentation found at -http://docs.python.org/library/pickle.html also apply to ``dill`` -if one will ``import dill as pickle``. The source code is also generally -well documented, so further questions may be resolved by inspecting the -code itself. Please feel free to submit a ticket on github, or ask a -question on stackoverflow (**@Mike McKerns**). -If you would like to share how you use ``dill`` in your work, please send -an email (to **mmckerns at uqfoundation dot org**). - - -Citation -======== - -If you use ``dill`` to do research that leads to publication, we ask that you -acknowledge use of ``dill`` by citing the following in your publication:: - - M.M. McKerns, L. Strand, T. Sullivan, A. Fang, M.A.G. Aivazis, - "Building a framework for predictive science", Proceedings of - the 10th Python in Science Conference, 2011; - http://arxiv.org/pdf/1202.1056 - - Michael McKerns and Michael Aivazis, - "pathos: a framework for heterogeneous computing", 2010- ; - https://uqfoundation.github.io/pathos.html - -Please see https://uqfoundation.github.io/pathos.html or -http://arxiv.org/pdf/1202.1056 for further information. - -""" % {'relver' : stable_version, 'thisver' : this_version} - -# write readme file -with open('README', 'w') as file: - file.write(long_description) - -# generate 'info' file contents -def write_info_py(filename='dill/info.py'): - contents = """# THIS FILE GENERATED FROM SETUP.PY -this_version = '%(this_version)s' -stable_version = '%(stable_version)s' -readme = '''%(long_description)s''' -license = '''%(license_text)s''' -""" - with open(filename, 'w') as file: - file.write(contents % {'this_version' : this_version, - 'stable_version' : stable_version, - 'long_description' : long_description, - 'license_text' : license_text }) - return - -# write info file -write_info_py() - -# build the 'setup' call -setup_code = """ -setup(name='dill', - version='%s', - description='serialize all of python', - long_description = '''%s''', - author = 'Mike McKerns', - maintainer = 'Mike McKerns', - license = '3-clause BSD', - platforms = ['Linux', 'Windows', 'Mac'], - url = 'https://pypi.org/project/dill', - download_url = 'https://github.com/uqfoundation/dill/releases/download/dill-%s/dill-%s.tar.gz', - python_requires='>=2.6, !=3.0.*', - classifiers = ['Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'Intended Audience :: Science/Research', - 'License :: OSI Approved :: BSD License', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.2', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Topic :: Scientific/Engineering', - 'Topic :: Software Development'], - - packages = ['dill','dill.tests'], - package_dir = {'dill':'dill', 'dill.tests':'tests'}, -""" % (target_version, long_description, stable_version, stable_version) - -# add dependencies -ctypes_version = '>=1.0.1' -objgraph_version = '>=1.7.2' -pyreadline_version = '>=1.7.1' -if has_setuptools: - setup_code += """ - zip_safe=False, -""" - if sys.platform[:3] == 'win': - setup_code += """ - extras_require = {'readline': ['pyreadline%s'], 'graph': ['objgraph%s']}, -""" % (pyreadline_version, objgraph_version) - # verrrry unlikely that this is still relevant - elif hex(sys.hexversion) < '0x20500f0': - setup_code += """ - install_requires = ['ctypes%s'], - extras_require = {'readline': [], 'graph': ['objgraph%s']}, -""" % (ctypes_version, objgraph_version) - else: - setup_code += """ - extras_require = {'readline': [], 'graph': ['objgraph%s']}, -""" % (objgraph_version) - -# add the scripts, and close 'setup' call -setup_code += """ - scripts=['scripts/undill','scripts/get_objgraph']) -""" - -# exec the 'setup' code -exec(setup_code) - -# if dependencies are missing, print a warning -try: - import ctypes - import readline -except ImportError: - print ("\n***********************************************************") - print ("WARNING: One of the following dependencies is unresolved:") - print (" ctypes %s" % ctypes_version) - if sys.platform[:3] == 'win': - print (" readline %s" % pyreadline_version) - print ("***********************************************************\n") - - -if __name__=='__main__': - pass - -# end of file +if __name__ == "__main__": + setup()