Repository: ESMValGroup/ESMValCore

Issue:
Reference bibtex filenames can only contain the characters that match `\w` regex
Issue reported by @alistairsellar

> Could you have a look at the following warnings from [`main_log.txt`](https://esmvaltool.dkrz.de/shared/esmvaltool/esmvalbot-output/autoassess_soilmoisture_obs_fly-litxq94v/recipe_autoassess_landsurface_soilmoisture_20230613_071633/run/main_log.txt)?
> 
> > WARNING [20879] The reference file /mnt/esmvaltool_disk2/esmvalbot-work/esmvalbotwork-autoassess_soilmoisture_obs_fly-litxq94v/ESMValTool/esmvaltool/references/soilmoisture.bibtex does not exist, citation information incomplete.
> > WARNING [20879] The reference file /mnt/esmvaltool_disk2/esmvalbot-work/esmvalbotwork-autoassess_soilmoisture_obs_fly-litxq94v/ESMValTool/esmvaltool/references/esacci.bibtex does not exist, citation information incomplete.
> > WARNING [20879] No provenance information was written to /mnt/esmvaltool_disk2/shared/esmvaltool/esmvalbot-output/autoassess_soilmoisture_obs_fly-litxq94v/recipe_autoassess_landsurface_soilmoisture_20230613_071633/run/plot_standard/plot_landsurf_soilmoisture/diagnostic_provenance.yml. Unable to record provenance for files created by diagnostic script

I believe that there is a parsing error somewhere. I'm referencing `esacci-soilmoisture` in my diag_script and recipe for consistency with file names and bibtex label: `esmvaltool/references/esacci-soilmoisture.bibtex`, but it is looking for separate references for `esacci` and `soilmoisture` implying that it has been split on `-` into separate ids. I can get rid of the warnings by remving the `-` from file name and references, but then it would be inconsistent with the other `references/esacci-*.bibtex` files. What do you reckon?

_Originally posted by @alistairsellar in https://github.com/ESMValGroup/ESMValTool/issues/3197#issuecomment-1589813326_
            

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/ESMValGroup/ESMValCore/pull/2097?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup) Report
> Merging [#2097](https://app.codecov.io/gh/ESMValGroup/ESMValCore/pull/2097?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup) (37e8b6f) into [main](https://app.codecov.io/gh/ESMValGroup/ESMValCore/commit/179312e41f964bcb9cbd44f0ee234d62127d20ab?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup) (179312e) will **not change** coverage.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##             main    #2097   +/-   ##
=======================================
  Coverage   93.08%   93.08%           
=======================================
  Files         237      237           
  Lines       12793    12793           
=======================================
  Hits        11909    11909           
  Misses        884      884           
```


| [Impacted Files](https://app.codecov.io/gh/ESMValGroup/ESMValCore/pull/2097?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup) | Coverage Δ | |
|---|---|---|
| [esmvalcore/\_citation.py](https://app.codecov.io/gh/ESMValGroup/ESMValCore/pull/2097?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup#diff-ZXNtdmFsY29yZS9fY2l0YXRpb24ucHk=) | `80.99% <100.00%> (ø)` | |


alistairsellar: Hi @bouweandela here is the PR for the parsing bug #2092. Please could you review?

I've marked as 2.9 but appreciate the Core deadline for that has passed, so understand if it gets bumped to 2.10.
bouweandela: Thanks @alistairsellar! I've added a unit test for you. It looks like there were no unit tests for the module yet, so I started it in a new file.
alistairsellar: > Thanks @alistairsellar! I've added a unit test for you. It looks like there were no unit tests for the module yet, so I started it in a new file.

Thanks @bouweandela! Nice to see how a unit test can be added for such a simple change - this had not occurred to me as something that was even applicable for this change, but of course it is.

Patch:
diff --git a/esmvalcore/_citation.py b/esmvalcore/_citation.py
index 96e9286f4..5637f115b 100644
--- a/esmvalcore/_citation.py
+++ b/esmvalcore/_citation.py
@@ -137,7 +137,7 @@ def _extract_tags(tags):
     For example, a single entry in the list `tags` could be the string
     "['acknow_project', 'acknow_author']".
     """
-    pattern = re.compile(r'\w+')
+    pattern = re.compile(r'[\w-]+')
     return set(pattern.findall(str(tags)))
 
 


Test patch:
diff --git a/tests/unit/test_citation.py b/tests/unit/test_citation.py
new file mode 100644
index 000000000..4bd8bbdb1
--- /dev/null
+++ b/tests/unit/test_citation.py
@@ -0,0 +1,7 @@
+from esmvalcore import _citation
+
+
+def test_extract_tags():
+    tags = "['example1', 'example_2', 'example-3']"
+    result = _citation._extract_tags(tags)
+    assert result == {'example1', 'example_2', 'example-3'}