From 80867675b3f9881ccfcc3a68dd39c4c59a30a41d Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Fri, 10 Dec 2021 14:10:18 +0900 Subject: [PATCH 01/15] feat: add config spec to exclude bibtex fields --- pubs/config/spec.py | 3 +++ tests/str_fixtures.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pubs/config/spec.py b/pubs/config/spec.py index b691f80..ee8579d 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -35,6 +35,9 @@ max_authors = integer(default=3) # the full python stack is printed. debug = boolean(default=False) +# which bibliographic fields to exclude from bibtex files. +bibtex_field_excludes = force_list(default=list()) + [formating] # Enable bold formatting, if the terminal supports it. diff --git a/tests/str_fixtures.py b/tests/str_fixtures.py index d2fbfec..2e79f52 100644 --- a/tests/str_fixtures.py +++ b/tests/str_fixtures.py @@ -138,6 +138,9 @@ edit_cmd = "vim" # the full python stack is printed. debug = False +# which bibliographic fields to exclude from bibtex files. +bibtex_field_excludes = + [formating] # Enable bold formatting, if the terminal supports it. From 5a10a5631b3ed7ac548d4f004bc3b48f651c0c3d Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Fri, 10 Dec 2021 14:36:25 +0900 Subject: [PATCH 02/15] feat(cmd add): exclude bibtex fields if specified --- pubs/commands/add_cmd.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index ada5e7c..e143fb2 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -116,6 +116,12 @@ def command(conf, args): if bibentry is None: ui.error('invalid bibfile {}.'.format(bibfile)) + # exclude bibtex fields if specified + for item in bibentry.values(): + for field in conf['main']['bibtex_field_excludes']: + if field in item: + del item[field] + # citekey citekey = args.citekey From b9c65bda39f3b720446bf4298e8a91cd5e7d2fe8 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Fri, 10 Dec 2021 14:49:17 +0900 Subject: [PATCH 03/15] feat(cmd import): exclude bibtex fields if specified --- pubs/commands/import_cmd.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pubs/commands/import_cmd.py b/pubs/commands/import_cmd.py index dbc5480..c7bf5c6 100644 --- a/pubs/commands/import_cmd.py +++ b/pubs/commands/import_cmd.py @@ -40,7 +40,7 @@ def parser(subparsers, conf): return parser -def many_from_path(ui, bibpath, ignore=False): +def many_from_path(ui, bibpath, bibfield_excludes=[], ignore=False): """Extract list of papers found in bibliographic files in path. The behavior is to: @@ -62,7 +62,13 @@ def many_from_path(ui, bibpath, ignore=False): biblist = [] for filepath in all_files: try: - biblist.append(coder.decode_bibdata(read_text_file(filepath))) + bibentry = coder.decode_bibdata(read_text_file(filepath)) + # exclude bibtex fields if specified + for item in bibentry.values(): + for field in bibfield_excludes: + if field in item: + del item[field] + biblist.append(bibentry) except coder.BibDecodingError: error = "Could not parse bibtex at {}.".format(filepath) if ignore: @@ -100,7 +106,9 @@ def command(conf, args): rp = repo.Repository(conf) # Extract papers from bib - papers = many_from_path(ui, bibpath, ignore=args.ignore_malformed) + papers = many_from_path(ui, bibpath, + bibfield_excludes=conf['main']['bibtex_field_excludes'], + ignore=args.ignore_malformed) keys = args.keys or papers.keys() for k in keys: p = papers[k] From b208bc45bc83e835174893644e230965ff1563ec Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Fri, 10 Dec 2021 14:51:42 +0900 Subject: [PATCH 04/15] feat(cmd export): exclude bibtex fields if specified --- pubs/commands/export_cmd.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pubs/commands/export_cmd.py b/pubs/commands/export_cmd.py index b316efc..042d053 100644 --- a/pubs/commands/export_cmd.py +++ b/pubs/commands/export_cmd.py @@ -53,6 +53,11 @@ def command(conf, args): for p in papers: bib[p.citekey] = p.bibdata + # exclude bibtex fields if specified + for field in conf['main']['bibtex_field_excludes']: + if field in bib[p.citekey]: + del bib[p.citekey][field] + exporter = endecoder.EnDecoder() bibdata_raw = exporter.encode_bibdata(bib, args.ignore_fields) ui.message(bibdata_raw) From d2dfe7dc9aa4c95f71aae6b0da790acb96cac858 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Fri, 10 Dec 2021 14:56:07 +0900 Subject: [PATCH 05/15] feat(cmd edit): exclude bibtex fields if specified --- pubs/commands/edit_cmd.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pubs/commands/edit_cmd.py b/pubs/commands/edit_cmd.py index 5ea7679..a3126f9 100644 --- a/pubs/commands/edit_cmd.py +++ b/pubs/commands/edit_cmd.py @@ -59,6 +59,12 @@ def command(conf, args): ui.info(("The metadata of paper '{}' was successfully " "edited.".format(color.dye_out(citekey, 'citekey')))) else: + # exclude bibtex fields if specified + for item in content.values(): + for field in conf['main']['bibtex_field_excludes']: + if field in item: + del item[field] + new_paper = Paper.from_bibentry(content, metadata=paper.metadata) if rp.rename_paper(new_paper, old_citekey=paper.citekey): From df52580a0f015aba284ea5433f56ac6c27337588 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Fri, 10 Dec 2021 17:22:37 +0900 Subject: [PATCH 06/15] test: add tests for excluding bibtex fields --- tests/test_usecase.py | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 9219657..20e8242 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -437,6 +437,17 @@ class TestAdd(URLContentTestCase): self.execute_cmds(cmds) self.assertEqual(cm.exception.code, 1) + def test_add_excludes_bibtex_fields(self): + self.execute_cmds(['pubs init']) + config = conf.load_conf() + config['main']['bibtex_field_excludes'] = ['abstract', 'publisher'] + conf.save_conf(config) + self.execute_cmds(['pubs add data/pagerank.bib']) + with FakeFileOpen(self.fs)(self.default_pubs_dir + '/bib/Page99.bib', 'r') as buf: + out = endecoder.EnDecoder().decode_bibdata(buf.read()) + for bib in out.values(): + self.assertFalse('abstract' in bib or 'publisher' in bib) + class TestList(DataCommandTestCase): @@ -829,6 +840,21 @@ class TestUsecase(DataCommandTestCase): ] self.execute_cmds(cmds) + def test_editor_excludes_bibtex_field(self): + cmds = ['pubs init', + 'pubs add data/pagerank.bib', + ] + self.execute_cmds(cmds) + config = conf.load_conf() + config['main']['bibtex_field_excludes'] = ['author'] + conf.save_conf(config) + cmds = [('pubs edit Page99', ['@misc{Page99, title="TTT", author="auth"}', 'n'])] + self.execute_cmds(cmds) + with FakeFileOpen(self.fs)(self.default_pubs_dir + '/bib/Page99.bib', 'r') as buf: + out = endecoder.EnDecoder().decode_bibdata(buf.read()) + for bib in out.values(): + self.assertFalse('author' in bib) + def test_add_aborts(self): with self.assertRaises(FakeSystemExit): cmds = ['pubs init', @@ -908,6 +934,18 @@ class TestUsecase(DataCommandTestCase): fixtures.page_bibentry, ignore_fields=['author', 'title']) self.assertEqual(outs[2], expected + os.linesep) + def test_export_excludes_bibtex_field(self): + cmds = ['pubs init', + 'pubs add data/pagerank.bib' + ] + self.execute_cmds(cmds) + config = conf.load_conf() + config['main']['bibtex_field_excludes'] = ['url'] + conf.save_conf(config) + outs = self.execute_cmds(['pubs export Page99']) + for bib in endecoder.EnDecoder().decode_bibdata(outs[0]).values(): + self.assertFalse('url' in bib) + def test_import(self): cmds = ['pubs init', 'pubs import data/', @@ -970,6 +1008,17 @@ class TestUsecase(DataCommandTestCase): outs = self.execute_cmds(cmds) self.assertEqual(1 + 1, len(outs[-1].split('\n'))) + def test_import_excludes_bibtex_field(self): + self.execute_cmds(['pubs init']) + config = conf.load_conf() + config['main']['bibtex_field_excludes'] = ['abstract'] + conf.save_conf(config) + self.execute_cmds(['pubs import data/ Page99']) + with FakeFileOpen(self.fs)(self.default_pubs_dir + '/bib/Page99.bib', 'r') as buf: + out = endecoder.EnDecoder().decode_bibdata(buf.read()) + for bib in out.values(): + self.assertFalse('abstract' in bib) + def test_update(self): cmds = ['pubs init', 'pubs add data/pagerank.bib', From 040e756f211ba5e859ece01f298d3379f063a189 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Fri, 10 Dec 2021 21:21:41 +0900 Subject: [PATCH 07/15] refactor: add utility function to exclude bibtex fields --- pubs/commands/add_cmd.py | 5 +---- pubs/commands/edit_cmd.py | 7 ++----- pubs/commands/export_cmd.py | 8 +++----- pubs/commands/import_cmd.py | 10 ++++------ pubs/utils.py | 6 ++++++ 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index e143fb2..88091f6 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -117,10 +117,7 @@ def command(conf, args): ui.error('invalid bibfile {}.'.format(bibfile)) # exclude bibtex fields if specified - for item in bibentry.values(): - for field in conf['main']['bibtex_field_excludes']: - if field in item: - del item[field] + utils.remove_bibtex_fields(bibentry, conf['main']['bibtex_field_excludes']) # citekey diff --git a/pubs/commands/edit_cmd.py b/pubs/commands/edit_cmd.py index a3126f9..591c2d1 100644 --- a/pubs/commands/edit_cmd.py +++ b/pubs/commands/edit_cmd.py @@ -6,7 +6,7 @@ from .. import color from ..uis import get_ui from ..endecoder import EnDecoder -from ..utils import resolve_citekey +from ..utils import resolve_citekey, remove_bibtex_fields from ..completion import CiteKeyCompletion from ..events import ModifyEvent @@ -60,10 +60,7 @@ def command(conf, args): "edited.".format(color.dye_out(citekey, 'citekey')))) else: # exclude bibtex fields if specified - for item in content.values(): - for field in conf['main']['bibtex_field_excludes']: - if field in item: - del item[field] + remove_bibtex_fields(content, conf['main']['bibtex_field_excludes']) new_paper = Paper.from_bibentry(content, metadata=paper.metadata) diff --git a/pubs/commands/export_cmd.py b/pubs/commands/export_cmd.py index 042d053..c3c3a89 100644 --- a/pubs/commands/export_cmd.py +++ b/pubs/commands/export_cmd.py @@ -5,7 +5,7 @@ import argparse from .. import repo from ..uis import get_ui from .. import endecoder -from ..utils import resolve_citekey_list +from ..utils import resolve_citekey_list, remove_bibtex_fields from ..endecoder import BIBFIELD_ORDER from ..completion import CiteKeyCompletion, CommaSeparatedListCompletion @@ -53,10 +53,8 @@ def command(conf, args): for p in papers: bib[p.citekey] = p.bibdata - # exclude bibtex fields if specified - for field in conf['main']['bibtex_field_excludes']: - if field in bib[p.citekey]: - del bib[p.citekey][field] + # exclude bibtex fields if specified + remove_bibtex_fields(bib, conf['main']['bibtex_field_excludes']) exporter = endecoder.EnDecoder() bibdata_raw = exporter.encode_bibdata(bib, args.ignore_fields) diff --git a/pubs/commands/import_cmd.py b/pubs/commands/import_cmd.py index c7bf5c6..918709d 100644 --- a/pubs/commands/import_cmd.py +++ b/pubs/commands/import_cmd.py @@ -11,6 +11,7 @@ from .. import content from ..paper import Paper from ..uis import get_ui from ..content import system_path, read_text_file +from ..utils import remove_bibtex_fields from ..command_utils import add_doc_copy_arguments @@ -40,7 +41,7 @@ def parser(subparsers, conf): return parser -def many_from_path(ui, bibpath, bibfield_excludes=[], ignore=False): +def many_from_path(ui, bibpath, excluded_bibtex_fields=[], ignore=False): """Extract list of papers found in bibliographic files in path. The behavior is to: @@ -64,10 +65,7 @@ def many_from_path(ui, bibpath, bibfield_excludes=[], ignore=False): try: bibentry = coder.decode_bibdata(read_text_file(filepath)) # exclude bibtex fields if specified - for item in bibentry.values(): - for field in bibfield_excludes: - if field in item: - del item[field] + remove_bibtex_fields(bibentry, excluded_bibtex_fields) biblist.append(bibentry) except coder.BibDecodingError: error = "Could not parse bibtex at {}.".format(filepath) @@ -107,7 +105,7 @@ def command(conf, args): rp = repo.Repository(conf) # Extract papers from bib papers = many_from_path(ui, bibpath, - bibfield_excludes=conf['main']['bibtex_field_excludes'], + excluded_bibtex_fields=conf['main']['bibtex_field_excludes'], ignore=args.ignore_malformed) keys = args.keys or papers.keys() for k in keys: diff --git a/pubs/utils.py b/pubs/utils.py index 120edfd..8c3ebbf 100644 --- a/pubs/utils.py +++ b/pubs/utils.py @@ -87,3 +87,9 @@ def standardize_doi(doi): new_doi = match.group(0) return new_doi + +def remove_bibtex_fields(bibentry, excluded_bibtex_fields=[]): + for item in bibentry.values(): + for field in excluded_bibtex_fields: + if field in item: + del item[field] From a14d6441a4fe17afc01b9f6e1d6e759b8a5dda60 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Sat, 11 Dec 2021 12:49:41 +0900 Subject: [PATCH 08/15] refactor: rename variables --- pubs/commands/import_cmd.py | 6 +++--- pubs/utils.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pubs/commands/import_cmd.py b/pubs/commands/import_cmd.py index 918709d..a33e467 100644 --- a/pubs/commands/import_cmd.py +++ b/pubs/commands/import_cmd.py @@ -41,7 +41,7 @@ def parser(subparsers, conf): return parser -def many_from_path(ui, bibpath, excluded_bibtex_fields=[], ignore=False): +def many_from_path(ui, bibpath, bibtex_field_excludes=[], ignore=False): """Extract list of papers found in bibliographic files in path. The behavior is to: @@ -65,7 +65,7 @@ def many_from_path(ui, bibpath, excluded_bibtex_fields=[], ignore=False): try: bibentry = coder.decode_bibdata(read_text_file(filepath)) # exclude bibtex fields if specified - remove_bibtex_fields(bibentry, excluded_bibtex_fields) + remove_bibtex_fields(bibentry, bibtex_field_excludes) biblist.append(bibentry) except coder.BibDecodingError: error = "Could not parse bibtex at {}.".format(filepath) @@ -105,7 +105,7 @@ def command(conf, args): rp = repo.Repository(conf) # Extract papers from bib papers = many_from_path(ui, bibpath, - excluded_bibtex_fields=conf['main']['bibtex_field_excludes'], + bibtex_field_excludes=conf['main']['bibtex_field_excludes'], ignore=args.ignore_malformed) keys = args.keys or papers.keys() for k in keys: diff --git a/pubs/utils.py b/pubs/utils.py index 8c3ebbf..a49894a 100644 --- a/pubs/utils.py +++ b/pubs/utils.py @@ -88,8 +88,8 @@ def standardize_doi(doi): return new_doi -def remove_bibtex_fields(bibentry, excluded_bibtex_fields=[]): +def remove_bibtex_fields(bibentry, fields): for item in bibentry.values(): - for field in excluded_bibtex_fields: + for field in fields: if field in item: del item[field] From d9c8af7c9a81eac3fb37f3b7e260caae531e5752 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Wed, 5 Jan 2022 13:51:43 +0100 Subject: [PATCH 09/15] rename `bibtex_field_excludes` into `exclude_bibtex_fields` --- pubs/commands/add_cmd.py | 2 +- pubs/commands/edit_cmd.py | 2 +- pubs/commands/export_cmd.py | 2 +- pubs/commands/import_cmd.py | 6 +++--- pubs/config/spec.py | 6 ++++-- tests/str_fixtures.py | 2 +- tests/test_usecase.py | 8 ++++---- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index 88091f6..b56927e 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -117,7 +117,7 @@ def command(conf, args): ui.error('invalid bibfile {}.'.format(bibfile)) # exclude bibtex fields if specified - utils.remove_bibtex_fields(bibentry, conf['main']['bibtex_field_excludes']) + utils.remove_bibtex_fields(bibentry, conf['main']['exclude_bibtex_fields']) # citekey diff --git a/pubs/commands/edit_cmd.py b/pubs/commands/edit_cmd.py index 591c2d1..3e52383 100644 --- a/pubs/commands/edit_cmd.py +++ b/pubs/commands/edit_cmd.py @@ -60,7 +60,7 @@ def command(conf, args): "edited.".format(color.dye_out(citekey, 'citekey')))) else: # exclude bibtex fields if specified - remove_bibtex_fields(content, conf['main']['bibtex_field_excludes']) + remove_bibtex_fields(content, conf['main']['exclude_bibtex_fields']) new_paper = Paper.from_bibentry(content, metadata=paper.metadata) diff --git a/pubs/commands/export_cmd.py b/pubs/commands/export_cmd.py index c3c3a89..9c3831b 100644 --- a/pubs/commands/export_cmd.py +++ b/pubs/commands/export_cmd.py @@ -54,7 +54,7 @@ def command(conf, args): bib[p.citekey] = p.bibdata # exclude bibtex fields if specified - remove_bibtex_fields(bib, conf['main']['bibtex_field_excludes']) + remove_bibtex_fields(bib, conf['main']['exclude_bibtex_fields']) exporter = endecoder.EnDecoder() bibdata_raw = exporter.encode_bibdata(bib, args.ignore_fields) diff --git a/pubs/commands/import_cmd.py b/pubs/commands/import_cmd.py index a33e467..775ae41 100644 --- a/pubs/commands/import_cmd.py +++ b/pubs/commands/import_cmd.py @@ -41,7 +41,7 @@ def parser(subparsers, conf): return parser -def many_from_path(ui, bibpath, bibtex_field_excludes=[], ignore=False): +def many_from_path(ui, bibpath, exclude_bibtex_fields=[], ignore=False): """Extract list of papers found in bibliographic files in path. The behavior is to: @@ -65,7 +65,7 @@ def many_from_path(ui, bibpath, bibtex_field_excludes=[], ignore=False): try: bibentry = coder.decode_bibdata(read_text_file(filepath)) # exclude bibtex fields if specified - remove_bibtex_fields(bibentry, bibtex_field_excludes) + remove_bibtex_fields(bibentry, exclude_bibtex_fields) biblist.append(bibentry) except coder.BibDecodingError: error = "Could not parse bibtex at {}.".format(filepath) @@ -105,7 +105,7 @@ def command(conf, args): rp = repo.Repository(conf) # Extract papers from bib papers = many_from_path(ui, bibpath, - bibtex_field_excludes=conf['main']['bibtex_field_excludes'], + exclude_bibtex_fields=conf['main']['exclude_bibtex_fields'], ignore=args.ignore_malformed) keys = args.keys or papers.keys() for k in keys: diff --git a/pubs/config/spec.py b/pubs/config/spec.py index ee8579d..a323ada 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -35,8 +35,10 @@ max_authors = integer(default=3) # the full python stack is printed. debug = boolean(default=False) -# which bibliographic fields to exclude from bibtex files. -bibtex_field_excludes = force_list(default=list()) +# which bibliographic fields to exclude from bibtex files. By default, none. +# Please note that excluding critical fields such as `title` or `author` +# will break many commands of pubs. +exclude_bibtex_fields = force_list(default=list()) [formating] diff --git a/tests/str_fixtures.py b/tests/str_fixtures.py index 2e79f52..7dfd5b8 100644 --- a/tests/str_fixtures.py +++ b/tests/str_fixtures.py @@ -139,7 +139,7 @@ edit_cmd = "vim" debug = False # which bibliographic fields to exclude from bibtex files. -bibtex_field_excludes = +exclude_bibtex_fields = [formating] diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 20e8242..053543d 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -440,7 +440,7 @@ class TestAdd(URLContentTestCase): def test_add_excludes_bibtex_fields(self): self.execute_cmds(['pubs init']) config = conf.load_conf() - config['main']['bibtex_field_excludes'] = ['abstract', 'publisher'] + config['main']['exclude_bibtex_fields'] = ['abstract', 'publisher'] conf.save_conf(config) self.execute_cmds(['pubs add data/pagerank.bib']) with FakeFileOpen(self.fs)(self.default_pubs_dir + '/bib/Page99.bib', 'r') as buf: @@ -846,7 +846,7 @@ class TestUsecase(DataCommandTestCase): ] self.execute_cmds(cmds) config = conf.load_conf() - config['main']['bibtex_field_excludes'] = ['author'] + config['main']['exclude_bibtex_fields'] = ['author'] conf.save_conf(config) cmds = [('pubs edit Page99', ['@misc{Page99, title="TTT", author="auth"}', 'n'])] self.execute_cmds(cmds) @@ -940,7 +940,7 @@ class TestUsecase(DataCommandTestCase): ] self.execute_cmds(cmds) config = conf.load_conf() - config['main']['bibtex_field_excludes'] = ['url'] + config['main']['exclude_bibtex_fields'] = ['url'] conf.save_conf(config) outs = self.execute_cmds(['pubs export Page99']) for bib in endecoder.EnDecoder().decode_bibdata(outs[0]).values(): @@ -1011,7 +1011,7 @@ class TestUsecase(DataCommandTestCase): def test_import_excludes_bibtex_field(self): self.execute_cmds(['pubs init']) config = conf.load_conf() - config['main']['bibtex_field_excludes'] = ['abstract'] + config['main']['exclude_bibtex_fields'] = ['abstract'] conf.save_conf(config) self.execute_cmds(['pubs import data/ Page99']) with FakeFileOpen(self.fs)(self.default_pubs_dir + '/bib/Page99.bib', 'r') as buf: From 6271b0bd1ce1afac889573e05a5bb1d21233aed2 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Wed, 5 Jan 2022 14:10:29 +0100 Subject: [PATCH 10/15] stricter tests for exclude_bibtex_fields --- tests/test_usecase.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 053543d..98f819d 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -447,6 +447,7 @@ class TestAdd(URLContentTestCase): out = endecoder.EnDecoder().decode_bibdata(buf.read()) for bib in out.values(): self.assertFalse('abstract' in bib or 'publisher' in bib) + self.assertTrue('title' in bib and 'author' in bib) class TestList(DataCommandTestCase): @@ -854,6 +855,7 @@ class TestUsecase(DataCommandTestCase): out = endecoder.EnDecoder().decode_bibdata(buf.read()) for bib in out.values(): self.assertFalse('author' in bib) + self.assertTrue('title' in bib) def test_add_aborts(self): with self.assertRaises(FakeSystemExit): @@ -945,6 +947,7 @@ class TestUsecase(DataCommandTestCase): outs = self.execute_cmds(['pubs export Page99']) for bib in endecoder.EnDecoder().decode_bibdata(outs[0]).values(): self.assertFalse('url' in bib) + self.assertTrue('title' in bib and 'author' in bib) def test_import(self): cmds = ['pubs init', @@ -1018,6 +1021,7 @@ class TestUsecase(DataCommandTestCase): out = endecoder.EnDecoder().decode_bibdata(buf.read()) for bib in out.values(): self.assertFalse('abstract' in bib) + self.assertTrue('title' in bib and 'author' in bib) def test_update(self): cmds = ['pubs init', From bf79085e3876fb764ee194be7c35b7207e9a7d70 Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Wed, 5 Jan 2022 15:01:40 +0100 Subject: [PATCH 11/15] update changelog, contributor after #273 --- changelog.md | 1 + readme.md | 1 + 2 files changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index ca05610..0d95750 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ ### Implemented enhancements +- Possibily to exclude bibtext field when adding references ([#273](https://github.com/pubs/pubs/pull/273) by [Mitsuhiro Nakamura](https://github.com/m15a)) - Migration from Travis CI to Github actions ([#260](https://github.com/pubs/pubs/pull/260)) - Allow passing named arguments to custom commands ([#241](https://github.com/pubs/pubs/pull/241) by [jkulhanek](https://github.com/jkulhanek)) - Added support for non-standard bibtex types, e.g. @collection, @software, etc. ([#226](https://github.com/pubs/pubs/pull/226)) diff --git a/readme.md b/readme.md index 446a8ad..daf7c3d 100644 --- a/readme.md +++ b/readme.md @@ -187,3 +187,4 @@ You can access the self-documented configuration by using `pubs conf`, and all t - [Jonáš Kulhánek](https://github.com/jkulhanek) - [Dominik Stańczak](https://github.com/StanczakDominik) - [Gustavo José de Sousa](https://github.com/guludo) +- [Mitsuhiro Nakamura](https://github.com/m15a) From de189e325b945399a8d905b55cadfaa0e9a7bebd Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Sun, 4 Apr 2021 22:53:30 +0900 Subject: [PATCH 12/15] Change tag display --- pubs/commands/tag_cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubs/commands/tag_cmd.py b/pubs/commands/tag_cmd.py index c12bf8f..99ccbdb 100644 --- a/pubs/commands/tag_cmd.py +++ b/pubs/commands/tag_cmd.py @@ -87,7 +87,7 @@ def command(conf, args): rp = Repository(conf) if citekeyOrTag is None: - ui.message(color.dye_out(' '.join(sorted(rp.get_tags())), 'tag')) + ui.message(color.dye_out(', '.join(sorted(rp.get_tags())), 'tag')) else: not_citekey = False try: @@ -97,7 +97,7 @@ def command(conf, args): if not not_citekey: p = rp.pull_paper(citekeyOrTag) if tags is None: - ui.message(color.dye_out(' '.join(sorted(p.tags)), 'tag')) + ui.message(color.dye_out(', '.join(sorted(p.tags)), 'tag')) else: add_tags, remove_tags = _tag_groups(_parse_tag_seq(tags)) for tag in add_tags: From e2c83b75aa6d16a046881df2824f616ed7b6fa51 Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Sun, 4 Apr 2021 22:54:31 +0900 Subject: [PATCH 13/15] Remove the dot for homogeneity --- pubs/commands/import_cmd.py | 2 +- pubs/commands/statistics_cmd.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pubs/commands/import_cmd.py b/pubs/commands/import_cmd.py index 775ae41..b8f663b 100644 --- a/pubs/commands/import_cmd.py +++ b/pubs/commands/import_cmd.py @@ -22,7 +22,7 @@ _IGNORING_MSG = " Ignoring it." def parser(subparsers, conf): parser = subparsers.add_parser( 'import', - help='import paper(s) to the repository.') + help='import paper(s) to the repository') parser.add_argument( 'bibpath', help=("path to bibtex, bibtexml or bibyaml file, or a directory " diff --git a/pubs/commands/statistics_cmd.py b/pubs/commands/statistics_cmd.py index a606fa0..9f8a9f3 100644 --- a/pubs/commands/statistics_cmd.py +++ b/pubs/commands/statistics_cmd.py @@ -6,7 +6,7 @@ from .. import color def parser(subparsers, conf): parser = subparsers.add_parser( 'statistics', - help="show statistics on the repository.") + help="show statistics on the repository") return parser From 009cb808a43369fd3cebfce13b624f1717f9545b Mon Sep 17 00:00:00 2001 From: Florian Richoux Date: Mon, 5 Apr 2021 13:55:08 +0900 Subject: [PATCH 14/15] Update tests for the new tag display --- changelog.md | 1 + readme.md | 1 + tests/test_usecase.py | 12 ++++++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 0d95750..6b4dd39 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ ### Implemented enhancements - Possibily to exclude bibtext field when adding references ([#273](https://github.com/pubs/pubs/pull/273) by [Mitsuhiro Nakamura](https://github.com/m15a)) +- Less ambiguous tag display for tags with space ([#265](https://github.com/pubs/pubs/pull/265) by [Florian Richoux](https://github.com/richoux)) - Migration from Travis CI to Github actions ([#260](https://github.com/pubs/pubs/pull/260)) - Allow passing named arguments to custom commands ([#241](https://github.com/pubs/pubs/pull/241) by [jkulhanek](https://github.com/jkulhanek)) - Added support for non-standard bibtex types, e.g. @collection, @software, etc. ([#226](https://github.com/pubs/pubs/pull/226)) diff --git a/readme.md b/readme.md index daf7c3d..1b0aa3d 100644 --- a/readme.md +++ b/readme.md @@ -187,4 +187,5 @@ You can access the self-documented configuration by using `pubs conf`, and all t - [Jonáš Kulhánek](https://github.com/jkulhanek) - [Dominik Stańczak](https://github.com/StanczakDominik) - [Gustavo José de Sousa](https://github.com/guludo) +- [Florian Richoux](https://github.com/richoux) - [Mitsuhiro Nakamura](https://github.com/m15a) diff --git a/tests/test_usecase.py b/tests/test_usecase.py index 98f819d..13433d6 100644 --- a/tests/test_usecase.py +++ b/tests/test_usecase.py @@ -602,7 +602,7 @@ class TestTag(DataCommandTestCase): 'pubs list', ] correct = ['', - '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) | network,search\n' + + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) | network, search\n' + '[Turing1950] Turing, Alan M "Computing machinery and intelligence" Mind (1950) \n', ] out = self.execute_cmds(cmds) @@ -750,9 +750,9 @@ class TestUsecase(DataCommandTestCase): '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) [pdf] \n', '\n', '', - 'network search\n', + 'network, search\n', 'info: Assuming search to be a tag.\n' - '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) [pdf] | network,search\n', + '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) [pdf] | network, search\n', ] cmds = ['pubs init -p /paper_first', @@ -797,7 +797,7 @@ class TestUsecase(DataCommandTestCase): '', '', '', - 'search network\n', + 'search, network\n', ] cmds = ['pubs init -p paper_first/', @@ -810,7 +810,7 @@ class TestUsecase(DataCommandTestCase): out = self.execute_cmds(cmds) def clean(s): - return set(s.strip().split(' ')) + return set(s.strip().split(', ')) self.assertEqual(clean(correct[2]), clean(out[2])) self.assertEqual(clean(correct[4]), clean(out[4])) @@ -907,7 +907,7 @@ class TestUsecase(DataCommandTestCase): meta = str_fixtures.turing_meta line = '[Page99] Page, Lawrence et al. "The PageRank Citation Ranking: Bringing Order to the Web." (1999) \n' - line1 = re.sub('\n', '| AI,computer\n', line) + line1 = re.sub('\n', '| AI, computer\n', line) cmds = ['pubs init', 'pubs add data/pagerank.bib', From fde2efc39ac53fb66c6ff0349d8e117ca00c31ab Mon Sep 17 00:00:00 2001 From: "Fabien C. Y. Benureau" Date: Thu, 6 Jan 2022 12:34:05 +0100 Subject: [PATCH 15/15] fix tag display in oneliner() --- pubs/pretty.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubs/pretty.py b/pubs/pretty.py index 6b12fb6..8ec1bf8 100644 --- a/pubs/pretty.py +++ b/pubs/pretty.py @@ -78,7 +78,7 @@ def paper_oneliner(p, citekey_only=False, max_authors=3): else 'NOEXT'), 'tag') tags = '' if len(p.tags) == 0 else '| {}'.format( - ','.join(color.dye_out(t, 'tag') for t in sorted(p.tags))) + ', '.join(color.dye_out(t, 'tag') for t in sorted(p.tags))) return '[{citekey}] {descr}{doc} {tags}'.format( citekey=color.dye_out(p.citekey, 'citekey'), descr=bibdesc, tags=tags, doc=doc_str)