Skip to content

Commit

Permalink
EDIT: run pre-commit action
Browse files Browse the repository at this point in the history
  • Loading branch information
vdmitriyev committed Mar 7, 2024
1 parent 7b1eafc commit e664d40
Show file tree
Hide file tree
Showing 23 changed files with 115 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: docs/_build/
force_orphan: true
force_orphan: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ generated/*
*.log
*.bib
*.html
examples/json-examples/*
examples/json-examples/*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ sphinx-build docs docs/_build
sphinx-autobuild docs docs/_build/html
```

## License
## License

MIT
MIT

## Credits

Expand Down
19 changes: 9 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'orcidpyclient'
copyright = '2024, vdmitriyev'
author = 'vdmitriyev'
release = '1.2'
project = "orcidpyclient"
copyright = "2024, vdmitriyev"
author = "vdmitriyev"
release = "1.2"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

#
#
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
Expand All @@ -24,14 +24,13 @@
]


templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

#html_theme = 'alabaster'
# html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"
html_static_path = ['_static']
html_static_path = ["_static"]
6 changes: 3 additions & 3 deletions docs/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ How to install the package: [installation](installation.md)

### Basics Usage

#### A quick snippet to get info on the author
#### A quick snippet to get info on the author

The name of the author ```John Wilbanks```

Expand Down Expand Up @@ -114,7 +114,7 @@ import orcidpyclient

def get_affiliation(orcid:str):
"""Gets affiliation of the"""

author = pyorcid.get(orcid)
print(f'Educations : {author.educations}')
print(f'Employments : {author.employments}')
Expand All @@ -129,4 +129,4 @@ def empty_family_name():
get_affiliation(orcid = author.orcid)

empty_family_name()
```
```
2 changes: 0 additions & 2 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@
]
```
+ **NOTE**: To make in run on Mac OS, it's better if you will copy JabRef into the 'generated' folder directly


2 changes: 1 addition & 1 deletion docs/examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ vlbalist.py
orcid-log.log
output.txt
README.html
orcid-list.json
orcid-list.json
4 changes: 3 additions & 1 deletion docs/examples/extracting_bibtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def extract_bibtex_id(s):

_file.close()

print("[i] tex with \\nocite was created, check following file: {0}".format(file_name))
print(
"[i] tex with \\nocite was created, check following file: {0}".format(file_name)
)


def extract_bibtex(obj):
Expand Down
37 changes: 29 additions & 8 deletions docs/examples/orcid_bibtex_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ def log_traceback(ex, ex_traceback=None):
if ex_traceback is None:
ex_traceback = ex.__traceback__

tb_lines = [line.rstrip("\n") for line in traceback.format_exception(ex.__class__, ex, ex_traceback)]
tb_lines = [
line.rstrip("\n")
for line in traceback.format_exception(ex.__class__, ex, ex_traceback)
]

logging.exception(tb_lines)


def generate_bat(orcid_list, bat_name="buildall.{0}", separate=False, years=[], encoding="utf-8"):
def generate_bat(
orcid_list, bat_name="buildall.{0}", separate=False, years=[], encoding="utf-8"
):
"""
(list, str, str) -> None
Expand Down Expand Up @@ -103,7 +108,9 @@ def generate_bat(orcid_list, bat_name="buildall.{0}", separate=False, years=[],
_file.close()


def save_bibtex(bibtex, file_prefix="orcid-bibtex-output", separate=False, encoding="utf-8"):
def save_bibtex(
bibtex, file_prefix="orcid-bibtex-output", separate=False, encoding="utf-8"
):
"""
(dict, str, str) -> None
Expand Down Expand Up @@ -183,11 +190,23 @@ def extract_bitex(obj, author):
else:
bibtex[value.publicationyear].append(value.citation_value)
else:
nobibtex.append(form_bibtex([author], value.title, value.publicationyear))
print("[i] this publications is having no BIBTEX, new BIBTEX was generated {0}".format(value.title))
nobibtex.append(
form_bibtex([author], value.title, value.publicationyear)
)
print(
"[i] this publications is having no BIBTEX, new BIBTEX was generated {0}".format(
value.title
)
)
else:
nobibtex.append(form_bibtex([author], value.title, value.publicationyear))
print("[i] this publications is having no BIBTEX, new BIBTEX was generated {0}".format(value.title))
nobibtex.append(
form_bibtex([author], value.title, value.publicationyear)
)
print(
"[i] this publications is having no BIBTEX, new BIBTEX was generated {0}".format(
value.title
)
)
except Exception as ex:
_, _, ex_traceback = sys.exc_info()
log_traceback(ex, ex_traceback)
Expand Down Expand Up @@ -254,7 +273,9 @@ def main():
years[name] = sorted(tmp_list, reverse=True)

# saving bibtex into separated files
save_bibtex(bibtex=orcid_bibtex, file_prefix=name, separate=separate_by_year)
save_bibtex(
bibtex=orcid_bibtex, file_prefix=name, separate=separate_by_year
)
orcid_extracted.append(name)
except Exception as ex:
_, _, ex_traceback = sys.exc_info()
Expand Down
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ examples
changelog
```

2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ pip install git+https://github.com/vdmitriyev/orcidpyclient.git
* Unzip archive
* Create *virtualenv* (```scripts/cmdInitiateEnv.bat```)
* Activate *virtualenv* (```scripts/cmdStartEnv.bat```)
* Run examples
* Run examples
5 changes: 4 additions & 1 deletion orcidpyclient/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
ORCID_PUBLIC_BASE_URL = f"https://pub.orcid.org/v{ORCID_API_VERSION}/"
ORCID_SANDBOX_BASE_URL = "https://pub.orcid.org/"

BASE_HEADERS = {"Accept": "application/orcid+json", "Content-Type": "application/json;charset=UTF-8"}
BASE_HEADERS = {
"Accept": "application/orcid+json",
"Content-Type": "application/json;charset=UTF-8",
}
11 changes: 9 additions & 2 deletions orcidpyclient/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def get(orcid_id: str, debug: bool = False):

json_body = _res.json()

logger.debug("RESPONSE (BASE): {0}".format(json.dumps(json_body, sort_keys=True, indent=4, separators=(",", ": "))))
logger.debug(
"RESPONSE (BASE): {0}".format(
json.dumps(json_body, sort_keys=True, indent=4, separators=(",", ": "))
)
)

return Author(json_body)

Expand Down Expand Up @@ -66,7 +70,10 @@ def search(query, debug: bool = False):
json_body = resp.json()
logger.debug(json_body)
if json_body.get("result") is not None:
return (get(res.get("orcid-identifier", {}).get("path")) for res in json_body.get("result", {}))
return (
get(res.get("orcid-identifier", {}).get("path"))
for res in json_body.get("result", {})
)
else:
return iter(list())

Expand Down
4 changes: 3 additions & 1 deletion orcidpyclient/logger_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

stdout_sh = logging.StreamHandler(sys.stdout)
stdout_sh.setLevel(getattr(logging, _logger_depth))
stdout_sh.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
stdout_sh.setFormatter(
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
)

logger.addHandler(stdout_sh)
36 changes: 28 additions & 8 deletions orcidpyclient/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ def _parse_publications(l):
# getting through all works
for _, d in enumerate(l):
path = d["work-summary"][0]["path"]
_url = "{0}{1}".format(ORCID_PUBLIC_BASE_URL, path[1:]) # remove first symbol '/'
_url = "{0}{1}".format(
ORCID_PUBLIC_BASE_URL, path[1:]
) # remove first symbol '/'
_res = requests.get(_url, headers=BASE_HEADERS)
_json_body = _res.json()
logger.debug(
"REQUEST (PUBLICATIONS): {0}".format(
json.dumps(_json_body, sort_keys=True, indent=4, separators=(",", ": "))
json.dumps(
_json_body, sort_keys=True, indent=4, separators=(",", ": ")
)
)
)
_publications.append(Publication(_json_body))
Expand All @@ -46,9 +50,17 @@ def _parse_publications(l):
"given_name": ["person", "name", "given-names", "value"],
"biography": ["person", "biography", "content"],
"keywords": to(["person", "keywords"], _parse_keywords),
"researcher_urls": to(["person", "researcher-urls", "researcher-url"], _parse_researcher_urls),
"educations": to(["activities-summary", "educations", "education-summary"], _parse_affiliations),
"employments": to(["activities-summary", "employments", "employment-summary"], _parse_affiliations),
"researcher_urls": to(
["person", "researcher-urls", "researcher-url"], _parse_researcher_urls
),
"educations": to(
["activities-summary", "educations", "education-summary"],
_parse_affiliations,
),
"employments": to(
["activities-summary", "employments", "employment-summary"],
_parse_affiliations,
),
},
)

Expand All @@ -72,10 +84,16 @@ def _parse_publications(l):
)

ExternalIDBase = dictmapper(
"ExternalIDBase", {"id": ["work-external-identifier-id", "value"], "type": ["work-external-identifier-type"]}
"ExternalIDBase",
{
"id": ["work-external-identifier-id", "value"],
"type": ["work-external-identifier-type"],
},
)

CitationBase = dictmapper("CitationBase", {"type": ["citation-type"], "value": ["citation-value"]})
CitationBase = dictmapper(
"CitationBase", {"type": ["citation-type"], "value": ["citation-value"]}
)

WebsiteBase = dictmapper("WebsiteBase", {"name": ["url-name"], "url": ["url", "value"]})

Expand All @@ -88,7 +106,9 @@ def _load_works(self):
_res = requests.get(_url, headers=BASE_HEADERS)
_json_body = _res.json()
logger.debug(
"RESPONSE (WORKS): {0}".format(json.dumps(_json_body, sort_keys=True, indent=4, separators=(",", ": ")))
"RESPONSE (WORKS): {0}".format(
json.dumps(_json_body, sort_keys=True, indent=4, separators=(",", ": "))
)
)
self._loaded_works = Works(_json_body)

Expand Down
7 changes: 5 additions & 2 deletions orcidpyclient/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def init(self, d, *args, **kwargs):
def getter_from_dict_path(path):
if not callable(path) and len(path) < 1:
raise ValueError(
"Dict paths should be iterables with at least one" " key or callable objects that take one argument."
"Dict paths should be iterables with at least one"
" key or callable objects that take one argument."
)

def getter(self):
Expand All @@ -42,7 +43,9 @@ def getter(self):

return getter

prop_mapping = dict((k, property(getter_from_dict_path(v))) for k, v in mapping.items())
prop_mapping = dict(
(k, property(getter_from_dict_path(v))) for k, v in mapping.items()
)
prop_mapping["__init__"] = init
return type(typename, tuple(), prop_mapping)

Expand Down
3 changes: 2 additions & 1 deletion requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tox==4.11.3
pytest==7.4.3
pytest==7.4.3
pre-commit==3.6.2
2 changes: 1 addition & 1 deletion requirements/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sphinx==7.2.6
myst-parser==2.0.0
sphinx-autobuild==2024.2.4
sphinx-rtd-theme==2.0.0
sphinx-rtd-theme==2.0.0
2 changes: 1 addition & 1 deletion scripts/cmdInitiateEnv.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cd ..
setlocal
:PROMPT
SET AREYOUSURE=N
SET /P AREYOUSURE=Do you want to create a new virtual environment (Y/[N])?
SET /P AREYOUSURE=Do you want to create a new virtual environment (Y/[N])?
IF /I "%AREYOUSURE%" NEQ "Y" GOTO END

SET PATH=C:\Compilers\Python311\Scripts\;C:\Compilers\Python311\;%PATH%
Expand Down
2 changes: 1 addition & 1 deletion scripts/cmdStartEnv.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ SET PATH=C:\Compilers\Python10\Scripts\;C:\Compilers\Python10\;%PATH%
set PYTHONUTF8=1
set PYTHONDONTWRITEBYTECODE=1
call .venv\Scripts\activate.bat
cmd
cmd
4 changes: 3 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def test_existing_name_object():

def test_non_existing_name():

authors = orcidpyclient.search("family-name:wilbanksTestName+AND+given-names:john", debug=True)
authors = orcidpyclient.search(
"family-name:wilbanksTestName+AND+given-names:john", debug=True
)
expected = "No authors found"
found = None

Expand Down
9 changes: 5 additions & 4 deletions tests/test_longruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
try:
import pyorcid
except:
sys.path.append('../')
sys.path.append("../")
import pyorcid


@pytest.mark.skip(reason="long run test")
def test_publication():

cnt_publications = 22

orcid_res = pyorcid.get('0000-0001-5661-4587')
cnt_publications_orcid = len(orcid_res.publications)
orcid_res = pyorcid.get("0000-0001-5661-4587")
cnt_publications_orcid = len(orcid_res.publications)

assert cnt_publications == cnt_publications_orcid
Loading

0 comments on commit e664d40

Please sign in to comment.