From c95cca8801554826002e4991d3834b67ffc22cb3 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 8 Apr 2024 13:44:47 +0200 Subject: [PATCH] Standardized setup.py --- README.md | 4 ++- pbcabi/__init__.py | 3 +-- pbcabi/_version.py | 1 + requirements_test.txt | 1 + setup.py | 63 ++++++++++++++++++++++++++++--------------- 5 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 pbcabi/_version.py create mode 100644 requirements_test.txt diff --git a/README.md b/README.md index 52be559..c3b1c84 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Partisia Blockchain ABI client -Utility library for parsing and processing the [Partisia Blockchain's ABI format](https://partisiablockchain.gitlab.io/documentation/smart-contracts/smart-contract-binary-formats.html).. +Utility library for parsing and processing the Partisia Blockchain ABI Format. + +The format is specified here: [Partisia Blockchain's ABI format](https://partisiablockchain.gitlab.io/documentation/smart-contracts/smart-contract-binary-formats.html).. ## Example usage diff --git a/pbcabi/__init__.py b/pbcabi/__init__.py index 91a7d3e..18faac0 100644 --- a/pbcabi/__init__.py +++ b/pbcabi/__init__.py @@ -8,8 +8,7 @@ Follows the ABI specification quite closely. The full ABI specification can be f import pbcabi.model import pbcabi.binaryreader - -__version__ = "0.1.0" +from ._version import __version__ def get_version(): """ diff --git a/pbcabi/_version.py b/pbcabi/_version.py new file mode 100644 index 0000000..df9144c --- /dev/null +++ b/pbcabi/_version.py @@ -0,0 +1 @@ +__version__ = '0.1.1' diff --git a/requirements_test.txt b/requirements_test.txt new file mode 100644 index 0000000..e079f8a --- /dev/null +++ b/requirements_test.txt @@ -0,0 +1 @@ +pytest diff --git a/setup.py b/setup.py index 3d8e3e7..dc3f026 100644 --- a/setup.py +++ b/setup.py @@ -1,28 +1,47 @@ #!/usr/bin/env python +import re -from os import path -from io import open -from setuptools import setup, find_packages -from enforce_typing import get_version +from setuptools import setup -HERE = path.abspath(path.dirname(__file__)) +PACKAGE_NAME = 'pbcabi' -with open(path.join(HERE, "README.md"), encoding="utf-8") as f: - LONG_DESCRIPTION = f.read() +with open('README.md') as f: + readme = f.read() -if __name__ == "__main__": - setup( - name="pbcabi", - version=get_version(), - description="Utility library for parsing and processing the Partisia Blockchain's ABI format", - long_description=LONG_DESCRIPTION, - long_description_content_type="text/markdown", - author="Jon Michael Aanes", - author_email="jonjmaa@gmail.com", - url="https://gitfub.space/Jmaa/pbcabi", - packages=find_packages(), - license="MIT", - python_requires=">=3.9", - classifiers=[], - ) +with open(PACKAGE_NAME + '/_version.py') as f: + text = f.read() + match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text) + version = match.group(2) + del match, text + +def read_requirements(path: str = 'requirements.txt'): + with open(path) as f: + return f.read().strip().split('\n') + + +def get_short_description(readme: str): + readme = re.sub(r'#+[^\n]*\n+', '', readme) + m = re.search(r'^\s*(\w+[\w\s,`]+\.)', readme) + try: + return m.group(1) + except AttributeError as err: + msg = 'Could not determine short description' + raise Exception(msg) from err + + +setup( + name=PACKAGE_NAME, + version=version, + description=get_short_description(readme), + long_description=readme, + long_description_content_type='text/markdown', + author='Jmaa', + author_email='jonjmaa@gmail.com', + url='https://gitfub.space/Jmaa/' + PACKAGE_NAME, + packages=[PACKAGE_NAME], + install_requires=read_requirements(), + extras_require={ + 'test': read_requirements('requirements_test.txt'), + }, +)