From 0ca79f6d25e0c54728cc93044b0c3634eb430fc1 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Thu, 18 Feb 2021 11:01:58 -0800 Subject: [PATCH 1/2] Cleanup requirements a little. Signed-off-by: Tim 'mithro' Ansell --- requirements.txt | 10 +++++++--- setup.py | 19 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index e3a9915f..9b701df3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,13 @@ -check-manifest +# Required for fasm tooling cython +setuptools>=42 +setuptools_scm[toml]>=3.4 +textx +wheel +# Testing +check-manifest flake8 pytest -textx tox twine -wheel yapf==0.24.0 diff --git a/setup.py b/setup.py index 784b8ad4..e63b930c 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ with open("README.md", "r") as fh: long_description = fh.read() + # Read in the version information FASM_VERSION_FILE = os.path.join(__dir__, 'fasm', 'version.py') with open(FASM_VERSION_FILE) as f: @@ -253,6 +254,7 @@ def run(self): setuptools.setup( + # Package human readable information name="fasm", version=version, author="SymbiFlow Authors", @@ -261,17 +263,28 @@ def run(self): long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/SymbiFlow/fasm", - packages=setuptools.find_packages(exclude=('tests*', )), - install_requires=['textx'], - include_package_data=True, + license="ISC", classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: ISC License (ISCL)", "Operating System :: OS Independent", ], + # Package contents control + packages=setuptools.find_packages(exclude=['tests*']), + include_package_data=True, entry_points={ 'console_scripts': ['fasm=fasm.tool:main'], }, + # Requirements + python_requires="~=3.6", + setup_requires=[ + "wheel", + "setuptools", + ], + install_requires=[ + 'textx', + ], + # C extension building ext_modules=[ CMakeExtension('parse_fasm', sourcedir='src', prefix='fasm/parser') ] + cythonize("fasm/parser/antlr_to_tuple.pyx"), From 5c80c40c89b5378dab141b14aa918d16896265f9 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Thu, 18 Feb 2021 11:01:58 -0800 Subject: [PATCH 2/2] Move to setuptools_scm for version output. --- pyproject.toml | 12 +++- setup.cfg | 7 ++- setup.py | 32 +++++----- update_version.py | 151 ---------------------------------------------- 4 files changed, 31 insertions(+), 171 deletions(-) delete mode 100755 update_version.py diff --git a/pyproject.toml b/pyproject.toml index e9f294dd..d92399e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,12 @@ [build-system] -requires = ["setuptools", "wheel", "cython"] +requires = [ + "cython", + "setuptools>=42", + "setuptools_scm[toml]>=3.4", + "wheel", +] + +[tool.setuptools_scm] +version_scheme = "post-release" +write_to = "fasm/version.py" +tag_regex = "v[0-9.]+" diff --git a/setup.cfg b/setup.cfg index 33aea034..f6586a0f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,8 @@ [metadata] license_files = LICENSE -[bdist_wheel] -universal=1 +[options] +setup_requires = + wheel + setuptools + setuptools_scm diff --git a/setup.py b/setup.py index e63b930c..6c65a529 100644 --- a/setup.py +++ b/setup.py @@ -32,22 +32,18 @@ long_description = fh.read() -# Read in the version information -FASM_VERSION_FILE = os.path.join(__dir__, 'fasm', 'version.py') -with open(FASM_VERSION_FILE) as f: - if 'UNKNOWN' in f.read(): - print( - "Running update_version.py to generate {}".format( - FASM_VERSION_FILE)) - subprocess.check_call(['python', 'update_version.py'], cwd=__dir__) -with open(FASM_VERSION_FILE) as f: - lines = f.readlines() - version_line = [v.strip() for v in lines if v.startswith('version_str')] -assert len(version_line) == 1, version_line -version_value = version_line[0].split(' = ', 1)[-1] -assert version_value[0] == '"', version_value -assert version_value[-1] == '"', version_value -version = version_value[1:-1] +# Generate the version number +def scm_version(): + def local_scheme(version): + if version.tag and not version.distance: + return version.format_with("") + else: + return version.format_choice("+{node}", "+{node}.dirty") + return { + "relative_to": __file__, + "version_scheme": "guess-next-dev", + "local_scheme": local_scheme + } # Based on: https://www.benjack.io/2018/02/02/python-cpp-revisited.html @@ -256,7 +252,7 @@ def run(self): setuptools.setup( # Package human readable information name="fasm", - version=version, + use_scm_version=scm_version(), author="SymbiFlow Authors", author_email="symbiflow@lists.librecores.org", description="FPGA Assembly (FASM) Parser and Generation library", @@ -280,8 +276,10 @@ def run(self): setup_requires=[ "wheel", "setuptools", + "setuptools_scm", ], install_requires=[ + "importlib_metadata; python_version<'3.8'", # for __version__ 'textx', ], # C extension building diff --git a/update_version.py b/update_version.py deleted file mode 100755 index 099ec365..00000000 --- a/update_version.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env python3 - -import platform -import subprocess -import sys - -VERSION_FILE = 'fasm/version.py' -VERSION_FILE_TEMPLATE = '''\ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (C) 2017-2020 The SymbiFlow Authors. -# -# Use of this source code is governed by a ISC-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/ISC -# -# SPDX-License-Identifier: ISC - -# ** WARNING ** -# This file is auto-generated by the update_version.py script. -# ** WARNING ** - -version_str = "{version}" -version_tuple = {version_tuple} -try: - from packaging.version import Version as V - pversion = V("{version}") -except ImportError: - pass - -git_hash = "{git_hash}" -git_describe = "{git_describe}" -git_msg = """\\ -{git_msg} -""" -''' - -GIT = 'git' -if platform.system() == 'Windows': - GIT = 'git.exe' - - -def get_hash(): - cmd = [GIT, 'rev-parse', 'HEAD'] - try: - return subprocess.check_output(cmd).decode('utf-8').strip() - except OSError: - print(cmd) - raise - - -def get_describe(): - cmd = [ - GIT, 'describe', '--tags', 'HEAD', '--match', 'v*', '--exclude', '*-r*' - ] - try: - return subprocess.check_output(cmd).decode('utf-8').strip() - except OSError: - print(cmd) - raise - - -def get_msg(): - cmd = [GIT, 'log', '-1', 'HEAD'] - try: - data = subprocess.check_output(cmd).decode('utf-8') - except OSError: - print(cmd) - raise - return '\n'.join(line.rstrip() for line in data.split('\n')) - - -def create_version_tuple(git_describe): - """ - >>> t = '''\\ - ... v0.0 - ... v0.0.0 - ... v1.0.1-265-g5f0c7a7 - ... v0.0-7004-g1cf70ea2 - ... ''' - >>> for d in t.splitlines(): - ... v = create_version_tuple(d) - ... print((create_version_str(v), v)) - ('0.0', (0, 0, None)) - ('0.0.0', (0, 0, 0, None)) - ('1.0.1.post265', (1, 0, 1, 265)) - ('0.0.post7004', (0, 0, 7004)) - """ - vtag = git_describe.strip() - if vtag.startswith('v'): - vtag = vtag[1:] - - vbits = vtag.split('.') - vpost = [None] - if '-' in vbits[-1]: - vend = vbits.pop(-1).split('-') - assert len(vend) == 3, (vtag, vbits, vend) - assert len(vend[0]) > 0, (vtag, vbits, vend) - vbits.append(vend.pop(0)) - vpost = [int(vend.pop(0))] - assert vend[-1].startswith('g'), (vtag, vbits, vend, vpost) - vbits = [int(i) for i in vbits] - vbits.extend(vpost) - return tuple(vbits) - - -def create_version_str(version_tuple): - vbits = [str(i) for i in version_tuple] - if version_tuple[-1] is None: - vbits.pop(-1) - else: - vbits[-1] = 'post' + vbits[-1] - return '.'.join(vbits) - - -def update_version_py(args): - output = VERSION_FILE_TEMPLATE.format(**args) - - old = '' - try: - with open(VERSION_FILE) as f: - old = f.read() - except IOError as e: - print(e) - - if old != output: - with open(VERSION_FILE, 'w') as f: - f.write(output) - print('Updated {}'.format(VERSION_FILE)) - - -def main(args): - git_hash = get_hash() - git_describe = get_describe() - git_msg = get_msg() - - version_tuple = create_version_tuple(git_describe) - version = create_version_str(version_tuple) - - update_version_py(locals()) - - return 0 - - -if __name__ == "__main__": - import doctest - failure_count, test_count = doctest.testmod() - if failure_count > 0: - sys.exit(-1) - sys.exit(main(sys.argv))