22#
33"""setuptools-based setup.py for unpythonic.
44
5- Tested on Python 3.6 .
5+ Tested on Python 3.8 .
66
77Usage as usual with setuptools:
88 python3 setup.py build
1818 python3 setup.py --help bdist_wheel # or any command
1919"""
2020
21- #########################################################
22- # General config
23- #########################################################
24-
25- # Name of the top-level package of the library.
26- #
27- # This is also the top level of its source tree, relative to the top-level project directory setup.py resides in.
28- #
29- libname = "unpythonic"
30-
31- # Short description for package list on PyPI
32- #
33- SHORTDESC = "Supercharge your Python with parts of Lisp and Haskell."
21+ import ast
22+ import os
3423
35- #########################################################
36- # Init
37- #########################################################
24+ from setuptools import setup # type: ignore[import]
3825
39- import os
40- from setuptools import setup
4126
4227def read (* relpath , ** kwargs ): # https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-setup-script
4328 with open (os .path .join (os .path .dirname (__file__ ), * relpath ),
4429 encoding = kwargs .get ('encoding' , 'utf8' )) as fh :
4530 return fh .read ()
4631
47- # TODO: update version detector for Python 3.8 (accept also ast.Constant beside ast.Str)
48- #
4932# Extract __version__ from the package __init__.py
5033# (since it's not a good idea to actually run __init__.py during the build process).
5134#
5235# http://stackoverflow.com/questions/2058802/how-can-i-get-the-version-defined-in-setup-py-setuptools-in-my-package
5336#
54- import ast
55- init_py_path = os .path .join (libname , '__init__.py' )
37+ init_py_path = os .path .join ("unpythonic" , "__init__.py" )
5638version = None
5739try :
5840 with open (init_py_path ) as f :
5941 for line in f :
60- if line .startswith ('__version__' ):
61- version = ast .parse (line ).body [0 ].value .s
42+ if line .startswith ("__version__" ):
43+ module = ast .parse (line )
44+ expr = module .body [0 ]
45+ assert isinstance (expr , ast .Assign )
46+ v = expr .value
47+ if type (v ) is ast .Constant : # Python 3.8+
48+ # mypy understands `isinstance(..., ...)` but not `type(...) is ...`,
49+ # and we want to match on the exact type, not any subclass that might be
50+ # added in some future Python version.
51+ assert isinstance (v , ast .Constant )
52+ version = v .value
53+ elif type (v ) is ast .Str :
54+ assert isinstance (v , ast .Str ) # mypy
55+ version = v .s
6256 break
6357except FileNotFoundError :
6458 pass
6559if not version :
66- raise RuntimeError ("Version information not found in '{}'" . format ( init_py_path ) )
60+ raise RuntimeError (f "Version information not found in { init_py_path } " )
6761
6862#########################################################
6963# Call setup()
@@ -72,65 +66,36 @@ def read(*relpath, **kwargs): # https://blog.ionelmc.ro/2014/05/25/python-packa
7266setup (
7367 name = "unpythonic" ,
7468 version = version ,
69+ packages = ["unpythonic" , "unpythonic.syntax" ],
70+ provides = ["unpythonic" ],
71+ keywords = ["functional-programming" , "language-extension" , "syntactic-macros" ,
72+ "tail-call-optimization" , "tco" , "continuations" , "currying" , "lazy-evaluation" ,
73+ "dynamic-variable" , "macros" , "lisp" , "scheme" , "racket" , "haskell" ],
74+ install_requires = [], # mcpyrate is optional for us, so we can't really put it here even though we recommend it.
75+ python_requires = ">=3.6,<3.10" ,
7576 author = "Juha Jeronen" ,
7677 author_email = "juha.m.jeronen@gmail.com" ,
7778 url = "https://github.com/Technologicat/unpythonic" ,
78-
79- # https://packaging.python.org/guides/making-a-pypi-friendly-readme/
80- description = SHORTDESC ,
79+ description = "Supercharge your Python with parts of Lisp and Haskell." ,
8180 long_description = read ("README.md" ),
8281 long_description_content_type = "text/markdown" ,
83-
8482 license = "BSD" ,
85-
86- # free-form text field; http://stackoverflow.com/questions/34994130/what-platforms-argument-to-setup-in-setup-py-does
8783 platforms = ["Linux" ],
88-
89- # See
90- # https://pypi.python.org/pypi?%3Aaction=list_classifiers
91- #
92- # for the standard classifiers.
93- #
9484 classifiers = ["Development Status :: 4 - Beta" ,
9585 "Environment :: Console" ,
9686 "Intended Audience :: Developers" ,
9787 "License :: OSI Approved :: BSD License" ,
9888 "Operating System :: POSIX :: Linux" ,
9989 "Programming Language :: Python" ,
10090 "Programming Language :: Python :: 3" ,
101- "Programming Language :: Python :: 3.4" ,
102- "Programming Language :: Python :: 3.5" ,
10391 "Programming Language :: Python :: 3.6" ,
10492 "Programming Language :: Python :: 3.7" ,
93+ "Programming Language :: Python :: 3.8" ,
94+ "Programming Language :: Python :: 3.9" ,
10595 "Programming Language :: Python :: Implementation :: CPython" ,
10696 "Programming Language :: Python :: Implementation :: PyPy" ,
10797 "Topic :: Software Development :: Libraries" ,
10898 "Topic :: Software Development :: Libraries :: Python Modules"
10999 ],
110-
111- # See
112- # http://setuptools.readthedocs.io/en/latest/setuptools.html
113- #
114- python_requires = ">=3.4,<3.8" ,
115- install_requires = [], # MacroPy is optional for us, so we can't really put "macropy3" here even though we recommend it.
116- # setup_requires=[], # TODO: Using setup_requires is discouraged in favor of https://www.python.org/dev/peps/pep-0518/
117- # test_requires=["macropy3"], # TODO: not very useful, because only "python3 setup.py test" installs these, and we don't use that.
118- provides = ["unpythonic" ],
119-
120- # keywords for PyPI (in case you upload your project)
121- #
122- # e.g. the keywords your project uses as topics on GitHub, minus "python" (if there)
123- #
124- keywords = ["functional-programming" , "language-extension" , "syntactic-macros" ,
125- "tail-call-optimization" , "tco" , "continuations" , "currying" , "lazy-evaluation" ,
126- "dynamic-variable" , "macros" , "lisp" , "scheme" , "racket" , "haskell" ],
127-
128- # Declare packages so that python -m setup build will copy .py files (especially __init__.py).
129- #
130- # This **does not** automatically recurse into subpackages, so they must also be declared.
131- #
132- packages = ["unpythonic" , "unpythonic.syntax" ],
133- scripts = ["macropy3" ],
134-
135- zip_safe = False # macros are not zip safe, because the zip importer fails to find sources, and MacroPy needs them.
100+ zip_safe = False # macros are not zip safe, because the zip importer fails to find sources.
136101)
0 commit comments