From 47e35b3b7f6e851a3a9c3a6a1370b379ae25ccbb Mon Sep 17 00:00:00 2001 From: Sylvain Tricot Date: Mon, 15 Jun 2020 16:48:01 +0200 Subject: [PATCH] New entry point in package. A module (cli.py) is used to provide an entry point for the msspec package. It is here to be PEX-compatible (https://github.com/pantsbuild/pex) that may be used to provide a zero-install msspec distribution. --- .gitignore | 2 ++ src/MANIFEST.in | 1 + src/SConstruct | 25 +++++++++++++-- src/msspec/cli.py | 71 +++++++++++++++++++++++++++++++++++++++++++ src/msspec/version.py | 12 +++++--- src/pip.freeze | 1 + src/setup.py | 14 ++------- 7 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 src/msspec/cli.py diff --git a/.gitignore b/.gitignore index 81c4a60..f217143 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ src/msspec/results.txt **/*build/ **/*dist/ **/*.egg-info/ +.ropeproject +.project diff --git a/src/MANIFEST.in b/src/MANIFEST.in index 55761a1..cfb311f 100644 --- a/src/MANIFEST.in +++ b/src/MANIFEST.in @@ -3,3 +3,4 @@ recursive-include . SConstruct include setup_requirements.txt include requirements.txt include pip.freeze +include VERSION diff --git a/src/SConstruct b/src/SConstruct index 5673fa9..d9d91fd 100644 --- a/src/SConstruct +++ b/src/SConstruct @@ -1,5 +1,8 @@ import os import subprocess +import datetime +from pkg_resources import parse_version +from setuptools_scm import get_version ############################################################################### def filtered_glob(env, pattern, omit=[], @@ -30,13 +33,30 @@ def install_module(env, module): env.Alias('install', destdir) return None +def version_action(target, source, env): + with open(str(target[0]), 'w') as fd: + v = get_version(root='../', relative_to='./', version_scheme="post-release") + v = parse_version(v) + if v._version.post[-1] == 0: + version = v.base_version + else: + version = v.public + fd.write(version + '\n') + now = datetime.datetime.now().isoformat() + fd.write(f'compiled on {now}\n') + p = subprocess.run([env['FORTRAN'], "--version"], stdout=subprocess.PIPE) + fd.write(p.stdout.decode('utf8')) + + f2py_bld = Builder(generator=f2py_generator) +version_bld = Builder(action=version_action) # define the default build environment std = Environment(tools=['default', 'fortran'], F2PY_OPTS=[], LIBS=[]) std.AddMethod(filtered_glob, "FilteredGlob") std.AddMethod(install_module, "InstallModule") std['BUILDERS']['F2py'] = f2py_bld +std['BUILDERS']['Version'] = version_bld ############################################################################### @@ -96,7 +116,8 @@ if GetOption('verbose'): Export('env') -#SConscript('msspec/spec/fortran/SConstruct') -#SConscript('msspec/phagen/fortran/SConstruct') SConscript('msspec/spec/fortran/SConstruct', variant_dir='build/build_spec') SConscript('msspec/phagen/fortran/SConstruct', variant_dir='build/build_phagen') + +version_file = env.Version('VERSION', []) +Depends(version_file, "install") diff --git a/src/msspec/cli.py b/src/msspec/cli.py new file mode 100644 index 0000000..a51d78c --- /dev/null +++ b/src/msspec/cli.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# Copyright © 2016-2020 - Rennes Physics Institute +# +# This file is part of msspec. +# +# msspec is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# msspec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with msspec. If not, see . +# +# Source file : src/msspec/cli.py +# Last modified: jeu. 04 juin 2020 16:54:12 +# Committed by : "Sylvain Tricot " + + +import sys +import textwrap +import subprocess +from msspec.iodata import Data +from pip._internal.cli.main import main as pipmain + + +def print_info(): + s = textwrap.dedent(""" + This application is a take-away Python environment + to run msspec. + + Below is a list of all packages bundled with this + interpreter. + """) + print(s) + pipmain(['list']) + s = textwrap.dedent(""" + To run a script with this interpreter, please launch + this application with your script as an argument. + + I let you with the interactive environment. Type in + +D to exit. + + """) + print(s) + +def load_py(*args): + subprocess.run(['python'] + list(args)) + +def load_hdf5(fname): + data = Data.load(fname) + data.view() + + +def main(): + argv = sys.argv + argc = len(argv) + if argc > 1: + if argv[1].endswith('.hdf5'): + load_hdf5(argv[1]) + else: + load_py(*argv[1:]) + else: + print_info() + subprocess.run(['ipython', '--profile=msspec']) + exit() diff --git a/src/msspec/version.py b/src/msspec/version.py index ca1e1fb..53caa06 100644 --- a/src/msspec/version.py +++ b/src/msspec/version.py @@ -25,14 +25,14 @@ import os from pkg_resources import DistributionNotFound from pkg_resources import get_distribution from pkg_resources import parse_version -from setuptools_scm import get_version - # find the version number # 1- Try to read it from the git info # 2- If it fails, try to read it from the distribution file +# 3- If it fails, try to read it from the VERSION file try: + from setuptools_scm import get_version v = get_version(root='../../', relative_to=__file__, version_scheme="post-release") v = parse_version(v) if v._version.post[-1] == 0: @@ -43,5 +43,9 @@ except Exception as err: try: __version__ = get_distribution(__name__.strip('.version')).version except Exception as err: - print("Unable to get the version number!") - __version__ = "9.9.9" + try: + with open("../VERSION", "r") as fd: + __version__ = fd.readline() + except Exception as err: + print("Unable to get the version number!") + __version__ = "9.9.9" diff --git a/src/pip.freeze b/src/pip.freeze index abc1fa7..26b724c 100644 --- a/src/pip.freeze +++ b/src/pip.freeze @@ -54,3 +54,4 @@ traitlets==4.3.3 urllib3==1.25.8 wcwidth==0.1.9 wheel==0.34.2 +wxPython@https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/wxPython-4.0.7.post2-cp36-cp36m-linux_x86_64.whl diff --git a/src/setup.py b/src/setup.py index 8a71613..21b552e 100644 --- a/src/setup.py +++ b/src/setup.py @@ -24,17 +24,7 @@ import sys sys.path.insert(0, "msspec") from setuptools import setup, find_packages -try: - from version import __version__ -except Exception as err: - __version__ = "8.8.8" - - -with open('setup_requirements.txt', 'r') as fd: - SETUP_REQUIREMENTS = fd.read().strip().split('\n') - -with open('requirements.txt', 'r') as fd: - REQUIREMENTS = fd.read().strip().split('\n') +from version import __version__ with open('pip.freeze', 'r') as fd: REQUIREMENTS = fd.read().strip().split('\n') @@ -83,4 +73,6 @@ if __name__ == "__main__": ], keywords='spectroscopy atom electron photon multiple scattering', license='GPL', + entry_points={ + 'console_scripts': ['msspec=msspec.cli:main']} )