From e2cb97bcff9d94a8c053494d758a946d05355ae1 Mon Sep 17 00:00:00 2001 From: Christian Fufezan Date: Thu, 15 Dec 2022 12:25:36 +0100 Subject: [PATCH 1/5] First setup.cfg + scm install --- setup.py | 88 +++++++++++++++++++--------------------------- uparma/version.txt | 2 +- 2 files changed, 38 insertions(+), 52 deletions(-) diff --git a/setup.py b/setup.py index 451864e..af09af3 100644 --- a/setup.py +++ b/setup.py @@ -1,52 +1,38 @@ -#!/usr/bin/env python3 -from setuptools import setup -import os - - -# We store our version number in a simple text file: -version_path = os.path.join(os.path.dirname(__file__), "uparma", "version.txt") - -with open(version_path, "r") as version_file: - uparma_py_version = version_file.read().strip() - -with open("requirements.txt") as req_file: - reqs = req_file.readlines() - - -setup( - name="uparma", - version=uparma_py_version, - packages=["uparma"], - package_dir={"uparma": "uparma"}, - description="uparma", - package_data={ - "uparma": [ - "version.txt", - "lib_version.txt", - ] - }, - install_requires=reqs, - long_description="Universal Parameter Mapper for Proteomics tools", - author="... and Christian Fufezan", - author_email="christian@fufezan.net", - url="http://github.com/uparma/uparma-py", - license="Lesser GNU General Public License (LGPL)", - platforms="any that supports python 3.4", - classifiers=[ - "Development Status :: 4 - Beta", - "Environment :: Console", - "Intended Audience :: Science/Research", - "Intended Audience :: Developers", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Operating System :: POSIX :: SunOS/Solaris", - "Operating System :: Unix", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Topic :: Scientific/Engineering :: Bio-Informatics", - "Topic :: Scientific/Engineering :: Chemistry", - "Topic :: Scientific/Engineering :: Medical Science Apps.", - "Topic :: Software Development :: Libraries :: Python Modules", - ], +import setuptools + + +def branch_dependent_version(): + import setuptools_scm + + def void(version): + return "" + + def version_scheme(version): + if version.branch not in ["main", "master"]: + _v = setuptools_scm.get_version(local_scheme=void) + else: + _v = str(version.tag) + return _v + + def local_scheme(version): + if version.branch not in ["main", "master"]: + _v = setuptools_scm.get_version(version_scheme=void) + else: + _v = "" + return _v + + scm_version = { + "root": ".", + "relative_to": __file__, + "version_scheme": version_scheme, + "local_scheme": local_scheme + # >> "no-local-version" not quit good enough + # >> on dev "node-and-timestamp", # version_scheme, + } + return scm_version + + +setuptools.setup( + use_scm_version=branch_dependent_version, + setup_requires=["setuptools_scm"], ) diff --git a/uparma/version.txt b/uparma/version.txt index 6d44d22..4eb1de0 100644 --- a/uparma/version.txt +++ b/uparma/version.txt @@ -1 +1 @@ -0.9.14 +0.9.15.dev0+g33ac409.d20221215 \ No newline at end of file From 7a67f5435920b114708760f1694f12c8864fc316 Mon Sep 17 00:00:00 2001 From: Christian Fufezan Date: Thu, 15 Dec 2022 12:26:16 +0100 Subject: [PATCH 2/5] Remove version.txt --- .gitignore | 1 + pyproject.toml | 47 ++++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 36 +++++++++++++++++++++++++++++++++++ uparma/version.txt | 1 - 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml create mode 100644 setup.cfg delete mode 100644 uparma/version.txt diff --git a/.gitignore b/.gitignore index 92ec8f9..f86e44c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ pyenv .idea .DS_Store .tox +uparma/version.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d49be33 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,47 @@ +[dev-dependencies] +black = { version = "^18.3-alpha.0", python = "^3.8" } + +[build-system] +requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "uparma/version.txt" + +[tool.black] +line-length = 88 +target-version = ["py38"] +include = '\.pyi?$' +extend-exclude = ''' +/( + # The following are specific to Black, you probably don't want those. + | blib2to3 + | profiling +)/ +''' + +[tool.tox] +legacy_tox_ini = """ + +[tox] +envlist = py38,py39 +isolated_build = True + +[testenv] +passenv = + * +commands = + pytest {posargs} + +[testenv:coverage] +deps = -Ur{toxinidir}/requirements_dev.txt +commands = + coverage erase + coverage run --source=ursgal {envbindir}/pytest {posargs} + coverage report -m +""" + +[tool.pytest.ini_options] +markers = [ + "slow: marks tests as slow (deselect with '-m \"not slow\"')", +] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..d1b0651 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,36 @@ +[metadata] +name = uparma +description = tba +long_description = tba +author = tba +author_email = christian@fufezan.net +url = https://github.com/uparma +license = tba +classifier = + Development Status :: 4 - Beta + Environment :: Console + Intended Audience :: Education + Intended Audience :: Science/Research + Intended Audience :: Developers + License :: OSI Approved :: MIT License + Operating System :: MacOS :: MacOS X + Operating System :: Microsoft :: Windows + Operating System :: POSIX + Operating System :: POSIX :: SunOS/Solaris + Operating System :: Unix + Programming Language :: Python :: 3.5 + Topic :: Scientific/Engineering :: Bio-Informatics + Topic :: Scientific/Engineering :: Chemistry + Topic :: Scientific/Engineering :: Medical Science Apps + +[options] +packages = find_namespace: +install_requires = + pytest==6.2.2 + requests==2.25.1 + +[options.package_data] +uparama = *.json + +[egg_info] +egg_base = . diff --git a/uparma/version.txt b/uparma/version.txt deleted file mode 100644 index 4eb1de0..0000000 --- a/uparma/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.9.15.dev0+g33ac409.d20221215 \ No newline at end of file From 12114aac318487019e5944fa4840983002c3ad1b Mon Sep 17 00:00:00 2001 From: Christian Fufezan Date: Thu, 15 Dec 2022 13:27:49 +0100 Subject: [PATCH 3/5] Add dummy and exception for json.decode.error so files are downloaded again --- .gitignore | 1 - setup.cfg | 2 +- uparma/__init__.py | 12 ++++++++---- uparma/parameters.json | 0 uparma/styles.json | 0 uparma/uparma.py | 10 +++++++--- 6 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 uparma/parameters.json create mode 100644 uparma/styles.json diff --git a/.gitignore b/.gitignore index f86e44c..f47177c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ __pycache__ *.pyc docs/build -*.json build pyenv .idea diff --git a/setup.cfg b/setup.cfg index d1b0651..151f063 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,7 @@ install_requires = requests==2.25.1 [options.package_data] -uparama = *.json +uparma = *.txt, *.json [egg_info] egg_base = . diff --git a/uparma/__init__.py b/uparma/__init__.py index ab722a1..f3a1282 100644 --- a/uparma/__init__.py +++ b/uparma/__init__.py @@ -1,9 +1,13 @@ import os +from importlib.metadata import PackageNotFoundError, version -# Load version -version_path = os.path.join(os.path.dirname(__file__), "version.txt") -with open(version_path, "r") as version_file: - __version__ = version_file.read().strip() +try: + __version__ = version(__name__) +except PackageNotFoundError: + __version__ = None + +# Version +__version_str__ = str(__version__) lib_version_path = os.path.join(os.path.dirname(__file__), "lib_version.txt") with open(lib_version_path, "r") as lib_version_file: diff --git a/uparma/parameters.json b/uparma/parameters.json new file mode 100644 index 0000000..e69de29 diff --git a/uparma/styles.json b/uparma/styles.json new file mode 100644 index 0000000..e69de29 diff --git a/uparma/uparma.py b/uparma/uparma.py index eefc077..575ca31 100755 --- a/uparma/uparma.py +++ b/uparma/uparma.py @@ -84,6 +84,13 @@ def __init__( refresh_jsons = True # we will have to pull + if refresh_jsons is False: + with open(full_path) as j: + try: + self.jsons[url_id] = json.load(j) + except json.decoder.JSONDecodeError: + refresh_jsons = True + if refresh_jsons is True: with requests.get(url) as req: with open(full_path, "w") as j: @@ -94,9 +101,6 @@ def __init__( ) print(json.dumps(req.json(), indent=2, sort_keys=True), file=j) self.jsons[url_id] = req.json() - else: - with open(full_path) as j: - self.jsons[url_id] = json.load(j) # Let's overwrite with custom if parameter_data is not None: From dd3c293344662e9473e00fd564594c1fee356413 Mon Sep 17 00:00:00 2001 From: Christian Fufezan Date: Thu, 15 Dec 2022 13:37:24 +0100 Subject: [PATCH 4/5] Remove need for uparma.__lib_version__ --- uparma/uparma.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/uparma/uparma.py b/uparma/uparma.py index 575ca31..138e723 100755 --- a/uparma/uparma.py +++ b/uparma/uparma.py @@ -14,11 +14,13 @@ ( "general", "parameters", - ): f"https://raw.githubusercontent.com/uparma/uparma-lib/v{uparma.__lib_version__}/jsons/parameters.json", + ): f"https://raw.githubusercontent.com/uparma/uparma-lib/master/jsons/parameters.json", + # f"https://raw.githubusercontent.com/uparma/uparma-lib/v{uparma.__lib_version__}/jsons/parameters.json", ( "general", "styles", - ): f"https://raw.githubusercontent.com/uparma/uparma-lib/v{uparma.__lib_version__}/jsons/styles.json", + ): f"https://raw.githubusercontent.com/uparma/uparma-lib/master/jsons/styles.json", + # f"https://raw.githubusercontent.com/uparma/uparma-lib/v{uparma.__lib_version__}/jsons/styles.json", } base_path = Path(__file__) From 8d78e217fe4f4d8ab732200f185dded50ddbb4c6 Mon Sep 17 00:00:00 2001 From: MKoesters <17874544+MKoesters@users.noreply.github.com> Date: Thu, 15 Dec 2022 14:35:41 +0100 Subject: [PATCH 5/5] remove unused tox.ini --- pyproject.toml | 1 - tox.ini | 17 ----------------- 2 files changed, 18 deletions(-) delete mode 100644 tox.ini diff --git a/pyproject.toml b/pyproject.toml index d49be33..1fc9111 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,6 @@ commands = pytest {posargs} [testenv:coverage] -deps = -Ur{toxinidir}/requirements_dev.txt commands = coverage erase coverage run --source=ursgal {envbindir}/pytest {posargs} diff --git a/tox.ini b/tox.ini deleted file mode 100644 index bb3b7be..0000000 --- a/tox.ini +++ /dev/null @@ -1,17 +0,0 @@ -# content of: tox.ini , put in same dir as setup.py -[tox] -envlist = py38,py39 - -[testenv] -# install pytest in the virtualenv where commands will be executed -deps = -Ur{toxinidir}/requirements.txt -commands = - pytest {posargs} - -[testenv:coverage] -deps = -Ur{toxinidir}/requirements.txt -commands = - coverage erase - coverage run --source=ursgal {envbindir}/pytest {posargs} - coverage report -m -