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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def build(self, resource_key, logger):

def run(self):

GettingStartedWeb.app.run(port=int(os.environ.get("PORT", 5000)))
GettingStartedWeb.app.run(port=int(os.environ.get("PORT", 5151)))

# First we make a JSON route that will be called from the client side and will return
# a JSON encoded property database using any additional evidence provided by the client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def build(self, resource_key, logger):
return self

def run(self):
UserAgentClientHintsWeb.app.run(port=int(os.environ.get("PORT", 5000)))
UserAgentClientHintsWeb.app.run(port=int(os.environ.get("PORT", 5151)))

# The main route performs device detection and renders the results. On the
# second request, any additional client hints headers requested via the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def run(self):
# The pipeline lives as long as the app, and is closed when the server
# stops, which releases the native data it holds.
with GettingStartedWeb.pipeline:
GettingStartedWeb.app.run(port=int(os.environ.get("PORT", 5001)))
GettingStartedWeb.app.run(port=int(os.environ.get("PORT", 5151)))

# First we make a JSON route that will be called from the client side and will return
# a JSON encoded property database using any additional evidence provided by the client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def run(self):
# The pipeline lives as long as the app, and is closed when the server
# stops, which releases the native data it holds.
with UserAgentClientHintsWeb.pipeline:
UserAgentClientHintsWeb.app.run(port=5001)
UserAgentClientHintsWeb.app.run(port=5151)

# The main route performs device detection and renders the results. On the
# second request, any additional client hints headers requested via the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# *********************************************************************
# 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 listens on port 5151 by default. The examples that read
the PORT environment variable still do, because that is how the CI starts
them on ports of its own. The checks read the examples' source, so they
start no server and 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_devicedetection_examples")
WEB_EXAMPLES = [
os.path.join(EXAMPLES, "cloud", "gettingstarted_web", "app.py"),
os.path.join(EXAMPLES, "cloud", "useragentclienthints_web", "app.py"),
os.path.join(EXAMPLES, "onpremise", "gettingstarted_web", "app.py"),
os.path.join(EXAMPLES, "onpremise", "useragentclienthints_web", "app.py"),
]
# The examples whose port the PORT environment variable sets.
PORT_FROM_ENVIRONMENT = WEB_EXAMPLES[:3]


def read_port(node):
# The default port and the environment variable that overrides it, from
# a number, int() of one, or os.environ.get(name, number).
if isinstance(node, ast.Constant):
return int(node.value), None
if isinstance(node, ast.Call):
if getattr(node.func, "id", None) == "int" and node.args:
return read_port(node.args[0])
if getattr(node.func, "attr", None) == "get" and len(node.args) == 2:
port, _ = read_port(node.args[1])
return port, getattr(node.args[0], "value", None)
return None, None


def port_setting(path):
# The port the example passes to run, as read_port gives it.
with open(path, encoding="utf-8") as source:
tree = ast.parse(source.read())
for node in ast.walk(tree):
if (isinstance(node, ast.Call)
and isinstance(node.func, ast.Attribute)
and node.func.attr == "run"):
for keyword in node.keywords:
if keyword.arg == "port":
return read_port(keyword.value)
return None, None


class WebExamplePortTests(unittest.TestCase):

def test_every_web_example_listens_on_5151_by_default(self):
for path in WEB_EXAMPLES:
with self.subTest(example=path):
self.assertEqual(5151, port_setting(path)[0])

def test_the_port_environment_variable_still_sets_the_port(self):
for path in PORT_FROM_ENVIRONMENT:
with self.subTest(example=path):
self.assertEqual("PORT", port_setting(path)[1])


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def main(resource_key = None):
"the start of this message with the key.")
else:
build_pipeline(resource_key)
app.run(debug=False)
app.run(port=5151, debug=False)

