From 7d624ba891e61268e7f2c69ea5e10cf3d9dd9b02 Mon Sep 17 00:00:00 2001 From: pcubillos Date: Sat, 12 Jan 2019 12:47:15 +0100 Subject: [PATCH 1/3] Refactored files and package structure to a standard package format. Fixed a few typos here and there. Updated docstring examples accordingly. --- CHANGELOG.txt | 7 +++ bibmanager/__init__.py | 12 ++-- bibmanager/__main__.py | 16 +++--- bibmanager/ads_manager/__init__.py | 14 +++++ bibmanager/{ => ads_manager}/ads_manager.py | 18 +++--- bibmanager/bib_manager/__init__.py | 14 +++++ bibmanager/{ => bib_manager}/bib_manager.py | 56 +++++++++---------- bibmanager/config_manager/__init__.py | 14 +++++ .../{ => config_manager}/config_manager.py | 12 ++-- bibmanager/latex_manager/__init__.py | 14 +++++ .../{ => latex_manager}/latex_manager.py | 25 +++++++-- bibmanager/utils/__init__.py | 13 +++++ bibmanager/{ => utils}/utils.py | 33 +++++------ setup.py | 11 ++-- 14 files changed, 177 insertions(+), 82 deletions(-) create mode 100644 bibmanager/ads_manager/__init__.py rename bibmanager/{ => ads_manager}/ads_manager.py (97%) create mode 100644 bibmanager/bib_manager/__init__.py rename bibmanager/{ => bib_manager}/bib_manager.py (96%) create mode 100644 bibmanager/config_manager/__init__.py rename bibmanager/{ => config_manager}/config_manager.py (96%) create mode 100644 bibmanager/latex_manager/__init__.py rename bibmanager/{ => latex_manager}/latex_manager.py (93%) create mode 100644 bibmanager/utils/__init__.py rename bibmanager/{ => utils}/utils.py (96%) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ba7c408..abbdf4e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -789,5 +789,12 @@ Added MANIFEST.in file. Bumped bibmanager version to 0.5.6. + +***** Sat Jan 12 12:15:33 CET 2019 ***** + +Refactored files and package structure to a standard package format. +Fixed a few typos here and there. +Updated docstring examples accordingly. + ***** diff --git a/bibmanager/__init__.py b/bibmanager/__init__.py index ad50f8a..303cd8c 100644 --- a/bibmanager/__init__.py +++ b/bibmanager/__init__.py @@ -1,12 +1,16 @@ # Copyright (c) 2018-2019 Patricio Cubillos and contributors. # bibmanager is open-source software under the MIT license (see LICENSE). -from . import VERSION as ver -from .bib_manager import * +__all__ = ["bib_manager", "config_manager", "latex_manager", "ads_manager", + "utils"] -from .bib_manager import __all__ as bm_all +from . import bib_manager +from . import config_manager +from . import latex_manager +from . import ads_manager +from . import utils -__all__ = bm_all +from . import VERSION as ver __version__ = f"{ver.BM_VER}.{ver.BM_MIN}.{ver.BM_REV}" diff --git a/bibmanager/__main__.py b/bibmanager/__main__.py index 87b5094..5435f4e 100644 --- a/bibmanager/__main__.py +++ b/bibmanager/__main__.py @@ -5,15 +5,15 @@ import os import argparse import textwrap + import prompt_toolkit -sys.path.append(os.path.dirname(os.path.realpath(__file__))) -import bibmanager as bm -# FINDME: Temporary hack until setting BM as a package: -import latex_manager as lm -import config_manager as cm -import ads_manager as am -from utils import BOLD, END +from . import bib_manager as bm +from . import latex_manager as lm +from . import config_manager as cm +from . import ads_manager as am +from .utils import BOLD, END +from .__init__ import __version__ as ver def cli_reset(args): @@ -190,7 +190,7 @@ def main(): parser.add_argument('-v', '--version', action='version', help="Show bibmanager's version.", - version=f'bibmanager version {bm.__version__}') + version=f'bibmanager version {ver}') # Parser Main Documentation: main_description = """ diff --git a/bibmanager/ads_manager/__init__.py b/bibmanager/ads_manager/__init__.py new file mode 100644 index 0000000..c9d8a4e --- /dev/null +++ b/bibmanager/ads_manager/__init__.py @@ -0,0 +1,14 @@ +# Copyright (c) 2018-2019 Patricio Cubillos and contributors. +# bibmanager is open-source software under the MIT license (see LICENSE). + +from .ads_manager import * +from .ads_manager import __all__ + + +# Clean up top-level namespace--delete everything that isn't in __all__ +# or is a magic attribute, and that isn't a submodule of this package +for varname in dir(): + if not ((varname.startswith('__') and varname.endswith('__')) or + varname in __all__ ): + del locals()[varname] +del(varname) diff --git a/bibmanager/ads_manager.py b/bibmanager/ads_manager/ads_manager.py similarity index 97% rename from bibmanager/ads_manager.py rename to bibmanager/ads_manager/ads_manager.py index 1c1189c..eda5b05 100644 --- a/bibmanager/ads_manager.py +++ b/bibmanager/ads_manager/ads_manager.py @@ -7,14 +7,16 @@ import os import re import json -import requests import urllib import textwrap import pickle -import bib_manager as bm -import config_manager as cm -from utils import BM_CACHE, BOLD, END, BANNER, ignored, parse_name, get_authors +import requests + +from .. import bib_manager as bm +from .. import config_manager as cm +from ..utils import BM_CACHE, BOLD, END, BANNER, ignored, parse_name, \ + get_authors # FINDME: Is to possible to check a token is valid? @@ -91,7 +93,7 @@ def search(querry, start=0, cache_rows=200, sort='pubdate+desc'): Examples -------- - >>> import ads_manager as am + >>> import bibmanager.ads_manager as am >>> # Search entries by author (note the need for double quotes, >>> # otherwise, the search might produce bogus results): >>> querry = 'author:"cubillos, p"' @@ -153,7 +155,7 @@ def display(results, start, index, rows, nmatch, short=True): Examples -------- - >>> import ads_manager as am + >>> import bibmanager.ads_manager as am >>> start = index = 0 >>> querry = 'author:"^cubillos, p" property:refereed' >>> results, nmatch = am.search(querry, start=start) @@ -194,7 +196,7 @@ def add_bibtex(input_bibcodes, input_keys, update_keys=True): Examples -------- - >>> import ads_manager as am + >>> import bibmanager.ads_manager as am >>> # A successful add call: >>> bibcodes = ['1925PhDT.........1P'] >>> keys = ['Payne1925phdStellarAtmospheres'] @@ -336,7 +338,7 @@ def key_update(key, bibcode, alternate_bibcode): Examples -------- - >>> import ads_manager as am + >>> import bibmanager.ads_manager as am >>> key = 'BeaulieuEtal2010arxivGJ436b' >>> bibcode = '2011ApJ...731...16B' >>> alternate_bibcode = '2010arXiv1007.0324B' diff --git a/bibmanager/bib_manager/__init__.py b/bibmanager/bib_manager/__init__.py new file mode 100644 index 0000000..c789814 --- /dev/null +++ b/bibmanager/bib_manager/__init__.py @@ -0,0 +1,14 @@ +# Copyright (c) 2018-2019 Patricio Cubillos and contributors. +# bibmanager is open-source software under the MIT license (see LICENSE). + +from .bib_manager import * +from .bib_manager import __all__ + + +# Clean up top-level namespace--delete everything that isn't in __all__ +# or is a magic attribute, and that isn't a submodule of this package +for varname in dir(): + if not ((varname.startswith('__') and varname.endswith('__')) or + varname in __all__ ): + del locals()[varname] +del(varname) diff --git a/bibmanager/bib_manager.py b/bibmanager/bib_manager/bib_manager.py similarity index 96% rename from bibmanager/bib_manager.py rename to bibmanager/bib_manager/bib_manager.py index befcffb..72ab1e7 100644 --- a/bibmanager/bib_manager.py +++ b/bibmanager/bib_manager/bib_manager.py @@ -13,6 +13,7 @@ import pickle import urllib import subprocess + import numpy as np import prompt_toolkit from prompt_toolkit.formatted_text import PygmentsTokens @@ -21,10 +22,8 @@ from pygments.token import Token from pygments.lexers.bibtex import BibTeXLexer -ROOT = os.path.realpath(os.path.dirname(__file__)) + '/' -sys.path.append(ROOT) -import config_manager as cm -from utils import HOME, BM_DATABASE, BM_BIBFILE, BM_TMP_BIB, BANNER, \ +from .. import config_manager as cm +from ..utils import ROOT, HOME, BM_DATABASE, BM_BIBFILE, BM_TMP_BIB, BANNER, \ Sort_author, ordinal, count, cond_split, parse_name, \ purify, initials, get_authors, get_fields, req_input, ignored @@ -50,10 +49,10 @@ def __init__(self, entry): entry: String A bibliographic entry text. - Example - ------- - >>> import bib_manager as bm - >>> from utils import Author + Examples + -------- + >>> import bibmanager.bib_manager as bm + >>> from bibmanager.utils import Author >>> entry = '''@Misc{JonesEtal2001scipy, author = {Eric Jones and Travis Oliphant and Pearu Peterson}, title = {{SciPy}: Open source scientific tools for {Python}}, @@ -145,9 +144,9 @@ def __contains__(self, author): author: String An author name in a valid BibTeX format. - Example - ------- - >>> import bibm as bm + Examples + -------- + >>> import bibmanager.bib_manager as bm >>> bib = bm.Bib('''@ARTICLE{DoeEtal2020, author = {{Doe}, J. and {Perez}, J. and {Dupont}, J.}, title = "What Have the Astromomers ever Done for Us?", @@ -273,7 +272,7 @@ def display_bibs(labels, bibs): Examples -------- - >>> import bibm as bm + >>> import bibmanager.bib_manager as bm >>> e1 = '''@Misc{JonesEtal2001scipy, author = {Eric Jones and Travis Oliphant and Pearu Peterson}, title = {{SciPy}: Open source scientific tools for {Python}}, @@ -425,8 +424,9 @@ def loadfile(bibfile=None, text=None): Examples -------- - >>> import bibm as bm - >>> bibfile = "../examples/sample.bib" + >>> import bibmanager.bib_manager as bm + >>> import os + >>> bibfile = os.path.expanduser("~") + "/.bibmanager/examples/sample.bib" >>> bibs = bm.loadfile(bibfile) """ entries = [] # Store Lists of bibtex entries @@ -495,12 +495,11 @@ def merge(bibfile=None, new=None, take="old"): Examples -------- - >>> import bib_manager as bm - >>> # Load bibmabager database (TBD: update with bm/examples/new.bib): - >>> newbib = (os.path.expanduser("~") - + "/Dropbox/latex/2018_hd209/current/hd209nuv.bib") - >>> new = bm.loadfile(newbib) - >>> # Merge new into database: + >>> import bibmanager.bib_manager as bm + >>> import os + >>> # TBD: Need to add sample2.bib into package. + >>> newbib = os.path.expanduser("~") + "/.bibmanager/examples/sample2.bib" + >>> # Merge newbib into database: >>> bm.merge(newbib, take='old') """ bibs = load() @@ -573,8 +572,8 @@ def save(entries): Examples -------- - >>> import bibm as bm - >>> # [Load some entries] + >>> import bibmanager.bib_manager as bm + >>> # TBD: Load some entries >>> bm.save(entries) """ # FINDME: Don't pickle-save the Bib() objects directly, but store them @@ -594,7 +593,7 @@ def load(): Examples -------- - >>> import bibm as bm + >>> import bibmanager.bib_manager as bm >>> bibs = bm.load() """ try: @@ -647,10 +646,11 @@ def init(bibfile=BM_BIBFILE, reset_db=True, reset_config=False): reset_config: Bool If True, reset the config file. - Example - ------- - >>> import bib_manager as bm - >>> bibfile = '../examples/sample.bib' + Examples + -------- + >>> import bibmanager.bib_manager as bm + >>> import os + >>> bibfile = os.path.expanduser("~") + "/.bibmanager/examples/sample.bib" >>> bm.init(bibfile) """ # First install ever: @@ -764,7 +764,7 @@ def search(authors=None, year=None, title=None, key=None, bibcode=None): Examples -------- - >>> import bib_manager as bm + >>> import bibmanager.bib_manager as bm >>> # Search by last name: >>> matches = bm.search(authors="Cubillos") >>> # Search by last name and initial: diff --git a/bibmanager/config_manager/__init__.py b/bibmanager/config_manager/__init__.py new file mode 100644 index 0000000..eeb591a --- /dev/null +++ b/bibmanager/config_manager/__init__.py @@ -0,0 +1,14 @@ +# Copyright (c) 2018-2019 Patricio Cubillos and contributors. +# bibmanager is open-source software under the MIT license (see LICENSE). + +from .config_manager import * +from .config_manager import __all__ + + +# Clean up top-level namespace--delete everything that isn't in __all__ +# or is a magic attribute, and that isn't a submodule of this package +for varname in dir(): + if not ((varname.startswith('__') and varname.endswith('__')) or + varname in __all__ ): + del locals()[varname] +del(varname) diff --git a/bibmanager/config_manager.py b/bibmanager/config_manager/config_manager.py similarity index 96% rename from bibmanager/config_manager.py rename to bibmanager/config_manager/config_manager.py index 8472259..8f95af6 100644 --- a/bibmanager/config_manager.py +++ b/bibmanager/config_manager/config_manager.py @@ -9,7 +9,7 @@ import textwrap from pygments.styles import STYLE_MAP -from utils import ROOT, HOME +from ..utils import ROOT, HOME styles = textwrap.fill(", ".join(style for style in iter(STYLE_MAP)), @@ -75,7 +75,7 @@ def display(key=None): Examples -------- - >>> import config_manager as cm + >>> import bibmanager.config_manager as cm >>> # Show all parameters and values: >>> cm.display() bibmanager configuration file: @@ -129,7 +129,7 @@ def get(key): Examples -------- - >>> import config_manager as cm + >>> import bibmanager.config_manager as cm >>> cm.get('paper') 'letter' >>> cm.get('style') @@ -157,15 +157,15 @@ def set(key, value): Examples -------- - >>> import config_manager as cm + >>> import bibmanager.config_manager as cm >>> # Update text editor: >>> cm.set('text_editor', 'vim') text_editor updated to: vim. >>> # Invalid bibmanager parameter: >>> cm.set('styles', 'arduino') - ValueError: 'styles' is not a valid bibmanager config parameter. - The available parameters are: ['style', 'text_editor', 'paper', 'ads_token'] + ValueError: 'styles' is not a valid bibmanager config parameter. The available + parameters are: ['style', 'text_editor', 'paper', 'ads_token', 'ads_display'] >>> # Attempt to set an invalid style: >>> cm.set('style', 'fake_style') diff --git a/bibmanager/latex_manager/__init__.py b/bibmanager/latex_manager/__init__.py new file mode 100644 index 0000000..6ff686c --- /dev/null +++ b/bibmanager/latex_manager/__init__.py @@ -0,0 +1,14 @@ +# Copyright (c) 2018-2019 Patricio Cubillos and contributors. +# bibmanager is open-source software under the MIT license (see LICENSE). + +from .latex_manager import * +from .latex_manager import __all__ + + +# Clean up top-level namespace--delete everything that isn't in __all__ +# or is a magic attribute, and that isn't a submodule of this package +for varname in dir(): + if not ((varname.startswith('__') and varname.endswith('__')) or + varname in __all__ ): + del locals()[varname] +del(varname) diff --git a/bibmanager/latex_manager.py b/bibmanager/latex_manager/latex_manager.py similarity index 93% rename from bibmanager/latex_manager.py rename to bibmanager/latex_manager/latex_manager.py index 9e49441..157898c 100644 --- a/bibmanager/latex_manager.py +++ b/bibmanager/latex_manager/latex_manager.py @@ -1,14 +1,17 @@ # Copyright (c) 2018-2019 Patricio Cubillos and contributors. # bibmanager is open-source software under the MIT license (see LICENSE). +__all__ = ['no_comments', 'citations', 'build_bib', 'clear_latex', + 'compile_latex', 'compile_pdflatex'] + import os import re import subprocess import numpy as np -import bib_manager as bm -import config_manager as cm -from utils import ignored, cd +from .. import bib_manager as bm +from .. import config_manager as cm +from ..utils import ignored, cd def no_comments(text): @@ -28,13 +31,14 @@ def no_comments(text): Examples -------- + >>> import bibmanager.latex_manager as lm >>> text = r''' Hello, this is dog. % This is a comment line. This line ends with a comment. % A comment However, this is a percentage \%, not a comment. OK, byee.''' - >>> print(no_comments(text)) + >>> print(lm.no_comments(text)) Hello, this is dog. This line ends with a comment. However, this is a percentage \%, not a comment. @@ -66,7 +70,8 @@ def citations(text): Examples -------- - >>> import latex_manager as lm + >>> import bibmanager.latex_manager as lm + >>> import os >>> # Syntax matches any of these calls: >>> tex = r''' \citep{AuthorA}. @@ -103,12 +108,20 @@ def citations(text): >>> print(citation, end=" ") AuthorA AuthorB AuthorC AuthorD AuthorE AuthorF AuthorG AuthorH AuthorI AuthorJ AuthorK AuthorL AuthorM AuthorN AuthorO AuthorP AuthorQ AuthorR AuthorS AuthorT AuthorU AuthorV AuthorW AuthorX AuthorY AuthorZ AuthorAA - >>> with open("sample.tex") as f: + >>> texfile = os.path.expanduser('~')+"/.bibmanager/examples/sample.tex" + >>> with open(texfile) as f: >>> tex = f.read() >>> tex = lm.no_comments(tex) >>> cites = [citation for citation in lm.citations(tex)] >>> for key in np.unique(cites): >>> print(key) + AASteamHendrickson2018aastex62 + Astropycollab2013aaAstropy + Hunter2007ieeeMatplotlib + JonesEtal2001scipy + MeurerEtal2017pjcsSYMPY + PerezGranger2007cseIPython + vanderWaltEtal2011numpy """ # This RE pattern matches: # - Latex commands: \defcitealias, \nocite, \cite diff --git a/bibmanager/utils/__init__.py b/bibmanager/utils/__init__.py new file mode 100644 index 0000000..441d3a9 --- /dev/null +++ b/bibmanager/utils/__init__.py @@ -0,0 +1,13 @@ +# Copyright (c) 2018-2019 Patricio Cubillos and contributors. +# bibmanager is open-source software under the MIT license (see LICENSE). + +from .utils import * +from .utils import __all__ + +# Clean up top-level namespace--delete everything that isn't in __all__ +# or is a magic attribute, and that isn't a submodule of this package +for varname in dir(): + if not ((varname.startswith('__') and varname.endswith('__')) or + varname in __all__ ): + del locals()[varname] +del(varname) diff --git a/bibmanager/utils.py b/bibmanager/utils/utils.py similarity index 96% rename from bibmanager/utils.py rename to bibmanager/utils/utils.py index 454d40e..e3b63a4 100644 --- a/bibmanager/utils.py +++ b/bibmanager/utils/utils.py @@ -11,7 +11,7 @@ 'ignored', 'cd', # Functions: 'ordinal', 'count', 'nest', 'cond_split', 'cond_next', - 'parse_name', 'repr_author', 'purify', 'initials', + 'parse_name', 'repr_author', 'purify', 'initials', 'get_authors', 'next_char', 'last_char', 'get_fields', 'req_input' ] @@ -24,7 +24,7 @@ # Directories/files: HOME = os.path.expanduser("~") + "/.bibmanager/" -ROOT = os.path.realpath(os.path.dirname(__file__)) + '/' +ROOT = os.path.realpath(os.path.dirname(__file__) + '/..') + '/' BM_DATABASE = HOME + "bm_database.pickle" BM_BIBFILE = HOME + "bm_bibliography.bib" @@ -88,7 +88,7 @@ def ordinal(number): Examples -------- - >>> from utils import ordinal + >>> from bibmanager.utils import ordinal >>> print(ordinal(1)) 1st >>> print(ordinal(2)) @@ -128,7 +128,7 @@ def count(text): Examples -------- - >>> from utils import count + >>> from bibmanager.utils import count >>> count('{Hello} world') 0 """ @@ -151,7 +151,7 @@ def nest(text): Examples -------- - >>> from utils import nest + >>> from bibmanager.utils import nest >>> s = "{{P\\'erez}, F. and {Granger}, B.~E.}," >>> n = nest(s) >>> print(f"{s}\n{''.join([str(v) for v in n])}") @@ -197,7 +197,7 @@ def cond_split(text, pattern, nested=None, nlev=-1, ret_nests=False): Examples -------- - >>> from utils import cond_split + >>> from bibmanager.utils import cond_split >>> # Split an author list string delimited by ' and ' pattern: >>> cond_split("{P\\'erez}, F. and {Granger}, B.~E.", " and ") ["{P\\'erez}, F.", '{Granger}, B.~E.'] @@ -268,7 +268,7 @@ def cond_next(text, pattern, nested, nlev=1): Examples -------- - >>> from utils import nest, cond_next + >>> from bibmanager.utils import nest, cond_next >>> text = '"{{HITEMP}, the high-temperature molecular database}",' >>> nested = nest(text) >>> # Ignore comma within braces: @@ -303,7 +303,7 @@ def parse_name(name, nested=None): Examples -------- - >>> from utils import parse_name + >>> from bibmanager.utils import parse_name >>> names = ['{Hendrickson}, A.', >>> 'Eric Jones', >>> '{AAS Journals Team}', @@ -388,7 +388,7 @@ def repr_author(Author): Examples -------- - >>> from utils import repr_author, parse_name + >>> from bibmanager.utils import repr_author, parse_name >>> names = ['Last', 'First Last', 'First von Last', 'von Last, First', >>> 'von Last, sr., First'] >>> for name in names: @@ -430,7 +430,7 @@ def purify(name, german=False): Examples -------- - >>> from utils import purify + >>> from bibmanager.utils import purify >>> names = ["St{\\'{e}}fan", "{{\\v S}ime{\\v c}kov{\\'a}}", "{AAS Journals Team}", @@ -485,7 +485,7 @@ def initials(name): Examples -------- - >>> from utils import initials + >>> from bibmanager.utils import initials >>> names = ["", "D.", "D. W.", "G.O.", '{\\"O}. H.', "J. Y.-K.", >>> "Phil", "Phill Henry Scott"] >>> for name in names: @@ -520,7 +520,7 @@ def get_authors(authors, short=True): Examples -------- - >>> from utils import get_authors, parse_name + >>> from bibmanager.utils import get_authors, parse_name >>> author_lists = [ >>> [parse_name('{Hunter}, J. D.')], >>> [parse_name('{AAS Journals Team}'), parse_name('{Hendrickson}, A.')], @@ -563,7 +563,7 @@ def next_char(text): Examples -------- - >>> from utils import next_char + >>> from bibmanager.utils import next_char >>> texts = ["Hello", " Hello", " Hello ", "", "\n Hello", " "] >>> for text in texts: >>> print(f"{text!r:11}: {next_char(text)}") @@ -598,7 +598,7 @@ def last_char(text): Examples -------- - >>> from utils import last_char + >>> from bibmanager.utils import last_char >>> texts = ["Hello", " Hello", " Hello ", "", "\n Hello", " "] >>> for text in texts: >>> print(f"{text!r:12}: {last_char(text)}") @@ -638,7 +638,7 @@ def get_fields(entry): Example ------- - >>> from utils import get_fields + >>> from bibmanager.utils import get_fields >>> entry = ''' @Article{Hunter2007ieeeMatplotlib, Author = {{Hunter}, J. D.}, @@ -655,6 +655,7 @@ def get_fields(entry): >>> # Get the entry's key: >>> print(next(fields)) Hunter2007ieeeMatplotlib + >>> # Now get the fields, values, and nested level: >>> for key, value, nested in fields: >>> print(f"{key:9}: {value}\n{'':11}{''.join([str(v) for v in nested])}") @@ -724,7 +725,7 @@ def req_input(prompt, options): Examples -------- - >>> from utils import req_input + >>> from bibmanager.utils import req_input >>> req_input('Enter number between 0 and 9: ', options=np.arange(10)) >>> # Enter the number 10: Enter number between 0 and 9: 10 diff --git a/setup.py b/setup.py index f339ded..6cb6e62 100644 --- a/setup.py +++ b/setup.py @@ -7,9 +7,8 @@ from setuptools.command.develop import develop from setuptools.command.install import install -topdir = os.path.dirname(os.path.realpath(__file__)) -import bibmanager as bm -from utils import ignored +import bibmanager as bibm +from bibmanager.utils import ignored class Init_Bibmanager_Develop(develop): @@ -17,7 +16,7 @@ class Init_Bibmanager_Develop(develop): def run(self): develop.run(self) with ignored(OSError): - bm.init() + bibm.bib_manager.init() class Init_Bibmanager_Install(install): @@ -25,11 +24,11 @@ class Init_Bibmanager_Install(install): def run(self): install.run(self) with ignored(OSError): - bm.init() + bibm.bib_manager.init() setup(name = "bibmanager", - version = bm.__version__, + version = bibm.__version__, author = "Patricio Cubillos", author_email = "patricio.cubillos@oeaw.ac.at", url = "https://github.com/pcubillos/bibmanager", From e5cd49f97477ad9f7d515f53bcedfd0bc9ea6380 Mon Sep 17 00:00:00 2001 From: pcubillos Date: Sat, 12 Jan 2019 13:00:34 +0100 Subject: [PATCH 2/3] Moved ads_token and ads_display loading into functions to update them at runtime. Removed unnecessary constants (url paths) from ads_manager.py --- CHANGELOG.txt | 6 ++++++ bibmanager/ads_manager/ads_manager.py | 21 +++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index abbdf4e..7ec647d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -798,3 +798,9 @@ Updated docstring examples accordingly. ***** +Moved ads_token and ads_display loading into functions +to update them at runtime. +Removed unnecessary constants (url paths) from ads_manager.py + +***** + diff --git a/bibmanager/ads_manager/ads_manager.py b/bibmanager/ads_manager/ads_manager.py index eda5b05..95a26de 100644 --- a/bibmanager/ads_manager/ads_manager.py +++ b/bibmanager/ads_manager/ads_manager.py @@ -19,19 +19,11 @@ get_authors -# FINDME: Is to possible to check a token is valid? -token = cm.get('ads_token') -rows = int(cm.get('ads_display')) - -ADSQUERRY = "https://api.adsabs.harvard.edu/v1/search/query?" -ADSEXPORT = "https://api.adsabs.harvard.edu/v1/export/bibtex" -ADSURL = "https://ui.adsabs.harvard.edu/\#abs/" - - def manager(querry=None): """ A manager, it doesn't really do anything, it just delegates. """ + rows = int(cm.get('ads_display')) if querry is None and not os.path.exists(BM_CACHE): print("There are no more entries for this querry.") return @@ -72,7 +64,7 @@ def search(querry, start=0, cache_rows=200, sort='pubdate+desc'): https://ui.adsabs.harvard.edu/ start: Integer Starting index of entry to return. - rows: Integer + cache_rows: Integer Maximum number of entries to return. sort: String Sorting field and direction to use. @@ -115,8 +107,11 @@ def search(querry, start=0, cache_rows=200, sort='pubdate+desc'): ValueError: Invalid ADS request: org.apache.solr.search.SyntaxError: org.apache.solr.common.SolrException: undefined field properties """ + token = cm.get('ads_token') querry = urllib.parse.quote(querry) - r = requests.get(f'{ADSQUERRY}q={querry}&start={start}&rows={cache_rows}' + + r = requests.get('https://api.adsabs.harvard.edu/v1/search/query?' + f'q={querry}&start={start}&rows={cache_rows}' f'&sort={sort}&fl=title,author,year,bibcode,pub', headers={'Authorization': f'Bearer {token}'}) resp = r.json() @@ -167,7 +162,8 @@ def display(results, start, index, rows, nmatch, short=True): author_list = [parse_name(author) for author in result['author']] authors = textwrap.fill(f"Authors: {get_authors(author_list, short)}", **wrap_kw) - adsurl = f"adsurl: {ADSURL}{result['bibcode']}" + adsurl = ("adsurl: https://ui.adsabs.harvard.edu/\#abs/" + + f"{result['bibcode']}") bibcode = f"\n{BOLD}bibcode{END}: {result['bibcode']}" print(f"\n{title}\n{authors}\n{adsurl}{bibcode}") if index + rows < nmatch: @@ -215,6 +211,7 @@ def add_bibtex(input_bibcodes, input_keys, update_keys=True): >>> am.add_bibtex(bibcodes, keys) Warning: bibcode '1925PhDT.....X...1P' not found. """ + token = cm.get('ads_token') # Keep the originals untouched (copies will be modified): bibcodes, keys = input_bibcodes.copy(), input_keys.copy() From 4e3f653d9aa28a06014f583e8cf8049e380900df Mon Sep 17 00:00:00 2001 From: pcubillos Date: Sat, 12 Jan 2019 13:05:46 +0100 Subject: [PATCH 3/3] Bumped bibmanager version to 0.6.0. This next merge closes #12 --- CHANGELOG.txt | 5 +++++ bibmanager/VERSION.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7ec647d..e4dfd2d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -804,3 +804,8 @@ Removed unnecessary constants (url paths) from ads_manager.py ***** +Bumped bibmanager version to 0.6.0. +This next merge closes #12 + +***** + diff --git a/bibmanager/VERSION.py b/bibmanager/VERSION.py index 98db88e..3359dae 100644 --- a/bibmanager/VERSION.py +++ b/bibmanager/VERSION.py @@ -3,5 +3,5 @@ # bibmanager Version: BM_VER = 0 # Major version -BM_MIN = 5 # Minor version -BM_REV = 6 # Revision +BM_MIN = 6 # Minor version +BM_REV = 0 # Revision