Skip to content

Commit 5cc2ee8

Browse files
Add statistics python project to build pipeline (#10175)
1 parent bbf5e48 commit 5cc2ee8

7 files changed

Lines changed: 220 additions & 7 deletions

File tree

.pipelines/NuGetGallery-CI.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,40 @@ extends:
126126
testResultsFiles: $(NuGetGalleryPath)\Results.*.xml
127127
failTaskOnFailedTests: true
128128

129+
- stage: statslogparser
130+
displayName: StatsLogPasrser
131+
dependsOn: []
132+
jobs:
133+
- job: build_and_test
134+
displayName: statslogparser build and test
135+
cancelTimeoutInMinutes: 1
136+
variables:
137+
PIPX_HOME: $(Agent.ToolsDirectory)\pipx
138+
steps:
139+
- checkout: self
140+
fetchDepth: 1
141+
clean: true
142+
fetchTags: false
143+
path: $(NuGetGalleryDirectory)
144+
- task: UsePythonVersion@0
145+
inputs:
146+
versionSpec: '3.10'
147+
- script: |
148+
python -m pip install --user pipx
149+
pipx ensurepath
150+
displayName: 'Install tools'
151+
- script: |
152+
pipx install poetry
153+
poetry install
154+
poetry build
155+
poetry run pytest tests/ --cov loginterpretation --cov-report html
156+
workingDirectory: $(NuGetGalleryPath)\python\StatsLogParser
157+
templateContext:
158+
outputs:
159+
- output: pipelineArtifact
160+
path: $(NuGetGalleryPath)\python\StatsLogParser\dist
161+
artifact: StatsLogParser
162+
129163
- stage: jobs
130164
displayName: NuGet.Jobs.sln
131165
dependsOn: []

python/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ htmlcov/
4747
.cache
4848
nosetests.xml
4949
coverage.xml
50+
test-output.xml
5051
*.cover
5152
*.py,cover
5253
.hypothesis/

python/StatsLogParser/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ In your CLI, go to the `python/StatsLogParser` directory and then run `poetry in
1414

1515
### Dev and Test
1616
VS Code is recommended -- open the `python/StatsLogParser` folder and ensure you have the Python extensions installed. Poetry extensions are recommended too for environment activation. Testing is with pytest.
17+
To test on the CLI, you can run `poetry run pytest tests/` and to get code coverage, `poetry run pytest tests/ --cov loginterpretation --cov-report html`
1718

1819
### Dependencies
1920
Dependencies are in the `pyproject.toml` file. If you add/update dependencies, run `poetry export -f requirements.txt --output requirements.txt` to update the `requirements.txt` as both the that file and the `whl` will be needed for Spark.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*
2+
!*.whl

python/StatsLogParser/loginterpretation/useragentparser.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from collections import namedtuple
33
from typing import Optional
44
import re
5-
import pkg_resources
5+
import pkgutil
66
from ua_parser import user_agent_parser
77
from ua_parser._regexes import USER_AGENT_PARSERS
88
import yaml
@@ -47,11 +47,8 @@ def _replace_whitespace_with_plus_sign(match):
4747

4848
@staticmethod
4949
def _read_known_clients_yaml() -> str:
50-
file_name = pkg_resources.resource_filename(__name__, 'knownclients.yaml')
51-
with open(file_name, 'r', encoding='utf-8-sig') as file:
52-
yaml_file = file.read()
53-
54-
return yaml_file
50+
file_data = pkgutil.get_data(__name__, 'knownclients.yaml').decode('utf-8-sig')
51+
return file_data
5552

5653
@staticmethod
5754
def _create_parser_data_from_yaml(yaml_content) -> list[user_agent_parser.UserAgentParser]:

python/StatsLogParser/poetry.lock

Lines changed: 177 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/StatsLogParser/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ua-parser = "^0.18.0"
1313

1414
[tool.poetry.group.test.dependencies]
1515
pytest = "^8.3.2"
16+
pytest-cov = "^5.0.0"
17+
pytest-azurepipelines = "^1.0.5"
1618

1719
[build-system]
1820
requires = ["poetry-core"]

0 commit comments

Comments
 (0)