Skip to content

Commit

Permalink
auto-versionning
Browse files Browse the repository at this point in the history
  • Loading branch information
dubssieg committed Nov 29, 2023
1 parent 603c962 commit ddd1963
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 17 deletions.
18 changes: 18 additions & 0 deletions __namespace__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
NAME: str = "gfagraphs"
AUTHOR: str = "Siegfried Dubois",
AUTHOR_EMAIL: str = "siegfried.dubois@inria.fr",
LICENCE: str = "LICENCE"
DESCRIPTION: str = "Library to parse, edit and handle in memory GFA graphs"
REQUIRED_PYTHON: tuple = (3, 10)
WORKSPACE: str = ""
MAIN_MODULE: str = ""
MAIN_FUNC: str = ""

# Change this to ovveride default version number
OVERRIDE_VN: bool = True
VN: str = "0.2.0"

# Fill this part if your tool features command-line interface
HAS_COMMAND_LINE: bool = False
COMMAND: dict = {'console_scripts': [
f'{NAME}={WORKSPACE}.{MAIN_MODULE}:{MAIN_FUNC}']}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "gfagraphs"
version = "0.1.81"
version = "0.2.0"
authors = [
{ name="Tharos", email="dubois.siegfried@gmail.com" },
]
Expand Down
95 changes: 79 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,89 @@
#!/usr/bin/env python3
from sys import version_info, stderr
from setuptools import setup, find_packages
from subprocess import run, PIPE
from __namespace__ import *
from sys import version_info, stderr
from setuptools import setup
from pkg_resources import require
from sys import argv

# Getting requirements
with open("requirements.txt", 'r', encoding='utf-8') as rreader:
requirements: list[str] = [x.strip() for x in rreader.readlines()]

# Get remote URL
_url: str = run(['git', 'config', '--get', 'remote.origin.url'],
stdout=PIPE).stdout.decode(encoding='utf-8').strip()


if argv[1] in ('install', 'sdist', 'bdist_wheel'):
# Checking if Python version is correct
if version_info[:2] < REQUIRED_PYTHON:
stderr.write(
f"{NAME} requires Python {'.'.join(REQUIRED_PYTHON)} or higher and your current version is {version_info[:2]}.")
exit(1)

NAME = "gfagraphs"
CURRENT_PYTHON = version_info[:2]
REQUIRED_PYTHON = (3, 10)
# Computing version number
if OVERRIDE_VN:
_iv: str = VN
else:
try:
_iv: list = [int(x) for x in require(NAME)[0].version.split('.')]
_iv[-1] += 1
except:
_iv: list = [0, 0, 0]
finally:
_iv: str = '.'.join([str(x) for x in _iv])

if CURRENT_PYTHON < REQUIRED_PYTHON:
stderr.write(
f"{NAME} requires Python 3.10 or higher and your current version is {CURRENT_PYTHON}.")
exit(1)
_sb, _eb = "{", "}"
with open('pyproject.toml', 'w', encoding='utf-8') as tomlwriter:
tomlwriter.write(
f"""[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "{NAME}"
version = "{_iv}"
authors = [
{_sb} name="{AUTHOR[0]}", email="{AUTHOR_EMAIL[0]}" {_eb},
]
description = "{DESCRIPTION}"
readme = "README.md"
requires-python = ">={'.'.join([str(x) for x in REQUIRED_PYTHON])}"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
[project.urls]
"Homepage" = "{_url}"
"Bug Tracker" = "{_url}/issues"
"""
)
else:
_iv: str = VN if OVERRIDE_VN else require(NAME)[0].version

# Additionnal parameters
_adp: dict = {}
if HAS_COMMAND_LINE:
_adp['entry_points'] = COMMAND


# Install procedure
setup(
name=NAME,
version='0.1.81',
description='Abstraction layer for GFA file format',
url='https://github.com/Tharos-ux/gfatypes',
author='Tharos',
author_email='dubois.siegfried@gmail.com',
license='MIT',
packages=find_packages(),
version=_iv,
description=DESCRIPTION,
url=_url,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
license=LICENCE,
zip_safe=False,
install_requires=['networkx', 'tharos-pytools']
packages=find_packages(),
install_requires=requirements,
long_description=open("README.md", encoding='utf-8').read(),
long_description_content_type='text/markdown',
**_adp
)

0 comments on commit ddd1963

Please sign in to comment.