# Every end, with no key or once the server stops, finishes here.
ExampleUtils.print_find_out_more(FIND_OUT_MORE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def main(data_file = None):
# The pipeline lives as long as the app, and is closed when the server
# stops, which releases the native data it holds.
with build_pipeline(data_file):
app.run(debug=False)
app.run(port=5151, debug=False)

ExampleUtils.print_find_out_more(FIND_OUT_MORE)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# *********************************************************************
# 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 listens on port 5151 by default, rather than on the port
Flask picks when none is given. The checks read the examples' source, so
they start no server and 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 read_port(node):
# The default port, from a number, int() of one, or
# os.environ.get(name, number).
if isinstance(node, ast.Constant):
return int(node.value)
if isinstance(node, ast.Call):
if getattr(node.func, "id", None) == "int" and node.args:
return read_port(node.args[0])
if getattr(node.func, "attr", None) == "get" and len(node.args) == 2:
return read_port(node.args[1])
return None


def default_port(path):
# The port the example passes to app.run, or None when it passes none.
with open(path, encoding="utf-8") as source:
tree = ast.parse(source.read())
for node in ast.walk(tree):
if (isinstance(node, ast.Call)
and isinstance(node.func, ast.Attribute)
and node.func.attr == "run"):
for keyword in node.keywords:
if keyword.arg == "port":
return read_port(keyword.value)
return None


class WebExamplePortTests(unittest.TestCase):

def test_every_web_example_listens_on_5151_by_default(self):
for path in WEB_EXAMPLES:
with self.subTest(example=path):
self.assertEqual(5151, default_port(path))


if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions location/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ To run the web example navigate into Examples folder:

#### Linux

Execute `export FLASK_APP=web` where `web` is the example file, and start your application via `flask run`.
Execute `export FLASK_APP=web` where `web` is the example file, and start your application via `flask run --port 5151`.

#### Windows

Execute `$env:FLASK_APP = "web"` where `web` is the example file, and start your application via `flask run`.
Execute `$env:FLASK_APP = "web"` where `web` is the example file, and start your application via `flask run --port 5151`.

A Flow Data cannot be used by two threads at once, so the web example
creates a Flow Data for each request, uses it only in the code that handles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ and the web example with
.venv/bin/python -m fiftyone_pipeline_examples.cloud.mixed.gettingstarted_web
```

then open <http://localhost:5000>. Set `PORT` to listen on another port.
then open <http://localhost:5151>. Set `PORT` to listen on another port.

### Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# ```
# python -m fiftyone_pipeline_examples.cloud.mixed.gettingstarted_web
# ```
# and open http://localhost:5000, or the port named by the PORT environment
# and open http://localhost:5151, or the port named by the PORT environment
# variable. Use the form on the page, or add ?client-ip=8.8.8.8 to the
# address, to look up an IP address other than your own.
#
Expand Down Expand Up @@ -491,7 +491,7 @@ def main(argv):
print_find_out_more()
sys.exit(1)

create_app(pipeline).run(port=int(os.environ.get("PORT", 5000)))
create_app(pipeline).run(port=int(os.environ.get("PORT", 5151)))


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# *********************************************************************
# 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 web example listens on port 5151 by default, and on the port the
PORT environment variable names when it is set. The check reads the
example's source, so it starts no server and needs no network.
"""

import ast
import os
import unittest

APP = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "src",
"fiftyone_pipeline_examples", "cloud", "mixed", "gettingstarted_web",
"app.py")


def run_port():
# The expression the example passes to run as its port.
with open(APP, encoding="utf-8") as source:
tree = ast.parse(source.read())
for node in ast.walk(tree):
if (isinstance(node, ast.Call)
and isinstance(node.func, ast.Attribute)
and node.func.attr == "run"):
for keyword in node.keywords:
if keyword.arg == "port":
return keyword.value
return None


class CloudMixedWebPortTests(unittest.TestCase):

def test_listens_on_5151_unless_port_names_another(self):
port = run_port()
# int(os.environ.get("PORT", 5151))
self.assertIsInstance(port, ast.Call)
get = port.args[0]
self.assertEqual("get", get.func.attr)
self.assertEqual(["PORT", 5151], [arg.value for arg in get.args])


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
``_51DEGREES_CLOUD_ENDPOINT`` is the cloud API base including the ``/api/v4/``
segment, defaulting to ``https://cloud.51degrees.com/api/v4/``, and is
the same variable the cloud request engine and the ``DidClient`` honour.
``PORT`` is the port to listen on, defaulting to 5100.
``PORT`` is the port to listen on, defaulting to 5151.

Standard library plus this package. Run ``python server.py`` then open
``http://localhost:5100/``.
``http://localhost:5151/``.
"""

import asyncio
Expand Down Expand Up @@ -121,7 +121,7 @@ def env(name):
# demo works unchanged against either.
API = (env("_51DEGREES_CLOUD_ENDPOINT")
or DEFAULT_API).rstrip("/") + "/"
PORT = int(os.environ.get("PORT", "5100"))
PORT = int(os.environ.get("PORT", "5151"))

# Where to go next. The page ends with these links, and the demo prints
# them when it stops before the page is served.
Expand Down
4 changes: 2 additions & 2 deletions pipeline/fiftyone_pipeline_did/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ unreachable cloud answers 502 with `{ "error": ... }`.
| `_51DEGREES_RESOURCE_KEY` | Required. The page's resource key, public by nature |
| `_51DEGREES_LICENSE_KEY` | Optional. A licence key of the same account, held server side only. Only an account that holds licence keys needs one to redeem, so an account holding none runs without it |
| `_51DEGREES_CLOUD_ENDPOINT` | Optional. The cloud API base including the `/api/v4/` segment, defaulting to `https://cloud.51degrees.com/api/v4/`. This is the same variable the cloud request engine honours. A host other than cloud.51degrees.com would be used to (a) use an on premise web server, or (b) use a privately hosted version of the 51Degrees cloud for performance reasons, which is the private hosting option of the cloud service. Both run the same service, so the demo works unchanged against either |
| `PORT` | The port to listen on, defaulting to `5100` |
| `PORT` | The port to listen on, defaulting to `5151` |

### Running

Expand All @@ -686,7 +686,7 @@ cd fiftyone_pipeline_did/examples/creator_context_web
python server.py
```

then open `http://localhost:5100/`. To demonstrate across two devices,
then open `http://localhost:5151/`. To demonstrate across two devices,
serve on an address both can reach and open the copied link on the
second device.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const sandbox = {
navigator: { clipboard: { writeText: function () {} } },
location: {
search: given ? '?51did=' + encodeURIComponent(given) : '',
origin: 'http://localhost:5100',
origin: 'http://localhost:5151',
pathname: '/'
}
};
Expand Down
Loading
Loading