From 72600e9a3950390e32e9c8898f302cf27d24c66a Mon Sep 17 00:00:00 2001 From: skilkis Date: Thu, 5 Nov 2020 15:53:52 +0100 Subject: [PATCH 1/3] Add install_requirements to setup.py --- setup.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup.py b/setup.py index 83a32b0..3b3483d 100644 --- a/setup.py +++ b/setup.py @@ -73,4 +73,12 @@ def read(*parts): ], keywords='scopus python api document retrieval information scholar academic', + + # Dependencies of pyscopus + install_requires=[ + 'numpy', + 'pandas', + 'requests', + ] + ) From 04ac429921a9690c562b115bf44fdfb860911a12 Mon Sep 17 00:00:00 2001 From: skilkis Date: Thu, 5 Nov 2020 15:54:37 +0100 Subject: [PATCH 2/3] Fix installation errors due to missing packages This commit fixes installation errors due to the install_requirements specified not being available during install time when setup.py is run. To fix this a static .version file is created, removing the need for having the package version to be specified in __init__.py of the pyscopus package. Summary of Changes: - Removed __version__ attribute from __init__.py - Added static .version file to contain the current package version - Removed import of pyscopus in setup.py to fix installation error - Changed `HERE` directory to `ROOT_DIR` and preferred use of Path class over os.path.abspath --- .version | 1 + pyscopus/__init__.py | 2 -- setup.py | 13 +++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 .version diff --git a/.version b/.version new file mode 100644 index 0000000..aadb7c0 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +1.0.3a2 \ No newline at end of file diff --git a/pyscopus/__init__.py b/pyscopus/__init__.py index 543436e..d768889 100644 --- a/pyscopus/__init__.py +++ b/pyscopus/__init__.py @@ -1,5 +1,3 @@ import os.path from pyscopus.scopus import Scopus from pkg_resources import get_distribution, DistributionNotFound - -__version__ = '1.0.3a2' diff --git a/setup.py b/setup.py index 3b3483d..70f39fa 100644 --- a/setup.py +++ b/setup.py @@ -2,8 +2,9 @@ from setuptools import setup, find_packages # To use a consistent encoding import os, codecs +from pathlib import Path -HERE = os.path.abspath(os.path.dirname(__file__)) +ROOT_DIR = Path(__file__).parent def read(*parts): @@ -11,11 +12,11 @@ def read(*parts): Build an absolute path from *parts* and and return the contents of the resulting file. Assume UTF-8 encoding. """ - with codecs.open(os.path.join(HERE, *parts), "rb", "utf-8") as f: + with codecs.open(os.path.join(ROOT_DIR, *parts), "rb", "utf-8") as f: return f.read() -import pyscopus -VERSION = pyscopus.__version__ +with open(ROOT_DIR / ".version") as f: + __version__ = f.readline() setup( name='pyscopus', @@ -27,14 +28,14 @@ def read(*parts): # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version=VERSION, + version=__version__, description='A Python wrapper for Scopus API', long_description=read("README.rst"), # The project's main homepage. url='http://zhiyzuo.github.io/python-scopus/', - download_url='https://github.com/zhiyzuo/python-scopus/tarball/' + VERSION, + download_url='https://github.com/zhiyzuo/python-scopus/tarball/' + __version__, # Author details author='Zhiya Zuo', From d08b5917d24515e53ff93812e28f24a64b4f2eb3 Mon Sep 17 00:00:00 2001 From: skilkis Date: Thu, 5 Nov 2020 16:20:46 +0100 Subject: [PATCH 3/3] Change version to use Git tag when available This commit will enable setuptools to use the SCM (in this case Git) version tags. The fallback when Git is unavailable is then the static version stored in the .version file --- setup.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 70f39fa..3275687 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,8 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages # To use a consistent encoding -import os, codecs +import os +import codecs from pathlib import Path ROOT_DIR = Path(__file__).parent @@ -80,6 +81,14 @@ def read(*parts): 'numpy', 'pandas', 'requests', - ] + 'setuptools >= 40' + 'setuptools_scm', + ], + # Allowing setuptools to use Git tags for the version + use_scm_version={ + 'fallback_version': __version__, + 'write_to': '.version', + 'write_to_template': '{version}', + } )