commonmeta-py 0.117__py3-none-any.whl → 0.118__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
commonmeta/__init__.py CHANGED
@@ -10,7 +10,7 @@ commonmeta-py is a Python library to convert scholarly metadata
10
10
  """
11
11
 
12
12
  __title__ = "commonmeta-py"
13
- __version__ = "0.117"
13
+ __version__ = "0.118"
14
14
  __author__ = "Martin Fenner"
15
15
  __license__ = "MIT"
16
16
 
@@ -1,8 +1,9 @@
1
1
  """InvenioRDM writer for commonmeta-py"""
2
2
 
3
+ import logging
3
4
  import re
4
5
  from time import time
5
- from typing import Optional
6
+ from typing import Any, Dict, Optional, Tuple
6
7
  from urllib.parse import urlparse
7
8
 
8
9
  import orjson as json
@@ -15,6 +16,7 @@ from ..constants import (
15
16
  COMMUNITY_TRANSLATIONS,
16
17
  CROSSREF_FUNDER_ID_TO_ROR_TRANSLATIONS,
17
18
  INVENIORDM_IDENTIFIER_TYPES,
19
+ Commonmeta,
18
20
  )
19
21
  from ..date_utils import get_iso8601_date
20
22
  from ..doi_utils import doi_from_url, normalize_doi
@@ -28,6 +30,7 @@ from ..utils import (
28
30
  validate_ror,
29
31
  )
30
32
 
33
+ logger = logging.getLogger(__name__)
31
34
 
32
35
  def write_inveniordm(metadata):
33
36
  """Write inveniordm"""
@@ -384,7 +387,12 @@ def write_inveniordm_list(metalist):
384
387
  return [write_inveniordm(item) for item in metalist.items]
385
388
 
386
389
 
387
- def push_inveniordm(metadata, host: str, token: str, legacy_key: str):
390
+ def push_inveniordm(
391
+ metadata: Commonmeta,
392
+ host: str,
393
+ token: str,
394
+ legacy_key: str
395
+ ) -> Tuple[Dict[str, Any], Optional[Exception]]:
388
396
  """Push record to InvenioRDM"""
389
397
 
390
398
  record = {}
@@ -392,22 +400,22 @@ def push_inveniordm(metadata, host: str, token: str, legacy_key: str):
392
400
 
393
401
  try:
394
402
  # Remove IsPartOf relation with InvenioRDM community identifier after storing it
395
- community_index = None
396
- if hasattr(metadata, "relations") and metadata.relations:
397
- for i, relation in enumerate(metadata.relations):
398
- if relation.get("type") == "IsPartOf" and relation.get(
399
- "id", ""
400
- ).startswith("https://rogue-scholar.org/api/communities/"):
401
- slug = relation.get("id").split("/")[5]
402
- community_id, _ = search_by_slug(slug, "blog", host, token)
403
- if community_id:
404
- record["community"] = slug
405
- record["community_id"] = community_id
406
- community_index = i
407
-
408
- # Remove the relation if we found and processed it
409
- if community_index is not None and hasattr(metadata, "relations"):
410
- metadata.relations.pop(community_index)
403
+ # community_index = None
404
+ # if hasattr(metadata, "relations") and metadata.relations:
405
+ # for i, relation in enumerate(metadata.relations):
406
+ # if relation.get("type") == "IsPartOf" and relation.get(
407
+ # "id", ""
408
+ # ).startswith("https://rogue-scholar.org/api/communities/"):
409
+ # slug = relation.get("id").split("/")[5]
410
+ # community_id, _ = search_by_slug(slug, "blog", host, token)
411
+ # if community_id:
412
+ # record["community"] = slug
413
+ # record["community_id"] = community_id
414
+ # community_index = i
415
+
416
+ # # Remove the relation if we found and processed it
417
+ # if community_index is not None and hasattr(metadata, "relations"):
418
+ # metadata.relations.pop(community_index)
411
419
 
412
420
  # Remove InvenioRDM rid after storing it
413
421
  # rid_index = None
@@ -450,7 +458,8 @@ def push_inveniordm(metadata, host: str, token: str, legacy_key: str):
450
458
 
451
459
  if hasattr(metadata, "subjects"):
452
460
  for subject in metadata.subjects:
453
- slug = string_to_slug(subject.get("subject", ""))
461
+ subject_name = subject.get("subject", "")
462
+ slug = string_to_slug(subject_name)
454
463
  if slug in COMMUNITY_TRANSLATIONS:
455
464
  slug = COMMUNITY_TRANSLATIONS[slug]
456
465
 
@@ -477,7 +486,11 @@ def push_inveniordm(metadata, host: str, token: str, legacy_key: str):
477
486
  if host == "rogue-scholar.org" and legacy_key is not None:
478
487
  record = update_legacy_record(record, legacy_key)
479
488
  except Exception as e:
480
- print(f"Unexpected error: {str(e)}")
489
+ logger.error(f"Unexpected error in push_inveniordm: {str(e)}", exc_info=True, extra={
490
+ "host": host,
491
+ "record_id": record.get("id")
492
+ })
493
+ record["status"] = "error"
481
494
 
482
495
  return record
483
496
 
@@ -504,11 +517,11 @@ def search_by_doi(doi, host, token) -> Optional[str]:
504
517
  )
505
518
  response.raise_for_status()
506
519
  data = response.json()
507
- if py_.get(data, "hits.total") or 0 > 0:
520
+ if py_.get(data, "hits.total", 0) > 0:
508
521
  return py_.get(data, "hits.hits.0.id")
509
522
  return None
510
523
  except requests.exceptions.RequestException as e:
511
- print(f"Error searching for DOI: {str(e)}")
524
+ logger.error(f"Error searching for DOI {doi}: {str(e)}", exc_info=True)
512
525
  return None
513
526
 
514
527
 
@@ -526,17 +539,17 @@ def create_draft_record(record, host, token, input):
526
539
  record["status"] = "failed_rate_limited"
527
540
  return record
528
541
  if response.status_code != 201:
529
- print(response.json())
542
+ logger.error(f"Failed to create draft record: {response.status_code} - {response.json()}")
530
543
  record["status"] = "failed_create_draft"
531
544
  return record
532
545
  data = response.json()
533
- record["id"]: data.get("id", None)
546
+ record["id"] = data.get("id", None)
534
547
  record["created"] = data.get("created", None)
535
548
  record["updated"] = data.get("updated", None)
536
549
  record["status"] = "draft"
537
550
  return record
538
551
  except requests.exceptions.RequestException as e:
539
- print(f"Error creating draft record: {str(e)}")
552
+ logger.error(f"Error creating draft record: {str(e)}", exc_info=True)
540
553
  record["status"] = "error_draft"
541
554
  return record
542
555
 
@@ -557,7 +570,7 @@ def edit_published_record(record, host, token):
557
570
  record["status"] = "edited"
558
571
  return record
559
572
  except requests.exceptions.RequestException as e:
560
- print(f"Error creating draft from published record: {str(e)}")
573
+ logger.error(f"Error creating draft from published record: {str(e)}", exc_info=True)
561
574
  record["status"] = "error_edit_published_record"
562
575
  return record
563
576
 
@@ -581,7 +594,7 @@ def update_draft_record(record, host, token, inveniordm_data):
581
594
  record["status"] = "updated"
582
595
  return record
583
596
  except requests.exceptions.RequestException as e:
584
- print(f"Error updating draft record: {str(e)}")
597
+ logger.error(f"Error updating draft record: {str(e)}", exc_info=True)
585
598
  record["status"] = "error_update_draft_record"
586
599
  return record
587
600
 
@@ -604,8 +617,8 @@ def publish_draft_record(record, host, token):
604
617
  record["status"] = "failed_rate_limited"
605
618
  return record
606
619
  if response.status_code != 202:
607
- print(response.json())
608
- record["status"] = "failed_publish_draft"
620
+ logger.error(f"Failed to publish draft record: {response.status_code} - {response.json()}")
621
+ record["status"] = "error_publish_draft_record"
609
622
  return record
610
623
  data = response.json()
611
624
  record["uuid"] = py_.get(data, "metadata.identifiers.0.identifier")
@@ -614,7 +627,7 @@ def publish_draft_record(record, host, token):
614
627
  record["status"] = "published"
615
628
  return record
616
629
  except requests.exceptions.RequestException as e:
617
- print(f"Error publishing draft record: {str(e)}")
630
+ logger.error(f"Error publishing draft record: {str(e)}", exc_info=True)
618
631
  record["status"] = "error_publish_draft_record"
619
632
  return record
620
633
 
@@ -634,7 +647,7 @@ def add_record_to_community(record, host, token, community_id):
634
647
  response.raise_for_status()
635
648
  return record
636
649
  except requests.exceptions.RequestException as e:
637
- print(f"Error adding record to community: {str(e)}")
650
+ logger.error(f"Error adding record to community: {str(e)}", exc_info=True)
638
651
  return record
639
652
 
640
653
 
@@ -682,7 +695,7 @@ def update_legacy_record(record, legacy_key: str):
682
695
  return record
683
696
 
684
697
  except requests.exceptions.RequestException as e:
685
- print(f"Error updating legacy record: {str(e)}")
698
+ logger.error(f"Error updating legacy record: {str(e)}", exc_info=True)
686
699
  record["status"] = "error_update_legacy_record"
687
700
  return record
688
701
 
@@ -700,11 +713,11 @@ def search_by_slug(slug, type_value, host, token) -> Optional[str]:
700
713
  )
701
714
  response.raise_for_status()
702
715
  data = response.json()
703
- if py_.get(data, "hits.total") or 0 > 0:
716
+ if py_.get(data, "hits.total", 0) > 0:
704
717
  return py_.get(data, "hits.hits.0.id")
705
718
  return None
706
719
  except requests.exceptions.RequestException as e:
707
- print(f"Error searching for community: {str(e)}")
720
+ logger.error(f"Error searching for community: {str(e)}", exc_info=True)
708
721
  return None
709
722
 
710
723
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commonmeta-py
3
- Version: 0.117
3
+ Version: 0.118
4
4
  Summary: Library for conversions to/from the Commonmeta scholarly metadata format
5
5
  Project-URL: Homepage, https://python.commonmeta.org
6
6
  Project-URL: Repository, https://github.com/front-matter/commonmeta-py
@@ -1,4 +1,4 @@
1
- commonmeta/__init__.py,sha256=PewWTIqOQpCR4ity3t6THBO24iVtVoQrhf6Bd6itSF4,2098
1
+ commonmeta/__init__.py,sha256=RbBIG26IxRjdvGzHH77sogy-rtAEHC51It7TQ6wPjS0,2098
2
2
  commonmeta/api_utils.py,sha256=y5KLfIOWOjde7LXZ36u-eneQJ-Q53yXUZg3hWpCBS2E,2685
3
3
  commonmeta/author_utils.py,sha256=3lYW5s1rOUWNTKs1FP6XLfEUY3yCLOe_3L_VdJTDMp0,8585
4
4
  commonmeta/base_utils.py,sha256=-MGy9q2uTiJEkPWQUYOJMdq-3tRpNnvBwlLjvllQ5g8,11164
@@ -80,11 +80,11 @@ commonmeta/writers/commonmeta_writer.py,sha256=QpfyhG__7o_XpsOTCPWxGymO7YKwZi2LQ
80
80
  commonmeta/writers/crossref_xml_writer.py,sha256=d-Rb2Vd_g3UW8GM4APIT7fivSQ5GMssZ6Ubi3OykHaw,33479
81
81
  commonmeta/writers/csl_writer.py,sha256=4gDYs1EzK4_L2UIRTfs25wgHmYRwdRP2zmfxF9387oU,2779
82
82
  commonmeta/writers/datacite_writer.py,sha256=bcinpwhq7XnVthKHH8-sdXA34dSlvFH4ImYH768iaQU,6428
83
- commonmeta/writers/inveniordm_writer.py,sha256=NZhNCAsNSLl5OYMjgOzmf_3DopILxWNYkIS4sSXC3ak,24976
83
+ commonmeta/writers/inveniordm_writer.py,sha256=el4Eapa9HHg1ceddHb9rd4d1MAsM1ZBZ1F4jQUV8mbI,25717
84
84
  commonmeta/writers/ris_writer.py,sha256=3SdyEvMRaPRP1SV1MB-MXBlunE7x6og7RF1zuWtetPc,2094
85
85
  commonmeta/writers/schema_org_writer.py,sha256=s18_x0ReXwAGBoEAwp2q-HCgFQ-h5qRg6JyAlqCoSFE,5871
86
- commonmeta_py-0.117.dist-info/METADATA,sha256=2Gmzajh3uMNxvylQurm9NUOYCGnWzW6IcG2Ksw_pqzQ,7652
87
- commonmeta_py-0.117.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
- commonmeta_py-0.117.dist-info/entry_points.txt,sha256=U4w4BoRuS3rN5t5Y-uYSyOeU5Lh_VRVMS9OIDzIgw4w,50
89
- commonmeta_py-0.117.dist-info/licenses/LICENSE,sha256=wsIvxF9Q9GC9vA_s79zTWP3BkXJdfUNRmALlU8GbW1s,1074
90
- commonmeta_py-0.117.dist-info/RECORD,,
86
+ commonmeta_py-0.118.dist-info/METADATA,sha256=BD1a2ouuh4hYizCty5tBGQuQM3m6LWVf1zfmTQwnFPU,7652
87
+ commonmeta_py-0.118.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
+ commonmeta_py-0.118.dist-info/entry_points.txt,sha256=U4w4BoRuS3rN5t5Y-uYSyOeU5Lh_VRVMS9OIDzIgw4w,50
89
+ commonmeta_py-0.118.dist-info/licenses/LICENSE,sha256=wsIvxF9Q9GC9vA_s79zTWP3BkXJdfUNRmALlU8GbW1s,1074
90
+ commonmeta_py-0.118.dist-info/RECORD,,