From 8af9655620656a70e0f2cab3798eed1c8d10a259 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 6 Aug 2020 17:01:20 -0700 Subject: [PATCH] Switch from requirements.txt to setup.py --- my-project-name | 10 +++++++++ requirements.txt | 3 --- setup.cfg | 19 ++++++++++++++++ setup.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 3 deletions(-) create mode 100755 my-project-name delete mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/my-project-name b/my-project-name new file mode 100755 index 0000000..688af36 --- /dev/null +++ b/my-project-name @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +import asyncio + +try: + from my_project_name import main + + # Run the main function of the bot + asyncio.get_event_loop().run_until_complete(main.main()) +except ImportError: + print("Unable to import my_project_main.main") diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 26f4dcf..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -matrix-nio>=0.8.0 -Markdown>=3.1.1 -PyYAML>=5.1.2 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..9a8e15b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,19 @@ +[flake8] +# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes +# for error codes. The ones we ignore are: +# W503: line break before binary operator +# W504: line break after binary operator +# E203: whitespace before ':' (which is contrary to pep8?) +# E731: do not assign a lambda expression, use a def +# E501: Line too long (black enforces this for us) +ignore=W503,W504,E203,E731,E501 + +[isort] +line_length = 88 +sections=FUTURE,STDLIB,COMPAT,THIRDPARTY,FIRSTPARTY,TESTS,LOCALFOLDER +default_section=THIRDPARTY +known_first_party=my_project_name +known_tests=tests +multi_line_output=3 +include_trailing_comma=true +combine_as_imports=true diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4eaad64 --- /dev/null +++ b/setup.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +import os + +from setuptools import find_packages, setup + + +def exec_file(path_segments): + """Execute a single python file to get the variables defined in it""" + result = {} + code = read_file(path_segments) + exec(code, result) + return result + + +def read_file(path_segments): + """Read a file from the package. Takes a list of strings to join to + make the path""" + file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), *path_segments) + with open(file_path) as f: + return f.read() + + +version = exec_file(("my_project_name", "__init__.py"))["__version__"] +long_description = read_file(("README.md",)) + + +setup( + name="my-project-name", + version=version, + url="https://github.com/anoadragon453/nio-template", + description="A matrix bot to remind you about things!", + packages=find_packages(exclude=["tests", "tests.*"]), + install_requires=[ + "matrix-nio[e2e]>=0.10.0", + "Markdown>=3.1.1", + "PyYAML>=5.1.2", + ], + extras_require={ + "dev": [ + "isort==5.0.4", + "flake8==3.8.3", + "flake8-comprehensions==3.2.3", + "black==19.10b0", + ], + }, + classifiers=[ + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + ], + long_description=long_description, + long_description_content_type="text/markdown", + # Allow the user to run the bot with `my-project-name ...` + scripts=["my-project-name"], +)