Skip to content

Commit 61417d5

Browse files
Michael HallikMichael Hallik
authored andcommitted
Adding pepy PRO statistics.
1 parent 448f206 commit 61417d5

File tree

3 files changed

+144
-4
lines changed

3 files changed

+144
-4
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Update Pepy Downloads Badge
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 1' # Every Monday at 00:00 UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-badge:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.10'
19+
20+
- name: Install dependencies
21+
run: pip install requests
22+
23+
- name: Run badge script
24+
env:
25+
PEPY_API_KEY: ${{ secrets.PEPY_API_KEY }}
26+
run: python fetch_pepy_downloads.py
27+
28+
- name: Commit and push badge
29+
run: |
30+
git config user.name github-actions
31+
git config user.email github-actions@github.com
32+
git add badge_pepy_downloads.svg
33+
git commit -m "Update Pepy downloads badge"
34+
git push

README.md

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[![PyPI version](https://img.shields.io/pypi/v/robotframework-xmlvalidator.svg)](https://pypi.org/project/robotframework-xmlvalidator/)
22
[![License](https://img.shields.io/pypi/l/robotframework-xmlvalidator?cacheSeconds=600)](LICENSE)
33
[![Tests](https://github.com/MichaelHallik/robotframework-xmlvalidator/actions/workflows/test.yml/badge.svg)](https://github.com/MichaelHallik/robotframework-xmlvalidator/actions/workflows/test.yml)
4-
<!-- [![PyPI Downloads](https://static.pepy.tech/badge/robotframework-xmlvalidator)](https://pepy.tech/projects/robotframework-xmlvalidator) -->
5-
[![PyPI Downloads](https://pepy.tech/badge/robotframework-xmlvalidator?cacheSeconds=3600)](https://pepy.tech/project/robotframework-xmlvalidator)
4+
[![Total Downloads](https://github.com/MichaelHallik/robotframework-xmlvalidator/raw/main/badge_pepy_downloads.svg)](https://pepy.tech/project/robotframework-xmlvalidator)
65

76
<details>
87
<summary><strong>📚 Table of Contents</strong></summary>
@@ -26,6 +25,7 @@
2625
- [Further examples](#further-examples)
2726
- [Using the library](#using-the-library)
2827
- [Keyword overview](#keyword-overview)
28+
- [Error collection](#error-collection)
2929
- [Keyword documentation](#keyword-documentation)
3030
- [Keyword example usage](#keyword-example-usage)
3131
- [A few basic examples](#a-few-basic-examples)
@@ -215,6 +215,63 @@ Of course, you may also refer to specific XML/XSD files (instead of to folders).
215215

216216
See for more details the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
217217

218+
### Error collection
219+
220+
Errors that are collected and returned can be categorized as follows:
221+
222+
1. XSD Schema violations.
223+
224+
The following types of XSD schema violations are detected during validation:
225+
226+
1. Detects missing or extra elements that violate cardinality rules, e.g.:
227+
- Verifies that all mandatory elements (minOccurs > 0) are present in the XML.
228+
- Ensures that optional elements (minOccurs = 0) do not exceed their maximum allowed occurrences (maxOccurs).
229+
230+
2. Sequence and Order Violations:
231+
- Validates the order of child elements within a parent element if the schema specifies a sequence model (`<xsd:sequence>`).
232+
- Detects elements that are out of order or missing in a sequence.
233+
234+
3. Datatype Violations:
235+
- Ensures that element and attribute values conform to their specified datatypes (e.g., xs:string, xs:integer, xs:dateTime).
236+
- Identifies invalid formats, such as incorrect date or time formats for xs:date and xs:dateTime.
237+
238+
4. Pattern and Enumeration Violations:
239+
- Checks that values conform to patterns defined using `<xsd:pattern>`.
240+
- Ensures that values fall within allowed enumerations specified in the schema.
241+
242+
5. Attribute Validation:
243+
- Verifies that required attributes are present.
244+
- Ensures that attribute values adhere to their declared datatypes and constraints.
245+
246+
6. Namespace Compliance:
247+
- Validates that elements and attributes belong to the correct namespaces as defined in the schema.
248+
- Detects namespace mismatches or missing namespace declarations.
249+
250+
7. Group Model Violations:
251+
- Validates conformance with `<xsd:choice>` and `<xsd:all>` group models, ensuring correct usage of child elements as per the schema.
252+
253+
8. Referential Constraints:
254+
- Checks for violations in `<xsd:key>`, `<xsd:keyref>`, and `<xsd:unique>` constraints.
255+
256+
9. Document Structure and Completeness:
257+
- Ensures that the XML document adheres to the hierarchical structure defined by the schema.
258+
- Detects incomplete or improperly nested elements.
259+
260+
10. General Schema Violations:
261+
- Detects schema-level issues, such as invalid imports or includes, during schema compilation if they affect validation.
262+
263+
2. Errors following from malformed XML and/or XSD files.
264+
265+
Checks whether handling of the involved XML file (e.g. during dynamic schema matching) resulted in an error. For instance because a file:
266+
- does not exist (i.e. could not be found at the spefified location)
267+
- is empty
268+
- is not of the correct file type (.xml, .xsd)
269+
- is not well-formed (syntactycally correct)
270+
271+
Any such error does not lead to a failing test, but is collected and reported.
272+
273+
However, when, at the end of a test run one or more errors have been collected, the test will be marked as 'FAILED'.
274+
218275
### Keyword documentation
219276

220277
See the [keyword documention](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
@@ -425,7 +482,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
425482

426483
The overall process:
427484

428-
![Contributing to the project](./docs/images/contributing.JPG)
485+
![Contributing to robotframework-xmlvalidator](./docs/images/contributing.JPG)
429486

430487
This project uses Poetry for dependency and packaging management.
431488

@@ -510,7 +567,7 @@ GitHub Actions CI is defined under [github/workflows/](.github/workflows/), in p
510567

511568
The test workflow:
512569

513-
![Test workflow diagram](./docs/images/test_workflow.JPG)
570+
![Workflow diagram for the robotframework-xmlvalidator project](./docs/images/test_workflow.JPG)
514571

515572
In [.github/](.github/) you’ll also find the various contribution templates:
516573

fetch_pepy_downloads.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import requests
3+
4+
PEPY_API_URL = "https://pepy.tech/api/v2/projects/{package}/downloads"
5+
PACKAGE_NAME = "robotframework-xmlvalidator"
6+
API_KEY = os.getenv("PEPY_API_KEY")
7+
8+
SVG_BADGE_TEMPLATE = '''<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20">
9+
<linearGradient id="a" x2="0" y2="100%%">
10+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
11+
<stop offset="1" stop-opacity=".1"/>
12+
</linearGradient>
13+
<rect rx="3" width="200" height="20" fill="#555"/>
14+
<rect rx="3" x="70" width="130" height="20" fill="#4c1"/>
15+
<path fill="#4c1" d="M70 0h4v20h-4z"/>
16+
<rect rx="3" width="200" height="20" fill="url(#a)"/>
17+
<g fill="#fff" text-anchor="middle"
18+
font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
19+
<text x="35" y="15" fill="#010101" fill-opacity=".3">downloads</text>
20+
<text x="35" y="14">downloads</text>
21+
<text x="135" y="15" fill="#010101" fill-opacity=".3">{count}</text>
22+
<text x="135" y="14">{count}</text>
23+
</g>
24+
</svg>
25+
'''
26+
27+
def fetch_download_count():
28+
headers = {
29+
"Authorization": f"Token {API_KEY}"
30+
}
31+
32+
response = requests.get(PEPY_API_URL.format(package=PACKAGE_NAME), headers=headers)
33+
response.raise_for_status()
34+
35+
data = response.json()
36+
total_downloads = data.get("total_downloads", 0)
37+
return f"{total_downloads:,}" # format with commas
38+
39+
def create_badge_svg(count, output_path="badge_pepy_downloads.svg"):
40+
svg_content = SVG_BADGE_TEMPLATE.format(count=count)
41+
with open(output_path, "w") as f:
42+
f.write(svg_content)
43+
print(f"Badge written to {output_path}")
44+
45+
if __name__ == "__main__":
46+
if not API_KEY:
47+
raise EnvironmentError("PEPY_API_KEY not set in environment variables.")
48+
count = fetch_download_count()
49+
create_badge_svg(count)

0 commit comments

Comments
 (0)