Giter Site home page Giter Site logo

sureshjoshi / example-adhoc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pantsbuild/example-adhoc

0.0 0.0 0.0 61 KB

Example uses of the Pants adhoc command functionality

License: Apache License 2.0

Shell 41.69% JavaScript 1.22% Python 18.16% ANTLR 1.27% Starlark 37.67%

example-adhoc's Introduction

Pants adhoc_tool examples

This is an example repository to demonstrate support for unsupported languages and arbitrary 3rd-party tools in Pants.

The examples use the adhoc_tool and system_binary targets, that were added as experimental features in Pants 2.16.0a0, and will

See pantsbuild.org for much more detailed documentation of adhoc_tool and system_binary Full documentation will available before Pants 2.16 stable release.

This is only one possible way of laying out your project with Pants. See pantsbuild.org/docs/source-roots#examples for some other example layouts.

This repository demonstrates advanced uses of Pants. For more introductory use cases, consider looking at example-python or example-jvm.

Examples

Using a JVM artifact from Maven to generate Python source code

Using adhoc_tool, you can run a Maven artifact that's declared by a jvm_artifact target. We can use that to run the JVM-based antlr parser generator to transparently produce Python bindings, which can then be imported from our first-party Python code.

To see the demo in practice, run ./pants run antlr/antlr_demo.py.

This demo uses:

  • jvm_artifact to declare a dependency on the Antlr parser generator
  • adhoc_tool which asks Pants to run the Antlr dependency as a build step, outputting files containing Python bindings (as loose files)
  • experimental_wrap_as_python_sources, which allows subsequent steps to consume the loose files as Python sources that can be imported.

Note that sources declared by experimental_wrap_as_* targets can not currently be detected using Dependency Inference.

Building a JavaScript asset for inclusion in a web application

Using system_binary, you can declare dependencies on tools that are managed externally to Pants, including basic compatibility checks by way of version constraints.

This allows you to use tools from languages that aren't directly supported by Pants. We can use that to manage a node_modules directory using yarn and node binaries that were installed onto the host system (e.g. by Homebrew or apt).

Our demo produces a simple CLI script that imports an npm dependency and functions from a first-party library and links them together using Parcel. Package resolution and tool execution is handled by yarn.

To see the demo in practice, run ./pants run javascript:run-js-app, or ./pants package javascript:packaged-js to package the JavaScript code into a zip file.

This demo uses:

  • system_binary to declare dependencies on node and yarn binaries. The fingerprint* fields are used to declare version constraints that can be used to ensure builds are reproducible across multiple execution environments.
  • adhoc_tool to execute the yarn install and yarn parcel commands.
  • run_shell_command to run the generated JavaScript artifact with node.
  • archive to package the generated JavaScript archive into a zip file

Automatically generating JavaScript bindings for a Flask web app with an OpenAPI schema

Using adhoc_tool, you can run individual first-party sources to fetch their output. This can produce inputs for other targets.

In this example, a small Flask web application can dump an OpenAPI schema, which can in turn be used to transparently generate bindings for other languages.

To see the demo in practive, run ./pants export-codegen openapi:webapp-js-bindings

This demo uses

  • python_source to declare a runnable Python source, webapp.py.
  • jvm_artifact to declare a dependency on the JVM-based OpenAPI client generator
  • adhoc_tool to run the webapp.py source, and saving its stdout to a file using the stdout= field
  • adhoc_tool to run the JVM client generator

example-adhoc's People

Contributors

huonw avatar sureshjoshi avatar alextereshenkov avatar chrisjrn avatar

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.