From a624efff297336a9483ba7ea45368b16ea9d629e Mon Sep 17 00:00:00 2001 From: Oscar Arbelaez Date: Sat, 28 Jun 2025 09:33:04 +0100 Subject: [PATCH 1/3] Fix issue with typer --- pyproject.toml | 4 ++-- src/bibx/cli.py | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bd8ca4c..543915c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ dependencies = [ "networkx~=3.0", "pydantic~=2.10.6", "requests~=2.32.3", - "typer[all]~=0.9.0", + "typer[all]~=0.16.0", ] requires-python = ">=3.9" classifiers = [ @@ -44,7 +44,7 @@ dev = [ ] [project.scripts] -bibx = "bibx.cli:app" +bibx = "bibx.cli:main" [tool.ruff.lint] select = [ diff --git a/src/bibx/cli.py b/src/bibx/cli.py index ad391e9..189b3ef 100644 --- a/src/bibx/cli.py +++ b/src/bibx/cli.py @@ -21,7 +21,7 @@ @app.callback() -def main( +def set_verbose( verbose: Annotated[ # noqa: FBT002 bool, typer.Option("--verbose", "-v", help="Enable verbose logging.") ] = False, @@ -99,14 +99,8 @@ def openalex( help="how to handle references", default=EnrichReferences.BASIC, ), - verbose: bool = typer.Option( - help="be more verbose", - default=False, - ), ) -> None: """Run the sap algorithm on a seed file of any supported format.""" - if verbose: - logging.basicConfig(level=logging.INFO) c = query_openalex(" ".join(query), enrich=enrich) s = Sap() graph = s.create_graph(c) @@ -115,5 +109,10 @@ def openalex( rprint(graph) +def main() -> None: + """Entry point for the CLI.""" + app() + + if __name__ == "__main__": app() From bf8af29ce21894875d16217cef8f1c597df36efd Mon Sep 17 00:00:00 2001 From: Oscar Arbelaez Date: Sat, 28 Jun 2025 09:33:34 +0100 Subject: [PATCH 2/3] Fix issue with files without id --- src/bibx/builders/wos.py | 4 ++-- src/bibx/collection.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bibx/builders/wos.py b/src/bibx/builders/wos.py index 43273ac..c46decb 100644 --- a/src/bibx/builders/wos.py +++ b/src/bibx/builders/wos.py @@ -261,7 +261,7 @@ def __init__(self, *isi_files: TextIO) -> None: def build(self) -> Collection: """Build a collection of articles from Web of Science (WoS) ISI files.""" articles = self._get_articles_from_files() - return Collection(list(articles)) + return Collection(Collection.deduplicate_articles(list(articles))) def _get_articles_as_str_from_files(self) -> Iterable[str]: for file in self._files: @@ -369,7 +369,7 @@ def _parse(cls, key: str, value: list[str]) -> dict: if key in cls.FIELDS: field = cls.FIELDS[key] parsed_value = field.parse(value) - return {new_key: parsed_value for new_key in [field.key, *field.aliases]} + return dict.fromkeys([field.key, *field.aliases], parsed_value) logger.debug("Found an unknown field with key %s and value %s", key, value) return {key: _ident(value)} diff --git a/src/bibx/collection.py b/src/bibx/collection.py index fc33677..48c91f3 100644 --- a/src/bibx/collection.py +++ b/src/bibx/collection.py @@ -46,6 +46,8 @@ def _uniqe_articles_by_id(cls, articles: list[Article]) -> dict[str, Article]: graph = nx.Graph() id_to_article: defaultdict[str, list[Article]] = defaultdict(list) for article in cls._all_articles(articles): + if not article.ids: + continue first, *rest = article.ids # Add a loop edge so that the unique articles are included graph.add_edge(first, first) @@ -74,7 +76,7 @@ def _uniqe_articles_by_id(cls, articles: list[Article]) -> dict[str, Article]: articles.append(article) visited.add(id(article)) merged = reduce(Article.merge, articles) - article_by_id.update({id_: merged for id_ in ids}) + article_by_id.update(dict.fromkeys(ids, merged)) return article_by_id From 571c9054d1a673e3a2e3e3acb50ff7e282cf0ee3 Mon Sep 17 00:00:00 2001 From: Oscar Arbelaez Date: Sat, 28 Jun 2025 10:40:26 +0100 Subject: [PATCH 3/3] Update version --- src/bibx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bibx/__init__.py b/src/bibx/__init__.py index 4b8d583..5cef193 100644 --- a/src/bibx/__init__.py +++ b/src/bibx/__init__.py @@ -28,7 +28,7 @@ "read_wos", ] -__version__ = "0.6.3" +__version__ = "0.7.0" def query_openalex(