Skip to content

Commit dc30dec

Browse files
author
Gerit Wagner
committed
fix pylint warnings
1 parent 3fbd8dc commit dc30dec

26 files changed

Lines changed: 111 additions & 123 deletions

File tree

colrev/packages/colrev_project/src/colrev_project.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ def _load_records_to_import(self, *, project_url: str, project_name: str) -> dic
107107
Repo.clone_from(project_url, temp_path, depth=1)
108108

109109
try:
110-
import colrev.review_manager
110+
# pylint: disable=import-outside-toplevel
111+
import colrev.review_manager as colrev_review_manager
111112

112-
project_review_manager = colrev.review_manager.ReviewManager(
113+
project_review_manager = colrev_review_manager.ReviewManager(
113114
path_str=str(temp_path)
114115
)
115116
except colrev_exceptions.RepoSetupError as exc:

colrev/packages/dblp/src/dblp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class DBLPSearchSourceSettings(colrev.search_file.ExtendedSearchFile, BaseModel)
4141
filepath: Path
4242
search_type: SearchType
4343
search_parameters: dict
44-
version: typing.Optional[str]
4544
comment: typing.Optional[str]
4645

4746
_details = {

colrev/packages/files_dir/src/files_dir.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class FilesSearchSource(base_classes.SearchSourcePackageBaseClass):
4141

4242
CURRENT_SYNTAX_VERSION = "0.1.0"
4343

44-
# pylint: disable=too-many-instance-attributes
45-
4644
endpoint = "colrev.files_dir"
4745
source_identifier = Fields.FILE
4846
search_types = [SearchType.FILES]
@@ -84,6 +82,13 @@ def __init__(
8482

8583
self.local_index = colrev.env.local_index.LocalIndex()
8684

85+
# SearchSource only supported in the context of a CoLRev project
86+
# pylint: disable=import-outside-toplevel
87+
import colrev.review_manager as colrev_review_manager
88+
89+
self.review_manager = colrev_review_manager.ReviewManager()
90+
colrev.ops.check.CheckOperation(self.review_manager)
91+
8792
def _update_if_pdf_renamed(
8893
self,
8994
*,
@@ -641,12 +646,6 @@ def _run_dir_search(
641646
def search(self, rerun: bool) -> None:
642647
"""Run a search of a Files directory"""
643648

644-
# TODO / TBD: replace review_manager?
645-
import colrev.review_manager
646-
647-
self.review_manager = colrev.review_manager.ReviewManager()
648-
colrev.ops.check.CheckOperation(self.review_manager)
649-
650649
self.rerun = rerun
651650
self._validate_source()
652651

colrev/packages/github/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### API search
88

9-
ℹ️ Restriction: API searches require an GitHub access token to retrieve all the relevant meta data.
9+
ℹ️ Restriction: API searches require an GitHub access token to retrieve all the relevant meta data. Store the token in the `GITHUB_API_TOKEN` environment variable (for example with `export GITHUB_API_TOKEN="<your-token>"`). If it is not set you will be prompted to enter the token and it will be stored for the current session.
1010

1111
In your GitHub account, a classic [personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) can be created. It is not necessary to select any scopes.
1212

colrev/packages/github/src/github_search_source.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import logging
6+
import os
67
import re
78
import typing
89
from multiprocessing import Lock
@@ -155,8 +156,7 @@ def add_endpoint(
155156

156157
@classmethod
157158
def _get_api_key(cls) -> str:
158-
env_man = colrev.env.environment_manager.EnvironmentManager()
159-
api_key = env_man.get_settings_by_key(cls.SETTINGS["api_key"])
159+
api_key = os.getenv("GITHUB_API_TOKEN")
160160
if api_key is not None and is_github_api_key({}, api_key):
161161
return api_key
162162

@@ -169,8 +169,8 @@ def _get_api_key(cls) -> str:
169169
]
170170
answers = inquirer.prompt(questions)
171171
input_key = answers["github_api_key"]
172-
env_man.update_registry(cls.SETTINGS["api_key"], input_key)
173-
print("API key saved in environment settings.")
172+
os.environ["GITHUB_API_TOKEN"] = input_key
173+
print("API key saved in environment variables.")
174174
return input_key
175175

176176
def _run_api_search(
@@ -190,6 +190,8 @@ def _run_api_search(
190190
github_connection = Github(auth=auth)
191191

192192
# Searching on Github
193+
# TODO : check: does not seem to retrieve all repositories?!
194+
# (e.g., for "colrev", it should be 25, but only 19 are retrieved)
193195
repositories = github_connection.search_repositories(query=query)
194196

195197
# Saving search results

colrev/packages/github/src/record_transformer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,13 @@ def _update_record_based_on_citation_cff(
9090
try:
9191
content = repo.get_contents("CITATION.cff")
9292
citation_data = content.decoded_content.decode("utf-8")
93-
9493
_set_title(record_dict=record_dict, citation_data=citation_data)
9594
_set_authors(record_dict=record_dict, citation_data=citation_data)
9695
_set_year_and_release_date(record_dict=record_dict, citation_data=citation_data)
9796
_set_version(record_dict, citation_data)
9897
_set_url(record_dict=record_dict, citation_data=citation_data)
99-
10098
except GithubException:
101-
record_dict = {}
99+
pass
102100
return record_dict
103101

104102

@@ -107,7 +105,6 @@ def repo_to_record(
107105
) -> colrev.record.record.Record:
108106
"""Convert a GitHub repository to a record"""
109107

110-
# Set default values
111108
record_dict = {
112109
Fields.ENTRYTYPE: "software",
113110
Fields.TITLE: repo.name,
@@ -126,6 +123,5 @@ def repo_to_record(
126123
# Use data from CITATION.cff file (if available)
127124
_update_record_based_on_citation_cff(record_dict, repo)
128125

129-
record_dict = {k: v for k, v in record_dict.items() if v}
130-
126+
record_dict = {k: v for k, v in record_dict.items() if v not in (None, "", [], {})}
131127
return colrev.record.record.Record(data=record_dict)

colrev/packages/ieee/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ colrev search --add colrev.ieee -p "https://ieeexploreapi.ieee.org/api/v1/search
2020

2121
All configured metadata fields, the abstract and the document text are queried.
2222

23-
It is not necessary to pass an API key as a parameter here. In order to keep the key secret, you will be prompted to enter it through user input if it is not already stored in the settings. The api key can be requested via the [IEEE Xplore API Portal](https://developer.ieee.org/member/register).
23+
It is not necessary to pass an API key as a parameter here. In order to keep the key secret, set it in the `IEEE_API_KEY` environment variable (for example with `export IEEE_API_KEY="<your-api-key>"`). The api key can be requested via the [IEEE Xplore API Portal](https://developer.ieee.org/member/register). If the variable is not defined, colrev will prompt for the key and store it for the current session.
2424

2525
Specific parameters can also be searched for, such as issn, isbn, doi, article_number, author, publication_year. For each of these, append "parameter=value" to the URL.
2626

colrev/packages/ieee/src/ieee.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
from __future__ import annotations
44

55
import logging
6+
import os
67
import typing
78
from pathlib import Path
89

910
import pandas as pd
1011
from pydantic import Field
1112

12-
import colrev.env.environment_manager
1313
import colrev.ops.prep
1414
import colrev.ops.search_api_feed
1515
import colrev.package_manager.package_base_classes as base_classes
@@ -60,8 +60,6 @@ def __init__(
6060
self.logger = logger or logging.getLogger(__name__)
6161
self.verbose_mode = verbose_mode
6262

63-
self.environment_manager = colrev.env.environment_manager.EnvironmentManager()
64-
6563
if search_file:
6664
self.search_source = search_file
6765
else:
@@ -192,10 +190,13 @@ def search(self, rerun: bool) -> None:
192190
raise NotImplementedError
193191

194192
def _get_api_key(self) -> str:
195-
api_key = self.environment_manager.get_settings_by_key(self.SETTINGS["api_key"])
196-
if api_key is None or len(api_key) != 24:
197-
api_key = input("Please enter api key: ")
198-
self.environment_manager.update_registry(self.SETTINGS["api_key"], api_key)
193+
api_key = os.getenv("IEEE_API_KEY")
194+
if api_key and len(api_key) == 24:
195+
return api_key
196+
197+
api_key = input("Please enter api key: ")
198+
if api_key:
199+
os.environ["IEEE_API_KEY"] = api_key
199200
return api_key
200201

201202
def _run_api_search(

colrev/packages/importer/src/importer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#! /usr/bin/env python
22
"""Importer"""
3+
import shutil
34
from pathlib import Path
45

56
import inquirer
@@ -104,6 +105,8 @@ def _import_prescreening_decisions(
104105
*,
105106
other_review_manager: colrev.review_manager.ReviewManager,
106107
) -> None:
108+
109+
# pylint: disable=colrev-records-variable-naming-convention
107110
colrev.ops.check.CheckOperation(other_review_manager)
108111
other_records = other_review_manager.dataset.load_records_dict()
109112
review_manager.get_prescreen_operation()
@@ -163,6 +166,7 @@ def _import_records(
163166
colrev.ops.check.CheckOperation(review_manager)
164167
colrev.ops.check.CheckOperation(other_review_manager)
165168

169+
# pylint: disable=colrev-records-variable-naming-convention
166170
other_records = other_review_manager.dataset.load_records_dict()
167171
records = review_manager.dataset.load_records_dict()
168172

@@ -226,7 +230,6 @@ def _import_records(
226230
print()
227231

228232
matched_df = match(blocked_df, verbosity_level=0)
229-
# TODO : mechanism in bib-dedupe to make sure that the cluster function is called?! (data structure!)
230233
duplicate_id_sets = cluster(matched_df, verbosity_level=0)
231234

232235
for duplicate_id_set in duplicate_id_sets:
@@ -250,7 +253,6 @@ def _import_records(
250253
if not target_path.parent.is_dir():
251254
target_path.parent.mkdir(parents=True, exist_ok=True)
252255
if not target_path.is_file():
253-
import shutil
254256

255257
shutil.copyfile(original_path, target_path)
256258
else:

colrev/packages/local_index/src/local_index.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,14 @@ def _apply_correction(self, *, source_url: str, change_list: list) -> None:
864864

865865
# TBD: other modes of accepting changes?
866866
# e.g., only-metadata, no-changes, all(including optional fields)
867-
import colrev.review_manager
868867

869-
check_review_manager = colrev.review_manager.ReviewManager(path_str=source_url)
868+
# SearchSource only supported in the context of a CoLRev project
869+
# pylint: disable=import-outside-toplevel
870+
import colrev.review_manager as colrev_review_manager
871+
872+
# self.review_manager = colrev_review_manager.ReviewManager()
873+
874+
check_review_manager = colrev_review_manager.ReviewManager(path_str=source_url)
870875
check_operation = colrev.ops.check.CheckOperation(check_review_manager)
871876

872877
git_repo = check_review_manager.dataset.git_repo

0 commit comments

Comments
 (0)