GithubHelp home page GithubHelp logo

Validation strategy about mapbox-cli-py HOT 4 CLOSED

mapbox avatar mapbox commented on June 19, 2024
Validation strategy

from mapbox-cli-py.

Comments (4)

perrygeo avatar perrygeo commented on June 19, 2024

Per chat w @sgillies:

  • Write validation logic in SDK
  • Write click callbacks in CLI (which leverage the validation logic in the SDK)
  • Simple functions instead of stateful methods (keep it testable)

I'm still stuck on exactly how the implementation is going to look, it could take one of several forms but I'm currently leaning towards:

  • mapbox.validate module exposing a bunch of functions with the signature f(val) -> val and raise a ValueError if anything was wrong.
  • mapboxcli.validate module with a bunch of wrapper functions that call ^ and reraise click.BadParameter. These would be click callbacks and take the signature f(ctx, param, val) -> val

The validation modules could even handle the geojson feature validation and normalization.

from mapbox-cli-py.

perrygeo avatar perrygeo commented on June 19, 2024

@sgillies, I created validation branches in both the sdk and cli. Started off with geocoding, let's review this before I go ahead with the other services:

In the CLI:
957694d

In the SDK:
mapbox/mapbox-sdk-py@b235003

from mapbox-cli-py.

sgillies avatar sgillies commented on June 19, 2024

Agreed that we shouldn't repeat ourselves. How about this (a restatement of our conclusions from yesterday plus some new thoughts):

SDK

  • In the SDK we are committed to preventing requests that will fail 💯 because of invalid arguments (image sizes, travel modes, geocoding datasets)
  • Let's validate them using functions in a validation module, not with in-line code.
  • Raise SDK-specific exceptions that derive from ValueError (or KeyError for, say, travel modes).

CLI

  • We're committed 💯 to sparing CLI users from reading tracebacks.
  • The CLI takes responsibility for validating: input/output file paths and the few other things that aren't a concern of the SDK
  • Otherwise, rely on the SDK, re-raising its errors as you suggest above.
  • We could reserve the option to write validiating Click callbacks using methods from the SDK's validation module if we have a future need.

from mapbox-cli-py.

perrygeo avatar perrygeo commented on June 19, 2024

👍 I'll work on implementing this soon.

rely on the SDK, re-raising its errors ...
write validiating Click callbacks using methods from the SDK's validation module if we have a future need

I realized that writing click callbacks means testing everything twice (once on arg parsing, once when you run it). I think just catching SDK exceptions is sufficient and DRY (as long as we have a consistent exception to look out for)

from mapbox-cli-py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.