diff --git a/.gitignore b/.gitignore index 92ec8f9..f47177c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ __pycache__ *.pyc docs/build -*.json build pyenv .idea .DS_Store .tox +uparma/version.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1fc9111 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,46 @@ +[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] +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..151f063 --- /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] +uparma = *.txt, *.json + +[egg_info] +egg_base = . 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/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 - 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..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__) @@ -84,6 +86,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 +103,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: diff --git a/uparma/version.txt b/uparma/version.txt deleted file mode 100644 index 7a50b68..0000000 --- a/uparma/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.9.18