Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/somef/regular_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,26 +711,34 @@ def extract_doi_badges(readme_text, repository_metadata: Result, source) -> Resu
else:
match = re.search(constants.REGEXP_ZENODO_DOI, readme_text)
if match:
badge_url = match.group(0)
# badge_url = match.group(0)
badge_url = f"https://doi.org/{match.group(1)}"
try:
if badge_url is not None:
response = requests.get(badge_url, allow_redirects=True, timeout=10)
match = re.search(constants.REGEXP_ZENODO_JSON_LD,
response.text,
re.DOTALL | re.IGNORECASE
)
if match:
json_ld_text = match.group(1).strip()
try:
json_ld_data = json.loads(json_ld_text)
identifier = json_ld_data.get('identifier')
repository_metadata.add_result(constants.CAT_IDENTIFIER,
{
constants.PROP_TYPE: constants.URL,
constants.PROP_VALUE: identifier,
}, 1, constants.TECHNIQUE_REGULAR_EXPRESSION, source)
except json.JSONDecodeError:
logging.warning("Error parsing Zenodo JSON-LD")
if badge_url.startswith("https://doi.org/"):
repository_metadata.add_result(constants.CAT_IDENTIFIER,
{
constants.PROP_TYPE: constants.URL,
constants.PROP_VALUE: badge_url,
}, 1, constants.TECHNIQUE_REGULAR_EXPRESSION, source)
else:
response = requests.get(badge_url, allow_redirects=True, timeout=10)
match = re.search(constants.REGEXP_ZENODO_JSON_LD,
response.text,
re.DOTALL | re.IGNORECASE
)
if match:
json_ld_text = match.group(1).strip()
try:
json_ld_data = json.loads(json_ld_text)
identifier = json_ld_data.get('identifier')
repository_metadata.add_result(constants.CAT_IDENTIFIER,
{
constants.PROP_TYPE: constants.URL,
constants.PROP_VALUE: identifier,
}, 1, constants.TECHNIQUE_REGULAR_EXPRESSION, source)
except json.JSONDecodeError:
logging.warning("Error parsing Zenodo JSON-LD")
except requests.RequestException as e:
logging.warning(f"Error fetching DOI from Zenodo badge: {e}")
else:
Expand Down
103 changes: 103 additions & 0 deletions src/somef/test/test_data/README-gammapy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
.. image:: https://anaconda.org/conda-forge/gammapy/badges/license.svg
:target: https://github.com/gammapy/gammapy/blob/main/LICENSE.rst
:alt: Licence

.. image:: http://img.shields.io/badge/powered%20by-AstroPy-orange.svg?style=flat
:target: http://www.astropy.org/

|

.. image:: https://anaconda.org/conda-forge/gammapy/badges/platforms.svg
:target: https://anaconda.org/conda-forge/gammapy

|

.. image:: http://img.shields.io/pypi/v/gammapy.svg?text=version
:target: https://pypi.org/project/gammapy/
:alt: Latest release

.. image:: https://img.shields.io/pypi/dm/gammapy?label=downloads%20%7C%20pip&logo=PyPI
:alt: PyPI - Downloads

.. image:: https://anaconda.org/conda-forge/gammapy/badges/version.svg
:target: https://anaconda.org/conda-forge/gammapy

.. image:: https://img.shields.io/conda/dn/conda-forge/gammapy?label=downloads%20%7C%20conda&logo=Conda-Forge
:target: https://anaconda.org/conda-forge/gammapy

.. image:: https://img.shields.io/badge/launch-binder-579aca.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJXmsr1olJXmsrmZYH1olL1olKkfaPobXvviGabgadXmsqThKuofKHmZ4Dobnr1olJXmsr1olJXmspXmsr1olJXmsrfZ4TuhWn1olL1olJXmsqBi7X1olJXmspZmslbmMhbms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qzaml05/+orHLksVO+95kX7/7qgJvnjlrfr2Ggsyx0eoy9uPzN5SPd86aXggOsEKW2Prz7du3VID3/tzs/sSRs2w7ovVHKtjrX2pd7ZMlTxAYfBAL9jiDwfLkq55Tm7ifhMlTGPyCAs7RFRhn47JnlcB9RM5T97ASuZXIcVNuUDIndpDbdsfrqsOppeXl5Y+XVKdjFCTh+zGaVuj0d9zy05PPK3QzBamxdwtTCrzyg/2Rvf2EstUjordGwa/kx9mSJLr8mLLtCW8HHGJc2R5hS219IiF6PnTusOqcMl57gm0Z8kanKMAQg0qSyuZfn7zItsbGyO9QlnxY0eCuD1XL2ys/MsrQhltE7Ug0uFOzufJFE2PxBo/YAx8XPPdDwWN0MrDRYIZF0mSMKCNHgaIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC
:target: https://mybinder.org/v2/gh/gammapy/gammapy-webpage/master?urlpath=lab/tree/notebooks/

|

.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.4701488.svg?style=flat
:target: https://doi.org/10.5281/zenodo.4701488

.. image:: https://archive.softwareheritage.org/badge/origin/https://github.com/gammapy/gammapy/
:target: https://archive.softwareheritage.org/browse/origin/?origin_url=https://github.com/gammapy/gammapy

