From df0949d7313b11214c1758fbe7ee8c3334c53476 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 08:17:47 +0000 Subject: [PATCH 001/102] Say in AGENTS.md that a test failing on timing is fixed, not run again (#115) --- AGENTS.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 1b697ff7..39b710d7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -334,3 +334,11 @@ into `main` from any other branch. The four repositories were brought in with `git subtree add`, so commit SHAs match the originals. Use `git log --follow` to trace a file back through the import. + +## Tests that fail on timing + +A test that fails on a time limit, a performance threshold or a timeout is +fixed, not run again until it passes. Either the limit is set to fit the +slowest runner the test runs on, with each runner's measurement behind it, or +the reason it takes too long is found and fixed. A failure that comes and goes +costs everyone who meets it the time to look into it. From d7480eee6b0cf39ac154c1bdd2e2b8bfc602d321 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 19:10:51 +0000 Subject: [PATCH 002/102] Label a one-package release with its version, not its last character (#54) * Label a one-package release with its version, not its last character When the release plan holds one package, $plan.Version is a single string, Sort-Object hands it back as a string, and [-1] took its last character, so a plan releasing 4.5.3 alone gave the run the label 3, which the publish's version check refuses. The sort is now collected into an array first. * Test the publish label for a plan of one package, several packages and none --- ci/get-next-package-version.Tests.ps1 | 46 +++++++++++++++++++++++++++ ci/get-next-package-version.ps1 | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 ci/get-next-package-version.Tests.ps1 diff --git a/ci/get-next-package-version.Tests.ps1 b/ci/get-next-package-version.Tests.ps1 new file mode 100644 index 00000000..706e6f0c --- /dev/null +++ b/ci/get-next-package-version.Tests.ps1 @@ -0,0 +1,46 @@ +# Tests for ci/get-next-package-version.ps1, which labels a publish with the +# highest version in the release plan. +# +# Each test copies the script to a throwaway folder beside a packages.ps1 +# whose release plan is the versions the test gives, so the test states the +# plan it labels. + +Describe 'get-next-package-version.ps1' { + BeforeAll { + $script:Label = Join-Path $PSScriptRoot 'get-next-package-version.ps1' + + function Get-Label([string[]]$Versions) { + $folder = Join-Path ([IO.Path]::GetTempPath()) ` + ([Guid]::NewGuid().ToString()) + $null = New-Item -ItemType Directory $folder + try { + Copy-Item $script:Label $folder + $list = ($Versions | ForEach-Object { "'$_'" }) -join ', ' + Set-Content (Join-Path $folder 'packages.ps1') @" +function Get-ReleasePlan(`$RepoPath) { + @(@($list) | ForEach-Object { + [pscustomobject]@{ Name = "package-`$_"; Version = `$_ } + }) +} +"@ + & (Join-Path $folder 'get-next-package-version.ps1') ` + -RepoName 'repository' -VariableName 'TestLabel' + return $global:TestLabel + } finally { + Remove-Item -Recurse -Force $folder + } + } + } + + It 'labels a plan of one package with its whole version' { + Get-Label @('4.5.3') | Should -Be '4.5.3' + } + + It 'labels a plan of several packages with the highest version' { + Get-Label @('4.5.3', '4.5.10', '4.5.9') | Should -Be '4.5.10' + } + + It 'gives a valid version when nothing is released' { + Get-Label @() | Should -Be '4.5.0' + } +} diff --git a/ci/get-next-package-version.ps1 b/ci/get-next-package-version.ps1 index d94aa4d7..0456e988 100644 --- a/ci/get-next-package-version.ps1 +++ b/ci/get-next-package-version.ps1 @@ -13,7 +13,7 @@ $ErrorActionPreference = "Stop" # build-package.ps1 and publish-package.ps1, all from the same release plan. $plan = @(Get-ReleasePlan $RepoName) if ($plan.Count -gt 0) { - $label = ($plan.Version | Sort-Object { [version]$_ })[-1] + $label = @($plan.Version | Sort-Object { [version]$_ })[-1] } else { # Nothing to release. Any valid version will do, because # package-update-required.ps1 stops the publish before it is used. From 94073ec8422a85850dd84039627fe55daef6827c Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 19:11:21 +0000 Subject: [PATCH 003/102] Point AGENTS.md at the one list of environment variable names (#109) * DOC: Point at the one list of environment variable names AGENTS.md gains a section linking common-ci's list of environment variable names (environment-variables.md, made from environment-variables.json) at commit 18f9a570, and saying the list decides. Documentation only. * DOC: Link the list of environment variable names at d8a9c596 The list at that commit holds the names review found missing. * Keep one Releases section in AGENTS.md --- AGENTS.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 39b710d7..f09f4b1a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -250,6 +250,19 @@ example logs an error that names the variable and the configurator. assets, and the IP Intelligence example tests use the Asn file and throw their output away. +## Environment variable names + +[common-ci's list of environment variable names](https://github.com/51Degrees/common-ci/blob/d8a9c596eabf69dd5581a08e9360cdd1c9b3d9e8/environment-variables.md) +holds every environment variable name that the packages, tests, examples and +CI scripts of every language read, with what each name holds and the +deprecated names each replaced. The list decides. Use the names it gives, and +when a change needs a new name, or reads an old name again, change +[`environment-variables.json`](https://github.com/51Degrees/common-ci/blob/d8a9c596eabf69dd5581a08e9360cdd1c9b3d9e8/environment-variables.json) +in common-ci in the same piece of work. This repository's own name +check, [`ci/check-environment-variable-names.ps1`](ci/check-environment-variable-names.ps1), still keeps a +list of its own. Where the two differ, common-ci's list is the one to +follow. + ## Products keep their own CI scripts Each product folder still has the `ci/` scripts it had as its own repository, @@ -321,14 +334,6 @@ draft and has no review requested. When a release is wanted, one pull request merges `rc` into `main`, and the "Only rc into main" check fails a pull request into `main` from any other branch. -## Releases - -Pull requests go to `rc`, not `main`, and stay drafts until they have been -reviewed, because the nightly merges any pull request into `rc` that is not a -draft and has no review requested. When a release is wanted, one pull request -merges `rc` into `main`, and the "Only rc into main" check fails a pull request -into `main` from any other branch. - ## History The four repositories were brought in with `git subtree add`, so commit SHAs From 5b5a833239d435676a1ab0450be22bce0c0807a2 Mon Sep 17 00:00:00 2001 From: Eugene Dorfman Date: Fri, 13 Nov 2026 20:12:07 +0100 Subject: [PATCH 004/102] Run the Cloud 51Did tests on pull requests into rc (#88) Pull requests go to rc, so a 51Did change was first checked against the live cloud only when the release pull request into main opened. --- .github/workflows/cloud-51did.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cloud-51did.yml b/.github/workflows/cloud-51did.yml index 5f258dc1..2a2e6ee2 100644 --- a/.github/workflows/cloud-51did.yml +++ b/.github/workflows/cloud-51did.yml @@ -29,7 +29,7 @@ on: schedule: - cron: '30 5 * * *' pull_request: - branches: [main] + branches: [main, rc] paths: - 'pipeline/fiftyone_pipeline_did/**' - 'pipeline/owid-python/**' From 5eb295ce76d4666d71234dcbf0ff2eab5d0c1e07 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 22:29:52 +0000 Subject: [PATCH 005/102] Release a package only for a change that counts, leaving out documentation, tests, examples and manifest metadata (#60) Reviewed and approved at head ec8b2fdd94f4f31fbda1dfad1ad31227fbdca734. The pull request body says what changed and how it was tested. --- AGENTS.md | 17 ++- ci/packages.Tests.ps1 | 295 +++++++++++++++++++++++++++++++++++++ ci/packages.json | 19 +++ ci/packages.ps1 | 110 ++++++++++++-- ci/release-plan-filter.ps1 | 39 +++++ ci/release-plan-filter.py | 194 ++++++++++++++++++++++++ 6 files changed, 657 insertions(+), 17 deletions(-) create mode 100644 ci/release-plan-filter.ps1 create mode 100644 ci/release-plan-filter.py diff --git a/AGENTS.md b/AGENTS.md index f09f4b1a..3fe39ce4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -280,11 +280,18 @@ touches all of them ([ci/packages.ps1](ci/packages.ps1), ## Versions are per package Every package is versioned and tagged on its own, `/`. A -package is released when its folders changed since its last tag, or when a -package it depends on is released. The examples packages are tested but never -published. common-ci's publish carries one version; here it is only a label, -and the release plan in `ci/packages.ps1` decides what is built, published -and tagged. Never push a plain `4.5.x` tag: nothing here reads one. +package is released when a file that counts in its folders changed since its +last tag, or when a package it depends on is released. Documentation +(`*.md`, `docs/`), tests (`tests/`, `test/`), examples (`examples/`) and +`LICENSE` files do not count, nor do files a package's `Ignore` globs in +`ci/packages.json` match, unless it sets `IgnoreDefaults` to false. A +`setup.py`, `setup.cfg` or `pyproject.toml` whose change is only to the +description, keywords, urls, classifiers, readme, authors or maintainers does +not count either, which `ci/release-plan-filter.ps1` works out with Python. +The examples packages are tested but never published. common-ci's publish +carries one version, which here is only a label, and the release plan in +`ci/packages.ps1` decides what is built, published and tagged. Never push a +plain `4.5.x` tag, because nothing here reads one. `ci/packages.json` is the list of packages and what each depends on. Add a package there, with a `FirstVersion` if it has never been released, or it is diff --git a/ci/packages.Tests.ps1 b/ci/packages.Tests.ps1 index 766d1380..243d87a6 100644 --- a/ci/packages.Tests.ps1 +++ b/ci/packages.Tests.ps1 @@ -247,6 +247,267 @@ Describe 'Get-ReleasePlan' { $script:Repo = New-Repo @('p/new/a.py') @() { Get-ReleasePlan $script:Repo $graph } | Should -Throw '*FirstVersion*' } + + It 'says how many files counted' { + $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') + Add-Commit $script:Repo @('device/dd/a.py', 'device/dd/b.py') + (@(Get-ReleasePlan $script:Repo $script:Graph) | + Where-Object Name -eq 'dd').Reason | + Should -Be 'changed since 4.5.96 (2 files)' + } + + It 'releases nothing for a change only to documentation, tests or examples' { + $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') + Add-Commit $script:Repo @( + 'device/dd/readme.md', 'device/dd/docs/guide.txt', + 'device/dd/tests/test_a.py', 'device/dd/test/a.py', + 'device/dd/examples/a.py', 'device/dd/LICENSE', + 'pipeline/core/sub/notes.md') + @(Get-ReleasePlan $script:Repo $script:Graph).Count | Should -Be 0 + } + + It 'ignores documentation, tests and examples whatever their case' { + $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') + Add-Commit $script:Repo @( + 'device/dd/README.MD', 'device/dd/Tests/a.py', + 'device/dd/Examples/a.py') + @(Get-ReleasePlan $script:Repo $script:Graph).Count | Should -Be 0 + } + + It 'releases for the code changed beside the documentation' { + $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') + Add-Commit $script:Repo @('device/dd/readme.md', 'device/dd/a.py') + $plan = @(Get-ReleasePlan $script:Repo $script:Graph) + $plan.Name | Should -Be @('dd') + $plan[0].Reason | Should -Be 'changed since 4.5.96 (1 file)' + } + + It 'leaves out the files a package''s Ignore globs match' { + $graph = @($script:Graph | ForEach-Object { $_.PSObject.Copy() }) + ($graph | Where-Object Name -eq 'dd') | + Add-Member Ignore @('device/dd/tox.ini') + $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') + Add-Commit $script:Repo @('device/dd/tox.ini') + @(Get-ReleasePlan $script:Repo $graph).Count | Should -Be 0 + } + + It 'counts documentation for a package that turns the defaults off' { + $graph = @($script:Graph | ForEach-Object { $_.PSObject.Copy() }) + ($graph | Where-Object Name -eq 'dd') | Add-Member IgnoreDefaults $false + $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') + Add-Commit $script:Repo @('device/dd/readme.md') + @(Get-ReleasePlan $script:Repo $graph).Name | Should -Be @('dd') + } + + It 'refuses IgnoreDefaults given as text' { + $graph = @($script:Graph | ForEach-Object { $_.PSObject.Copy() }) + ($graph | Where-Object Name -eq 'dd') | Add-Member IgnoreDefaults 'false' + $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') + Add-Commit $script:Repo @('device/dd/readme.md') + { Get-ReleasePlan $script:Repo $graph } | + Should -Throw '*IgnoreDefaults*true or false*' + } +} + +Describe 'release-plan-filter.ps1' { + BeforeAll { + # A setup.py, setup.cfg and pyproject.toml like the ones here, with + # the metadata the filter leaves out and settings it does not. Line + # endings are made LF, whatever the checkout gave this file. + $script:SetupPy = @' +import setuptools + +setuptools.setup( + name="dd", + version=read("version.txt"), + author="51Degrees Engineering", + author_email="engineering@51degrees.com", + project_urls={"Source": "https://github.com/51Degrees/51degrees-python"}, + description=("Device detection."), + keywords=["51degrees", "device-detection"], + long_description=read("readme.md"), + long_description_content_type='text/markdown', + python_requires=">=3.10", + install_requires=["fiftyone_pipeline_core"], + classifiers=["Programming Language :: Python"], +) +'@.Replace("`r`n", "`n") + $script:SetupCfg = @' +[metadata] +name = dd +description = Device detection. +url = https://github.com/51Degrees/51degrees-python + +[options] +install_requires = + fiftyone_pipeline_core +'@.Replace("`r`n", "`n") + "`n" + $script:Pyproject = @' +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "dd" +description = "Device detection." +keywords = [ + "51degrees", + "device-detection", +] +dependencies = ["fiftyone_pipeline_core"] + +[project.urls] +Source = "https://github.com/51Degrees/51degrees-python" +'@.Replace("`r`n", "`n") + "`n" + + # A repository with the given files, holding the filter as this + # repository does, with the tags of the small graph and the tag of + # dd on the commit that adds the files. + function New-FilterRepo([hashtable]$Files) { + $repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') + $null = New-Item -ItemType Directory -Force (Join-Path $repo 'ci') + foreach ($name in 'release-plan-filter.ps1', 'release-plan-filter.py') { + Copy-Item (Join-Path $PSScriptRoot $name) (Join-Path $repo 'ci') + } + Set-Files $repo $Files + git -C $repo tag -f 'dd/4.5.96' | Out-Null + return $repo + } + + # Commits the files with exactly the text given. + function Set-Files([string]$Repo, [hashtable]$Files) { + foreach ($file in $Files.Keys) { + $full = Join-Path $Repo $file + $null = New-Item -ItemType Directory -Force (Split-Path $full) + [IO.File]::WriteAllText($full, $Files[$file]) + } + git -C $Repo add -A + git -C $Repo -c user.name=test -c user.email=test@example.com ` + commit --quiet --allow-empty -m 'Change' + } + + function Get-DdPlan([string]$Repo) { + return @(Get-ReleasePlan $Repo $script:Graph | + Where-Object Name -eq 'dd') + } + } + + It 'does not release for a setup.py change only to metadata' { + $script:Repo = New-FilterRepo @{ 'device/dd/setup.py' = $script:SetupPy } + $changed = $script:SetupPy + $changed = $changed.Replace('Device detection.', 'Device detection for Python.') + $changed = $changed.Replace('"device-detection"]', '"device-detection", "user-agent"]') + $changed = $changed.Replace('51degrees-python"}', '51degrees-python", "Docs": "x"}') + $changed = $changed.Replace('51Degrees Engineering', '51Degrees') + $changed = $changed.Replace('"Programming Language :: Python"]', + '"Programming Language :: Python", "Typing :: Typed"]') + $changed = $changed.Replace("'text/markdown'", "'text/x-rst'") + Set-Files $script:Repo @{ 'device/dd/setup.py' = $changed + "# A note.`n" } + (Get-DdPlan $script:Repo).Count | Should -Be 0 + } + + It 'releases for a setup.py change to anything else' { + $script:Repo = New-FilterRepo @{ 'device/dd/setup.py' = $script:SetupPy } + $changed = $script:SetupPy.Replace('["fiftyone_pipeline_core"]', + '["fiftyone_pipeline_core>=4.5.40"]') + Set-Files $script:Repo @{ 'device/dd/setup.py' = $changed } + $plan = Get-DdPlan $script:Repo + $plan.Count | Should -Be 1 + $plan[0].Reason | Should -Be 'changed since 4.5.96 (1 file)' + } + + It 'counts the code changed beside a setup.py change only to metadata' { + $script:Repo = New-FilterRepo @{ 'device/dd/setup.py' = $script:SetupPy } + Set-Files $script:Repo @{ + 'device/dd/setup.py' = $script:SetupPy.Replace( + 'Device detection.', 'Device detection for Python.') + 'device/dd/src/a.py' = 'print(1)' + } + (Get-DdPlan $script:Repo)[0].Reason | + Should -Be 'changed since 4.5.96 (1 file)' + } + + It 'does not release for a setup.cfg change only to metadata' { + $script:Repo = New-FilterRepo @{ 'device/dd/setup.cfg' = $script:SetupCfg } + $changed = $script:SetupCfg.Replace('Device detection.', 'Device detection for Python.') + $changed = $changed.Replace('51degrees-python', '51degrees-python/tree/main') + Set-Files $script:Repo @{ 'device/dd/setup.cfg' = $changed } + (Get-DdPlan $script:Repo).Count | Should -Be 0 + } + + It 'releases for a setup.cfg change to its options' { + $script:Repo = New-FilterRepo @{ 'device/dd/setup.cfg' = $script:SetupCfg } + Set-Files $script:Repo @{ 'device/dd/setup.cfg' = + $script:SetupCfg + " fiftyone_pipeline_engines`n" } + (Get-DdPlan $script:Repo).Count | Should -Be 1 + } + + It 'does not release for a pyproject.toml change only to metadata' { + $script:Repo = New-FilterRepo @{ 'device/dd/pyproject.toml' = $script:Pyproject } + $changed = $script:Pyproject.Replace('"Device detection."', '"Device detection for Python."') + $changed = $changed.Replace(" `"device-detection`",`n", + " `"device-detection`",`n `"user-agent`",`n") + $changed = $changed.Replace('Source = ', "Docs = `"x`"`nSource = ") + $changed += "`n[[project.authors]]`nname = `"51Degrees`"`n" + Set-Files $script:Repo @{ 'device/dd/pyproject.toml' = $changed } + (Get-DdPlan $script:Repo).Count | Should -Be 0 + } + + It 'does not release for a change only to the maintainers in ' -ForEach @( + @{ Case = 'setup.py'; File = 'setup.py'; Start = 'SetupPy' + Was = 'author_email="engineering@51degrees.com",' + Changed = "author_email=`"engineering@51degrees.com`",`n maintainer=`"51Degrees`",`n maintainer_email=`"support@51degrees.com`"," } + @{ Case = 'setup.cfg'; File = 'setup.cfg'; Start = 'SetupCfg' + Was = "name = dd`n" + Changed = "name = dd`nmaintainer = 51Degrees`nmaintainer_email = support@51degrees.com`n" } + @{ Case = 'a pyproject.toml key'; File = 'pyproject.toml'; Start = 'Pyproject' + Was = 'dependencies = ' + Changed = "maintainers = [{ name = `"51Degrees`" }]`ndependencies = " } + @{ Case = 'a pyproject.toml table'; File = 'pyproject.toml'; Start = 'Pyproject' + Was = '[project.urls]' + Changed = "[[project.maintainers]]`nname = `"51Degrees`"`n`n[project.urls]" } + ) { + $text = @{ + SetupPy = $script:SetupPy + SetupCfg = $script:SetupCfg + Pyproject = $script:Pyproject + }[$Start] + $changed = $text.Replace($Was, $Changed) + $changed | Should -Not -Be $text + $script:Repo = New-FilterRepo @{ "device/dd/$File" = $text } + Set-Files $script:Repo @{ "device/dd/$File" = $changed } + (Get-DdPlan $script:Repo).Count | Should -Be 0 + } + + It 'releases for a pyproject.toml change to ' -ForEach @( + @{ Was = '["fiftyone_pipeline_core"]'; Changed = '["fiftyone_pipeline_core>=4.5"]' } + @{ Was = '"setuptools>=42"'; Changed = '"setuptools>=61"' } + ) { + $script:Repo = New-FilterRepo @{ 'device/dd/pyproject.toml' = $script:Pyproject } + Set-Files $script:Repo @{ 'device/dd/pyproject.toml' = + $script:Pyproject.Replace($Was, $Changed) } + (Get-DdPlan $script:Repo).Count | Should -Be 1 + } + + It 'releases for a manifest that is new since the last tag' { + $script:Repo = New-FilterRepo @{} + Set-Files $script:Repo @{ 'device/dd/setup.py' = $script:SetupPy } + (Get-DdPlan $script:Repo).Count | Should -Be 1 + } + + It 'releases for a manifest it cannot read' { + $script:Repo = New-FilterRepo @{ 'device/dd/setup.py' = $script:SetupPy } + Set-Files $script:Repo @{ 'device/dd/setup.py' = 'setup(' } + (Get-DdPlan $script:Repo).Count | Should -Be 1 + } + + It 'releases for a manifest that is not UTF-8' { + $script:Repo = New-FilterRepo @{ 'device/dd/setup.py' = $script:SetupPy } + [IO.File]::WriteAllBytes((Join-Path $script:Repo 'device/dd/setup.py'), + [byte[]](0x23, 0xff, 0xfe, 0x0a)) + Set-Files $script:Repo @{} + (Get-DdPlan $script:Repo).Count | Should -Be 1 + } } Describe 'Get-BuildPlan' { @@ -320,6 +581,40 @@ Describe 'the real packages.json' { Get-ToxGaps (Split-Path $PSScriptRoot) $script:Real | Should -BeNullOrEmpty } + + Context 'a change to a package''s tox.ini' { + BeforeAll { + $published = @($script:Real | Where-Object Publish -eq $true) + $script:RealTags = @($published | ForEach-Object { "$($_.Name)/4.5.1" }) + $script:RealFiles = @($script:Real | ForEach-Object { + "$($_.Path)/src/a.py" + "$($_.Path)/tox.ini" + }) + } + + It 'releases nothing, whichever package it sits beside' { + $script:Repo = New-Repo $script:RealFiles $script:RealTags + Add-Commit $script:Repo ($script:Real | ForEach-Object { "$($_.Path)/tox.ini" }) + @(Get-ReleasePlan $script:Repo $script:Real).Count | Should -Be 0 + } + + It 'still releases a package for a change to its source' { + $script:Repo = New-Repo $script:RealFiles $script:RealTags + Add-Commit $script:Repo @( + 'pipeline/fiftyone_pipeline_core/tox.ini', + 'pipeline/fiftyone_pipeline_core/src/a.py') + $plan = @(Get-ReleasePlan $script:Repo $script:Real) + $plan.Name | Should -Contain 'fiftyone_pipeline_core' + ($plan | Where-Object Name -eq 'fiftyone_pipeline_core').Reason | + Should -Be 'changed since 4.5.1 (1 file)' + } + + It 'is ignored by every package, so one added later counts for nothing' { + foreach ($package in $script:Real) { + $package.Ignore | Should -Contain '**/tox.ini' -Because $package.Name + } + } + } } } diff --git a/ci/packages.json b/ci/packages.json index deb06ce9..d9dcd87d 100644 --- a/ci/packages.json +++ b/ci/packages.json @@ -3,6 +3,7 @@ "Name": "fiftyone_pipeline_core", "Product": "pipeline", "Path": "pipeline/fiftyone_pipeline_core", + "Ignore": ["**/tox.ini"], "DependsOn": [], "Publish": true }, @@ -10,6 +11,7 @@ "Name": "fiftyone_pipeline_engines", "Product": "pipeline", "Path": "pipeline/fiftyone_pipeline_engines", + "Ignore": ["**/tox.ini"], "DependsOn": ["fiftyone_pipeline_core"], "Publish": true }, @@ -17,6 +19,7 @@ "Name": "fiftyone_pipeline_engines_fiftyone", "Product": "pipeline", "Path": "pipeline/fiftyone_pipeline_engines_fiftyone", + "Ignore": ["**/tox.ini"], "DependsOn": ["fiftyone_pipeline_engines"], "Publish": true }, @@ -24,6 +27,7 @@ "Name": "fiftyone_pipeline_cloudrequestengine", "Product": "pipeline", "Path": "pipeline/fiftyone_pipeline_cloudrequestengine", + "Ignore": ["**/tox.ini"], "DependsOn": ["fiftyone_pipeline_engines"], "Publish": true }, @@ -31,6 +35,7 @@ "Name": "fiftyone_pipeline_translation", "Product": "pipeline", "Path": "pipeline/fiftyone_pipeline_translation", + "Ignore": ["**/tox.ini"], "DependsOn": ["fiftyone_pipeline_core"], "Publish": true }, @@ -38,6 +43,7 @@ "Name": "fiftyone_pipeline_did", "Product": "pipeline", "Path": "pipeline/fiftyone_pipeline_did", + "Ignore": ["**/tox.ini"], "ExtraPaths": ["pipeline/owid-python"], "DependsOn": [], "Publish": true @@ -46,6 +52,7 @@ "Name": "fiftyone_pipeline_examples", "Product": "pipeline", "Path": "pipeline/examples", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_pipeline_core", "fiftyone_pipeline_engines", @@ -57,6 +64,7 @@ "Name": "fiftyone_devicedetection_shared", "Product": "device-detection", "Path": "device-detection/fiftyone_devicedetection_shared", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_pipeline_core", "fiftyone_pipeline_engines", @@ -69,6 +77,7 @@ "Name": "fiftyone_devicedetection_cloud", "Product": "device-detection", "Path": "device-detection/fiftyone_devicedetection_cloud", + "Ignore": ["**/tox.ini"], "DependsOn": ["fiftyone_devicedetection_shared"], "Publish": true }, @@ -76,6 +85,7 @@ "Name": "fiftyone_devicedetection_onpremise", "Product": "device-detection", "Path": "device-detection/fiftyone_devicedetection_onpremise", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_devicedetection_shared", "fiftyone_pipeline_engines_fiftyone" @@ -87,6 +97,7 @@ "Name": "fiftyone_devicedetection", "Product": "device-detection", "Path": "device-detection/fiftyone_devicedetection", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_devicedetection_shared", "fiftyone_devicedetection_cloud", @@ -98,6 +109,7 @@ "Name": "fiftyone_devicedetection_examples", "Product": "device-detection", "Path": "device-detection/fiftyone_devicedetection_examples", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_devicedetection_cloud", "fiftyone_devicedetection" @@ -108,6 +120,7 @@ "Name": "fiftyone_location", "Product": "location", "Path": "location", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_pipeline_core", "fiftyone_pipeline_engines", @@ -119,6 +132,7 @@ "Name": "fiftyone_ipintelligence_shared", "Product": "ip-intelligence", "Path": "ip-intelligence/fiftyone_ipintelligence_shared", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_pipeline_core", "fiftyone_pipeline_engines", @@ -132,6 +146,7 @@ "Name": "fiftyone_ipintelligence_cloud", "Product": "ip-intelligence", "Path": "ip-intelligence/fiftyone_ipintelligence_cloud", + "Ignore": ["**/tox.ini"], "DependsOn": ["fiftyone_ipintelligence_shared"], "Publish": true, "FirstVersion": "4.5.0" @@ -140,6 +155,7 @@ "Name": "fiftyone_ipintelligence_onpremise", "Product": "ip-intelligence", "Path": "ip-intelligence/fiftyone_ipintelligence_onpremise", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_ipintelligence_shared", "fiftyone_pipeline_engines_fiftyone" @@ -152,6 +168,7 @@ "Name": "fiftyone_ipintelligence_translation", "Product": "ip-intelligence", "Path": "ip-intelligence/fiftyone_ipintelligence_translation", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_pipeline_core", "fiftyone_pipeline_translation" @@ -163,6 +180,7 @@ "Name": "fiftyone_ipintelligence", "Product": "ip-intelligence", "Path": "ip-intelligence/fiftyone_ipintelligence", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_ipintelligence_shared", "fiftyone_ipintelligence_cloud", @@ -175,6 +193,7 @@ "Name": "fiftyone_ipintelligence_examples", "Product": "ip-intelligence", "Path": "ip-intelligence/fiftyone_ipintelligence_examples", + "Ignore": ["**/tox.ini"], "DependsOn": [ "fiftyone_ipintelligence", "fiftyone_ipintelligence_translation" diff --git a/ci/packages.ps1 b/ci/packages.ps1 index 429c43ff..7529a333 100644 --- a/ci/packages.ps1 +++ b/ci/packages.ps1 @@ -4,10 +4,20 @@ # which version. # # Each package has its own version, tagged '/'. A package is -# released when a file under its folder changed since its last tag, or when a -# package it depends on is being released, because its requirement on that -# package moves. This is the scheme in 51Degrees/rust#205, which the per -# language repositories follow. +# released when a file that counts under its folders changed since its last +# tag, or when a package it depends on is being released, because its +# requirement on that package moves. This is the scheme in 51Degrees/rust#205, +# which the per language repositories follow. +# +# Every file counts except those matched by the package's Ignore globs in +# packages.json and, unless its IgnoreDefaults is false, by +# $ReleasePlanDefaultIgnore, so a change only to documentation, tests or +# examples releases nothing. release-plan-filter.ps1 then leaves out a +# manifest whose change is only to metadata such as links. These are the +# fields and the filter of common-ci's steps/release-plan.ps1. +# +# A submodule in Path or ExtraPaths changes as one path, its own, so any move +# of it counts. Neither the globs nor the filter see inside it. # Reads packages.json. Kept as a function so the tests can give their own list. function Get-Packages([string]$RepoPath) { @@ -30,6 +40,79 @@ function Test-PathUnder([string]$Path, [string]$Folder) { return $Path -eq $Folder -or $Path.StartsWith("$Folder/") } +# The files whose changes do not release a package, being documentation, +# tests, examples and LICENSE files wherever they sit and whatever their case, +# unless the package sets IgnoreDefaults to false. These are git glob +# pathspecs from the repository root, where '**/' matches any number of +# folders, none included. +$ReleasePlanDefaultIgnore = @( + '**/*.md' + '**/docs/**' + '**/tests/**' + '**/test/**' + '**/examples/**' + '**/LICENSE*' +) + +# The pathspecs that leave out of a package's changes the files its Ignore +# globs match and, unless IgnoreDefaults is false, the default set. +# PowerShell on Linux and macOS replaces a native command's argument that +# holds a '*' with the files it matches, if any. Each of these starts with +# ':(', which no file in a checkout starts with, so git receives it as written. +function Get-PackageExcludes($Package) { + $defaults = $Package.IgnoreDefaults + if ($null -ne $defaults -and $defaults -isnot [bool]) { + throw "$($Package.Name) gives IgnoreDefaults as '$defaults', where " + + "packages.json must give true or false." + } + $excludes = @($Package.Ignore | Where-Object { $_ } | + ForEach-Object { ":(exclude,glob)$_" }) + if ($defaults -ne $false) { + # The defaults ignore case, as one language names a folder Tests or + # Examples where another names it tests or examples. + $excludes = @($ReleasePlanDefaultIgnore | + ForEach-Object { ":(exclude,glob,icase)$_" }) + $excludes + } + return $excludes +} + +# The files under the package's folders that changed since the given tag, as +# paths from the repository root, apart from those it ignores. +function Get-ChangedFiles([string]$RepoPath, $Package, [string]$From) { + # A failure is reported below, naming the package, whatever the caller's + # preference. Set for this function only. + $PSNativeCommandUseErrorActionPreference = $false + $pathspecs = @(Get-PackagePaths $Package) + @(Get-PackageExcludes $Package) + $files = @(& git -C $RepoPath diff --name-only $From HEAD -- $pathspecs) + if ($LASTEXITCODE -ne 0) { + throw "git could not list the changes to $($Package.Name) since $From." + } + return $files +} + +# The files that count among a package's changed files. The repository's +# ci/release-plan-filter.ps1 decides when there is one, and otherwise every +# file counts. A path the filter returns that it was not given stops the +# plan, because a filter that rewrote a path would otherwise release a +# package on a file that never changed. +function Select-CountedFiles([string]$RepoPath, $Package, [string]$From, + [string[]]$Files) { + $filter = Join-Path $RepoPath 'ci/release-plan-filter.ps1' + if ($Files.Count -eq 0 -or (Test-Path $filter -PathType Leaf) -eq $false) { + return $Files + } + $filter = (Resolve-Path $filter).ProviderPath + $kept = @(& $filter -RepoPath $RepoPath -Package $Package -From $From ` + -Files $Files | Where-Object { $_ }) + foreach ($file in $kept) { + if ($Files -cnotcontains $file) { + throw "ci/release-plan-filter.ps1 returned '$file' for " + + "$($Package.Name), which is not one of the files it was given." + } + } + return $kept +} + # Each tox.ini that does not install every package its package depends on, # directly or through another, from this checkout, as a line naming what is # missing. Taken from a package index instead, a dependency is tested at its @@ -224,11 +307,6 @@ function Get-ReleasedVersions([string]$RepoPath, [string]$Name, # from packages.json. Packages that are not published, the examples, are never # in the plan; a change to them is tested but releases nothing. function Get-ReleasePlan([string]$RepoPath, $Packages = $null) { - # 'git diff --quiet' exits 1 to say a package changed. That is an answer, - # not a failure, but a caller that stops on a failing native command, as - # publish-package.ps1 does, stopped there and failed the publish. Set for - # this function only. - $PSNativeCommandUseErrorActionPreference = $false if ($null -eq $Packages) { $Packages = Get-Packages $RepoPath } @@ -254,10 +332,18 @@ function Get-ReleasePlan([string]$RepoPath, $Packages = $null) { $last = $released[-1] $previous[$package.Name] = $last $tag = "$($package.Name)/$last" - & git -C $RepoPath diff --quiet $tag HEAD -- (Get-PackagePaths $package) - if ($LASTEXITCODE -eq 1) { - $reasons[$package.Name] = "changed since $last" + $files = @(Get-ChangedFiles $RepoPath $package $tag) + $counted = @(Select-CountedFiles $RepoPath $package $tag $files) + if ($counted.Count -gt 0) { + $noun = 'files' + if ($counted.Count -eq 1) { + $noun = 'file' + } + $reasons[$package.Name] = + "changed since $last ($($counted.Count) $noun)" } + # A filter may leave an exit code that was an answer, which must not + # read as a failure to the script that called this. $global:LASTEXITCODE = 0 } diff --git a/ci/release-plan-filter.ps1 b/ci/release-plan-filter.ps1 new file mode 100644 index 00000000..dcd316aa --- /dev/null +++ b/ci/release-plan-filter.ps1 @@ -0,0 +1,39 @@ +param ( + [Parameter(Mandatory)][string]$RepoPath, + [Parameter(Mandatory)]$Package, + [Parameter(Mandatory)][string]$From, + [Parameter(Mandatory)][string[]]$Files +) +$ErrorActionPreference = "Stop" + +# Called by the release plan for each package with changed files left once +# the Ignore globs have left theirs out, and returns the files that count. +# A pyproject.toml, setup.py or setup.cfg whose change since $From is only to +# the description, keywords, urls, classifiers, readme, authors or maintainers +# does not count, which release-plan-filter.py works out. Every other file +# counts. +# +# Python is required rather than optional, because a job that counted every +# file would plan different releases from a job that could compare them. + +$manifests = 'pyproject.toml', 'setup.py', 'setup.cfg' +$compare = @($Files | Where-Object { (Split-Path -Leaf $_) -in $manifests }) +$counted = @($Files | Where-Object { (Split-Path -Leaf $_) -notin $manifests }) + +if ($compare.Count -gt 0) { + $python = Get-Command python, python3 -CommandType Application ` + -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($null -eq $python) { + throw "Python is needed to tell whether a change to " + + "$($compare -join ', ') is only to metadata, and none was found." + } + $PSNativeCommandUseErrorActionPreference = $false + $script = Join-Path $PSScriptRoot 'release-plan-filter.py' + $changed = @(& $python.Source -I $script $RepoPath $From @compare) + if ($LASTEXITCODE -ne 0) { + throw "release-plan-filter.py failed for $($Package.Name) since $From." + } + $counted += $changed | Where-Object { $_ } +} + +$counted diff --git a/ci/release-plan-filter.py b/ci/release-plan-filter.py new file mode 100644 index 00000000..94191c90 --- /dev/null +++ b/ci/release-plan-filter.py @@ -0,0 +1,194 @@ +"""Prints the manifest files whose change since a tag is more than metadata. + +Usage: release-plan-filter.py [ ...] + +Each file is a pyproject.toml, setup.py or setup.cfg, as a path from the +repository root. Its text at the tag and at HEAD is compared with the +description, keywords, urls, classifiers, readme, authors and maintainers +left out, so a file is printed when anything else changed, and left out when +only those did. A file that is missing on either side, or that cannot be read as what +its name says, is printed, so a release is never skipped by mistake. + +Only the standard library is used, and the same way on every Python this +repository supports, so every job of a publish works out the same plan. +""" + +import ast +import configparser +import os +import re +import subprocess +import sys + +# The setup() arguments and setup.cfg [metadata] options that are metadata. +SETUP_METADATA = frozenset(( + "description", "long_description", "long_description_content_type", + "keywords", "url", "project_urls", "download_url", "classifiers", + "author", "author_email", "maintainer", "maintainer_email")) + +# The pyproject.toml [project] keys that are metadata. +PROJECT_METADATA = frozenset(( + "description", "keywords", "urls", "classifiers", "readme", "authors", + "maintainers")) + +# A table header, such as [project.urls] or [[project.maintainers]]. +HEADER = re.compile(r"^\[\[?\s*([^\]]+?)\s*\]\]?\s*(#.*)?$") + +# The start of a key and value. The first part of a dotted key is the one +# that says what it is, as urls in urls.Homepage. +ASSIGNMENT = re.compile( + r"^(\"[^\"]*\"|'[^']*'|[A-Za-z0-9_-]+)" + r"(?:\s*\.\s*(?:\"[^\"]*\"|'[^']*'|[A-Za-z0-9_-]+))*\s*=") + + +def bytes_at(repository, revision, path): + """The file's content at the revision, or None when it is not there.""" + found = subprocess.run( + ["git", "-C", repository, "show", revision + ":" + path], + capture_output=True) + if found.returncode != 0: + return None + return found.stdout + + +class StripSetupMetadata(ast.NodeTransformer): + """Removes the metadata arguments from every call of setup().""" + + def visit_Call(self, node): + self.generic_visit(node) + name = node.func.attr if isinstance(node.func, ast.Attribute) \ + else getattr(node.func, "id", None) + if name == "setup": + node.keywords = [ + keyword for keyword in node.keywords + if keyword.arg not in SETUP_METADATA] + return node + + +def setup_py(text): + # The syntax tree leaves out comments and layout as well. + return ast.dump(StripSetupMetadata().visit(ast.parse(text))) + + +def setup_cfg(text): + parser = configparser.RawConfigParser() + parser.optionxform = str + parser.read_string(text) + return { + section: { + key: value for key, value in parser.items(section) + if section != "metadata" or key not in SETUP_METADATA} + for section in parser.sections()} + + +def toml_lines(text): + """The lines of a TOML file that are not metadata, each with the table + and key it belongs to, leaving out blank lines and comments. + + A small reader rather than tomllib, which Python 3.10 does not have. It + follows tables, keys, values that run over several lines in brackets or + in triple quotes, and comments, which is enough to place every line. + """ + kept = [] + table = "" + key = None + depth = 0 + quote = None + for line in text.splitlines(): + stripped = line.strip() + if quote is None and depth == 0: + if stripped == "" or stripped.startswith("#"): + continue + header = HEADER.match(stripped) + if header: + table = header.group(1).replace(" ", "") + key = None + if not is_metadata(table, None): + kept.append((table, None, stripped)) + continue + assignment = ASSIGNMENT.match(stripped) + if assignment is None: + # Not TOML this reader knows, so it counts unless the whole + # table is metadata. + if not is_metadata(table, "?"): + kept.append((table, "?", stripped)) + continue + key = assignment.group(1).strip("\"'") + value = stripped[assignment.end():] + else: + value = stripped + depth, quote = scan(value, depth, quote) + if not is_metadata(table, key): + kept.append((table, key, stripped)) + return kept + + +def scan(value, depth, quote): + """The bracket depth and the open triple quote after the value.""" + position = 0 + while position < len(value): + if quote is not None: + end = value.find(quote, position) + if end < 0: + return depth, quote + position = end + 3 + quote = None + continue + character = value[position] + if value.startswith('"""', position) or \ + value.startswith("'''", position): + quote = value[position:position + 3] + position += 3 + continue + if character in "\"'": + end = value.find(character, position + 1) + position = len(value) if end < 0 else end + 1 + continue + if character == "#": + break + if character in "[{": + depth += 1 + elif character in "]}": + depth -= 1 + position += 1 + return depth, quote + + +def is_metadata(table, key): + if table == "project": + return key in PROJECT_METADATA + return table in ( + "project.urls", "project.authors", "project.maintainers", + "project.readme") + + +READERS = { + "setup.py": setup_py, + "setup.cfg": setup_cfg, + "pyproject.toml": toml_lines, +} + + +def counts(repository, tag, path): + """Whether the change to the file since the tag is more than metadata.""" + reader = READERS.get(os.path.basename(path)) + before = bytes_at(repository, tag, path) + after = bytes_at(repository, "HEAD", path) + if reader is None or before is None or after is None: + return True + try: + return reader(before.decode("utf-8")) != reader(after.decode("utf-8")) + except (SyntaxError, ValueError, configparser.Error, + UnicodeDecodeError): + return True + + +def main(arguments): + repository, tag = arguments[0], arguments[1] + for path in arguments[2:]: + if counts(repository, tag, path): + print(path) + + +if __name__ == "__main__": + main(sys.argv[1:]) From e1bcf98abe395311d01ab8c9033662f13403a981 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 22:30:39 +0000 Subject: [PATCH 006/102] Measure changes from rc and build pull requests on fewer entries (#33) Reviewed and approved at head 2e8d370b289685606789a3c8ee66ae61f81003b7. The pull request body says what changed and how it was tested. --- .github/workflows/nightly-pipeline.yml | 52 +++++++------ .github/workflows/pull-requests.yml | 10 +++ .github/workflows/release-pull-request.yml | 32 ++++++++ AGENTS.md | 11 ++- ci/build-project.ps1 | 5 +- ci/dispatch.ps1 | 7 +- ci/fetch-assets.ps1 | 5 +- ci/packages.ps1 | 11 ++- ci/run-integration-tests.ps1 | 8 +- ci/run-performance-tests.ps1 | 5 +- ci/run-unit-tests.ps1 | 5 +- ci/select-options.Tests.ps1 | 69 ++++++++++++++++++ ci/select-options.ps1 | 73 +++++++++++++++++++ ci/setup-environment.ps1 | 5 +- device-detection/ci/run-integration-tests.ps1 | 13 +++- 15 files changed, 273 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/release-pull-request.yml create mode 100644 ci/select-options.Tests.ps1 create mode 100644 ci/select-options.ps1 diff --git a/.github/workflows/nightly-pipeline.yml b/.github/workflows/nightly-pipeline.yml index e44f9d29..7f434943 100644 --- a/.github/workflows/nightly-pipeline.yml +++ b/.github/workflows/nightly-pipeline.yml @@ -15,53 +15,59 @@ on: default: '' schedule: # The 51degrees-cxx nightly starts at 00:35 and ends by about 02:35, so - # its release reaches this submodule update the same night. - - cron: '0 3 * * *' + # its release reaches this submodule update the same night. The Java and + # Node nightlies start at 03:00 and want macOS runners too, so this one + # starts after them. + - cron: '0 5 * * *' jobs: - SubmoduleUpdate: - name: Nightly Submodule Update - uses: 51Degrees/common-ci/.github/workflows/nightly-submodule-update.yml@main + # The publish builds main, which the pull requests into rc do not change, so + # it runs first and has the runners before the pull request builds do. + Publish: + name: Nightly Publish + uses: 51Degrees/common-ci/.github/workflows/nightly-publish.yml@main with: repo-name: ${{ github.event.repository.name }} org-name: ${{ github.event.repository.owner.login }} dryrun: ${{ inputs.dryrun || false }} common-ci-ref: ${{ inputs.common-ci-ref || '' }} + cache-assets: true secrets: token: ${{ secrets.ACCESS_TOKEN }} + DeviceDetection: ${{ secrets.DEVICE_DETECTION_KEY }} + DeviceDetectionUrl: ${{ secrets.DEVICE_DETECTION_URL }} + CsvUrl: ${{ secrets.CSV_URL }} + IpIntelligence: ${{ secrets.IP_INTELLIGENCE_KEY }} + IpIntelligenceUrl: ${{ secrets.IPI_DATA_FILE_URL }} + TestResourceKey: ${{ secrets._51DEGREES_RESOURCE_KEY_BESPOKE }} + PypiToken: ${{ secrets.PYPI_TOKEN }} + TestPypiToken: ${{ secrets.TEST_PYPI_TOKEN }} - PullRequests: - if: ${{ !cancelled() }} - needs: SubmoduleUpdate - name: Nightly Pull Requests - uses: 51Degrees/common-ci/.github/workflows/nightly-pull-requests.yml@main + SubmoduleUpdate: + name: Nightly Submodule Update + uses: 51Degrees/common-ci/.github/workflows/nightly-submodule-update.yml@main with: repo-name: ${{ github.event.repository.name }} org-name: ${{ github.event.repository.owner.login }} dryrun: ${{ inputs.dryrun || false }} common-ci-ref: ${{ inputs.common-ci-ref || '' }} - skip-lite-tests: ${{ inputs.skip-lite-tests || false }} - cache-assets: true secrets: token: ${{ secrets.ACCESS_TOKEN }} - DeviceDetection: ${{ secrets.DEVICE_DETECTION_KEY }} - DeviceDetectionUrl: ${{ secrets.DEVICE_DETECTION_URL }} - CsvUrl: ${{ secrets.CSV_URL }} - IpIntelligence: ${{ secrets.IP_INTELLIGENCE_KEY }} - IpIntelligenceUrl: ${{ secrets.IPI_DATA_FILE_URL }} - TestResourceKey: ${{ secrets._51DEGREES_RESOURCE_KEY_BESPOKE }} - Publish: + PullRequests: if: ${{ !cancelled() }} - needs: PullRequests - name: Nightly Publish - uses: 51Degrees/common-ci/.github/workflows/nightly-publish.yml@main + needs: [Publish, SubmoduleUpdate] + name: Nightly Pull Requests + uses: 51Degrees/common-ci/.github/workflows/nightly-pull-requests.yml@main with: repo-name: ${{ github.event.repository.name }} org-name: ${{ github.event.repository.owner.login }} dryrun: ${{ inputs.dryrun || false }} common-ci-ref: ${{ inputs.common-ci-ref || '' }} + skip-lite-tests: ${{ inputs.skip-lite-tests || false }} cache-assets: true + # One configuration that fails does not cancel the others. + fail-fast: false secrets: token: ${{ secrets.ACCESS_TOKEN }} DeviceDetection: ${{ secrets.DEVICE_DETECTION_KEY }} @@ -70,5 +76,3 @@ jobs: IpIntelligence: ${{ secrets.IP_INTELLIGENCE_KEY }} IpIntelligenceUrl: ${{ secrets.IPI_DATA_FILE_URL }} TestResourceKey: ${{ secrets._51DEGREES_RESOURCE_KEY_BESPOKE }} - PypiToken: ${{ secrets.PYPI_TOKEN }} - TestPypiToken: ${{ secrets.TEST_PYPI_TOKEN }} diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 0d600a54..10b95bd4 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -13,6 +13,10 @@ on: common-ci-ref: type: string default: '' + full-matrix: + description: 'Build every configuration, not only those the changes need' + type: boolean + default: false jobs: PullRequests: @@ -25,6 +29,12 @@ jobs: common-ci-ref: ${{ inputs.common-ci-ref || '' }} skip-lite-tests: ${{ inputs.skip-lite-tests || false }} cache-assets: true + # Each pull request is built on the configurations its changes need, + # as ci/select-options.ps1 chooses, and one that fails does not cancel + # the others. With nothing eligible, the nightly builds rc instead. + full-matrix: ${{ inputs.full-matrix || false }} + fail-fast: false + build-without-pull-requests: false secrets: token: ${{ secrets.ACCESS_TOKEN }} DeviceDetection: ${{ secrets.DEVICE_DETECTION_KEY }} diff --git a/.github/workflows/release-pull-request.yml b/.github/workflows/release-pull-request.yml new file mode 100644 index 00000000..8af10442 --- /dev/null +++ b/.github/workflows/release-pull-request.yml @@ -0,0 +1,32 @@ +name: Release Pull Request + +# Builds and tests the release pull request, rc into main, on every entry in +# ci/options.json, and never merges it. A pull request into rc is built only on +# the entries its changes need, so this is the full build of a release before +# it reaches main. See common-ci .github/workflows/release-pull-request.yml. +on: + pull_request: + branches: [main] + +# A push to rc while the release is open builds it again, in place of the +# build of the older rc. +concurrency: + group: release-pull-request-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + Release: + name: Release Pull Request + uses: 51Degrees/common-ci/.github/workflows/release-pull-request.yml@main + with: + repo-name: ${{ github.event.repository.name }} + org-name: ${{ github.event.repository.owner.login }} + cache-assets: true + secrets: + token: ${{ secrets.ACCESS_TOKEN }} + DeviceDetection: ${{ secrets.DEVICE_DETECTION_KEY }} + DeviceDetectionUrl: ${{ secrets.DEVICE_DETECTION_URL }} + CsvUrl: ${{ secrets.CSV_URL }} + IpIntelligence: ${{ secrets.IP_INTELLIGENCE_KEY }} + IpIntelligenceUrl: ${{ secrets.IPI_DATA_FILE_URL }} + TestResourceKey: ${{ secrets._51DEGREES_RESOURCE_KEY_BESPOKE }} diff --git a/AGENTS.md b/AGENTS.md index 3fe39ce4..c47453bf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -275,7 +275,16 @@ product is built or tested belongs in that product's `ci/`, not in the root. A change touches a product when it is in that product's folder, or in a package another product depends on; a change outside every product folder touches all of them ([ci/packages.ps1](ci/packages.ps1), -`Resolve-AffectedProducts`). +`Resolve-AffectedProducts`). A pull request's changes are measured from the +branch it merges into, `rc`. + +[ci/select-options.ps1](ci/select-options.ps1) chooses the entries a pull +request runs. The standard set is Python 3.14 and 3.10 on Linux, with the +Selenium contract on 3.14 alone. A native change adds Windows, a packaging +change adds the other Python versions on Linux, and a change outside the +product folders or to a `ci/` folder adds every entry but macOS. macOS and +performance run only when `rc` itself or the release pull request is built, +which `.github/workflows/release-pull-request.yml` does on every entry. ## Versions are per package diff --git a/ci/build-project.ps1 b/ci/build-project.ps1 index 3461d091..639d7435 100644 --- a/ci/build-project.ps1 +++ b/ci/build-project.ps1 @@ -1,5 +1,8 @@ param ( - [Parameter(Mandatory)][string]$RepoName + [Parameter(Mandatory)][string]$RepoName, + # The branch a pull request merges into, which its changes are measured + # against. + [string]$Branch = 'main' ) $ErrorActionPreference = "Stop" . (Join-Path $PSScriptRoot 'dispatch.ps1') diff --git a/ci/dispatch.ps1 b/ci/dispatch.ps1 index 4249d40b..06ba77ef 100644 --- a/ci/dispatch.ps1 +++ b/ci/dispatch.ps1 @@ -10,12 +10,15 @@ # Runs $Step for each affected product, or for each of $Products when given. # Every product is run even when an earlier one fails, so one run reports -# every broken product, and the step fails at the end if any did. +# every broken product, and the step fails at the end if any did. A pull +# request's changes are measured from the Branch in $Options, the branch it +# merges into. function Invoke-ProductStep([string]$Step, [string]$RepoName, [Collections.IDictionary]$Options, [string[]]$Products) { $failed = [Collections.Generic.List[string]]::new() if (-not $Products) { - $Products = Get-AffectedProducts $RepoName + $branch = $Options.Branch ? $Options.Branch : 'main' + $Products = Get-AffectedProducts $RepoName $branch } foreach ($product in $Products) { $script = Join-Path $RepoName $product 'ci' "$Step.ps1" diff --git a/ci/fetch-assets.ps1 b/ci/fetch-assets.ps1 index 802476f1..7a37794a 100644 --- a/ci/fetch-assets.ps1 +++ b/ci/fetch-assets.ps1 @@ -8,7 +8,10 @@ param ( [string]$DeviceDetectionUrl, [string]$CsvUrl, [string]$IpIntelligence, - [string]$IpIntelligenceUrl + [string]$IpIntelligenceUrl, + # The branch a pull request merges into, which its changes are measured + # against. + [string]$Branch = 'main' ) $ErrorActionPreference = "Stop" . (Join-Path $PSScriptRoot 'dispatch.ps1') diff --git a/ci/packages.ps1 b/ci/packages.ps1 index 7529a333..ec4bb89b 100644 --- a/ci/packages.ps1 +++ b/ci/packages.ps1 @@ -251,15 +251,18 @@ function Resolve-AffectedProducts($Packages, [string[]]$Changed) { } # The products a pull request changes, or every product when the checkout is -# not a pull request (a publish, or a run on main), as 51degrees-cxx does. -function Get-AffectedProducts([string]$RepoPath) { - # merge-base fails where there is no origin/main, which is an answer here. +# not a pull request (a publish, or a build of the branch itself), as +# 51degrees-cxx does. A pull request is checked out with the branch it merges +# into merged in, so the merge base with that branch leaves only the pull +# request's own changes. +function Get-AffectedProducts([string]$RepoPath, [string]$Branch = 'main') { + # merge-base fails where there is no such branch, which is an answer here. # Set for this function only, so a caller that stops on a failing native # command, as publish-package.ps1 does, is not stopped by it. $PSNativeCommandUseErrorActionPreference = $false $packages = Get-Packages $RepoPath $head = git -C $RepoPath rev-parse HEAD - $base = git -C $RepoPath merge-base origin/main HEAD 2>$null + $base = git -C $RepoPath merge-base "origin/$Branch" HEAD 2>$null if ($LASTEXITCODE -ne 0 -or $null -eq $base -or $base -eq $head) { $global:LASTEXITCODE = 0 return @($packages.Product | Select-Object -Unique) diff --git a/ci/run-integration-tests.ps1 b/ci/run-integration-tests.ps1 index ae1c20f8..59885cae 100644 --- a/ci/run-integration-tests.ps1 +++ b/ci/run-integration-tests.ps1 @@ -1,6 +1,12 @@ param ( [Parameter(Mandatory)][string]$RepoName, - [Parameter(Mandatory)][hashtable]$Keys + [Parameter(Mandatory)][hashtable]$Keys, + # The branch a pull request merges into, which its changes are measured + # against. + [string]$Branch = 'main', + # False, from select-options.ps1, on every entry of a pull request but + # one, so the browser contract runs once. + [bool]$SeleniumContract = $true ) $ErrorActionPreference = "Stop" . (Join-Path $PSScriptRoot 'dispatch.ps1') diff --git a/ci/run-performance-tests.ps1 b/ci/run-performance-tests.ps1 index 58401f22..4fa56758 100644 --- a/ci/run-performance-tests.ps1 +++ b/ci/run-performance-tests.ps1 @@ -1,7 +1,10 @@ param ( [Parameter(Mandatory)][string]$RepoName, [string]$Name, - [bool]$RunPerformance + [bool]$RunPerformance, + # The branch a pull request merges into, which its changes are measured + # against. + [string]$Branch = 'main' ) $ErrorActionPreference = "Stop" . (Join-Path $PSScriptRoot 'dispatch.ps1') diff --git a/ci/run-unit-tests.ps1 b/ci/run-unit-tests.ps1 index e74a60ff..38e3ee6e 100644 --- a/ci/run-unit-tests.ps1 +++ b/ci/run-unit-tests.ps1 @@ -1,5 +1,8 @@ param ( - [Parameter(Mandatory)][string]$RepoName + [Parameter(Mandatory)][string]$RepoName, + # The branch a pull request merges into, which its changes are measured + # against. + [string]$Branch = 'main' ) $ErrorActionPreference = "Stop" . (Join-Path $PSScriptRoot 'dispatch.ps1') diff --git a/ci/select-options.Tests.ps1 b/ci/select-options.Tests.ps1 new file mode 100644 index 00000000..9e0042dc --- /dev/null +++ b/ci/select-options.Tests.ps1 @@ -0,0 +1,69 @@ +# Tests for ci/select-options.ps1, with the entries of the real options.json +# read as common-ci's steps/select-options.ps1 reads them, as hashtables. + +BeforeAll { + $script:Select = Join-Path $PSScriptRoot 'select-options.ps1' + + # The names of the entries chosen for the changed files given, and the + # entries themselves in $script:Chosen. + function Get-Chosen([string[]]$ChangedFiles, [string[]]$CommentOnlyFiles = @()) { + $options = @(Get-Content -Raw (Join-Path $PSScriptRoot 'options.json') | + ConvertFrom-Json -AsHashtable) + $script:Chosen = @(& $script:Select -Options $options ` + -ChangedFiles $ChangedFiles -CommentOnlyFiles $CommentOnlyFiles 6>$null) + return @($script:Chosen | ForEach-Object { $_.Name } | Sort-Object) + } + + $script:StandardSet = @('Ubuntu_Python_3.10', 'Ubuntu_Python_3.14') +} + +Describe 'select-options.ps1' { + It 'builds the standard set for a change to a package''s code' { + Get-Chosen @('pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/flowdata.py') | + Should -Be $script:StandardSet + } + + It 'runs the Selenium contract on Python 3.14 alone, and no performance tests' { + $null = Get-Chosen @('location/src/fiftyone_location/location_cloud.py') + foreach ($entry in $script:Chosen) { + $entry.SeleniumContract | Should -Be ($entry.Name -eq 'Ubuntu_Python_3.14') + $entry.RunPerformance | Should -BeFalse + } + } + + It 'adds Windows for a change to an on-premise package' { + Get-Chosen @('device-detection/fiftyone_devicedetection_onpremise/src/fiftyone_devicedetection_onpremise/swig_data.py') | + Should -Be (@($script:StandardSet + 'Windows_Python_3.14') | Sort-Object) + } + + It 'adds Windows for a change to the cxx submodule' { + Get-Chosen @('cxx') | + Should -Be (@($script:StandardSet + 'Windows_Python_3.14') | Sort-Object) + } + + It 'leaves Windows out for a change only to the comments of an on-premise file' { + $file = 'ip-intelligence/fiftyone_ipintelligence_onpremise/src/fiftyone_ipintelligence_onpremise/swig_data.py' + Get-Chosen @($file) @($file) | Should -Be $script:StandardSet + } + + It 'adds Python 3.11 to 3.13 on Linux for a change to a setup.py' { + Get-Chosen @('location/setup.py') | Should -Be (@($script:StandardSet + + 'Ubuntu_Python_3.11' + 'Ubuntu_Python_3.12' + 'Ubuntu_Python_3.13') | + Sort-Object) + } + + It 'builds every entry but macOS for a change to ' -ForEach @( + @{ Case = 'a ci folder'; File = 'device-detection/ci/build-project.ps1' } + @{ Case = 'the root ci folder'; File = 'ci/packages.ps1' } + @{ Case = 'a file outside the product folders'; File = '.github/workflows/pull-requests.yml' } + ) { + $chosen = Get-Chosen @($File) + $chosen.Count | Should -Be 10 + $chosen | Where-Object { $_ -like 'macOS*' } | Should -BeNullOrEmpty + } + + It 'never builds macOS on a pull request' { + Get-Chosen @('cxx', 'ci/packages.ps1', 'location/setup.py') | + Where-Object { $_ -like 'macOS*' } | Should -BeNullOrEmpty + } +} diff --git a/ci/select-options.ps1 b/ci/select-options.ps1 new file mode 100644 index 00000000..cc22871f --- /dev/null +++ b/ci/select-options.ps1 @@ -0,0 +1,73 @@ +param( + # Every entry of options.json. + [Parameter(Mandatory)][object[]]$Options, + # The files the pull request changes, less documentation. + [string[]]$ChangedFiles, + # Those of the changed files whose change touches only comments. + [string[]]$CommentOnlyFiles +) +# Chooses the options.json entries a pull request is built on, for common-ci's +# steps/select-options.ps1. The branch itself and a release build every entry. +# Within each entry, packages.ps1 still builds only the products the change +# touches. +# +# The standard set is Python 3.14 and 3.10 on Linux, the newest and the oldest, +# with the Selenium contract on 3.14 alone. A change in more than its comments +# to an on-premise package, its data or the cxx submodule adds Windows, where +# the native module is built differently. A change to a setup.py, setup.cfg or +# pyproject.toml adds Python 3.11 to 3.13 on Linux, and a change outside the +# product folders or to a ci folder adds every entry. Only five macOS jobs run +# at once across the organisation, and the releases need them, so macOS is left +# to the branch and release builds, as is performance. + +$Standard = @('Ubuntu_Python_3.14', 'Ubuntu_Python_3.10') +$Contract = 'Ubuntu_Python_3.14' +$Native = @('Windows_Python_3.14') +$Versions = @('Ubuntu_Python_3.13', 'Ubuntu_Python_3.12', 'Ubuntu_Python_3.11') +$ProductFolders = @('pipeline/', 'device-detection/', 'ip-intelligence/', + 'location/') +# The data files come in through the cxx submodule, so a change to them is a +# change to cxx. +$NativePaths = @('device-detection/fiftyone_devicedetection_onpremise/', + 'ip-intelligence/fiftyone_ipintelligence_onpremise/') + +function Test-Under([string]$Path, [string[]]$Prefixes) { + return @($Prefixes | Where-Object { + $Path -eq $_.TrimEnd('/') -or $Path.StartsWith($_.TrimEnd('/') + '/') + }).Count -gt 0 +} + +# PowerShell names are not case sensitive, so these must not share a name with +# the lists above, such as $Native. +$code = @($ChangedFiles | Where-Object { $CommentOnlyFiles -notcontains $_ }) +$nativeChanged = @($code | Where-Object { + $_ -eq 'cxx' -or (Test-Under $_ $NativePaths) +}).Count -gt 0 +$setupChanged = @($code | Where-Object { + $_ -match '(^|/)(setup\.py|setup\.cfg|pyproject\.toml)$' +}).Count -gt 0 +$otherChanged = @($code | Where-Object { + $_ -ne 'cxx' -and (!(Test-Under $_ $ProductFolders) -or $_ -match '(^|/)ci/') +}).Count -gt 0 +Write-Host ("Native: $nativeChanged. Setup: $setupChanged. " + + "Outside the product folders or in a ci folder: $otherChanged.") + +foreach ($entry in $Options) { + $name = $entry.Name + if ($entry.Image -like 'macos*') { + Write-Host "$name is left to the branch and release builds" + continue + } + $why = if ($Standard -contains $name) { 'the standard set' } + elseif ($otherChanged) { 'a change outside the product folders or to CI' } + elseif ($nativeChanged -and $Native -contains $name) { 'a native change' } + elseif ($setupChanged -and $Versions -contains $name) { 'a packaging change' } + if (!$why) { + Write-Host "$name is not needed for this change" + continue + } + $entry.SeleniumContract = $name -eq $Contract + $entry.RunPerformance = $false + Write-Host "$name runs for $why" + $entry +} diff --git a/ci/setup-environment.ps1 b/ci/setup-environment.ps1 index 932f5d81..24c1b8bd 100644 --- a/ci/setup-environment.ps1 +++ b/ci/setup-environment.ps1 @@ -1,6 +1,9 @@ param ( [Parameter(Mandatory)][string]$RepoName, - [Parameter(Mandatory)][string]$LanguageVersion + [Parameter(Mandatory)][string]$LanguageVersion, + # The branch a pull request merges into, which its changes are measured + # against. + [string]$Branch = 'main' ) $ErrorActionPreference = "Stop" . (Join-Path $PSScriptRoot 'dispatch.ps1') diff --git a/device-detection/ci/run-integration-tests.ps1 b/device-detection/ci/run-integration-tests.ps1 index 9c45928e..ed7a17d2 100644 --- a/device-detection/ci/run-integration-tests.ps1 +++ b/device-detection/ci/run-integration-tests.ps1 @@ -2,7 +2,10 @@ param ( [Parameter(Mandatory=$true)] [string]$RepoName, [Parameter(Mandatory=$true)] - [Hashtable]$Keys + [Hashtable]$Keys, + # False, from the root select-options.ps1, on every entry of a pull + # request but one, so the browser contract runs once. + [bool]$SeleniumContract = $true ) if ($IsWindows) { @@ -47,6 +50,14 @@ if ($LASTEXITCODE -ne 0) { $failures += "the Python integration tests exited with code $LASTEXITCODE" } +if (-not $SeleniumContract) { + Write-Output "Another entry runs the Selenium contract tests for this pull request." + if ($failures.Count -gt 0) { + throw "Integration tests failed: $($failures -join '; ')" + } + return +} + # The shared Selenium contract tests are run against the cloud example and the # on-premise example in turn. Each result is also written as a trx file next # to the other integration results, so it is published with them. From 32ffdcf1205a5ce593fb55f5be733de5a18dffde Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 22:31:25 +0000 Subject: [PATCH 007/102] Point configuration page links at 51degrees.com/configure (#107) Reviewed and approved at head 60b403678245772f824bca80aa7d05b8d774e3d7. The pull request body says what changed and how it was tested. --- AGENTS.md | 4 ++-- README.md | 2 +- device-detection/fiftyone_devicedetection_cloud/readme.md | 2 +- .../fiftyone_devicedetection_cloud/tests/live_cloud.py | 2 +- .../cloud/configurator_console.py | 4 ++-- .../cloud/failuretomatch.py | 4 ++-- .../cloud/gettingstarted_console.json | 2 +- .../cloud/gettingstarted_console.py | 2 +- .../cloud/gettingstarted_web/app.py | 2 +- .../cloud/metadata_console.py | 2 +- .../cloud/nativemodellookup_console.py | 2 +- .../cloud/taclookup_console.json | 2 +- .../cloud/taclookup_console.py | 2 +- .../cloud/useragentclienthints_web/app.py | 2 +- .../src/fiftyone_devicedetection_examples/example_utils.py | 2 +- .../fiftyone_devicedetection_examples/tests/live_cloud.py | 2 +- device-detection/readme.md | 2 +- ip-intelligence/fiftyone_ipintelligence_cloud/readme.md | 2 +- ip-intelligence/fiftyone_ipintelligence_examples/readme.md | 2 +- .../cloud/getallproperties_console.py | 4 ++-- .../cloud/gettingstarted_console.py | 6 +++--- .../cloud/gettingstarted_web/app.py | 4 ++-- .../cloud/metadata_console.py | 4 ++-- .../fiftyone_ipintelligence_examples/cloud/mixed_console.py | 4 ++-- .../fiftyone_ipintelligence_examples/tests/live_cloud.py | 2 +- .../fiftyone_ipintelligence_onpremise/tests/live_cloud.py | 2 +- location/examples/cloud/gettingstarted.py | 6 +++--- location/examples/cloud/web.py | 6 +++--- location/readme.md | 2 +- location/tests/live_cloud.py | 2 +- .../fiftyone_pipeline_cloudrequestengine/examples/readme.md | 2 +- .../cloud/mixed/gettingstarted_console.py | 4 ++-- .../cloud/mixed/gettingstarted_web/app.py | 4 ++-- .../src/fiftyone_pipeline_examples/cloud/mixed/pipeline.py | 2 +- .../examples/tests/live_cloud.py | 2 +- pipeline/fiftyone_pipeline_cloudrequestengine/readme.md | 2 +- .../src/fiftyone_pipeline_cloudrequestengine/constants.py | 2 +- .../tests/live_cloud.py | 2 +- .../tests/test_cloudengine.py | 2 +- pipeline/fiftyone_pipeline_did/tests/live_cloud.py | 2 +- 40 files changed, 55 insertions(+), 55 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index c47453bf..01221404 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -202,10 +202,10 @@ describes. The cloud examples need a resource key, which a person creates in the configurator, so ask for one if none is set. A key with the properties the Device Detection cloud example uses can be made -[here](https://configure.51degrees.com/1QWJwHxl?utm_source=github&utm_medium=docs&utm_campaign=51degrees-python&utm_content=agents.md&utm_term=cloud-examples), +[here](https://51degrees.com/configure/1QWJwHxl?utm_source=github&utm_medium=docs&utm_campaign=51degrees-python&utm_content=agents.md&utm_term=cloud-examples), which is the configuration the example's own message names, and a key for IP Intelligence in the -[configurator](https://configure.51degrees.com/?utm_source=github&utm_medium=docs&utm_campaign=51degrees-python&utm_content=agents.md&utm_term=cloud-examples). +[configuration page](https://51degrees.com/configure/?utm_source=github&utm_medium=docs&utm_campaign=51degrees-python&utm_content=agents.md&utm_term=cloud-examples). The Device Detection and IP Intelligence cloud examples take the key as their first argument, or from `_51DEGREES_RESOURCE_KEY`. diff --git a/README.md b/README.md index 04fb4d05..0a8ba812 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ python -m pip install fiftyone-ipintelligence The table below lists the other packages. To build from source, see [Getting the code](#getting-the-code). -Try the [User-Agent tester](https://51degrees.com/developers/user-agent-tester?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=install) and [IP tester](https://51degrees.com/developers/ip-tester?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=install). For cloud use, [create a Resource Key](https://configure.51degrees.com/?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=install). +Try the [User-Agent tester](https://51degrees.com/developers/user-agent-tester?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=install) and [IP tester](https://51degrees.com/developers/ip-tester?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=install). For cloud use, [create a Resource Key](https://51degrees.com/configure/?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=install). Created from `pipeline-python`, `device-detection-python`, and `location-python`, this repository continues their work. diff --git a/device-detection/fiftyone_devicedetection_cloud/readme.md b/device-detection/fiftyone_devicedetection_cloud/readme.md index 07923fdc..c41fda5c 100644 --- a/device-detection/fiftyone_devicedetection_cloud/readme.md +++ b/device-detection/fiftyone_devicedetection_cloud/readme.md @@ -12,7 +12,7 @@ You can confirm this is working with the following micro-example. -* Create a resource key for free with the 51Degrees [configurator](https://configure.51degrees.com/np5M4nlF?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_cloud&utm_term=from-pypi). This defines the properties you want to access. +* Create a resource key for free with the 51Degrees [configuration page](https://51degrees.com/configure/np5M4nlF?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_cloud&utm_term=from-pypi). This defines the properties you want to access. * On the 'implement' page of the configurator, copy the resource key and replace YOUR_RESOURCE_KEY in the example below. Save this as exampledd.py * Run the example with `python exampledd.py` * Feel free to try different user-agents and property values. diff --git a/device-detection/fiftyone_devicedetection_cloud/tests/live_cloud.py b/device-detection/fiftyone_devicedetection_cloud/tests/live_cloud.py index 36bc26ad..2109e4a2 100644 --- a/device-detection/fiftyone_devicedetection_cloud/tests/live_cloud.py +++ b/device-detection/fiftyone_devicedetection_cloud/tests/live_cloud.py @@ -51,7 +51,7 @@ ACCESSIBLE_PROPERTIES_URL = ( "https://cloud.51degrees.com/api/v4/accessibleproperties?resource=") -CREATE_KEY_URL = "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" +CREATE_KEY_URL = "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" def _report_old_name(name, old_name): diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/configurator_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/configurator_console.py index 9e6d0b5f..6cd8ac4c 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/configurator_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/configurator_console.py @@ -25,7 +25,7 @@ from fiftyone_devicedetection_cloud.devicedetection_cloud_pipelinebuilder import DeviceDetectionCloudPipelineBuilder from fiftyone_devicedetection_examples.example_utils import ExampleUtils -# This example is displayed at the end of the [Configurator](https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=top) +# This example is displayed at the end of the [configuration page](https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=top) # process, which is used to create resource keys for use with the 51Degrees cloud service. # # It shows how to call the cloud with the newly created key and how to access the values @@ -99,7 +99,7 @@ def main(argv): "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=resource-key-required. " + "A resource key with the properties required by this " + "example can be created for free at " + - "https://configure.51degrees.com/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=resource-key-required. " + + "https://51degrees.com/configure/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=resource-key-required. " + "Once complete, populate the environment variable " + "mentioned at the start of this message with the key.") diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/failuretomatch.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/failuretomatch.py index 8258122c..c10939eb 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/failuretomatch.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/failuretomatch.py @@ -24,7 +24,7 @@ # First create the device detection pipeline with the desired settings. -# You need to create a resource key at https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-failuretomatch.py&utm_term=top +# You need to create a resource key at https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-failuretomatch.py&utm_term=top # and paste it into the code, replacing !!YOUR_RESOURCE_KEY!! below. # Alternatively, set the _51DEGREES_RESOURCE_KEY environment variable. The # key is read through ExampleUtils, as every other example reads it, so @@ -40,7 +40,7 @@ # The address stays on one line, because the campaign lint reads a # line at a time and a split address looks to it like a missing tag. print(" To include the properties used in this example, go to " - "https://configure.51degrees.com/bxXqZhLT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-failuretomatch.py&utm_term=resource-key-required") + "https://51degrees.com/configure/bxXqZhLT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-failuretomatch.py&utm_term=resource-key-required") else: pipeline = DeviceDetectionCloudPipelineBuilder({ diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.json b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.json index 214a588a..2caf8d14 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.json +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.json @@ -7,7 +7,7 @@ "elementParameters": { "settings": { // Obtain a resource key with the properties required to run this - // example for free: https://configure.51degrees.com/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.json&utm_term=settings + // example for free: https://51degrees.com/configure/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.json&utm_term=settings "resource_key": "!!ENTER_YOUR_RESOURCE_KEY_HERE!!", "cloud_request_origin": "51Degrees.example.com" } diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.py index 3a92915b..f763cfcf 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.py @@ -176,7 +176,7 @@ def main(argv): "see " + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.py&utm_term=resource-key-required. " + "A resource key with the properties required by this example can be " + - "created for free at https://configure.51degrees.com/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.py&utm_term=resource-key-required. " + + "created for free at https://51degrees.com/configure/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.py&utm_term=resource-key-required. " + "Once complete, populate the config file or environment variable " + "mentioned at the start of this message with the key.") else: diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/app.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/app.py index 93f448b3..94a2855d 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/app.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/app.py @@ -204,7 +204,7 @@ def main(argv): "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_web-app.py&utm_term=resource-key-required. " + "A resource key with the properties required by this " + "example can be created for free at " + - "https://configure.51degrees.com/g3gMZdPY?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_web-app.py&utm_term=resource-key-required. " + + "https://51degrees.com/configure/g3gMZdPY?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_web-app.py&utm_term=resource-key-required. " + "Once complete, populated the environment variable " + "mentioned at the start of this message with the key.") diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/metadata_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/metadata_console.py index d8b06656..7fc8ba08 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/metadata_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/metadata_console.py @@ -123,7 +123,7 @@ def main(argv): "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=resource-key-required. " + "A resource key with the properties required by this " + "example can be created for free at " + - "https://configure.51degrees.com/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=resource-key-required. " + + "https://51degrees.com/configure/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=resource-key-required. " + "Once complete, populate the environment variable " + "mentioned at the start of this message with the key.") diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/nativemodellookup_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/nativemodellookup_console.py index 98b7212e..868d0665 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/nativemodellookup_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/nativemodellookup_console.py @@ -133,7 +133,7 @@ def main(argv): "you will first need a license key, which can be purchased from our " + "pricing page: https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-nativemodellookup_console.py&utm_term=resource-key-required. Once this is done, a resource " + "key with the properties required by this example can be created at " + - "https://configure.51degrees.com/QKyYH5XT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-nativemodellookup_console.py&utm_term=resource-key-required. You can now populate the " + + "https://51degrees.com/configure/QKyYH5XT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-nativemodellookup_console.py&utm_term=resource-key-required. You can now populate the " + "environment variable mentioned at the start of this message with the " + "resource key or pass it as the first argument on the command line.") diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.json b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.json index 2bb00c22..9a393c31 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.json +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.json @@ -8,7 +8,7 @@ "settings": { // TAC lookup requires a license key, which can be purchased from our pricing page: // https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.json&utm_term=settings. You can then obtain a resource key with the properties - // required to run this example here: https://configure.51degrees.com/QKyYH5XT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.json&utm_term=settings + // required to run this example here: https://51degrees.com/configure/QKyYH5XT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.json&utm_term=settings "resource_key": "!!ENTER_YOUR_RESOURCE_KEY_HERE!!", // Update this with your domain name. "cloud_request_origin": "51Degrees.example.com" diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.py index 63355916..0d07605e 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.py @@ -134,7 +134,7 @@ def main(argv): "that you will first need a license key, which can be purchased " + "from our pricing page: https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.py&utm_term=resource-key-required. Once this is " + "done, a resource key with the properties required by this example " + - "can be created at https://configure.51degrees.com/QKyYH5XT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.py&utm_term=resource-key-required. You " + + "can be created at https://51degrees.com/configure/QKyYH5XT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.py&utm_term=resource-key-required. You " + "can now populate the environment variable mentioned at the start " + "of this message with the resource key or pass it as the first " + "argument on the command line.") diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/app.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/app.py index 728f0594..b47cce81 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/app.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/app.py @@ -139,7 +139,7 @@ def main(argv): "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-useragentclienthints_web-app.py&utm_term=resource-key-required. " + "A resource key with the properties required by this " + "example can be created for free at " + - "https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-useragentclienthints_web-app.py&utm_term=resource-key-required. " + + "https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-useragentclienthints_web-app.py&utm_term=resource-key-required. " + "Once complete, populated the environment variable " + "mentioned at the start of this message with the key.") diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/example_utils.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/example_utils.py index 98f38b8d..b6a96ff9 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/example_utils.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/example_utils.py @@ -213,7 +213,7 @@ def get_missing_resource_key_message(): return (f"No resource key found. Set the environment variable " f"'{ExampleUtils.RESOURCE_KEY_ENV_VAR}'. Create a resource key for free at " - "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-example_utils.py&utm_term=resource-key-required") + "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-example_utils.py&utm_term=resource-key-required") @staticmethod def get_data_file_path(): diff --git a/device-detection/fiftyone_devicedetection_examples/tests/live_cloud.py b/device-detection/fiftyone_devicedetection_examples/tests/live_cloud.py index 36bc26ad..2109e4a2 100644 --- a/device-detection/fiftyone_devicedetection_examples/tests/live_cloud.py +++ b/device-detection/fiftyone_devicedetection_examples/tests/live_cloud.py @@ -51,7 +51,7 @@ ACCESSIBLE_PROPERTIES_URL = ( "https://cloud.51degrees.com/api/v4/accessibleproperties?resource=") -CREATE_KEY_URL = "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" +CREATE_KEY_URL = "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" def _report_old_name(name, old_name): diff --git a/device-detection/readme.md b/device-detection/readme.md index 62f44556..0559335d 100644 --- a/device-detection/readme.md +++ b/device-detection/readme.md @@ -36,7 +36,7 @@ The API can either use our cloud service to get its data or it can use a local ( You will require a [resource key](https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=cloud) to use the Cloud API. You can create resource keys using our -[configurator](https://configure.51degrees.com/?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=cloud), see our +[configuration page](https://51degrees.com/configure/?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=cloud), see our [documentation](https://51degrees.com/documentation/_services__configurator.html?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=readme.md&utm_term=cloud) on how to use this. #### On-Premise diff --git a/ip-intelligence/fiftyone_ipintelligence_cloud/readme.md b/ip-intelligence/fiftyone_ipintelligence_cloud/readme.md index fc189448..760a2e04 100644 --- a/ip-intelligence/fiftyone_ipintelligence_cloud/readme.md +++ b/ip-intelligence/fiftyone_ipintelligence_cloud/readme.md @@ -11,7 +11,7 @@ location, network and registration information using the [51Degrees Pipeline API](https://51degrees.com/documentation/index.html?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_cloud&utm_term=introduction). To use the cloud service you will need a resource key. You can obtain one -from the [51Degrees Configurator](https://configure.51degrees.com/?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_cloud&utm_term=introduction). +from the [51Degrees configuration page](https://51degrees.com/configure/?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_cloud&utm_term=introduction). ## Usage diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/readme.md b/ip-intelligence/fiftyone_ipintelligence_examples/readme.md index 127fc3af..f812b3e8 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/readme.md +++ b/ip-intelligence/fiftyone_ipintelligence_examples/readme.md @@ -11,7 +11,7 @@ Usage examples for the 51Degrees IP intelligence engines. ## Cloud examples Require a resource key in the `_51DEGREES_RESOURCE_KEY` environment variable. -Obtain one from the [51Degrees Configurator](https://configure.51degrees.com/?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-readme.md&utm_term=cloud-examples). +Obtain one from the [51Degrees configuration page](https://51degrees.com/configure/?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-readme.md&utm_term=cloud-examples). - `cloud/gettingstarted_console.py` - resolve IP addresses using the cloud service from the console. diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/getallproperties_console.py b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/getallproperties_console.py index fc950959..e082fc68 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/getallproperties_console.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/getallproperties_console.py @@ -28,7 +28,7 @@ # how to enumerate the values returned. # # A resource key is required. You can obtain one from -# https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-getallproperties_console.py&utm_term=top - make sure to include all of the +# https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-getallproperties_console.py&utm_term=top - make sure to include all of the # properties that you want to see displayed by this example. # # Required PyPi Dependencies: @@ -107,7 +107,7 @@ def main(argv): "see " "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-getallproperties_console.py&utm_term=resource-key-required. " "A resource key with the properties required by this example " - "can be created for free at https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-getallproperties_console.py&utm_term=resource-key-required.") + "can be created for free at https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-getallproperties_console.py&utm_term=resource-key-required.") if __name__ == "__main__": main(sys.argv[1:]) diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_console.py b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_console.py index 48bfe83b..f9faf25f 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_console.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_console.py @@ -32,7 +32,7 @@ # 3. How to retrieve the results # # A resource key is required. You can obtain one from -# https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_console.py&utm_term=top +# https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_console.py&utm_term=top # # Required PyPi Dependencies: # - fiftyone_ipintelligence @@ -83,7 +83,7 @@ def run(self, resource_key, logger, output, cloud_endpoint = None): # general see the documentation at # https://51degrees.com/documentation/_pipeline_api__concepts__configuration__builders__index.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_console.py&utm_term=run settings = { - # Obtain a resource key from https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_console.py&utm_term=run + # Obtain a resource key from https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_console.py&utm_term=run "resource_key": resource_key } if cloud_endpoint: @@ -174,7 +174,7 @@ def main(argv): "information see " "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_console.py&utm_term=resource-key-required. " "A resource key with the properties required by this example " - "can be created for free at https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_console.py&utm_term=resource-key-required. " + "can be created for free at https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_console.py&utm_term=resource-key-required. " "Once complete, populate the environment variable mentioned at " "the start of this message with the key.") diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py index 59183683..90270ef4 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py @@ -28,7 +28,7 @@ # the 51Degrees cloud service. # # A resource key must be supplied in the `_51DEGREES_RESOURCE_KEY` environment -# variable. Obtain one from https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_web-app.py&utm_term=top +# variable. Obtain one from https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_web-app.py&utm_term=top # # Run with: # ``` @@ -92,7 +92,7 @@ def main(resource_key = None): raise Exception( "No resource key specified in the environment variable " f"'{ExampleUtils.CLOUD_RESOURCE_KEY_ENV_VAR}'. Obtain one from " - "https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_web-app.py&utm_term=resource-key-required") + "https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_web-app.py&utm_term=resource-key-required") build_pipeline(resource_key) app.run(debug=False) diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/metadata_console.py b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/metadata_console.py index 3d6d8f00..cef146be 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/metadata_console.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/metadata_console.py @@ -32,7 +32,7 @@ # resource key, rather than all properties the cloud service can return. # # A resource key is required. You can obtain one from -# https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-metadata_console.py&utm_term=top +# https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-metadata_console.py&utm_term=top # # Required PyPi Dependencies: # - fiftyone_ipintelligence @@ -106,7 +106,7 @@ def main(argv): "see " "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-metadata_console.py&utm_term=resource-key-required. " "A resource key with the properties required by this example " - "can be created for free at https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-metadata_console.py&utm_term=resource-key-required.") + "can be created for free at https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-metadata_console.py&utm_term=resource-key-required.") if __name__ == "__main__": main(sys.argv[1:]) diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/mixed_console.py b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/mixed_console.py index 2c228035..b9a0b2c3 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/mixed_console.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/mixed_console.py @@ -30,7 +30,7 @@ # # A resource key configured with both device detection and IP intelligence # properties is required. You can obtain one from -# https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-mixed_console.py&utm_term=top +# https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-mixed_console.py&utm_term=top # # Required PyPi Dependencies: # - fiftyone_ipintelligence @@ -172,7 +172,7 @@ def main(argv): f"'{ExampleUtils.CLOUD_RESOURCE_KEY_ENV_VAR}'. The 51Degrees cloud " "service is accessed using a 'ResourceKey'. A resource key " "configured with both device detection and IP intelligence " - "properties can be created at https://configure.51degrees.com/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-mixed_console.py&utm_term=resource-key-required.") + "properties can be created at https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-mixed_console.py&utm_term=resource-key-required.") if __name__ == "__main__": main(sys.argv[1:]) diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/tests/live_cloud.py b/ip-intelligence/fiftyone_ipintelligence_examples/tests/live_cloud.py index 36bc26ad..2109e4a2 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/tests/live_cloud.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/tests/live_cloud.py @@ -51,7 +51,7 @@ ACCESSIBLE_PROPERTIES_URL = ( "https://cloud.51degrees.com/api/v4/accessibleproperties?resource=") -CREATE_KEY_URL = "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" +CREATE_KEY_URL = "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" def _report_old_name(name, old_name): diff --git a/ip-intelligence/fiftyone_ipintelligence_onpremise/tests/live_cloud.py b/ip-intelligence/fiftyone_ipintelligence_onpremise/tests/live_cloud.py index 36bc26ad..2109e4a2 100644 --- a/ip-intelligence/fiftyone_ipintelligence_onpremise/tests/live_cloud.py +++ b/ip-intelligence/fiftyone_ipintelligence_onpremise/tests/live_cloud.py @@ -51,7 +51,7 @@ ACCESSIBLE_PROPERTIES_URL = ( "https://cloud.51degrees.com/api/v4/accessibleproperties?resource=") -CREATE_KEY_URL = "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" +CREATE_KEY_URL = "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" def _report_old_name(name, old_name): diff --git a/location/examples/cloud/gettingstarted.py b/location/examples/cloud/gettingstarted.py index 143cc373..adaacef0 100644 --- a/location/examples/cloud/gettingstarted.py +++ b/location/examples/cloud/gettingstarted.py @@ -36,7 +36,7 @@ # First create the device detection pipeline with the desired settings. -# You need to create a resource key at https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-gettingstarted.py&utm_term=top +# You need to create a resource key at https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-gettingstarted.py&utm_term=top # and paste it into the code, replacing !!YOUR_RESOURCE_KEY!! below. # Alternatively, add a _51DEGREES_RESOURCE_KEY environment variable. # resource_key is the old name of that variable. It is deprecated, and is @@ -70,9 +70,9 @@ def read_environment(name, old_name): if resource_key == "!!YOUR_RESOURCE_KEY!!": print(""" You need to create a resource key at - https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-gettingstarted.py&utm_term=resource-key-required and paste it into the code, + https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-gettingstarted.py&utm_term=resource-key-required and paste it into the code, 'replacing !!YOUR_RESOURCE_KEY!! - To get a resourcekey with the properties used in this example go to https://configure.51degrees.com/GCrtGh1L?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-gettingstarted.py&utm_term=resource-key-required + To get a resourcekey with the properties used in this example go to https://51degrees.com/configure/GCrtGh1L?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-gettingstarted.py&utm_term=resource-key-required """) else: diff --git a/location/examples/cloud/web.py b/location/examples/cloud/web.py index f893824f..c2b7d13a 100644 --- a/location/examples/cloud/web.py +++ b/location/examples/cloud/web.py @@ -36,7 +36,7 @@ # First create the location pipeline with the desired settings. -# You need to create a resource key at https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-web.py&utm_term=top +# You need to create a resource key at https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-web.py&utm_term=top # and paste it into the code, replacing !!YOUR_RESOURCE_KEY!! below. # Alternatively, add a _51DEGREES_RESOURCE_KEY environment variable. # resource_key is the old name of that variable. It is deprecated, and is @@ -70,9 +70,9 @@ def read_environment(name, old_name): if resource_key == "!!YOUR_RESOURCE_KEY!!": print(""" You need to create a resource key at - https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-web.py&utm_term=resource-key-required and paste it into the code, + https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-web.py&utm_term=resource-key-required and paste it into the code, 'replacing !!YOUR_RESOURCE_KEY!! - To get a resourcekey with the properties used in this example go to https://configure.51degrees.com/GCrtGh1L?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-web.py&utm_term=resource-key-required + To get a resourcekey with the properties used in this example go to https://51degrees.com/configure/GCrtGh1L?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=examples-cloud-web.py&utm_term=resource-key-required """) else: diff --git a/location/readme.md b/location/readme.md index dd21ab30..931eaf16 100644 --- a/location/readme.md +++ b/location/readme.md @@ -23,7 +23,7 @@ The [tested versions](https://51degrees.com/documentation/_product_summaries__te You can confirm this is working with the following micro-example. -* Create a resource key for free with the 51Degrees [configurator](https://configure.51degrees.com/6CTsmbPx?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_location&utm_term=from-pypi). This defines the properties you want to access. +* Create a resource key for free with the 51Degrees [configuration page](https://51degrees.com/configure/6CTsmbPx?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_location&utm_term=from-pypi). This defines the properties you want to access. * On the 'implement' page of the configurator, copy the resource key and replace YOUR_RESOURCE_KEY in the example below. Save this as examplelocation.py * Run the example with `python examplelocation.py` * Feel free to try different locations and property values. diff --git a/location/tests/live_cloud.py b/location/tests/live_cloud.py index 36bc26ad..2109e4a2 100644 --- a/location/tests/live_cloud.py +++ b/location/tests/live_cloud.py @@ -51,7 +51,7 @@ ACCESSIBLE_PROPERTIES_URL = ( "https://cloud.51degrees.com/api/v4/accessibleproperties?resource=") -CREATE_KEY_URL = "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" +CREATE_KEY_URL = "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" def _report_old_name(name, old_name): diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/readme.md b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/readme.md index c3457cd2..65d762ef 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/readme.md +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/readme.md @@ -31,7 +31,7 @@ The examples call the cloud service with a resource key or a licence key. A resource key carries the list of properties it returns. Create one carrying device detection and IP intelligence properties for free with the -[configurator](https://configure.51degrees.com?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-readme.md&utm_term=resource-key), +[configuration page](https://51degrees.com/configure?utm_source=github&utm_medium=readme&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-readme.md&utm_term=resource-key), and set the `_51DEGREES_RESOURCE_KEY` environment variable to it. A resource key limited to particular domains only answers a request whose origin is one of them, so set diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_console.py b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_console.py index 42ef1f62..2f4fcf70 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_console.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_console.py @@ -39,7 +39,7 @@ # # A resource key carries the list of properties it returns. Create one # carrying device detection and IP intelligence properties for free at -# https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_console.py&utm_term=header +# https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_console.py&utm_term=header # and set the _51DEGREES_RESOURCE_KEY environment variable to it, or pass it # as the first argument. # @@ -296,7 +296,7 @@ def main(argv): "A resource key carrying the device detection and IP " "intelligence properties this example uses can be created for " "free at " - "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_console.py&utm_term=resource-key-required. " + "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_console.py&utm_term=resource-key-required. " "Once complete, set the first environment variable named at " "the start of this message to the key.") return diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_web/app.py b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_web/app.py index f86331cf..445429d8 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_web/app.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_web/app.py @@ -37,7 +37,7 @@ # # A resource key carries the list of properties it returns. Create one # carrying device detection and IP intelligence properties for free at -# https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_web-app.py&utm_term=header +# https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_web-app.py&utm_term=header # and set the _51DEGREES_RESOURCE_KEY environment variable to it, or pass it # as the first argument. # @@ -434,7 +434,7 @@ def main(argv): "A resource key carrying the device detection and IP " "intelligence properties this example uses can be created for " "free at " - "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_web-app.py&utm_term=resource-key-required. " + "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_web-app.py&utm_term=resource-key-required. " "Once complete, set the first environment variable named at " "the start of this message to the key.") sys.exit(1) diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/pipeline.py b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/pipeline.py index 41895b64..7ce672ee 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/pipeline.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/pipeline.py @@ -114,7 +114,7 @@ def can_fill(engine): "The key carries neither the device detection nor the IP " "intelligence properties this example shows. Create a resource " "key that carries them for free at " - "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-pipeline.py&utm_term=key-carries-nothing") + "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-pipeline.py&utm_term=key-carries-nothing") builder = PipelineBuilder(pipeline_settings or {}).add(request_engine) diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/live_cloud.py b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/live_cloud.py index 36bc26ad..2109e4a2 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/live_cloud.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/live_cloud.py @@ -51,7 +51,7 @@ ACCESSIBLE_PROPERTIES_URL = ( "https://cloud.51degrees.com/api/v4/accessibleproperties?resource=") -CREATE_KEY_URL = "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" +CREATE_KEY_URL = "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" def _report_old_name(name, old_name): diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/readme.md b/pipeline/fiftyone_pipeline_cloudrequestengine/readme.md index e123445a..88b3e3cc 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/readme.md +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/readme.md @@ -16,7 +16,7 @@ The Pipeline is a generic web request intelligence and data processing solution This package uses the `engines` class created by the `fiftyone-pipeline-engines`. It makes available: -* A `Cloud Request Engine` which calls the 51Degrees cloud service to fetch properties and metadata about them based on a provided resource key. Get a resource key at https://configure.51degrees.com/?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine&utm_term=this-package-fiftyone_pipeline_cloudrequestengine +* A `Cloud Request Engine` which calls the 51Degrees cloud service to fetch properties and metadata about them based on a provided resource key. Get a resource key at https://51degrees.com/configure/?utm_source=pypi&utm_medium=package&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine&utm_term=this-package-fiftyone_pipeline_cloudrequestengine * A `Cloud Engine` template which reads data from the Cloud Request Engine. ## Credentials diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/src/fiftyone_pipeline_cloudrequestengine/constants.py b/pipeline/fiftyone_pipeline_cloudrequestengine/src/fiftyone_pipeline_cloudrequestengine/constants.py index fa7c879c..1ff994b8 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/src/fiftyone_pipeline_cloudrequestengine/constants.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/src/fiftyone_pipeline_cloudrequestengine/constants.py @@ -122,7 +122,7 @@ class Constants: "CloudRequestEngine needs a resource key or a licence key to " "authenticate with, as the cloud service answers 401 to a request " "that carries neither. Create a resource key for free at " - "https://configure.51degrees.com?utm_source=code&utm_medium=comment&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-src-fiftyone_pipeline_cloudrequestengine-constants.py&utm_term=no-credential") + "https://51degrees.com/configure?utm_source=code&utm_medium=comment&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-src-fiftyone_pipeline_cloudrequestengine-constants.py&utm_term=no-credential") MESSAGE_LICENSE_KEY_NEEDS_PROPERTIES = ( "CloudRequestEngine has a licence key and no requested_properties. " "A licence key names no properties of its own, so the cloud service " diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/live_cloud.py b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/live_cloud.py index 36bc26ad..2109e4a2 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/live_cloud.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/live_cloud.py @@ -51,7 +51,7 @@ ACCESSIBLE_PROPERTIES_URL = ( "https://cloud.51degrees.com/api/v4/accessibleproperties?resource=") -CREATE_KEY_URL = "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" +CREATE_KEY_URL = "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" def _report_old_name(name, old_name): diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudengine.py b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudengine.py index b88ed79d..2e34a95f 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudengine.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudengine.py @@ -41,7 +41,7 @@ def setUp(self): self.assertIsNotNone( self.resource_key, "You need to create a resource key at" - " https://configure.51degrees.com and paste it" + " https://51degrees.com/configure and paste it" " into the code, replacing !!YOUR_RESOURCE_KEY!!." " Please make sure to include IsMobile property." ) diff --git a/pipeline/fiftyone_pipeline_did/tests/live_cloud.py b/pipeline/fiftyone_pipeline_did/tests/live_cloud.py index 36bc26ad..2109e4a2 100644 --- a/pipeline/fiftyone_pipeline_did/tests/live_cloud.py +++ b/pipeline/fiftyone_pipeline_did/tests/live_cloud.py @@ -51,7 +51,7 @@ ACCESSIBLE_PROPERTIES_URL = ( "https://cloud.51degrees.com/api/v4/accessibleproperties?resource=") -CREATE_KEY_URL = "https://configure.51degrees.com?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" +CREATE_KEY_URL = "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=live_cloud.py&utm_term=resource-key-required" def _report_old_name(name, old_name): From 37fca5db5d760f500c8554585e36e6051b981a4c Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 23:05:47 +0000 Subject: [PATCH 008/102] Let Publish be run with common-ci's early release option (#118) --- .github/workflows/publish.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 195969ae..c02871b1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,6 +9,12 @@ on: common-ci-ref: type: string default: '' + # common-ci refuses a release less than a week after the last unless + # this is set, which is only for a release agreed to go out early. + allow-early-release: + description: 'Publish even though a package was released less than a week ago' + type: boolean + default: false jobs: Publish: @@ -19,6 +25,7 @@ jobs: org-name: ${{ github.event.repository.owner.login }} dryrun: ${{ inputs.dryrun || false }} common-ci-ref: ${{ inputs.common-ci-ref || '' }} + allow-early-release: ${{ inputs.allow-early-release || false }} cache-assets: true secrets: token: ${{ secrets.ACCESS_TOKEN }} From bc34f817984615d6b7b396ab20a4488c2d18db1c Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 23:27:13 +0000 Subject: [PATCH 009/102] Use common-ci's release plan in place of this repository's copy (#47) Step 1 of [common-ci#306](https://github.com/51Degrees/common-ci/issues/306). The release plan in `ci/packages.ps1`, which works out which packages a publish releases and at which version, moved to common-ci as `steps/release-plan.ps1` in [common-ci#307](https://github.com/51Degrees/common-ci/pull/307), and the rule that documentation, tests and examples do not count was added there by [common-ci#310](https://github.com/51Degrees/common-ci/pull/310). Both reached common-ci's `main`, which the workflows here use, in common-ci's release of 12 November. This repository then uses the shared step in place of its own copy, so that the rule is written once for every package repository. --- AGENTS.md | 7 +- ci/dispatch.Tests.ps1 | 12 +- ci/packages.Tests.ps1 | 206 +---------------------------- ci/packages.ps1 | 299 ++++-------------------------------------- 4 files changed, 40 insertions(+), 484 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 01221404..505c110a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -298,9 +298,10 @@ last tag, or when a package it depends on is released. Documentation description, keywords, urls, classifiers, readme, authors or maintainers does not count either, which `ci/release-plan-filter.ps1` works out with Python. The examples packages are tested but never published. common-ci's publish -carries one version, which here is only a label, and the release plan in -`ci/packages.ps1` decides what is built, published and tagged. Never push a -plain `4.5.x` tag, because nothing here reads one. +carries one version, which here is only a label, and the release plan +decides what is built, published and tagged. The release plan is common-ci's +`steps/release-plan.ps1`, which `ci/packages.ps1` loads, and common-ci tests +it. Never push a plain `4.5.x` tag, because nothing here reads one. `ci/packages.json` is the list of packages and what each depends on. Add a package there, with a `FirstVersion` if it has never been released, or it is diff --git a/ci/dispatch.Tests.ps1 b/ci/dispatch.Tests.ps1 index 3d75e0a2..352e667b 100644 --- a/ci/dispatch.Tests.ps1 +++ b/ci/dispatch.Tests.ps1 @@ -2,8 +2,8 @@ # # Each test builds a throwaway repository with two products, 'alpha' and # 'beta', whose ci/ scripts are written by the test, and runs the dispatcher -# from a folder laid out like a common-ci checkout, with common-ci's real -# steps/run-script.ps1, because that is how common-ci calls it. +# from a folder laid out like a common-ci checkout, with a copy of common-ci's +# real steps folder, because that is how common-ci calls it. BeforeAll { . (Join-Path $PSScriptRoot 'dispatch.ps1') @@ -17,6 +17,10 @@ BeforeAll { if ((Test-Path $script:RunScript) -eq $false) { throw "common-ci not found at '$commonCi'; set COMMON_CI to a checkout of it" } + # The whole steps folder is copied, because ci/packages.ps1 loads the + # release plan from the common-ci checkout that holds this repository's + # folder, and the release plan may load other steps beside it. + $script:Steps = Join-Path $commonCi 'steps' # A repository with packages.json naming one package in each product. function New-ProductRepo { @@ -45,8 +49,8 @@ BeforeAll { # A folder laid out like a common-ci checkout, which the dispatcher runs in. function New-CommonCi { $path = Join-Path ([IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString()) - $steps = New-Item -ItemType Directory -Force (Join-Path $path 'steps') - Copy-Item $script:RunScript $steps + $null = New-Item -ItemType Directory -Force $path + Copy-Item -Recurse $script:Steps (Join-Path $path 'steps') return $path } } diff --git a/ci/packages.Tests.ps1 b/ci/packages.Tests.ps1 index 243d87a6..63066049 100644 --- a/ci/packages.Tests.ps1 +++ b/ci/packages.Tests.ps1 @@ -1,9 +1,11 @@ -# Tests for ci/packages.ps1. +# Tests for ci/packages.ps1 and ci/release-plan-filter.ps1. # # The selection rules are tested against a small package list written here, so -# a test states exactly which graph it relies on. The release plan reads tags -# and diffs, so those tests build a throwaway git repository. One test reads the -# real packages.json, to catch a typo in a dependency name or a cycle. +# a test states exactly which graph it relies on. The release plan, which +# packages.ps1 loads from common-ci, is tested there. The tests of this +# repository's filter and of the build plan read tags and diffs, so they build +# a throwaway git repository. Some tests read the real packages.json, to catch +# a typo in a dependency name or a cycle, and to check its Ignore globs. BeforeAll { . (Join-Path $PSScriptRoot 'packages.ps1') @@ -75,40 +77,6 @@ AfterEach { $script:Repo = $null } -Describe 'Get-DependentClosure' { - It 'adds every package that depends on a changed one, through others' { - $closure = Get-DependentClosure $script:Graph @('core') - $closure | Sort-Object | Should -Be @( - 'core', 'dd', 'engines', 'examples', 'ipi', 'location') - } - - It 'adds nothing for a package nothing depends on' { - Get-DependentClosure $script:Graph @('did') | Should -Be @('did') - } - - It 'is empty when given nothing' { - @(Get-DependentClosure $script:Graph @()).Count | Should -Be 0 - } -} - -Describe 'Sort-ByDependency' { - It 'puts every package after the packages it depends on' { - $order = Sort-ByDependency $script:Graph @('dd', 'engines', 'core') - $order | Should -Be @('core', 'engines', 'dd') - } - - It 'ignores dependencies that are not being sorted' { - Sort-ByDependency $script:Graph @('dd') | Should -Be @('dd') - } - - It 'refuses a cycle rather than looping' { - $cycle = @( - New-Package 'a' 'p' 'p/a' @('b') - New-Package 'b' 'p' 'p/b' @('a')) - { Sort-ByDependency $cycle @('a', 'b') } | Should -Throw '*cycle*' - } -} - Describe 'Resolve-AffectedProducts' { It 'tests only the product of a package nothing depends on' { Resolve-AffectedProducts $script:Graph @('device/dd/a.py') | @@ -147,168 +115,6 @@ Describe 'Resolve-AffectedProducts' { } } -Describe 'Get-ReleasePlan' { - It 'releases nothing but first releases when nothing changed since the tags' { - $script:Repo = New-Repo $script:AllFiles $script:AllTags - Add-Commit $script:Repo @() - $plan = @(Get-ReleasePlan $script:Repo $script:Graph) - $plan.Name | Should -Be @('ipi') - $plan[0].Version | Should -Be '4.5.0' - $plan[0].Reason | Should -Be 'first release' - } - - It 'releases a changed package at the next patch, and its dependents' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('pipeline/engines/a.py') - $plan = @(Get-ReleasePlan $script:Repo $script:Graph) - $plan.Name | Should -Be @('engines', 'dd', 'ipi') - ($plan | Where-Object Name -eq 'engines').Version | Should -Be '4.5.39' - ($plan | Where-Object Name -eq 'dd').Version | Should -Be '4.5.97' - ($plan | Where-Object Name -eq 'dd').Reason | - Should -Be 'a package it depends on is released' - ($plan | Where-Object Name -eq 'ipi').Version | Should -Be '4.5.1' - } - - It 'releases a vendoring package when the vendored folder changes' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('pipeline/owid/a.py') - @(Get-ReleasePlan $script:Repo $script:Graph).Name | Should -Be @('did') - } - - It 'releases nothing for a change to an unpublished package' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('device/examples/a.py') - @(Get-ReleasePlan $script:Repo $script:Graph).Count | Should -Be 0 - } - - It 'releases nothing for a change outside every package' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('ci/build.ps1', 'device/docs/a.md') - @(Get-ReleasePlan $script:Repo $script:Graph).Count | Should -Be 0 - } - - It 'releases nothing a second time from a commit already released' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('device/dd/a.py') - git -C $script:Repo tag 'dd/4.5.97' - @(Get-ReleasePlan $script:Repo $script:Graph).Count | Should -Be 0 - } - - It 'continues from the highest tag, not the latest one made' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + @( - 'ipi/4.5.0', 'dd/4.5.9')) - Add-Commit $script:Repo @('device/dd/a.py') - (@(Get-ReleasePlan $script:Repo $script:Graph) | - Where-Object Name -eq 'dd').Version | Should -Be '4.5.97' - } - - It 'does not read another package''s tags as its own' { - # 'ipi' must not see tags of a package whose name starts with 'ipi'. - $graph = $script:Graph + (New-Package 'ipi_cloud' 'ipi' 'ipi/cloud' -FirstVersion '4.5.0') - $script:Repo = New-Repo ($script:AllFiles + 'ipi/cloud/a.py') ( - $script:AllTags + 'ipi_cloud/4.5.7') - $plan = @(Get-ReleasePlan $script:Repo $graph) - ($plan | Where-Object Name -eq 'ipi').Version | Should -Be '4.5.0' - } - - It 'plans a changed package for a caller that stops on native errors' { - # publish-package.ps1 stops on a failing native command; 'git diff - # --quiet' exiting 1 for a changed package once failed the publish. - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('device/dd/a.py') - $plan = & { - $ErrorActionPreference = 'Stop' - $PSNativeCommandUseErrorActionPreference = $true - @(Get-ReleasePlan $script:Repo $script:Graph) - } - $plan.Name | Should -Be @('dd') - } - - It 'reads the tags whatever folder it runs from' { - # PowerShell expands a wildcard in a native command's argument into - # matching files, so a tag pattern run from a folder that holds a - # folder of the same name, as the repository root holds 'location', - # once found no tags. - $script:Repo = New-Repo $script:AllFiles $script:AllTags - $here = Join-Path ([IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString()) - $null = New-Item -ItemType Directory -Force (Join-Path $here 'location') - $null = New-Item -ItemType File (Join-Path $here 'location' 'setup.py') - Push-Location $here - try { - (Get-ReleasedVersions $script:Repo 'location')[-1] | Should -Be ([version]'4.5.4') - } finally { - Pop-Location - Remove-Item -Recurse -Force $here - } - } - - It 'refuses a never-released package with no FirstVersion' { - $graph = @(New-Package 'new' 'p' 'p/new') - $script:Repo = New-Repo @('p/new/a.py') @() - { Get-ReleasePlan $script:Repo $graph } | Should -Throw '*FirstVersion*' - } - - It 'says how many files counted' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('device/dd/a.py', 'device/dd/b.py') - (@(Get-ReleasePlan $script:Repo $script:Graph) | - Where-Object Name -eq 'dd').Reason | - Should -Be 'changed since 4.5.96 (2 files)' - } - - It 'releases nothing for a change only to documentation, tests or examples' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @( - 'device/dd/readme.md', 'device/dd/docs/guide.txt', - 'device/dd/tests/test_a.py', 'device/dd/test/a.py', - 'device/dd/examples/a.py', 'device/dd/LICENSE', - 'pipeline/core/sub/notes.md') - @(Get-ReleasePlan $script:Repo $script:Graph).Count | Should -Be 0 - } - - It 'ignores documentation, tests and examples whatever their case' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @( - 'device/dd/README.MD', 'device/dd/Tests/a.py', - 'device/dd/Examples/a.py') - @(Get-ReleasePlan $script:Repo $script:Graph).Count | Should -Be 0 - } - - It 'releases for the code changed beside the documentation' { - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('device/dd/readme.md', 'device/dd/a.py') - $plan = @(Get-ReleasePlan $script:Repo $script:Graph) - $plan.Name | Should -Be @('dd') - $plan[0].Reason | Should -Be 'changed since 4.5.96 (1 file)' - } - - It 'leaves out the files a package''s Ignore globs match' { - $graph = @($script:Graph | ForEach-Object { $_.PSObject.Copy() }) - ($graph | Where-Object Name -eq 'dd') | - Add-Member Ignore @('device/dd/tox.ini') - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('device/dd/tox.ini') - @(Get-ReleasePlan $script:Repo $graph).Count | Should -Be 0 - } - - It 'counts documentation for a package that turns the defaults off' { - $graph = @($script:Graph | ForEach-Object { $_.PSObject.Copy() }) - ($graph | Where-Object Name -eq 'dd') | Add-Member IgnoreDefaults $false - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('device/dd/readme.md') - @(Get-ReleasePlan $script:Repo $graph).Name | Should -Be @('dd') - } - - It 'refuses IgnoreDefaults given as text' { - $graph = @($script:Graph | ForEach-Object { $_.PSObject.Copy() }) - ($graph | Where-Object Name -eq 'dd') | Add-Member IgnoreDefaults 'false' - $script:Repo = New-Repo $script:AllFiles ($script:AllTags + 'ipi/4.5.0') - Add-Commit $script:Repo @('device/dd/readme.md') - { Get-ReleasePlan $script:Repo $graph } | - Should -Throw '*IgnoreDefaults*true or false*' - } -} - Describe 'release-plan-filter.ps1' { BeforeAll { # A setup.py, setup.cfg and pyproject.toml like the ones here, with diff --git a/ci/packages.ps1 b/ci/packages.ps1 index ec4bb89b..17f73ca2 100644 --- a/ci/packages.ps1 +++ b/ci/packages.ps1 @@ -1,117 +1,26 @@ -# Shared by the scripts in this folder, which dot-source it. Reads the -# packages this repository publishes from packages.json, works out which -# products a pull request touches, and which packages a publish releases at -# which version. +# Shared by the scripts in this folder, which dot-source it. Works out which +# products a pull request touches, what a build of HEAD makes, and checks each +# package's tox.ini. # -# Each package has its own version, tagged '/'. A package is -# released when a file that counts under its folders changed since its last -# tag, or when a package it depends on is being released, because its -# requirement on that package moves. This is the scheme in 51Degrees/rust#205, -# which the per language repositories follow. -# -# Every file counts except those matched by the package's Ignore globs in -# packages.json and, unless its IgnoreDefaults is false, by -# $ReleasePlanDefaultIgnore, so a change only to documentation, tests or -# examples releases nothing. release-plan-filter.ps1 then leaves out a -# manifest whose change is only to metadata such as links. These are the -# fields and the filter of common-ci's steps/release-plan.ps1. -# -# A submodule in Path or ExtraPaths changes as one path, its own, so any move -# of it counts. Neither the globs nor the filter see inside it. - -# Reads packages.json. Kept as a function so the tests can give their own list. -function Get-Packages([string]$RepoPath) { - return Get-Content -Raw (Join-Path $RepoPath 'ci/packages.json') | - ConvertFrom-Json -} - -# The folders whose changes count as a change to the package: its own folder, -# and any folder it takes files from at build time, such as a submodule it -# vendors. -function Get-PackagePaths($Package) { - $paths = @($Package.Path) - if ($Package.ExtraPaths) { - $paths += $Package.ExtraPaths - } - return $paths -} - -function Test-PathUnder([string]$Path, [string]$Folder) { - return $Path -eq $Folder -or $Path.StartsWith("$Folder/") -} - -# The files whose changes do not release a package, being documentation, -# tests, examples and LICENSE files wherever they sit and whatever their case, -# unless the package sets IgnoreDefaults to false. These are git glob -# pathspecs from the repository root, where '**/' matches any number of -# folders, none included. -$ReleasePlanDefaultIgnore = @( - '**/*.md' - '**/docs/**' - '**/tests/**' - '**/test/**' - '**/examples/**' - '**/LICENSE*' -) - -# The pathspecs that leave out of a package's changes the files its Ignore -# globs match and, unless IgnoreDefaults is false, the default set. -# PowerShell on Linux and macOS replaces a native command's argument that -# holds a '*' with the files it matches, if any. Each of these starts with -# ':(', which no file in a checkout starts with, so git receives it as written. -function Get-PackageExcludes($Package) { - $defaults = $Package.IgnoreDefaults - if ($null -ne $defaults -and $defaults -isnot [bool]) { - throw "$($Package.Name) gives IgnoreDefaults as '$defaults', where " + - "packages.json must give true or false." - } - $excludes = @($Package.Ignore | Where-Object { $_ } | - ForEach-Object { ":(exclude,glob)$_" }) - if ($defaults -ne $false) { - # The defaults ignore case, as one language names a folder Tests or - # Examples where another names it tests or examples. - $excludes = @($ReleasePlanDefaultIgnore | - ForEach-Object { ":(exclude,glob,icase)$_" }) + $excludes - } - return $excludes -} - -# The files under the package's folders that changed since the given tag, as -# paths from the repository root, apart from those it ignores. -function Get-ChangedFiles([string]$RepoPath, $Package, [string]$From) { - # A failure is reported below, naming the package, whatever the caller's - # preference. Set for this function only. - $PSNativeCommandUseErrorActionPreference = $false - $pathspecs = @(Get-PackagePaths $Package) + @(Get-PackageExcludes $Package) - $files = @(& git -C $RepoPath diff --name-only $From HEAD -- $pathspecs) - if ($LASTEXITCODE -ne 0) { - throw "git could not list the changes to $($Package.Name) since $From." - } - return $files -} - -# The files that count among a package's changed files. The repository's -# ci/release-plan-filter.ps1 decides when there is one, and otherwise every -# file counts. A path the filter returns that it was not given stops the -# plan, because a filter that rewrote a path would otherwise release a -# package on a file that never changed. -function Select-CountedFiles([string]$RepoPath, $Package, [string]$From, - [string[]]$Files) { - $filter = Join-Path $RepoPath 'ci/release-plan-filter.ps1' - if ($Files.Count -eq 0 -or (Test-Path $filter -PathType Leaf) -eq $false) { - return $Files - } - $filter = (Resolve-Path $filter).ProviderPath - $kept = @(& $filter -RepoPath $RepoPath -Package $Package -From $From ` - -Files $Files | Where-Object { $_ }) - foreach ($file in $kept) { - if ($Files -cnotcontains $file) { - throw "ci/release-plan-filter.ps1 returned '$file' for " + - "$($Package.Name), which is not one of the files it was given." - } - } - return $kept +# Which packages a publish releases, and at which version, is worked out by +# common-ci's steps/release-plan.ps1 from ci/packages.json. common-ci runs +# these scripts from its own root, with this repository checked out inside +# it. A checkout of common-ci beside this repository is found too, or one +# elsewhere can be named with COMMON_CI. +$releasePlan = @( + $env:COMMON_CI, + (Join-Path $PSScriptRoot '..' '..'), + (Join-Path $PSScriptRoot '..' '..' 'common-ci')) | + Where-Object { $_ } | + ForEach-Object { Join-Path $_ 'steps' 'release-plan.ps1' } | + Where-Object { Test-Path $_ } | + Select-Object -First 1 +if ($null -eq $releasePlan) { + throw "common-ci's steps/release-plan.ps1 was not found. Set COMMON_CI " + + "to a checkout of common-ci." } +. $releasePlan +Remove-Variable releasePlan # Each tox.ini that does not install every package its package depends on, # directly or through another, from this checkout, as a line naming what is @@ -158,56 +67,6 @@ function Get-ToxGaps([string]$RepoPath, $Packages = $null) { return $gaps } -# The names of the given packages and of every package that depends on one of -# them, directly or through another. -function Get-DependentClosure($Packages, [string[]]$Names) { - $closure = [Collections.Generic.HashSet[string]]::new() - foreach ($name in @($Names | Where-Object { $_ })) { - $null = $closure.Add($name) - } - $grew = $true - while ($grew -eq $true) { - $grew = $false - foreach ($package in $Packages) { - if ($closure.Contains($package.Name) -eq $true) { - continue - } - foreach ($dependency in $package.DependsOn) { - if ($closure.Contains($dependency) -eq $true) { - $null = $closure.Add($package.Name) - $grew = $true - break - } - } - } - } - return @($closure) -} - -# The named packages, each after every package it depends on, so a release -# never publishes a package before the version it requires exists. -function Sort-ByDependency($Packages, [string[]]$Names) { - $remaining = [Collections.Generic.List[string]]::new([string[]]@($Names)) - $sorted = [Collections.Generic.List[string]]::new() - while ($remaining.Count -gt 0) { - $ready = @($remaining | Where-Object { - $name = $_ - $package = $Packages | Where-Object { $_.Name -eq $name } - @($package.DependsOn | Where-Object { - $remaining.Contains($_) -eq $true - }).Count -eq 0 - } | Sort-Object) - if ($ready.Count -eq 0) { - throw "packages.json has a dependency cycle among: $($remaining -join ', ')" - } - foreach ($name in $ready) { - $sorted.Add($name) - $null = $remaining.Remove($name) - } - } - return @($sorted) -} - # The products a set of changed files touches. A file in a package's folders # touches that package's product and the product of every package depending on # it, because a change to pipeline can break device-detection. @@ -251,10 +110,7 @@ function Resolve-AffectedProducts($Packages, [string[]]$Changed) { } # The products a pull request changes, or every product when the checkout is -# not a pull request (a publish, or a build of the branch itself), as -# 51degrees-cxx does. A pull request is checked out with the branch it merges -# into merged in, so the merge base with that branch leaves only the pull -# request's own changes. +# not a pull request (a publish, or a run on main), as 51degrees-cxx does. function Get-AffectedProducts([string]$RepoPath, [string]$Branch = 'main') { # merge-base fails where there is no such branch, which is an answer here. # Set for this function only, so a caller that stops on a failing native @@ -271,117 +127,6 @@ function Get-AffectedProducts([string]$RepoPath, [string]$Branch = 'main') { return Resolve-AffectedProducts $packages $changed } -# The parts of a version such as 4.5.38, or $null for anything else. -function ConvertTo-VersionParts([string]$Text) { - $match = [regex]::Match($Text, '^(\d+)\.(\d+)\.(\d+)$') - if ($match.Success -eq $false) { - return $null - } - return [version]::new([int]$match.Groups[1].Value, - [int]$match.Groups[2].Value, [int]$match.Groups[3].Value) -} - -# The package's released versions, read from its '/' tags, -# highest last. The '/' after the name keeps fiftyone_ipintelligence from -# reading the tags of fiftyone_ipintelligence_cloud. -function Get-ReleasedVersions([string]$RepoPath, [string]$Name, - [switch]$AtHead) { - # Tags are found by prefix, not with a 'name/*' pattern: PowerShell on - # Linux and macOS expands a '*' in an argument to a native command into - # matching files, so from a folder holding a 'location' folder git would - # be handed file names and find no tags. - $arguments = @('-C', $RepoPath, 'for-each-ref', - '--format=%(refname:strip=2)', "refs/tags/$Name/") - if ($AtHead -eq $true) { - $arguments += @('--points-at', 'HEAD') - } - $versions = foreach ($tag in (& git @arguments)) { - ConvertTo-VersionParts $tag.Substring($Name.Length + 1) - } - return @($versions | Where-Object { $null -ne $_ } | Sort-Object) -} - -# What a publish of HEAD releases: one entry per package, in the order to -# publish them, each with the version it is released at and why. -# -# A package already tagged at HEAD was released from this commit, so it is -# left out, which makes a second publish of the same commit release nothing. -# A package with no tag has never been released and starts at its FirstVersion -# from packages.json. Packages that are not published, the examples, are never -# in the plan; a change to them is tested but releases nothing. -function Get-ReleasePlan([string]$RepoPath, $Packages = $null) { - if ($null -eq $Packages) { - $Packages = Get-Packages $RepoPath - } - $published = @($Packages | Where-Object { $_.Publish -eq $true }) - - $previous = @{} - $reasons = @{} - foreach ($package in $published) { - $atHead = Get-ReleasedVersions $RepoPath $package.Name -AtHead - if ($atHead.Count -gt 0) { - continue - } - $released = Get-ReleasedVersions $RepoPath $package.Name - if ($released.Count -eq 0) { - if ([string]::IsNullOrEmpty($package.FirstVersion) -eq $true) { - throw "$($package.Name) has never been released and " + - "packages.json gives it no FirstVersion." - } - $previous[$package.Name] = $null - $reasons[$package.Name] = 'first release' - continue - } - $last = $released[-1] - $previous[$package.Name] = $last - $tag = "$($package.Name)/$last" - $files = @(Get-ChangedFiles $RepoPath $package $tag) - $counted = @(Select-CountedFiles $RepoPath $package $tag $files) - if ($counted.Count -gt 0) { - $noun = 'files' - if ($counted.Count -eq 1) { - $noun = 'file' - } - $reasons[$package.Name] = - "changed since $last ($($counted.Count) $noun)" - } - # A filter may leave an exit code that was an answer, which must not - # read as a failure to the script that called this. - $global:LASTEXITCODE = 0 - } - - # A dependent is released with its dependency, as long as it was not - # already released from this commit. - $candidates = @($published.Name | Where-Object { - $previous.ContainsKey($_) -eq $true - }) - $changed = @($reasons.Keys) - $toRelease = @(Get-DependentClosure $published $changed | Where-Object { - $candidates -contains $_ - }) - - foreach ($name in (Sort-ByDependency $published $toRelease)) { - $package = $published | Where-Object { $_.Name -eq $name } - $last = $previous[$name] - if ($null -eq $last) { - $version = $package.FirstVersion - } else { - $version = "$($last.Major).$($last.Minor).$($last.Build + 1)" - } - $reason = $reasons[$name] - if ($null -eq $reason) { - $reason = 'a package it depends on is released' - } - [pscustomobject]@{ - Name = $name - Path = $package.Path - Version = $version - Previous = $last - Reason = $reason - } - } -} - # What a build of HEAD makes: the release plan, or, when nothing changed since # the last release, every published package at its released version. Nothing # is published then, because package-update-required.ps1 finds the release From f084e8534ecbff33e68b69f04b7c48a3a20f4b8a Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 23:27:24 +0000 Subject: [PATCH 010/102] Keep certificate checks on in the usage sharing example (#116) Closes #51. --- .../onpremise/shareusage.py | 7 -- .../test_shareusage_certificate_checks.py | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 device-detection/fiftyone_devicedetection_examples/tests/test_shareusage_certificate_checks.py diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/onpremise/shareusage.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/onpremise/shareusage.py index 51bcff0c..fec5b948 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/onpremise/shareusage.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/onpremise/shareusage.py @@ -65,13 +65,6 @@ from fiftyone_devicedetection_shared.example_constants import EVIDENCE_FILE_NAME from ruamel.yaml import YAML -# Disable SSL verification for testing -import urllib3 -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) -import requests -_original_post = requests.post -requests.post = lambda *args, **kwargs: _original_post(*args, **{**kwargs, 'verify': False}) - # Configurable settings REQUESTED_PACKAGE_SIZE = 10 # Send after 10 entries (default is 10) SHARE_PERCENTAGE = 1 # Share 100% of data (1 = 100%) diff --git a/device-detection/fiftyone_devicedetection_examples/tests/test_shareusage_certificate_checks.py b/device-detection/fiftyone_devicedetection_examples/tests/test_shareusage_certificate_checks.py new file mode 100644 index 00000000..cf23df01 --- /dev/null +++ b/device-detection/fiftyone_devicedetection_examples/tests/test_shareusage_certificate_checks.py @@ -0,0 +1,66 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +The usage sharing example sends with certificate checks on, because it is the +code people copy into their own applications. The checks read the example's +source, so they need no data file and no network. +""" + +import ast +import os +import unittest + +EXAMPLE = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "src", + "fiftyone_devicedetection_examples", "onpremise", "shareusage.py") + + +class ShareUsageCertificateCheckTests(unittest.TestCase): + + def setUp(self): + with open(EXAMPLE, encoding="utf-8") as source: + self.tree = ast.parse(source.read()) + + def test_does_not_replace_requests_post(self): + for node in ast.walk(self.tree): + if isinstance(node, ast.Assign): + for target in node.targets: + self.assertNotEqual("requests.post", ast.unparse(target)) + + def test_does_not_turn_off_certificate_checks(self): + for node in ast.walk(self.tree): + if isinstance(node, ast.keyword): + self.assertNotEqual("verify", node.arg) + if isinstance(node, ast.Dict): + for key in node.keys: + self.assertFalse( + isinstance(key, ast.Constant) and key.value == "verify") + + def test_does_not_silence_certificate_warnings(self): + for node in ast.walk(self.tree): + if isinstance(node, ast.Call): + self.assertNotIn("disable_warnings", ast.unparse(node.func)) + + +if __name__ == "__main__": + unittest.main() From 175ca4adab7d765f22e2ba61ed37f3c410bbbac3 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 23:46:34 +0000 Subject: [PATCH 011/102] Hand the web request to the pipeline in the IP Intelligence web examples (#119) The Usage Sharing Element accepts no Evidence, and shares what it finds in the web request that the web integration adds as `server.http-request`, together with the Evidence given to the Pipeline (`found_evidence` in [`share_usage.py` lines 432 to 458 at 5b5a833](https://github.com/51Degrees/51degrees-python/blob/5b5a833239d435676a1ab0450be22bce0c0807a2/pipeline/fiftyone_pipeline_engines_fiftyone/src/fiftyone_pipeline_engines_fiftyone/share_usage.py#L432-L458)). `webevidence` in [`pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/web.py` line 139](https://github.com/51Degrees/51degrees-python/blob/5b5a833239d435676a1ab0450be22bce0c0807a2/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/web.py#L139) adds it for every request it reads. --- .../cloud/gettingstarted_web/app.py | 5 ++ .../onpremise/gettingstarted_web/app.py | 5 ++ .../test_web_examples_hand_over_request.py | 71 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 ip-intelligence/fiftyone_ipintelligence_examples/tests/test_web_examples_hand_over_request.py diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py index 90270ef4..c7100800 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py @@ -37,6 +37,7 @@ from flask import Flask, request +from fiftyone_pipeline_core.web import webevidence from fiftyone_ipintelligence.ipintelligence_pipelinebuilder import IpIntelligencePipelineBuilder from fiftyone_ipintelligence_examples.example_utils import ExampleUtils from fiftyone_ipintelligence_shared.constants import Constants @@ -63,6 +64,10 @@ def index(): # Create the flowdata object for this request. flowdata = pipeline.create_flowdata() + # Hand the whole request to the pipeline. Each engine takes the + # Evidence it reads from it, and usage sharing takes the request. + flowdata.evidence.add_from_dict(webevidence(request)) + # Use the IP address supplied as a query parameter, or fall back # to the address of the requester. client_ip = request.args.get("client-ip", request.remote_addr) diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/onpremise/gettingstarted_web/app.py b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/onpremise/gettingstarted_web/app.py index e6f25806..c65b5a4b 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/onpremise/gettingstarted_web/app.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/onpremise/gettingstarted_web/app.py @@ -38,6 +38,7 @@ from flask import Flask, request +from fiftyone_pipeline_core.web import webevidence from fiftyone_ipintelligence.ipintelligence_pipelinebuilder import IpIntelligencePipelineBuilder from fiftyone_ipintelligence_examples.example_utils import ExampleUtils from fiftyone_ipintelligence_examples.onpremise.countries_pipeline import ( @@ -103,6 +104,10 @@ def index(): # the results of the lookup straight away. with pipeline.create_flowdata() as flowdata: + # Hand the whole request to the pipeline. Each engine takes the + # Evidence it reads from it, and usage sharing takes the request. + flowdata.evidence.add_from_dict(webevidence(request)) + # Use the IP address supplied as a query parameter, or fall back # to the address of the requester. client_ip = request.args.get("client-ip", request.remote_addr) diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_web_examples_hand_over_request.py b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_web_examples_hand_over_request.py new file mode 100644 index 00000000..c77f83af --- /dev/null +++ b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_web_examples_hand_over_request.py @@ -0,0 +1,71 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Each web example hands the whole web request to the pipeline with +webevidence, which adds it as server.http-request. The usage sharing element +accepts no Evidence and shares what it finds in that request, so an example +that adds only the Evidence its engine reads shares nothing else. The checks +read the examples' source, so they need no data file and no network. +""" + +import ast +import os +import unittest + +EXAMPLES = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "src", + "fiftyone_ipintelligence_examples") +WEB_EXAMPLES = [ + os.path.join(EXAMPLES, "cloud", "gettingstarted_web", "app.py"), + os.path.join(EXAMPLES, "onpremise", "gettingstarted_web", "app.py"), +] + + +def called_names(function): + # The names of every function the given function calls. + names = set() + for node in ast.walk(function): + if isinstance(node, ast.Call): + target = node.func + names.add(target.attr if isinstance(target, ast.Attribute) + else getattr(target, "id", None)) + return names + + +class WebExamplesHandOverRequestTests(unittest.TestCase): + + def test_every_route_that_makes_flow_data_adds_the_web_request(self): + for path in WEB_EXAMPLES: + with open(path, encoding="utf-8") as source: + tree = ast.parse(source.read()) + routes = [node for node in ast.walk(tree) + if isinstance(node, ast.FunctionDef) + and "create_flowdata" in called_names(node)] + self.assertTrue(routes, path) + for route in routes: + with self.subTest(example=path, route=route.name): + self.assertIn("webevidence", called_names(route)) + + +if __name__ == "__main__": + unittest.main() From b1fc0903d7fdead3b743f59d1cd59361f37537a5 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 13 Nov 2026 23:57:47 +0000 Subject: [PATCH 012/102] Test each cloud example with no resource key set Each must end without an error, naming the environment variable to set and giving a tagged link to the page where a key is created. --- .../tests/test_cloud_examples_without_key.py | 132 ++++++++++++++++++ .../tests/test_cloud_examples_without_key.py | 122 ++++++++++++++++ location/tests/test_examples_without_key.py | 70 ++++++++++ .../tests/test_cloud_mixed_without_key.py | 82 +++++++++++ .../tests/test_creator_context_without_key.py | 53 +++++++ 5 files changed, 459 insertions(+) create mode 100644 device-detection/fiftyone_devicedetection_examples/tests/test_cloud_examples_without_key.py create mode 100644 ip-intelligence/fiftyone_ipintelligence_examples/tests/test_cloud_examples_without_key.py create mode 100644 location/tests/test_examples_without_key.py create mode 100644 pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_cloud_mixed_without_key.py create mode 100644 pipeline/fiftyone_pipeline_did/tests/test_creator_context_without_key.py diff --git a/device-detection/fiftyone_devicedetection_examples/tests/test_cloud_examples_without_key.py b/device-detection/fiftyone_devicedetection_examples/tests/test_cloud_examples_without_key.py new file mode 100644 index 00000000..cf6802fe --- /dev/null +++ b/device-detection/fiftyone_devicedetection_examples/tests/test_cloud_examples_without_key.py @@ -0,0 +1,132 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Runs each cloud example as it runs from a fresh clone, with no resource key +set. Each must end without an error, naming the environment variable to set +and giving a tagged link to the page where a key is created. +""" + +import io +import logging +import os +import runpy +import unittest +from contextlib import redirect_stdout +from unittest import mock + +from fiftyone_devicedetection_examples.example_utils import ExampleUtils +from fiftyone_devicedetection_examples.cloud import configurator_console +from fiftyone_devicedetection_examples.cloud import gettingstarted_console +from fiftyone_devicedetection_examples.cloud import metadata_console +from fiftyone_devicedetection_examples.cloud import nativemodellookup_console +from fiftyone_devicedetection_examples.cloud import taclookup_console +from fiftyone_devicedetection_examples.cloud.gettingstarted_web import ( + app as gettingstarted_web) +from fiftyone_devicedetection_examples.cloud.useragentclienthints_web import ( + app as useragentclienthints_web) + +# Every name a key can be read from, which a fresh clone does not set. +KEY_SETTINGS = [ + "_51DEGREES_RESOURCE_KEY", "resource_key", "RESOURCE_KEY", + "_51DEGREES_LICENSE_KEY", "license_key"] + +# A link to the page where a resource key is created, with the campaign +# tags every example's links carry. +CONFIGURE_LINK = ( + r"https://51degrees\.com/configure[^\s?]*\?utm_source=code" + r"&utm_medium=example&utm_campaign=51degrees-python&utm_content=") + + +class Recorder(logging.Handler): + """Keeps every message logged while it is attached.""" + + def __init__(self): + super().__init__(logging.DEBUG) + self.messages = [] + + def emit(self, record): + self.messages.append(record.getMessage()) + + +def run_without_key(run): + """Runs an example with no key in the environment, and returns what it + printed and logged.""" + printed = io.StringIO() + recorder = Recorder() + root = logging.getLogger() + root.addHandler(recorder) + try: + with mock.patch.dict(os.environ), redirect_stdout(printed): + for name in KEY_SETTINGS: + os.environ.pop(name, None) + run() + finally: + root.removeHandler(recorder) + return printed.getvalue() + "\n".join(recorder.messages) + + +class CloudExamplesWithoutKeyTests(unittest.TestCase): + + def assert_says_how_to_get_a_key(self, said, names_variable=True): + self.assertRegex(said, CONFIGURE_LINK) + if names_variable: + self.assertIn(ExampleUtils.RESOURCE_KEY_ENV_VAR, said) + + def test_configurator_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: configurator_console.main([]))) + + def test_gettingstarted_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: gettingstarted_console.main([]))) + + def test_metadata_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: metadata_console.main([]))) + + def test_nativemodellookup_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: nativemodellookup_console.main([]))) + + def test_taclookup_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: taclookup_console.main([]))) + + def test_gettingstarted_web(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: gettingstarted_web.main([]))) + + def test_useragentclienthints_web(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: useragentclienthints_web.main([]))) + + def test_failuretomatch(self): + # This example has no main and runs when it is run as a script. + self.assert_says_how_to_get_a_key(run_without_key( + lambda: runpy.run_module( + "fiftyone_devicedetection_examples.cloud.failuretomatch", + run_name="__main__"))) + + +if __name__ == "__main__": + unittest.main() diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_cloud_examples_without_key.py b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_cloud_examples_without_key.py new file mode 100644 index 00000000..3d5f02c3 --- /dev/null +++ b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_cloud_examples_without_key.py @@ -0,0 +1,122 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Runs each cloud example as it runs from a fresh clone, with no resource key +set. Each must end without an error, naming the environment variable to set +and giving a tagged link to the page where a key is created. +""" + +import io +import logging +import os +import unittest +from contextlib import redirect_stdout +from unittest import mock + +from fiftyone_ipintelligence_examples.example_utils import ExampleUtils +from fiftyone_ipintelligence_examples.cloud import getallproperties_console +from fiftyone_ipintelligence_examples.cloud import gettingstarted_console +from fiftyone_ipintelligence_examples.cloud import metadata_console +from fiftyone_ipintelligence_examples.cloud.gettingstarted_web import ( + app as gettingstarted_web) + +# The mixed example combines IP intelligence with device detection, which +# is an optional dependency. +try: + from fiftyone_ipintelligence_examples.cloud import mixed_console +except ImportError: + mixed_console = None + +# Every name a key can be read from, which a fresh clone does not set. +KEY_SETTINGS = [ + "_51DEGREES_RESOURCE_KEY", "resource_key", "RESOURCE_KEY", + "_51DEGREES_LICENSE_KEY", "license_key"] + +# A link to the page where a resource key is created, with the campaign +# tags every example's links carry. +CONFIGURE_LINK = ( + r"https://51degrees\.com/configure[^\s?]*\?utm_source=code" + r"&utm_medium=example&utm_campaign=51degrees-python&utm_content=") + + +class Recorder(logging.Handler): + """Keeps every message logged while it is attached.""" + + def __init__(self): + super().__init__(logging.DEBUG) + self.messages = [] + + def emit(self, record): + self.messages.append(record.getMessage()) + + +def run_without_key(run): + """Runs an example with no key in the environment, and returns what it + printed and logged.""" + printed = io.StringIO() + recorder = Recorder() + root = logging.getLogger() + root.addHandler(recorder) + try: + with mock.patch.dict(os.environ), redirect_stdout(printed): + for name in KEY_SETTINGS: + os.environ.pop(name, None) + run() + finally: + root.removeHandler(recorder) + return printed.getvalue() + "\n".join(recorder.messages) + + +class CloudExamplesWithoutKeyTests(unittest.TestCase): + + def assert_says_how_to_get_a_key(self, said): + self.assertIn(ExampleUtils.CLOUD_RESOURCE_KEY_ENV_VAR, said) + self.assertRegex(said, CONFIGURE_LINK) + + def test_getallproperties_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: getallproperties_console.main([]))) + + def test_gettingstarted_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: gettingstarted_console.main([]))) + + def test_metadata_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: metadata_console.main([]))) + + @unittest.skipIf( + mixed_console is None, "device detection package not available") + def test_mixed_console(self): + self.assert_says_how_to_get_a_key( + run_without_key(lambda: mixed_console.main([]))) + + def test_gettingstarted_web(self): + # The web example takes the key as its one argument, and starts no + # server when there is none. + self.assert_says_how_to_get_a_key( + run_without_key(lambda: gettingstarted_web.main())) + + +if __name__ == "__main__": + unittest.main() diff --git a/location/tests/test_examples_without_key.py b/location/tests/test_examples_without_key.py new file mode 100644 index 00000000..33f4158b --- /dev/null +++ b/location/tests/test_examples_without_key.py @@ -0,0 +1,70 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Runs each cloud example as it runs from a fresh clone, with no resource key +set. Each must end without an error and give a tagged link to the page +where a key is created. +""" + +import io +import os +import runpy +import unittest +from contextlib import redirect_stdout +from pathlib import Path +from unittest import mock + +EXAMPLES = Path(__file__).resolve().parent.parent / "examples" / "cloud" + +# Every name a key can be read from, which a fresh clone does not set. +KEY_SETTINGS = ["_51DEGREES_RESOURCE_KEY", "resource_key", "RESOURCE_KEY"] + +# A link to the page where a resource key is created, with the campaign +# tags every example's links carry. +CONFIGURE_LINK = ( + r"https://51degrees\.com/configure[^\s?]*\?utm_source=code" + r"&utm_medium=example&utm_campaign=51degrees-python&utm_content=") + + +def run_without_key(example): + """Runs an example file as a script with no key in the environment, and + returns what it printed.""" + printed = io.StringIO() + with mock.patch.dict(os.environ), redirect_stdout(printed): + for name in KEY_SETTINGS: + os.environ.pop(name, None) + runpy.run_path(str(EXAMPLES / example), run_name="__main__") + return printed.getvalue() + + +class LocationExamplesWithoutKeyTests(unittest.TestCase): + + def test_cloud_getting_started(self): + self.assertRegex(run_without_key("gettingstarted.py"), CONFIGURE_LINK) + + def test_cloud_web(self): + self.assertRegex(run_without_key("web.py"), CONFIGURE_LINK) + + +if __name__ == "__main__": + unittest.main() diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_cloud_mixed_without_key.py b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_cloud_mixed_without_key.py new file mode 100644 index 00000000..50c4ff0c --- /dev/null +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_cloud_mixed_without_key.py @@ -0,0 +1,82 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Runs the mixed cloud console as it runs from a fresh clone, with no key +set. It must end without an error, naming the environment variables to set +and giving a tagged link to the page where a key is created. +""" + +import io +import logging +import os +import unittest +from contextlib import redirect_stdout +from unittest import mock + +from fiftyone_pipeline_examples.cloud.mixed import gettingstarted_console +from fiftyone_pipeline_examples.example_utils import ExampleUtils + +# Every name a key can be read from, which a fresh clone does not set. +KEY_SETTINGS = [ + "_51DEGREES_RESOURCE_KEY", "resource_key", "RESOURCE_KEY", + "_51DEGREES_LICENSE_KEY", "license_key", "LICENSE_KEY"] + +# A link to the page where a resource key is created, with the campaign +# tags every example's links carry. +CONFIGURE_LINK = ( + r"https://51degrees\.com/configure[^\s?]*\?utm_source=code" + r"&utm_medium=example&utm_campaign=51degrees-python&utm_content=") + + +class Recorder(logging.Handler): + """Keeps every message logged while it is attached.""" + + def __init__(self): + super().__init__(logging.DEBUG) + self.messages = [] + + def emit(self, record): + self.messages.append(record.getMessage()) + + +class MixedConsoleWithoutKeyTests(unittest.TestCase): + + def test_says_how_to_get_a_key(self): + printed = io.StringIO() + recorder = Recorder() + root = logging.getLogger() + root.addHandler(recorder) + try: + with mock.patch.dict(os.environ), redirect_stdout(printed): + for name in KEY_SETTINGS: + os.environ.pop(name, None) + gettingstarted_console.main([]) + finally: + root.removeHandler(recorder) + said = printed.getvalue() + "\n".join(recorder.messages) + self.assertIn(ExampleUtils.RESOURCE_KEY_ENV_VAR, said) + self.assertRegex(said, CONFIGURE_LINK) + + +if __name__ == "__main__": + unittest.main() diff --git a/pipeline/fiftyone_pipeline_did/tests/test_creator_context_without_key.py b/pipeline/fiftyone_pipeline_did/tests/test_creator_context_without_key.py new file mode 100644 index 00000000..c1a3beae --- /dev/null +++ b/pipeline/fiftyone_pipeline_did/tests/test_creator_context_without_key.py @@ -0,0 +1,53 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +The creator context demo, started with no resource key, stops and says +which environment variable to set and where to create a key. +""" + +import unittest +from unittest import mock + +from .test_creator_context_server import load_server + +# A link to the page where a resource key is created, with the campaign +# tags every example's links carry. +CONFIGURE_LINK = ( + r"https://51degrees\.com/configure[^\s?]*\?utm_source=code" + r"&utm_medium=example&utm_campaign=51degrees-python&utm_content=") + + +class CreatorContextWithoutKeyTests(unittest.TestCase): + + def test_says_where_to_create_a_resource_key(self): + server = load_server() + with mock.patch.object(server, "RESOURCE", None): + with self.assertRaises(SystemExit) as stopped: + server.run() + said = str(stopped.exception.code) + self.assertIn("_51DEGREES_RESOURCE_KEY", said) + self.assertRegex(said, CONFIGURE_LINK) + + +if __name__ == "__main__": + unittest.main() From b1364f8b45e611d1537a4352f4fa5cd2b999c853 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 00:09:34 +0000 Subject: [PATCH 013/102] Test that every example ends with a Find out more section Each examples package, location and the pipeline packages that hold examples gain test_find_out_more.py. It reads every example file and fails, naming the file, when the file has no Find out more section, meaning a list of links whose 51degrees.com addresses carry a utm_term starting with find-out-more and a utm_content naming that file, and a link to the product's folder in this repository. Where an example can stop early without a key, a data file or the network, the test also runs it to that end and checks the section is printed there. The existing tests that capture what an example prints, or the page a web example serves, now also check for the section. The device lines check of the TAC and native model lookups leaves out the section's links, which are indented as device lines are. These fail until the examples print the section, which the next commits add. --- .../tests/test_cloudexamples.py | 11 +- .../tests/test_cloudgettingstartedweb.py | 1 + .../tests/test_examples_without_settings.py | 6 + .../tests/test_find_out_more.py | 191 ++++++++++++++++++ .../tests/test_onpremisegettingstartedweb.py | 1 + .../tests/test_examples_without_settings.py | 8 + .../tests/test_find_out_more.py | 173 ++++++++++++++++ location/tests/test_find_out_more.py | 99 +++++++++ .../examples/tests/test_find_out_more.py | 63 ++++++ .../tests/test_find_out_more.py | 71 +++++++ .../tests/test_find_out_more.py | 77 +++++++ .../tests/test_find_out_more.py | 71 +++++++ 12 files changed, 771 insertions(+), 1 deletion(-) create mode 100644 device-detection/fiftyone_devicedetection_examples/tests/test_find_out_more.py create mode 100644 ip-intelligence/fiftyone_ipintelligence_examples/tests/test_find_out_more.py create mode 100644 location/tests/test_find_out_more.py create mode 100644 pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_find_out_more.py create mode 100644 pipeline/fiftyone_pipeline_core/tests/test_find_out_more.py create mode 100644 pipeline/fiftyone_pipeline_did/tests/test_find_out_more.py create mode 100644 pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_find_out_more.py diff --git a/device-detection/fiftyone_devicedetection_examples/tests/test_cloudexamples.py b/device-detection/fiftyone_devicedetection_examples/tests/test_cloudexamples.py index eebe2361..97b50e11 100644 --- a/device-detection/fiftyone_devicedetection_examples/tests/test_cloudexamples.py +++ b/device-detection/fiftyone_devicedetection_examples/tests/test_cloudexamples.py @@ -92,7 +92,10 @@ def assert_device_lines_are_meaningful(self, output): has no value and gives the reason the cloud service supplied. """ - lines = [line for line in output.split("\n") + # The links of the section the example ends with are left out, + # because they are indented as device lines are. + devices = output.split("Find out more:")[0] + lines = [line for line in devices.split("\n") if line.startswith("\t")] self.assertGreater(len(lines), 0, @@ -112,6 +115,7 @@ def test_cloud_getting_started_console(self): self.assertIn("Input values:", output) self.assertIn("Mobile Device:", output) + self.assertIn("Find out more:", output) def test_cloud_nativemodellookup_console(self): example = NativeModelLookupConsole() @@ -123,6 +127,7 @@ def test_cloud_nativemodellookup_console(self): "Which devices are associated with the native model name " "'SC-03L'?", output) self.assert_device_lines_are_meaningful(output) + self.assertIn("Find out more:", output) def test_cloud_taclookup_console(self): example = TacLookupConsole() @@ -136,6 +141,7 @@ def test_cloud_taclookup_console(self): self.assertIn( "Which devices are associated with the TAC '35925406'?", output) self.assert_device_lines_are_meaningful(output) + self.assertIn("Find out more:", output) def test_cloud_metadata_console(self): example = MetaDataConsole() @@ -145,6 +151,7 @@ def test_cloud_metadata_console(self): self.assertIn("Accepted evidence keys:", output) self.assertIn("Property - ", output) + self.assertIn("Find out more:", output) def test_cloud_configurator_console(self): example = ConfiguratorConsole() @@ -154,6 +161,7 @@ def test_cloud_configurator_console(self): self.assertIn("device.ismobile: ", output) self.assertNotEqual("device.ismobile:", output.strip()) + self.assertIn("Find out more:", output) def test_cloud_failuretomatch(self): """The failure to match example is a script rather than a class, @@ -174,5 +182,6 @@ def test_cloud_failuretomatch(self): self.assertEqual(0, finished.returncode, output) self.assertNotIn("No resource key found", output) self.assertIn("a mobile device?", output) + self.assertIn("Find out more:", output) for marker in FAULT_MARKERS: self.assertNotIn(marker, output) diff --git a/device-detection/fiftyone_devicedetection_examples/tests/test_cloudgettingstartedweb.py b/device-detection/fiftyone_devicedetection_examples/tests/test_cloudgettingstartedweb.py index d3239b6a..440f3a81 100644 --- a/device-detection/fiftyone_devicedetection_examples/tests/test_cloudgettingstartedweb.py +++ b/device-detection/fiftyone_devicedetection_examples/tests/test_cloudgettingstartedweb.py @@ -41,6 +41,7 @@ class CloudGettingStartedWebTests(flask_unittest.ClientTestCase): def test_cloud_getting_started_web(self, client): response = client.get('/') self.assertEqual(200, response.status_code) + self.assertIn(b"Find out more", response.data) # The device id used to appear on the page only by accident, inside the JSON of the # inlined client-side script. Now that the script is served separately, check that the diff --git a/device-detection/fiftyone_devicedetection_examples/tests/test_examples_without_settings.py b/device-detection/fiftyone_devicedetection_examples/tests/test_examples_without_settings.py index 6e7fbef4..eee099e2 100644 --- a/device-detection/fiftyone_devicedetection_examples/tests/test_examples_without_settings.py +++ b/device-detection/fiftyone_devicedetection_examples/tests/test_examples_without_settings.py @@ -85,18 +85,21 @@ def test_gettingstarted_console(self): self.assertIn( ExampleUtils.get_enterprise_note(gettingstarted_console.CONTACT_US), printed) + self.assertIn("Find out more:", printed) def test_match_metrics(self): printed = run_without_settings(match_metrics.main) self.assertIn( ExampleUtils.get_enterprise_offer(match_metrics.CONTACT_US), printed) + self.assertIn("Find out more:", printed) def test_metadata_console(self): printed = run_without_settings(metadata_console.main) self.assertIn( ExampleUtils.get_enterprise_offer(metadata_console.CONTACT_US), printed) + self.assertIn("Find out more:", printed) def test_offline_processing(self): output = io.StringIO() @@ -119,6 +122,7 @@ def test_datafileupdate_console(self): printed = run_without_settings(datafileupdate_console.main) self.assertIn("The data file in use is the 'Lite' file", printed) self.assertIn(datafileupdate_console.CONTACT_US, printed) + self.assertIn("Find out more:", printed) # The two examples below need files that are not free, so in a fresh # clone the search for them finds nothing, which the tests stand in for. @@ -128,12 +132,14 @@ def test_csv_profile_metadata(self): printed = run_without_settings(csv_profile_metadata.main) self.assertIn(csv_profile_metadata.CSV_FILE_NAME, printed) self.assertIn(csv_profile_metadata.CONTACT_US, printed) + self.assertIn("Find out more:", printed) def test_profile_metadata_console(self): with mock.patch.object(ExampleUtils, "find_file", return_value=None): printed = run_without_settings(profile_metadata_console.main) self.assertIn("only the Enterprise data file has", printed) self.assertIn(profile_metadata_console.CONTACT_US, printed) + self.assertIn("Find out more:", printed) if __name__ == "__main__": diff --git a/device-detection/fiftyone_devicedetection_examples/tests/test_find_out_more.py b/device-detection/fiftyone_devicedetection_examples/tests/test_find_out_more.py new file mode 100644 index 00000000..6f381ace --- /dev/null +++ b/device-detection/fiftyone_devicedetection_examples/tests/test_find_out_more.py @@ -0,0 +1,191 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Every example ends with a "Find out more" section, which gives the person +running it links to follow up, wherever the example ends. The first checks +read the examples' source. The others run each example to an early end, with +no resource key or no data file, so none of them needs a key, a data file or +the network. +""" + +import io +import os +import re +import runpy +import unittest +from contextlib import redirect_stdout +from unittest import mock + +from fiftyone_devicedetection_examples.example_utils import ExampleUtils +from fiftyone_devicedetection_examples.cloud import configurator_console +from fiftyone_devicedetection_examples.cloud import ( + gettingstarted_console as cloud_gettingstarted_console) +from fiftyone_devicedetection_examples.cloud import ( + metadata_console as cloud_metadata_console) +from fiftyone_devicedetection_examples.cloud import nativemodellookup_console +from fiftyone_devicedetection_examples.cloud import taclookup_console +from fiftyone_devicedetection_examples.cloud.gettingstarted_web import ( + app as cloud_gettingstarted_web) +from fiftyone_devicedetection_examples.cloud.useragentclienthints_web import ( + app as cloud_useragentclienthints_web) +from fiftyone_devicedetection_examples.onpremise import gettingstarted_console +from fiftyone_devicedetection_examples.onpremise import match_metrics +from fiftyone_devicedetection_examples.onpremise import metadata_console +from fiftyone_devicedetection_examples.onpremise import shareusage + +# The product folder. Each link's utm_content is the path of its file below +# this folder. +PRODUCT = os.path.abspath(os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "..")) +EXAMPLES = os.path.join( + PRODUCT, "fiftyone_devicedetection_examples", "src", + "fiftyone_devicedetection_examples") +CLOUD = os.path.join(EXAMPLES, "cloud") +ONPREMISE = os.path.join(EXAMPLES, "onpremise") + +# Every file that holds a section. A web example has one in its page, and +# one in its app for the console. +SOURCES = [ + os.path.join(CLOUD, "configurator_console.py"), + os.path.join(CLOUD, "failuretomatch.py"), + os.path.join(CLOUD, "gettingstarted_console.py"), + os.path.join(CLOUD, "gettingstarted_web", "app.py"), + os.path.join(CLOUD, "gettingstarted_web", "templates", "index.html"), + os.path.join(CLOUD, "metadata_console.py"), + os.path.join(CLOUD, "nativemodellookup_console.py"), + os.path.join(CLOUD, "taclookup_console.py"), + os.path.join(CLOUD, "useragentclienthints_web", "app.py"), + os.path.join( + CLOUD, "useragentclienthints_web", "templates", "index.html"), + os.path.join(ONPREMISE, "csv_profile_metadata.py"), + os.path.join(ONPREMISE, "datafileupdate_console.py"), + os.path.join(ONPREMISE, "failuretomatch.py"), + os.path.join(ONPREMISE, "gettingstarted_console.py"), + os.path.join(ONPREMISE, "gettingstarted_web", "app.py"), + os.path.join(ONPREMISE, "gettingstarted_web", "templates", "index.html"), + os.path.join(ONPREMISE, "match_metrics.py"), + os.path.join(ONPREMISE, "metadata_console.py"), + os.path.join(ONPREMISE, "offlineprocessing.py"), + os.path.join(ONPREMISE, "performance.py"), + os.path.join(ONPREMISE, "profile_metadata_console.py"), + os.path.join(ONPREMISE, "shareusage.py"), + os.path.join(ONPREMISE, "useragentclienthints_web", "app.py"), + os.path.join( + ONPREMISE, "useragentclienthints_web", "templates", "index.html"), + os.path.join( + PRODUCT, "fiftyone_devicedetection", "examples", "gettingstarted.py"), +] + +# The name of the section, or of the list that holds its links. +SECTION_NAME = re.compile(r"(?i)find[ _]out[ _]more") + +# A 51degrees.com link in the section, which carries a utm_term that starts +# with "find-out-more". +SECTION_LINK = re.compile( + r"https://51degrees\.com/[^\s\"'<>)]*utm_term=find-out-more[^\s\"'<>)]*") + +# This product's folder in the repository, which every section links to. +REPOSITORY = ( + "https://github.com/51Degrees/51degrees-python/tree/main/" + "device-detection") + +# The settings that let an example get past its early end. +SETTINGS = [ + "_51DEGREES_RESOURCE_KEY", "resource_key", "RESOURCE_KEY", + "_51DEGREES_LICENSE_KEY", "license_key", "LICENSE_KEY"] + + +def slug(path): + """The utm_content of a link in the file, which is the path below the + product folder with each separator a hyphen.""" + return os.path.relpath(path, PRODUCT).replace(os.sep, "-") + + +def printed_by(run): + """Runs an example with the settings taken out of the environment, and + returns what it printed.""" + printed = io.StringIO() + with mock.patch.dict(os.environ), redirect_stdout(printed): + for name in SETTINGS: + os.environ.pop(name, None) + run() + return printed.getvalue() + + +class FindOutMoreSourceTests(unittest.TestCase): + + def test_every_example_has_a_find_out_more_section(self): + for path in SOURCES: + with self.subTest(example=slug(path)): + with open(path, encoding="utf-8") as source: + # A page separates the parameters with "&". + text = source.read().replace("&", "&") + self.assertRegex(text, SECTION_NAME) + links = SECTION_LINK.findall(text) + self.assertTrue( + links, "The section has no tagged 51degrees.com link") + for link in links: + self.assertIn(f"&utm_content={slug(path)}&", link) + self.assertIn(REPOSITORY, text) + + +class FindOutMoreAtEarlyEndsTests(unittest.TestCase): + + def test_cloud_examples_without_a_resource_key(self): + examples = { + "configurator_console": configurator_console.main, + "gettingstarted_console": cloud_gettingstarted_console.main, + "metadata_console": cloud_metadata_console.main, + "nativemodellookup_console": nativemodellookup_console.main, + "taclookup_console": taclookup_console.main, + "gettingstarted_web": cloud_gettingstarted_web.main, + "useragentclienthints_web": cloud_useragentclienthints_web.main, + } + for name, main in examples.items(): + with self.subTest(example=name): + self.assertIn("Find out more:", printed_by(lambda: main([]))) + + def test_cloud_failuretomatch_without_a_resource_key(self): + # This example has no main, and runs when it is run as a script. + printed = printed_by(lambda: runpy.run_module( + "fiftyone_devicedetection_examples.cloud.failuretomatch", + run_name="__main__")) + self.assertIn("Find out more:", printed) + + def test_onpremise_examples_without_a_data_file(self): + examples = { + "gettingstarted_console": gettingstarted_console.main, + "match_metrics": match_metrics.main, + "metadata_console": metadata_console.main, + "shareusage": shareusage.main, + } + for name, main in examples.items(): + with self.subTest(example=name): + with mock.patch.object( + ExampleUtils, "find_file", return_value=None): + printed = printed_by(lambda: main([])) + self.assertIn("Find out more:", printed) + + +if __name__ == "__main__": + unittest.main() diff --git a/device-detection/fiftyone_devicedetection_examples/tests/test_onpremisegettingstartedweb.py b/device-detection/fiftyone_devicedetection_examples/tests/test_onpremisegettingstartedweb.py index 5c8978ee..9787fe3c 100644 --- a/device-detection/fiftyone_devicedetection_examples/tests/test_onpremisegettingstartedweb.py +++ b/device-detection/fiftyone_devicedetection_examples/tests/test_onpremisegettingstartedweb.py @@ -49,6 +49,7 @@ def tearDownClass(cls): def test_onpremise_getting_started_web(self, client): response = client.get('/') self.assertEqual(200, response.status_code) + self.assertIn(b"Find out more", response.data) # The page references the client-side script by the '/51Degrees.core.js' name used # by the web integrations in the other Pipeline APIs, so check that the route diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_examples_without_settings.py b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_examples_without_settings.py index e3cdf702..557740d9 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_examples_without_settings.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_examples_without_settings.py @@ -78,6 +78,7 @@ def test_gettingstarted_console(self): self.assertIn( ExampleUtils.get_enterprise_note(gettingstarted_console.CONTACT_US), printed) + self.assertIn("Find out more:", printed) def test_countries_console(self): printed = run_without_settings(countries_console.main) @@ -86,12 +87,14 @@ def test_countries_console(self): "CountryCodesGeographical and CountryCodesPopulation properties", printed) self.assertIn(countries_console.CONTACT_US, printed) + self.assertIn("Find out more:", printed) def test_metadata_console(self): printed = run_without_settings(metadata_console.main) self.assertIn( ExampleUtils.get_enterprise_offer(metadata_console.CONTACT_US), printed) + self.assertIn("Find out more:", printed) def test_offlineprocessing(self): printed = run_without_settings(offlineprocessing.main) @@ -100,6 +103,7 @@ def test_offlineprocessing(self): "# " + ExampleUtils.get_enterprise_note( offlineprocessing.CONTACT_US), printed) + self.assertIn("Find out more:", printed) def test_compare_console(self): printed = run_without_settings(compare_console.main) @@ -108,6 +112,7 @@ def test_compare_console(self): "Latitude, Longitude, LocationConfidence and Country properties", printed) self.assertIn(compare_console.CONTACT_US, printed) + self.assertIn("Find out more:", printed) def test_performance_console(self): printed = run_without_settings( @@ -115,11 +120,13 @@ def test_performance_console(self): self.assertIn( ExampleUtils.get_enterprise_offer(performance_console.CONTACT_US), printed) + self.assertIn("Find out more:", printed) def test_datafileupdate_console(self): printed = run_without_settings(datafileupdate_console.main) self.assertIn("The data file in use is the", printed) self.assertIn(datafileupdate_console.CONTACT_US, printed) + self.assertIn("Find out more:", printed) @unittest.skipUnless( device_detection_available, "device detection is not installed") @@ -129,6 +136,7 @@ def test_mixed_console(self): self.assertIn( ExampleUtils.get_enterprise_note(mixed_console.CONTACT_US), printed) + self.assertIn("Find out more:", printed) if __name__ == "__main__": diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_find_out_more.py b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_find_out_more.py new file mode 100644 index 00000000..219fb7cb --- /dev/null +++ b/ip-intelligence/fiftyone_ipintelligence_examples/tests/test_find_out_more.py @@ -0,0 +1,173 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Every example ends with a "Find out more" section, which gives the person +running it links to follow up, wherever the example ends. The first checks +read the examples' source. The others run each example to an early end, with +no resource key or no data file, so none of them needs a key, a data file or +the network. +""" + +import io +import os +import re +import unittest +from contextlib import redirect_stdout +from unittest import mock + +from fiftyone_ipintelligence_examples.example_utils import ExampleUtils +from fiftyone_ipintelligence_examples.cloud import getallproperties_console +from fiftyone_ipintelligence_examples.cloud import ( + gettingstarted_console as cloud_gettingstarted_console) +from fiftyone_ipintelligence_examples.cloud import ( + metadata_console as cloud_metadata_console) +from fiftyone_ipintelligence_examples.cloud import ( + mixed_console as cloud_mixed_console) +from fiftyone_ipintelligence_examples.onpremise import compare_console +from fiftyone_ipintelligence_examples.onpremise import countries_console +from fiftyone_ipintelligence_examples.onpremise import datafileupdate_console +from fiftyone_ipintelligence_examples.onpremise import gettingstarted_console +from fiftyone_ipintelligence_examples.onpremise import metadata_console +from fiftyone_ipintelligence_examples.onpremise import mixed_console +from fiftyone_ipintelligence_examples.onpremise import offlineprocessing +from fiftyone_ipintelligence_examples.onpremise import performance_console + +# The product folder. Each link's utm_content is the path of its file below +# this folder. +PRODUCT = os.path.abspath(os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "..")) +EXAMPLES = os.path.join( + PRODUCT, "fiftyone_ipintelligence_examples", "src", + "fiftyone_ipintelligence_examples") +CLOUD = os.path.join(EXAMPLES, "cloud") +ONPREMISE = os.path.join(EXAMPLES, "onpremise") + +# Every file that holds a section. A web example builds its page in its app, +# so the app holds the section for the page. +SOURCES = [ + os.path.join(CLOUD, "getallproperties_console.py"), + os.path.join(CLOUD, "gettingstarted_console.py"), + os.path.join(CLOUD, "gettingstarted_web", "app.py"), + os.path.join(CLOUD, "metadata_console.py"), + os.path.join(CLOUD, "mixed_console.py"), + os.path.join(ONPREMISE, "compare_console.py"), + os.path.join(ONPREMISE, "countries_console.py"), + os.path.join(ONPREMISE, "datafileupdate_console.py"), + os.path.join(ONPREMISE, "gettingstarted_console.py"), + os.path.join(ONPREMISE, "gettingstarted_web", "app.py"), + os.path.join(ONPREMISE, "metadata_console.py"), + os.path.join(ONPREMISE, "mixed_console.py"), + os.path.join(ONPREMISE, "offlineprocessing.py"), + os.path.join(ONPREMISE, "performance_console.py"), + os.path.join( + PRODUCT, "fiftyone_ipintelligence", "examples", "gettingstarted.py"), +] + +# The name of the section, or of the list that holds its links. +SECTION_NAME = re.compile(r"(?i)find[ _]out[ _]more") + +# A 51degrees.com link in the section, which carries a utm_term that starts +# with "find-out-more". +SECTION_LINK = re.compile( + r"https://51degrees\.com/[^\s\"'<>)]*utm_term=find-out-more[^\s\"'<>)]*") + +# This product's folder in the repository, which every section links to. +REPOSITORY = ( + "https://github.com/51Degrees/51degrees-python/tree/main/" + "ip-intelligence") + +# The settings that let an example get past its early end. +SETTINGS = [ + "_51DEGREES_RESOURCE_KEY", "resource_key", "RESOURCE_KEY", + "_51DEGREES_LICENSE_KEY", "license_key", + ExampleUtils.IPI_PATH_ENV_VAR, ExampleUtils.DATA_FILE_ENV_VAR] + + +def slug(path): + """The utm_content of a link in the file, which is the path below the + product folder with each separator a hyphen.""" + return os.path.relpath(path, PRODUCT).replace(os.sep, "-") + + +def printed_by(run): + """Runs an example with the settings taken out of the environment, and + returns what it printed.""" + printed = io.StringIO() + with mock.patch.dict(os.environ), redirect_stdout(printed): + for name in SETTINGS: + os.environ.pop(name, None) + run() + return printed.getvalue() + + +class FindOutMoreSourceTests(unittest.TestCase): + + def test_every_example_has_a_find_out_more_section(self): + for path in SOURCES: + with self.subTest(example=slug(path)): + with open(path, encoding="utf-8") as source: + # A page separates the parameters with "&". + text = source.read().replace("&", "&") + self.assertRegex(text, SECTION_NAME) + links = SECTION_LINK.findall(text) + self.assertTrue( + links, "The section has no tagged 51degrees.com link") + for link in links: + self.assertIn(f"&utm_content={slug(path)}&", link) + self.assertIn(REPOSITORY, text) + + +class FindOutMoreAtEarlyEndsTests(unittest.TestCase): + + def test_cloud_examples_without_a_resource_key(self): + examples = { + "getallproperties_console": getallproperties_console.main, + "gettingstarted_console": cloud_gettingstarted_console.main, + "metadata_console": cloud_metadata_console.main, + "mixed_console": cloud_mixed_console.main, + } + for name, main in examples.items(): + with self.subTest(example=name): + self.assertIn("Find out more:", printed_by(lambda: main([]))) + + def test_onpremise_examples_without_a_data_file(self): + examples = { + "compare_console": compare_console.main, + "countries_console": countries_console.main, + "datafileupdate_console": datafileupdate_console.main, + "gettingstarted_console": gettingstarted_console.main, + "metadata_console": metadata_console.main, + "mixed_console": mixed_console.main, + "offlineprocessing": offlineprocessing.main, + "performance_console": performance_console.main, + } + for name, main in examples.items(): + with self.subTest(example=name): + with mock.patch.object( + ExampleUtils, "find_file", return_value=None): + printed = printed_by(lambda: main([])) + self.assertIn("Find out more:", printed) + + +if __name__ == "__main__": + unittest.main() diff --git a/location/tests/test_find_out_more.py b/location/tests/test_find_out_more.py new file mode 100644 index 00000000..a8b1ef44 --- /dev/null +++ b/location/tests/test_find_out_more.py @@ -0,0 +1,99 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Every example ends with a "Find out more" section, which gives the person +running it links to follow up, wherever the example ends. The first check +reads the examples' source. The other runs each example with no resource +key, so none of them needs a key or the network. +""" + +import io +import os +import re +import runpy +import unittest +from contextlib import redirect_stdout +from unittest import mock + +# The product folder. Each link's utm_content is the path of its file below +# this folder. +PRODUCT = os.path.abspath(os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..")) +EXAMPLES = os.path.join(PRODUCT, "examples", "cloud") + +# Every example. The web example has one section for the console and the +# same links at the end of its page. +SOURCES = [ + os.path.join(EXAMPLES, "gettingstarted.py"), + os.path.join(EXAMPLES, "web.py"), +] + +# The name of the section, or of the list that holds its links. +SECTION_NAME = re.compile(r"(?i)find[ _]out[ _]more") + +# A 51degrees.com link in the section, which carries a utm_term that starts +# with "find-out-more". +SECTION_LINK = re.compile( + r"https://51degrees\.com/[^\s\"'<>)]*utm_term=find-out-more[^\s\"'<>)]*") + +# This product's folder in the repository, which every section links to. +REPOSITORY = "https://github.com/51Degrees/51degrees-python/tree/main/location" + +# The settings that let an example get past its early end. +SETTINGS = ["_51DEGREES_RESOURCE_KEY", "resource_key", "RESOURCE_KEY"] + + +def slug(path): + """The utm_content of a link in the file, which is the path below the + product folder with each separator a hyphen.""" + return os.path.relpath(path, PRODUCT).replace(os.sep, "-") + + +class FindOutMoreTests(unittest.TestCase): + + def test_every_example_has_a_find_out_more_section(self): + for path in SOURCES: + with self.subTest(example=slug(path)): + with open(path, encoding="utf-8") as source: + text = source.read() + self.assertRegex(text, SECTION_NAME) + links = SECTION_LINK.findall(text) + self.assertTrue( + links, "The section has no tagged 51degrees.com link") + for link in links: + self.assertIn(f"&utm_content={slug(path)}&", link) + self.assertIn(REPOSITORY, text) + + def test_every_example_without_a_resource_key(self): + for path in SOURCES: + with self.subTest(example=slug(path)): + printed = io.StringIO() + with mock.patch.dict(os.environ), redirect_stdout(printed): + for name in SETTINGS: + os.environ.pop(name, None) + runpy.run_path(path, run_name="__main__") + self.assertIn("Find out more:", printed.getvalue()) + + +if __name__ == "__main__": + unittest.main() diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_find_out_more.py b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_find_out_more.py new file mode 100644 index 00000000..34195956 --- /dev/null +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_find_out_more.py @@ -0,0 +1,63 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +The mixed console ends with its "Find out more" section when it stops early, +as it does after a run. These run it to each early end, so they need no key +and no network. +""" + +from fiftyone_pipeline_examples.cloud.mixed import gettingstarted_console +from fiftyone_pipeline_examples.example_utils import ExampleUtils + +# Every name a key is read from. +KEY_SETTINGS = [ + ExampleUtils.RESOURCE_KEY_ENV_VAR, + ExampleUtils.LEGACY_RESOURCE_KEY_ENV_VAR, + ExampleUtils.LICENSE_KEY_ENV_VAR, + ExampleUtils.LEGACY_LICENSE_KEY_ENV_VAR, +] + + +def test_without_a_key(monkeypatch, capsys): + for name in KEY_SETTINGS: + monkeypatch.delenv(name, raising=False) + + gettingstarted_console.main([]) + + printed = capsys.readouterr().out + assert "Find out more:" in printed + for _, url in gettingstarted_console.GettingStartedConsole.FIND_OUT_MORE: + assert url in printed + + +def test_when_the_pipeline_cannot_be_built(monkeypatch, capsys): + # Stands in for a key the cloud service refuses, or one that carries + # none of the properties the example shows. + def refuse(*args, **kwargs): + raise ValueError("The key carries none of the properties.") + + monkeypatch.setattr(gettingstarted_console, "create_pipeline", refuse) + + gettingstarted_console.main(["a-resource-key"]) + + assert "Find out more:" in capsys.readouterr().out diff --git a/pipeline/fiftyone_pipeline_core/tests/test_find_out_more.py b/pipeline/fiftyone_pipeline_core/tests/test_find_out_more.py new file mode 100644 index 00000000..919888fe --- /dev/null +++ b/pipeline/fiftyone_pipeline_core/tests/test_find_out_more.py @@ -0,0 +1,71 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Every example ends with a "Find out more" section, which gives the person +running it links to follow up. The check reads the example's source, so it +needs no network. +""" + +import os +import re +import unittest + +# The product folder. Each link's utm_content is the path of its file below +# this folder. +PRODUCT = os.path.abspath(os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "..")) + +# The example of a custom flow element, a web page that ends with the +# section. +EXAMPLE = os.path.join( + PRODUCT, "fiftyone_pipeline_core", "examples", + "client_side_evidence_custom_flow_element.py") + +# The name of the section, or of the list that holds its links. +SECTION_NAME = re.compile(r"(?i)find[ _]out[ _]more") + +# A 51degrees.com link in the section, which carries a utm_term that starts +# with "find-out-more". +SECTION_LINK = re.compile( + r"https://51degrees\.com/[^\s\"'<>)]*utm_term=find-out-more[^\s\"'<>)]*") + +# This product's folder in the repository, which every section links to. +REPOSITORY = "https://github.com/51Degrees/51degrees-python/tree/main/pipeline" + + +class FindOutMoreTests(unittest.TestCase): + + def test_the_example_has_a_find_out_more_section(self): + with open(EXAMPLE, encoding="utf-8") as source: + text = source.read() + self.assertRegex(text, SECTION_NAME) + links = SECTION_LINK.findall(text) + self.assertTrue(links, "The section has no tagged 51degrees.com link") + content = os.path.relpath(EXAMPLE, PRODUCT).replace(os.sep, "-") + for link in links: + self.assertIn(f"&utm_content={content}&", link) + self.assertIn(REPOSITORY, text) + + +if __name__ == "__main__": + unittest.main() diff --git a/pipeline/fiftyone_pipeline_did/tests/test_find_out_more.py b/pipeline/fiftyone_pipeline_did/tests/test_find_out_more.py new file mode 100644 index 00000000..8574d07a --- /dev/null +++ b/pipeline/fiftyone_pipeline_did/tests/test_find_out_more.py @@ -0,0 +1,77 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +The 51Did example ends with a "Find out more" section, which gives the +person running it links to follow up. The example works offline, so it is +run as well as read. +""" + +import io +import os +import re +import runpy +import unittest +from contextlib import redirect_stdout + +# The product folder. Each link's utm_content is the path of its file below +# this folder. +PRODUCT = os.path.abspath(os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "..")) + +EXAMPLE = os.path.join( + PRODUCT, "fiftyone_pipeline_did", "examples", "fodid_example.py") + +# The name of the section, or of the list that holds its links. +SECTION_NAME = re.compile(r"(?i)find[ _]out[ _]more") + +# A 51degrees.com link in the section, which carries a utm_term that starts +# with "find-out-more". +SECTION_LINK = re.compile( + r"https://51degrees\.com/[^\s\"'<>)]*utm_term=find-out-more[^\s\"'<>)]*") + +# This product's folder in the repository, which every section links to. +REPOSITORY = "https://github.com/51Degrees/51degrees-python/tree/main/pipeline" + + +class FindOutMoreTests(unittest.TestCase): + + def test_the_example_has_a_find_out_more_section(self): + with open(EXAMPLE, encoding="utf-8") as source: + text = source.read() + self.assertRegex(text, SECTION_NAME) + links = SECTION_LINK.findall(text) + self.assertTrue(links, "The section has no tagged 51degrees.com link") + content = os.path.relpath(EXAMPLE, PRODUCT).replace(os.sep, "-") + for link in links: + self.assertIn(f"&utm_content={content}&", link) + self.assertIn(REPOSITORY, text) + + def test_the_example_ends_with_the_section(self): + printed = io.StringIO() + with redirect_stdout(printed): + runpy.run_path(EXAMPLE, run_name="__main__") + self.assertIn("Find out more:", printed.getvalue()) + + +if __name__ == "__main__": + unittest.main() diff --git a/pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_find_out_more.py b/pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_find_out_more.py new file mode 100644 index 00000000..e2489ad1 --- /dev/null +++ b/pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_find_out_more.py @@ -0,0 +1,71 @@ +# ********************************************************************* +# This Original Work is copyright of 51 Degrees Mobile Experts Limited. +# Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, +# Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. +# +# This Original Work is licensed under the European Union Public Licence +# (EUPL) v.1.2 and is subject to its terms as set out below. +# +# If a copy of the EUPL was not distributed with this file, You can obtain +# one at https://opensource.org/licenses/EUPL-1.2. +# +# The 'Compatible Licences' set out in the Appendix to the EUPL (as may be +# amended by the European Commission) shall be deemed incompatible for +# the purposes of the Work and the provisions of the compatibility +# clause in Article 5 of the EUPL shall not apply. +# +# If using the Work as, or as part of, a network application, by +# including the attribution notice(s) required under Article 5 of the EUPL +# in the end user terms of the application under an appropriate heading, +# such notice(s) shall fulfill the requirements of that article. +# ********************************************************************* + +""" +Every example ends with a "Find out more" section, which gives the person +running it links to follow up. The check reads the example's source rather +than running it, because the example builds a pipeline that shares usage +with 51Degrees. +""" + +import os +import re +import unittest + +# The product folder. Each link's utm_content is the path of its file below +# this folder. +PRODUCT = os.path.abspath(os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "..")) + +# The usage sharing example, a script that ends with the section. +EXAMPLE = os.path.join( + PRODUCT, "fiftyone_pipeline_engines_fiftyone", "examples", + "usagesharing", "usagesharing.py") + +# The name of the section, or of the list that holds its links. +SECTION_NAME = re.compile(r"(?i)find[ _]out[ _]more") + +# A 51degrees.com link in the section, which carries a utm_term that starts +# with "find-out-more". +SECTION_LINK = re.compile( + r"https://51degrees\.com/[^\s\"'<>)]*utm_term=find-out-more[^\s\"'<>)]*") + +# This product's folder in the repository, which every section links to. +REPOSITORY = "https://github.com/51Degrees/51degrees-python/tree/main/pipeline" + + +class FindOutMoreTests(unittest.TestCase): + + def test_the_example_has_a_find_out_more_section(self): + with open(EXAMPLE, encoding="utf-8") as source: + text = source.read() + self.assertRegex(text, SECTION_NAME) + links = SECTION_LINK.findall(text) + self.assertTrue(links, "The section has no tagged 51degrees.com link") + content = os.path.relpath(EXAMPLE, PRODUCT).replace(os.sep, "-") + for link in links: + self.assertIn(f"&utm_content={content}&", link) + self.assertIn(REPOSITORY, text) + + +if __name__ == "__main__": + unittest.main() From 63566d06c9b72f613ed2a23c3139f7da5e94a8bb Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 00:12:45 +0000 Subject: [PATCH 014/102] Share a key found in the request and the Evidence once, whatever its letters (#120) `ShareUsage.found_evidence` merges the values of the web request, which the web integration adds as `server.http-request`, with every Evidence value in the Flow Data, so that a key found in both places is shared once with the Evidence value ([`share_usage.py` lines 432 to 458 at 32ffdcf1](https://github.com/51Degrees/51degrees-python/blob/32ffdcf1205a5ce593fb55f5be733de5a18dffde/pipeline/fiftyone_pipeline_engines_fiftyone/src/fiftyone_pipeline_engines_fiftyone/share_usage.py#L432-L458)). It merged on the exact key. `webevidence` writes each header's key in lower case ([`web.py` line 91](https://github.com/51Degrees/51degrees-python/blob/32ffdcf1205a5ce593fb55f5be733de5a18dffde/pipeline/fiftyone_pipeline_core/src/fiftyone_pipeline_core/web.py#L91)), so a header an application added by hand in other letters, such as `header.User-Agent`, was found twice and both values were shared. --- .../share_usage.py | 16 ++++-- .../test_share_usage_accepts_no_evidence.py | 55 +++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/pipeline/fiftyone_pipeline_engines_fiftyone/src/fiftyone_pipeline_engines_fiftyone/share_usage.py b/pipeline/fiftyone_pipeline_engines_fiftyone/src/fiftyone_pipeline_engines_fiftyone/share_usage.py index 943674b8..3a91a980 100644 --- a/pipeline/fiftyone_pipeline_engines_fiftyone/src/fiftyone_pipeline_engines_fiftyone/share_usage.py +++ b/pipeline/fiftyone_pipeline_engines_fiftyone/src/fiftyone_pipeline_engines_fiftyone/share_usage.py @@ -435,9 +435,10 @@ def found_evidence(self, flow_data): The evidence the element finds to share. These are the values of the web request, when the web integration added it as server.http-request, and every evidence value in the flow data, - whether an element accepted it or not. A key found in both places - takes the evidence value. The web request itself is never one of - them. + whether an element accepted it or not. Keys are compared without + regard to case, so a key found in more than one place is found + once, with the evidence value and the evidence's spelling. The web + request itself is never one of them. @type flow_data: FlowData @param flow_data: The flow data being processed @@ -450,12 +451,15 @@ def found_evidence(self, flow_data): unaccepted = getattr(evidence, "get_unaccepted", dict)() web_request = unaccepted.get(HTTP_REQUEST_KEY) or \ evidence.get(HTTP_REQUEST_KEY) or {} + # The key of each value found, by its lower case form. A later + # source replaces both the value and the spelling of an earlier one. found = {} for source in (web_request, unaccepted, evidence.get_all()): for key, value in source.items(): - if str(key).lower() != HTTP_REQUEST_KEY: - found[key] = value - return found + folded = str(key).lower() + if folded != HTTP_REQUEST_KEY: + found[folded] = (key, value) + return dict(found.values()) def share_send_usage(self): """! diff --git a/pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_share_usage_accepts_no_evidence.py b/pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_share_usage_accepts_no_evidence.py index e683f856..503abff0 100644 --- a/pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_share_usage_accepts_no_evidence.py +++ b/pipeline/fiftyone_pipeline_engines_fiftyone/tests/test_share_usage_accepts_no_evidence.py @@ -25,8 +25,13 @@ depend on it. It shares what it finds in the flow data and in the web request instead, by the same rules as before.""" +import gzip +import re import unittest +from types import MappingProxyType +from unittest import mock +import requests from flask import Flask, request from fiftyone_pipeline_core.basiclist_evidence_keyfilter import \ @@ -82,6 +87,22 @@ def request_evidence(headers, path="/"): return webevidence(request) +def sent_on_close(usage): + """Closes the usage sharing element, which sends what it has queued, + and returns the text of each message it posted. The post is answered + with a 200 without leaving the process.""" + + sent = [] + + def post(url, headers=None, data=None, **kwargs): + sent.append(gzip.decompress(data).decode("utf8")) + return mock.Mock(status_code=200, text="") + + with mock.patch.object(requests, "post", post): + usage.close() + return sent + + class ShareUsageAcceptsNoEvidenceTests(unittest.TestCase): def test_the_pipeline_accepts_no_header_for_usage_sharing(self): @@ -171,6 +192,40 @@ def test_a_key_in_both_places_is_shared_once_with_the_evidence_value(self): self.assertIn( '
from the evidence
', shared) + def test_a_header_no_element_reads_is_in_the_message_sent(self): + usage = usage_element() + flowdata = pipeline_with(usage).create_flowdata() + flowdata.evidence.add_from_dict(request_evidence({ + "User-Agent": CHROME, + "X-Test": "only usage sharing reads this", + })) + flowdata.process() + + sent = sent_on_close(usage) + self.assertEqual(1, len(sent)) + self.assertIn( + '
only usage sharing reads this
', + sent[0]) + self.assertNotIn("http-request", sent[0]) + + def test_a_key_in_both_places_whose_letters_differ_is_shared_once(self): + usage = usage_element() + flowdata = pipeline_with(usage).create_flowdata() + # Added before the request, so the evidence keeps this spelling and + # the request carries the other one. + flowdata.evidence.add("HEADER.User-Agent", "evidence agent") + flowdata.evidence.add("server.http-request", MappingProxyType({ + "header.user-agent": "request agent"})) + flowdata.process() + + sent = sent_on_close(usage) + self.assertEqual(1, len(sent)) + names = re.findall( + r'
Date: Sat, 14 Nov 2026 00:26:25 +0000 Subject: [PATCH 015/102] Say in AGENTS.md that the IP Intelligence getting started example uses the Lite file (#124) [AGENTS.md](https://github.com/51Degrees/51degrees-python/blob/175ca4a/AGENTS.md) said the IP Intelligence on-premise `gettingstarted_console` "with no argument looks for the Asn file", shows registration values only once given the Lite file, and prints "This property is not present in the data file." for a property the file lacks. None of that is what the example does on `rc` at 175ca4a. --- AGENTS.md | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 505c110a..7530c8a4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,10 +10,10 @@ layout and how to get the code are in the [README](README.md). Device Detection's on-premise `gettingstarted_console` is the quickest example to show, because its data file is about 35 MB. IP Intelligence's -on-premise `gettingstarted_console` runs on the free Asn data file, which is -about 6 MB, and shows registration values once it is given the Lite file, -which is a download of about 230 MB. Run each command from the repository root -unless the step says otherwise. +on-premise `gettingstarted_console` runs on the free Lite data file, which is a +download of about 230 MB and has the registration values. The free Asn data +file, about 6 MB, has only the network properties. Run each command from the +repository root unless the step says otherwise. The on-premise engines are C and C++ code that is compiled when the package is installed. PyPI has only source distributions of @@ -150,16 +150,19 @@ macOS (`find_file` in python -m fiftyone_devicedetection_examples.onpremise.gettingstarted_console ``` -The IP Intelligence example with no argument looks for the Asn file in the -folder it runs in and in its `assets` and `cxx/data/ip-intelligence` folders, -then does the same in each of the seven folders above it, and downloads the -file into `cxx/data/ip-intelligence` when it is missing. To see registration -values, download the Lite file first, as "Data files" says, and give its path -as the first argument. +The IP Intelligence example with no argument looks for the Lite file, +`51Degrees-LiteV41.ipi`, in the folder it runs in and in its `assets`, +`cxx/data/ip-intelligence` and `cxx/data/device-detection` folders, then does +the same in each of the seven folders above it. When none of them has the +file, it downloads the file into the `cxx/data/ip-intelligence` folder that +holds the file's `.link` (`find_file` in +`ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/example_utils.py`). +To run it on the smaller Asn file, download that file first, as "Data files" +says, and give its path as the first argument. ``` python -m fiftyone_ipintelligence_examples.onpremise.gettingstarted_console -python -m fiftyone_ipintelligence_examples.onpremise.gettingstarted_console cxx/data/ip-intelligence/51Degrees-LiteV41.ipi +python -m fiftyone_ipintelligence_examples.onpremise.gettingstarted_console cxx/data/ip-intelligence/51Degrees-IPIV4AsnIpiV41.ipi ``` Either example uses a path given as the first argument as it is, so a file @@ -187,11 +190,12 @@ The IP Intelligence example logs `Using a '' data file created ''`, then for each of four IP addresses, starting with `116.154.188.222`, prints `Input values:` with `query.client-ip`, then `Results:` with a line for each of 16 properties, starting with `RegisteredName`, `RegisteredOwner` and -`RegisteredCountry`. A property the data file lacks reads -`This property is not present in the data file.` With the Asn file that is -every registration and location property, as the examples' README says. The -Lite file has RegisteredName, RegisteredOwner and RegisteredCountry, so with it -those three lines are read from the file. +`RegisteredCountry`. The Lite file has RegisteredName, RegisteredOwner and +RegisteredCountry, so those three lines are read from the file. Each property +the data file lacks reads `needs the Enterprise data file`, and after the last +address the example prints `Some of these properties need the Enterprise data +file. Contact us for a copy at` followed by a link. With the Asn file the +registration properties need the Enterprise data file as well. The paid data files have many more properties, as the [pricing page](https://51degrees.com/pricing?utm_source=github&utm_medium=docs&utm_campaign=51degrees-python&utm_content=agents.md&utm_term=correct-output) From 15f6f1bdb3defa7283b2bdfd6d266753b8aa9a53 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 03:51:16 +0000 Subject: [PATCH 016/102] Link to where resource keys are created when the 51Did demo has none The creator context demo's exit message with no resource key named the environment variable only. It now gives a tagged link to the configuration page, where a resource key is created. --- .../examples/creator_context_web/server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pipeline/fiftyone_pipeline_did/examples/creator_context_web/server.py b/pipeline/fiftyone_pipeline_did/examples/creator_context_web/server.py index a8b26698..9ead9d2c 100644 --- a/pipeline/fiftyone_pipeline_did/examples/creator_context_web/server.py +++ b/pipeline/fiftyone_pipeline_did/examples/creator_context_web/server.py @@ -296,7 +296,8 @@ def _is_json(text): def run(): if not RESOURCE: sys.exit("Set _51DEGREES_RESOURCE_KEY to the resource key of the " - "page.") + "page. Resource keys are created at " + "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_did-examples-creator_context_web-server.py&utm_term=resource-key-required") if not LICENCE: # Only an account that holds licence keys needs one to redeem, # because the licence key is what keeps redemption to the acting From 7277528c62b3fd799e56997cda52e8dc02b48223 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 03:51:17 +0000 Subject: [PATCH 017/102] Say how to get a resource key, and start nothing, when the IP Intelligence cloud web example has none The IP Intelligence cloud web example logged nothing and raised an exception with no key. It now logs the message the cloud console examples log, with tagged links to the resource keys page and the configuration page, and returns. --- .../cloud/gettingstarted_web/app.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py index c7100800..248d6dc0 100644 --- a/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py +++ b/ip-intelligence/fiftyone_ipintelligence_examples/src/fiftyone_ipintelligence_examples/cloud/gettingstarted_web/app.py @@ -37,6 +37,7 @@ from flask import Flask, request +from fiftyone_pipeline_core.logger import Logger from fiftyone_pipeline_core.web import webevidence from fiftyone_ipintelligence.ipintelligence_pipelinebuilder import IpIntelligencePipelineBuilder from fiftyone_ipintelligence_examples.example_utils import ExampleUtils @@ -93,11 +94,26 @@ def index(): def main(resource_key = None): if not resource_key: resource_key = ExampleUtils.get_resource_key() + + # Configure a logger to output to the console. + logger = Logger(min_level="info") + + # With no key there is nothing to serve, so say how to get one and + # start no server. if not resource_key: - raise Exception( + logger.log("error", "No resource key specified in the environment variable " - f"'{ExampleUtils.CLOUD_RESOURCE_KEY_ENV_VAR}'. Obtain one from " - "https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_web-app.py&utm_term=resource-key-required") + f"'{ExampleUtils.CLOUD_RESOURCE_KEY_ENV_VAR}'. The 51Degrees cloud " + "service is accessed using a 'ResourceKey'. For more " + "information see " + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_web-app.py&utm_term=resource-key-required. " + "A resource key with the properties required by this example " + "can be created for free at " + "https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_ipintelligence_examples-src-fiftyone_ipintelligence_examples-cloud-gettingstarted_web-app.py&utm_term=resource-key-required. " + "Once complete, populate the environment variable mentioned at " + "the start of this message with the key.") + return + build_pipeline(resource_key) app.run(debug=False) From d57fa8ddc0010f9ad4586549d563a72b06fec512 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 03:51:59 +0000 Subject: [PATCH 018/102] End the custom flow element, usage sharing and 51Did examples with a Find out more section The custom flow element example ends its page with the Build your own page, the Pipeline API documentation and this repository's pipeline folder. The usage sharing example prints the usage sharing documentation, the Pipeline API documentation and the pipeline folder last, and its expected output comment says the section follows. The 51Did example prints the 51Did page, its documentation, the 51Did inspector, the pipeline folder and the specifications repository after a successful run. --- ...lient_side_evidence_custom_flow_element.py | 29 +++++++++++++++++++ .../examples/fodid_example.py | 19 ++++++++++++ .../examples/usagesharing/usagesharing.py | 17 ++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/pipeline/fiftyone_pipeline_core/examples/client_side_evidence_custom_flow_element.py b/pipeline/fiftyone_pipeline_core/examples/client_side_evidence_custom_flow_element.py index e25c5723..d284ab95 100644 --- a/pipeline/fiftyone_pipeline_core/examples/client_side_evidence_custom_flow_element.py +++ b/pipeline/fiftyone_pipeline_core/examples/client_side_evidence_custom_flow_element.py @@ -30,12 +30,38 @@ # This latitude is also then passed in to the flowdata to calculate if # a person is in the northern or southern hemispheres. +import html + from fiftyone_pipeline_core.pipelinebuilder import PipelineBuilder from fiftyone_pipeline_core.web import json_response, webevidence from fiftyone_pipeline_core.basiclist_evidence_keyfilter import BasicListEvidenceKeyFilter from fiftyone_pipeline_core.flowelement import FlowElement from fiftyone_pipeline_core.elementdata_dictionary import ElementDataDictionary +# Where to go next, shown at the end of the page. +FIND_OUT_MORE = [ + ("Build your own", + "https://51degrees.com/build-your-own?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_core-examples-client_side_evidence_custom_flow_element.py&utm_term=find-out-more-build-your-own"), + ("Pipeline API documentation", + "https://51degrees.com/documentation/_pipeline_api__concepts__pipeline_basics.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_core-examples-client_side_evidence_custom_flow_element.py&utm_term=find-out-more-documentation"), + ("Pipeline API for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/pipeline"), +] + + +def find_out_more_html(): + """The Find out more section for the end of the page. A repository is + shown by its address, and any other link by its label.""" + items = "" + for label, url in FIND_OUT_MORE: + href = html.escape(url) + label = html.escape(label) + if url.startswith("https://github.com/"): + items += f"
  • {label}: {href}
  • " + else: + items += f"
  • {label}
  • " + return f"

    Find out more

      {items}
    " + # Function to get star sign from month and day def getStarSign(month, day): @@ -247,6 +273,9 @@ def server(): output += "" + # Where to go next. + output += find_out_more_html() + # Return the full output to the page return output diff --git a/pipeline/fiftyone_pipeline_did/examples/fodid_example.py b/pipeline/fiftyone_pipeline_did/examples/fodid_example.py index 18e16f37..a52b3c93 100644 --- a/pipeline/fiftyone_pipeline_did/examples/fodid_example.py +++ b/pipeline/fiftyone_pipeline_did/examples/fodid_example.py @@ -52,6 +52,20 @@ SAMPLE_TERMS = 1 # index 1, the Model Terms for Marketing # version 2 +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("51Did", + "https://51degrees.com/developers/51did?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_did-examples-fodid_example.py&utm_term=find-out-more-51did"), + ("51Did documentation", + "https://51degrees.com/documentation/_identifiers_51_did.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_did-examples-fodid_example.py&utm_term=find-out-more-documentation"), + ("51Did inspector", + "https://51degrees.com/developers/51did-inspector?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_did-examples-fodid_example.py&utm_term=find-out-more-51did-inspector"), + ("Pipeline API for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/pipeline"), + ("Specifications", + "https://github.com/51Degrees/specifications"), +] + def sample_payload(): """A canonical 38-byte Probabilistic payload: the flags byte, License @@ -109,6 +123,11 @@ def run(): "Expected a different envelope but the same match key across " "reissues.") + print("=" * 79) + print("Find out more:") + for label, url in FIND_OUT_MORE: + print(f"\t{label}: {url}") + if __name__ == "__main__": run() diff --git a/pipeline/fiftyone_pipeline_engines_fiftyone/examples/usagesharing/usagesharing.py b/pipeline/fiftyone_pipeline_engines_fiftyone/examples/usagesharing/usagesharing.py index ade418a8..375f3352 100644 --- a/pipeline/fiftyone_pipeline_engines_fiftyone/examples/usagesharing/usagesharing.py +++ b/pipeline/fiftyone_pipeline_engines_fiftyone/examples/usagesharing/usagesharing.py @@ -44,7 +44,7 @@ # # This example is available in full on [GitHub](https://github.com/51Degrees/51degrees-python/blob/main/pipeline/fiftyone_pipeline_engines_fiftyone/examples/usagesharing/usagesharing.py). # -# Expected output: +# Expected output, before the Find out more section: # ``` # Constructing pipeline from configuration file. # @@ -58,6 +58,16 @@ from fiftyone_pipeline_core.pipelinebuilder import PipelineBuilder from fiftyone_pipeline_engines_fiftyone.share_usage import ShareUsage +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("Usage sharing", + "https://51degrees.com/documentation/_pipeline_api__features__usage_sharing.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_engines_fiftyone-examples-usagesharing-usagesharing.py&utm_term=find-out-more-usage-sharing"), + ("Pipeline API documentation", + "https://51degrees.com/documentation/_pipeline_api__concepts__pipeline_basics.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_engines_fiftyone-examples-usagesharing-usagesharing.py&utm_term=find-out-more-documentation"), + ("Pipeline API for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/pipeline"), +] + print("Constructing pipeline from configuration file.") print() @@ -78,3 +88,8 @@ print("""Pipeline created with share usage element. Evidence processed with this pipeline will now be periodically shared with 51Degrees using the specified configuration.""") + +print("=" * 79) +print("Find out more:") +for label, url in FIND_OUT_MORE: + print(f"\t{label}: {url}") From 0559392a5c82adf76fae585d1da36df0ff98de74 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 03:52:00 +0000 Subject: [PATCH 019/102] End the mixed cloud console with a Find out more section at every end The mixed cloud console printed its section only after a run. Writing the section moves into GettingStartedConsole.print_find_out_more, which run still calls, and main now calls it too when there is no key and when the pipeline cannot be built, so each of the example's ends finishes with it. --- .../cloud/mixed/gettingstarted_console.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_console.py b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_console.py index 2f4fcf70..91b9c644 100644 --- a/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_console.py +++ b/pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/mixed/gettingstarted_console.py @@ -159,7 +159,7 @@ class GettingStartedConsole(): ("Time Zone Offset", "timezoneoffset"), ] - # Where to go next, printed after the results. + # Where to go next, printed when the example ends. FIND_OUT_MORE = [ ("Device detection", "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_console.py&utm_term=find-out-more-device-detection"), @@ -199,8 +199,19 @@ def run(self, pipeline, output): for evidence in self.EVIDENCE: self.analyse_evidence(evidence, pipeline, output) + self.print_find_out_more(output) + + @classmethod + def print_find_out_more(cls, output): + + """! + Write the "Find out more" section, a line of "=" and then each label + with its link. The example ends with it, whether it ran or stopped + early. + """ + message = ["=" * 79, "Find out more:"] - for label, url in self.FIND_OUT_MORE: + for label, url in cls.FIND_OUT_MORE: message.append(f"\t{label}: {url}") output("\n".join(message) + "\n") @@ -299,6 +310,7 @@ def main(argv): "https://51degrees.com/configure?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_pipeline_cloudrequestengine-examples-src-fiftyone_pipeline_examples-cloud-mixed-gettingstarted_console.py&utm_term=resource-key-required. " "Once complete, set the first environment variable named at " "the start of this message to the key.") + GettingStartedConsole.print_find_out_more(print) return try: @@ -311,6 +323,7 @@ def main(argv): # refused it, for example because the key is limited to domains # that do not include the origin sent. logger.log("error", str(error)) + GettingStartedConsole.print_find_out_more(print) return GettingStartedConsole().run(pipeline, print) From 00621e5ab204a8bada713cb221734fa2f1ff0b4c Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 00:14:43 +0000 Subject: [PATCH 020/102] End every Device Detection example with a Find out more section Each example now lists its own links, the Device Detection page, the resource keys documentation and pricing for the cloud examples, the Device Detection page and where to ask about the Enterprise data file for the on-premise ones, then this repository's device-detection folder, and 51degrees-cxx where the example uses the native engine. ExampleUtils gains print_find_out_more, which writes the section in the form the mixed cloud console uses, a line of "=" then "Find out more:" then each label and link on a tab-indented line. The section is printed at every clean end. A cloud console prints it after its results, and from main when there is no resource key. An on-premise console prints it from main, so it follows the results or the message that no data file was found. The data file update example prints it whether it updated the file, had no licence key or was stopped before downloading. The CSV and profile metadata examples write it where their progress messages go, so JSON on standard output stays valid. The offline processing example prints it to the console, because its results go to a file. The web examples end their pages with the section and print it to the console when the server stops, and the cloud ones also when there is no resource key. The scripts, failuretomatch, performance and the getting started example in fiftyone_devicedetection, print it last. --- .../examples/gettingstarted.py | 19 +++++++++++++++++++ .../cloud/configurator_console.py | 15 +++++++++++++++ .../cloud/failuretomatch.py | 14 ++++++++++++++ .../cloud/gettingstarted_console.py | 15 +++++++++++++++ .../cloud/gettingstarted_web/app.py | 16 ++++++++++++++++ .../gettingstarted_web/templates/index.html | 8 ++++++++ .../cloud/metadata_console.py | 15 +++++++++++++++ .../cloud/nativemodellookup_console.py | 15 +++++++++++++++ .../cloud/taclookup_console.py | 15 +++++++++++++++ .../cloud/useragentclienthints_web/app.py | 16 ++++++++++++++++ .../templates/index.html | 8 ++++++++ .../example_utils.py | 12 ++++++++++++ .../onpremise/csv_profile_metadata.py | 16 ++++++++++++++++ .../onpremise/datafileupdate_console.py | 16 ++++++++++++++++ .../onpremise/failuretomatch.py | 14 ++++++++++++++ .../onpremise/gettingstarted_console.py | 14 ++++++++++++++ .../onpremise/gettingstarted_web/app.py | 15 +++++++++++++++ .../gettingstarted_web/templates/index.html | 8 ++++++++ .../onpremise/match_metrics.py | 14 ++++++++++++++ .../onpremise/metadata_console.py | 14 ++++++++++++++ .../onpremise/offlineprocessing.py | 16 ++++++++++++++++ .../onpremise/performance.py | 14 ++++++++++++++ .../onpremise/profile_metadata_console.py | 16 ++++++++++++++++ .../onpremise/shareusage.py | 14 ++++++++++++++ .../onpremise/useragentclienthints_web/app.py | 15 +++++++++++++++ .../templates/index.html | 8 ++++++++ 26 files changed, 362 insertions(+) diff --git a/device-detection/fiftyone_devicedetection/examples/gettingstarted.py b/device-detection/fiftyone_devicedetection/examples/gettingstarted.py index b439c3d3..5cdf9325 100644 --- a/device-detection/fiftyone_devicedetection/examples/gettingstarted.py +++ b/device-detection/fiftyone_devicedetection/examples/gettingstarted.py @@ -22,6 +22,20 @@ from fiftyone_devicedetection.devicedetection_pipelinebuilder import DeviceDetectionPipelineBuilder +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection-examples-gettingstarted.py&utm_term=find-out-more-device-detection"), + ("Enterprise data file", + "https://51degrees.com/contact-us?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection-examples-gettingstarted.py&utm_term=find-out-more-enterprise-data-file"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection-examples-gettingstarted.py&utm_term=find-out-more-resource-keys"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), + ("Device detection engine", + "https://github.com/51Degrees/51degrees-cxx"), +] + # First create the device detection pipeline with the desired settings. data_file = "../../cxx/data/device-detection/51Degrees-LiteV4.1.hash" @@ -81,3 +95,8 @@ else: # Output why the value isn't meaningful print(flowdata2.device.ismobile.no_value_message()) + +print("=" * 79) +print("Find out more:") +for label, url in FIND_OUT_MORE: + print(f"\t{label}: {url}") diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/configurator_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/configurator_console.py index 6cd8ac4c..0ef8d9b8 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/configurator_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/configurator_console.py @@ -25,6 +25,18 @@ from fiftyone_devicedetection_cloud.devicedetection_cloud_pipelinebuilder import DeviceDetectionCloudPipelineBuilder from fiftyone_devicedetection_examples.example_utils import ExampleUtils +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=find-out-more-device-detection"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=find-out-more-resource-keys"), + ("Pricing", + "https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=find-out-more-pricing"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), +] + # This example is displayed at the end of the [configuration page](https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=top) # process, which is used to create resource keys for use with the 51Degrees cloud service. # @@ -79,6 +91,8 @@ def run(self, resource_key, logger, output): output("device.ismobile: " + f"{ExampleUtils.get_human_readable(device, 'ismobile')}") + ExampleUtils.print_find_out_more(FIND_OUT_MORE, output) + def main(argv): # Use the command line args to get the resource key if present. # Otherwise, get it from the environment variable. @@ -102,6 +116,7 @@ def main(argv): "https://51degrees.com/configure/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-configurator_console.py&utm_term=resource-key-required. " + "Once complete, populate the environment variable " + "mentioned at the start of this message with the key.") + ExampleUtils.print_find_out_more(FIND_OUT_MORE) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/failuretomatch.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/failuretomatch.py index c10939eb..ae926b41 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/failuretomatch.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/failuretomatch.py @@ -33,6 +33,18 @@ # it has no key. from fiftyone_devicedetection_examples.example_utils import ExampleUtils +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-failuretomatch.py&utm_term=find-out-more-device-detection"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-failuretomatch.py&utm_term=find-out-more-resource-keys"), + ("Pricing", + "https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-failuretomatch.py&utm_term=find-out-more-pricing"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), +] + resource_key = ExampleUtils.get_resource_key() or "!!YOUR_RESOURCE_KEY!!" if resource_key == "!!YOUR_RESOURCE_KEY!!": @@ -90,3 +102,5 @@ else: # Output why the value isn't meaningful print(flowdata2.device.ismobile.no_value_message()) + +ExampleUtils.print_find_out_more(FIND_OUT_MORE) diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.py index f763cfcf..7d525358 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_console.py @@ -45,6 +45,18 @@ from fiftyone_pipeline_core.pipelinebuilder import PipelineBuilder from fiftyone_devicedetection_examples.example_utils import ExampleUtils +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.py&utm_term=find-out-more-device-detection"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.py&utm_term=find-out-more-resource-keys"), + ("Pricing", + "https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.py&utm_term=find-out-more-pricing"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), +] + class GettingStartedConsole(): def run(self, config, logger, output): @@ -59,6 +71,8 @@ def run(self, config, logger, output): for values in self.EvidenceValues: self.analyseEvidence(values, pipeline, output) + ExampleUtils.print_find_out_more(FIND_OUT_MORE, output) + def analyseEvidence(self, evidence, pipeline, output): # FlowData is a data structure that is used to convey @@ -179,6 +193,7 @@ def main(argv): "created for free at https://51degrees.com/configure/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_console.py&utm_term=resource-key-required. " + "Once complete, populate the config file or environment variable " + "mentioned at the start of this message with the key.") + ExampleUtils.print_find_out_more(FIND_OUT_MORE) else: GettingStartedConsole().run(config, logger, print) diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/app.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/app.py index 94a2855d..7d9b1fd8 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/app.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/app.py @@ -84,6 +84,19 @@ import os import sys +# Where to go next, printed when the example ends. The page ends with the +# same links, in templates/index.html. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_web-app.py&utm_term=find-out-more-device-detection"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_web-app.py&utm_term=find-out-more-resource-keys"), + ("Pricing", + "https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-gettingstarted_web-app.py&utm_term=find-out-more-pricing"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), +] + class GettingStartedWeb(): app = Flask(__name__) @@ -208,5 +221,8 @@ def main(argv): "Once complete, populated the environment variable " + "mentioned at the start of this message with the key.") + # Printed once the server stops, or straight away when there is no key. + ExampleUtils.print_find_out_more(FIND_OUT_MORE) + if __name__ == "__main__": main(sys.argv[1:]) diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/templates/index.html b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/templates/index.html index f9ff4bd8..0d055c53 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/templates/index.html +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/gettingstarted_web/templates/index.html @@ -153,6 +153,14 @@

    Client-side evidence and Apple models

    Want to try on-premise? Contact us to discuss requirements.

    Contact us + +

    Find out more

    + {# diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/metadata_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/metadata_console.py index 7fc8ba08..b628ac2d 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/metadata_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/metadata_console.py @@ -53,6 +53,18 @@ from fiftyone_pipeline_core.basiclist_evidence_keyfilter import BasicListEvidenceKeyFilter from fiftyone_devicedetection_examples.example_utils import ExampleUtils +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=find-out-more-device-detection"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=find-out-more-resource-keys"), + ("Pricing", + "https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=find-out-more-pricing"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), +] + bgRed = "\u001b[41m" fgWhite = "\u001b[37;1m" colReset = "\u001b[0m" @@ -73,6 +85,8 @@ def run(self, resource_key, logger, output): # them to the cloud, so that's the engine we want the keys from. self.outputEvidenceKeyDetails(pipeline.get_element("cloud"), output) + ExampleUtils.print_find_out_more(FIND_OUT_MORE, output) + def outputEvidenceKeyDetails(self, engine, output): if (issubclass(type(engine.get_evidence_key_filter()), BasicListEvidenceKeyFilter)): @@ -126,6 +140,7 @@ def main(argv): "https://51degrees.com/configure/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=resource-key-required. " + "Once complete, populate the environment variable " + "mentioned at the start of this message with the key.") + ExampleUtils.print_find_out_more(FIND_OUT_MORE) if __name__ == "__main__": main(sys.argv[1:]) \ No newline at end of file diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/nativemodellookup_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/nativemodellookup_console.py index 868d0665..4b0b28b5 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/nativemodellookup_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/nativemodellookup_console.py @@ -45,6 +45,18 @@ from fiftyone_devicedetection_shared.constants import Constants from fiftyone_devicedetection_cloud.hardwareprofile_cloud import HardwareProfileCloud +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-nativemodellookup_console.py&utm_term=find-out-more-device-detection"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-nativemodellookup_console.py&utm_term=find-out-more-resource-keys"), + ("Pricing", + "https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-nativemodellookup_console.py&utm_term=find-out-more-pricing"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), +] + class NativeModelLookupConsole(): def run(self, resource_key, logger, output, cloudEndPoint = ""): @@ -82,6 +94,8 @@ def run(self, resource_key, logger, output, cloudEndPoint = ""): # Repeat for an alternative native model name. self.analyseModel(self._nativeModel2, pipeline, output) + ExampleUtils.print_find_out_more(FIND_OUT_MORE, output) + def analyseModel(self, nativemodel, pipeline, output): # Create the FlowData instance. data = pipeline.create_flowdata() @@ -136,6 +150,7 @@ def main(argv): "https://51degrees.com/configure/QKyYH5XT?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-nativemodellookup_console.py&utm_term=resource-key-required. You can now populate the " + "environment variable mentioned at the start of this message with the " + "resource key or pass it as the first argument on the command line.") + ExampleUtils.print_find_out_more(FIND_OUT_MORE) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.py index 0d07605e..dca57cc6 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/taclookup_console.py @@ -48,6 +48,18 @@ from fiftyone_pipeline_core.pipelinebuilder import PipelineBuilder from fiftyone_devicedetection_shared.constants import Constants +# Where to go next, printed when the example ends. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.py&utm_term=find-out-more-device-detection"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.py&utm_term=find-out-more-resource-keys"), + ("Pricing", + "https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-taclookup_console.py&utm_term=find-out-more-pricing"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), +] + class TacLookupConsole(): def run(self, config, logger, output): @@ -72,6 +84,8 @@ def run(self, config, logger, output): # Repeat for an alternative TAC. self.analyseTac(self._tac2, pipeline, output) + ExampleUtils.print_find_out_more(FIND_OUT_MORE, output) + def analyseTac(self, tac, pipeline, output): # Create the FlowData instance. data = pipeline.create_flowdata() @@ -138,6 +152,7 @@ def main(argv): "can now populate the environment variable mentioned at the start " + "of this message with the resource key or pass it as the first " + "argument on the command line.") + ExampleUtils.print_find_out_more(FIND_OUT_MORE) else: TacLookupConsole().run(config, logger, print) diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/app.py b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/app.py index b47cce81..c534ffbd 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/app.py +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/app.py @@ -52,6 +52,19 @@ from fiftyone_pipeline_core.logger import Logger from fiftyone_pipeline_core.web import webevidence, set_response_header +# Where to go next, printed when the example ends. The page ends with the +# same links, in templates/index.html. +FIND_OUT_MORE = [ + ("Device detection", + "https://51degrees.com/device-detection?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-useragentclienthints_web-app.py&utm_term=find-out-more-device-detection"), + ("Resource keys", + "https://51degrees.com/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-useragentclienthints_web-app.py&utm_term=find-out-more-resource-keys"), + ("Pricing", + "https://51degrees.com/pricing?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-useragentclienthints_web-app.py&utm_term=find-out-more-pricing"), + ("Device detection for Python", + "https://github.com/51Degrees/51degrees-python/tree/main/device-detection"), +] + class UserAgentClientHintsWeb(): app = Flask(__name__) @@ -143,6 +156,9 @@ def main(argv): "Once complete, populated the environment variable " + "mentioned at the start of this message with the key.") + # Printed once the server stops, or straight away when there is no key. + ExampleUtils.print_find_out_more(FIND_OUT_MORE) + if __name__ == "__main__": main(sys.argv[1:]) diff --git a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/templates/index.html b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/templates/index.html index b206b40c..1b84bc94 100644 --- a/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/templates/index.html +++ b/device-detection/fiftyone_devicedetection_examples/src/fiftyone_devicedetection_examples/cloud/useragentclienthints_web/templates/index.html @@ -101,6 +101,14 @@

    Detection results

    Want to try on-premise? Contact us to discuss requirements.

    Contact us
    + +

    Find out more

    +