|

.. image:: https://img.shields.io/badge/A&A-Published-Green.svg
:target: https://doi.org/10.1051/0004-6361/202346488

|

.. image:: https://img.shields.io/badge/Matomo-3152A0?style=for-the-badge&logo=Matomo&logoColor=white
:target: https://matomo.org/

Gammapy
=======

A Python Package for Gamma-ray Astronomy.

Gammapy is an open-source Python package for gamma-ray astronomy built on Numpy, Scipy and Astropy. It is used as core
library for the Science Analysis tools of the CTAO, recommended by the H.E.S.S.
collaboration to be used for Science publications, and is already widely used in the analysis of existing gamma-ray
instruments, such as MAGIC, VERITAS and HAWC.

* Webpage: https://gammapy.org
* Documentation: https://docs.gammapy.org/
* Code: https://github.com/gammapy/gammapy

Contributing Code, Documentation, or Feedback
+++++++++++++++++++++++++++++++++++++++++++++
The Gammapy Project is made both by and for its users, so we welcome and encourage contributions of many kinds. Our
goal is to keep this a positive, inclusive, successful, and growing community by abiding with the
`Gammapy Community Code of Conduct <https://gammapy.org/CoC.html>`_.

The Gammapy project uses a mechanism known as a `Developer Certificate of Origin` (DCO). The DCO is a binding statement
that asserts that you are the creator of your contribution, and that you wish to allow Gammapy to use your work to cite
you as contributor. More detailed information on contributing to the project or submitting feedback can be found on the
`Contributing page <https://github.com/gammapy/gammapy/blob/main/CONTRIBUTING.md>`_.

Licence
+++++++
Gammapy is licensed under a 3-clause BSD style license - see the
`LICENSE.rst <https://github.com/gammapy/gammapy/blob/main/LICENSE.rst>`_ file.

The Gammapy documentation is licensed under the `CC BY-NC-SA <https://creativecommons.org/licenses/by-nc-sa/4.0/>`_
license. Examples, recipes, and other code in the documentation are additionally licensed under the
`BSD 3-Clause "New" or "Revised" <https://opensource.org/license/BSD-3-Clause>`_ license.

Supporting the project
++++++++++++++++++++++
The Gammapy project is not sponsored and the development is made by the staff of `the institutes supporting the project
<https://gammapy.org/team.html#support>`_ over their research time. Any contribution is then encouraged, as punctual or
regular contributor.

Status shields
++++++++++++++

(mostly useful for developers)

* .. image:: https://app.codacy.com/project/badge/Grade/9c32a21a915d4a28823f3b44a99a2810
:target: https://app.codacy.com/gh/gammapy/gammapy/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade
:alt: Codacy

* .. image:: https://github.com/gammapy/gammapy/actions/workflows/ci.yml/badge.svg
:target: https://github.com/gammapy/gammapy/actions/workflows/ci.yml
:alt: GitHub actions CI

* .. image:: https://codecov.io/gh/gammapy/gammapy/branch/main/graph/badge.svg?style=flat
:target: https://codecov.io/gh/gammapy/gammapy
18 changes: 17 additions & 1 deletion src/somef/test/test_regular_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,20 @@ def test_repo_status_issue_1014(self):
assert len(status) == 1, f"Should be 1 status, but got {len(status)}"
extracted_url = status[0]['result']['value']
expected_url = "https://www.repostatus.org/#active"
self.assertEqual(extracted_url, expected_url)
self.assertEqual(extracted_url, expected_url)


def test_issue_1062(self):
"""A Zenodo DOI badge in an rst README yields the exact DOI from the badge,
not the latest version's DOI."""
with open(test_data_path + "README-gammapy.rst", "r") as data_file:
test_text = data_file.read()
identifiers = regular_expressions.extract_doi_badges(test_text, Result(),
test_data_path + "README-gammapy.rst")
doi_values = []
if "identifier" in identifiers.results:
for result in identifiers.results["identifier"]:
if "result" in result and "value" in result["result"]:
doi_values.append(result["result"]["value"])
assert doi_values == ["https://doi.org/10.5281/zenodo.4701488"], \
f"Expected the exact badge DOI, got {doi_values}"
3 changes: 2 additions & 1 deletion src/somef/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
# Detect zenodo latest doi in readme.
ZENODO_API_BASE = "https://zenodo.org/api"
REGEXP_ZENODO_LATEST_DOI = r':target:\s*(https://zenodo\.org/badge/latestdoi/\d+)'
REGEXP_ZENODO_DOI = r'https://zenodo\.org/badge/DOI/\d+'
# REGEXP_ZENODO_DOI = r'https://zenodo\.org/badge/DOI/\d+'
REGEXP_ZENODO_DOI = r'https://zenodo\.org/badge/DOI/(10\.\d{4,9}/zenodo\.\d+)'
REGEXP_ZENODO_JSON_LD = r"<script[^>]*type=['\"]application/ld\+json['\"][^>]*>(.*?)</script>"

# Detect copyright information in license files.
Expand Down
Loading