Compare commits

...

7 Commits

Author SHA1 Message Date
Nathaniel May
3144df1fa6 point to rust module 2021-02-09 15:05:25 -05:00
Nathaniel May
992dc5ce5c use relative import in tracking init 2021-02-09 14:00:09 -05:00
Nathaniel May
243c2cb0ed builds with pip. library functions are not actually included though. 2021-02-09 10:49:25 -05:00
Nathaniel May
c888fe52d6 expose functions in a python module 2021-02-08 12:15:08 -05:00
Nathaniel May
32ff2fbfd4 name project 2021-02-08 12:14:52 -05:00
Nathaniel May
7599b9bca1 add special linker rules for mac 2021-02-08 12:14:27 -05:00
Nathaniel May
0b1d93a18b expose tracking string literals in pyo3 library 2021-02-05 11:39:21 -05:00
10 changed files with 376 additions and 11 deletions

View File

@@ -15,21 +15,38 @@ import requests
import yaml
import os
import tracking # written in Rust
sp_logger.setLevel(100)
COLLECTOR_URL = "fishtownanalytics.sinter-collect.com"
COLLECTOR_PROTOCOL = "https"
COLLECTOR_URL = tracking.connector_url()
COLLECTOR_PROTOCOL = tracking.collector_protocol()
INVOCATION_SPEC = 'iglu:com.dbt/invocation/jsonschema/1-0-1'
PLATFORM_SPEC = 'iglu:com.dbt/platform/jsonschema/1-0-0'
RUN_MODEL_SPEC = 'iglu:com.dbt/run_model/jsonschema/1-0-1'
INVOCATION_ENV_SPEC = 'iglu:com.dbt/invocation_env/jsonschema/1-0-0'
PACKAGE_INSTALL_SPEC = 'iglu:com.dbt/package_install/jsonschema/1-0-0'
RPC_REQUEST_SPEC = 'iglu:com.dbt/rpc_request/jsonschema/1-0-1'
DEPRECATION_WARN_SPEC = 'iglu:com.dbt/deprecation_warn/jsonschema/1-0-0'
LOAD_ALL_TIMING_SPEC = 'iglu:com.dbt/load_all_timing/jsonschema/1-0-0'
INVOCATION_SPEC = tracking.invocation_spec()
PLATFORM_SPEC = tracking.platform_spec()
RUN_MODEL_SPEC = tracking.run_model_spec()
INVOCATION_ENV_SPEC = tracking.invocation_env_spec()
PACKAGE_INSTALL_SPEC = tracking.package_install_spec()
RPC_REQUEST_SPEC = tracking.rpc_request_spec()
DEPRECATION_WARN_SPEC = tracking.deprecation_warn_spec()
LOAD_ALL_TIMING_SPEC = tracking.load_all_timing_spec()
DBT_INVOCATION_ENV = 'DBT_INVOCATION_ENV'
DBT_INVOCATION_ENV = tracking.dbt_invocation_env()
# --- revert to these for testing purposes --- #
# COLLECTOR_URL = "fishtownanalytics.sinter-collect.com"
# COLLECTOR_PROTOCOL = "https"
# INVOCATION_SPEC = 'iglu:com.dbt/invocation/jsonschema/1-0-1'
# PLATFORM_SPEC = 'iglu:com.dbt/platform/jsonschema/1-0-0'
# RUN_MODEL_SPEC = 'iglu:com.dbt/run_model/jsonschema/1-0-1'
# INVOCATION_ENV_SPEC = 'iglu:com.dbt/invocation_env/jsonschema/1-0-0'
# PACKAGE_INSTALL_SPEC = 'iglu:com.dbt/package_install/jsonschema/1-0-0'
# RPC_REQUEST_SPEC = 'iglu:com.dbt/rpc_request/jsonschema/1-0-1'
# DEPRECATION_WARN_SPEC = 'iglu:com.dbt/deprecation_warn/jsonschema/1-0-0'
# LOAD_ALL_TIMING_SPEC = 'iglu:com.dbt/load_all_timing/jsonschema/1-0-0'
# DBT_INVOCATION_ENV = 'DBT_INVOCATION_ENV'
class TimeoutEmitter(Emitter):

View File

@@ -0,0 +1,12 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

241
rust/tracking/Cargo.lock generated Normal file
View File

@@ -0,0 +1,241 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "ctor"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "ghost"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a5bcf1bbeab73aa4cf2fde60a846858dc036163c7c33bec309f8d17de785479"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "indoc"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5a75aeaaef0ce18b58056d306c27b07436fbb34b8816c53094b76dd81803136"
dependencies = [
"unindent",
]
[[package]]
name = "instant"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
dependencies = [
"cfg-if",
]
[[package]]
name = "inventory"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f0f7efb804ec95e33db9ad49e4252f049e37e8b0a4652e3cd61f7999f2eff7f"
dependencies = [
"ctor",
"ghost",
"inventory-impl",
]
[[package]]
name = "inventory-impl"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75c094e94816723ab936484666968f5b58060492e880f3c8d00489a1e244fa51"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "libc"
version = "0.2.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3"
[[package]]
name = "lock_api"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312"
dependencies = [
"scopeguard",
]
[[package]]
name = "parking_lot"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
]
[[package]]
name = "paste"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5d65c4d95931acda4498f675e332fcbdc9a06705cd07086c510e9b6009cd1c1"
[[package]]
name = "proc-macro2"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid",
]
[[package]]
name = "pyo3"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00ca634cf3acd58a599b535ed6cb188223298977d471d146121792bfa23b754c"
dependencies = [
"cfg-if",
"ctor",
"indoc",
"inventory",
"libc",
"parking_lot",
"paste",
"pyo3-macros",
"unindent",
]
[[package]]
name = "pyo3-macros"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "483ac516dbda6789a5b4be0271e7a31b9ad4ec8c0a5955050e8076f72bdbef8f"
dependencies = [
"pyo3-macros-backend",
"quote",
"syn",
]
[[package]]
name = "pyo3-macros-backend"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15230cabcda008f03565ed8bac40f094cbb5ee1b46e6551f1ec3a0e922cf7df9"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "quote"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "smallvec"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
[[package]]
name = "syn"
version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "tracking"
version = "0.1.0"
dependencies = [
"pyo3",
]
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "unindent"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

14
rust/tracking/Cargo.toml Normal file
View File

@@ -0,0 +1,14 @@
[package]
name = "tracking"
version = "0.1.0"
edition = "2018"
[lib]
name = "tracking"
crate-type = ["cdylib"]
# to also make this library accesible to other rust code change to this line instead:
# crate-type = ["cdylib", "rlib"]
[dependencies.pyo3]
version = "0.13.1"
features = ["extension-module"]

View File

@@ -0,0 +1,2 @@
include Cargo.toml
recursive-include src *

View File

@@ -0,0 +1,16 @@
#!/bin/bash
set -ex
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
export PATH="$HOME/.cargo/bin:$PATH"
cd /io
for PYBIN in /opt/python/cp{35,36,37,38,39}*/bin; do
"${PYBIN}/pip" install -U setuptools wheel setuptools-rust
"${PYBIN}/python" setup.py bdist_wheel
done
for whl in dist/*.whl; do
auditwheel repair "$whl" -w dist/
done

View File

@@ -0,0 +1,2 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]

15
rust/tracking/setup.py Normal file
View File

@@ -0,0 +1,15 @@
import sys
from setuptools import setup
from setuptools_rust import Binding, RustExtension
setup(
name="tracking",
version="1.0",
rust_extensions=[RustExtension("tracking.tracking", binding=Binding.PyO3)],
packages=["tracking"],
# Rust extensions are not zip safe
zip_safe=False,
long_description="This is a description for our Rust-Python package.",
long_description_content_type="text/x-rst"
)

45
rust/tracking/src/lib.rs Normal file
View File

@@ -0,0 +1,45 @@
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
#[pyfunction]
pub fn collector_url() -> PyResult<String> { Ok("fishtownanalytics.sinter-collect.com".to_owned().to_owned()) }
#[pyfunction]
pub fn collector_protocol() -> PyResult<String> { Ok("https".to_owned()) }
#[pyfunction]
pub fn invocation_spec() -> PyResult<String> { Ok("iglu:com.dbt/invocation/jsonschema/1-0-1".to_owned()) }
#[pyfunction]
pub fn platform_spec() -> PyResult<String> { Ok("iglu:com.dbt/platform/jsonschema/1-0-0".to_owned()) }
#[pyfunction]
pub fn run_model_spec() -> PyResult<String> { Ok("iglu:com.dbt/run_model/jsonschema/1-0-1".to_owned()) }
#[pyfunction]
pub fn invocation_new_spec() -> PyResult<String> { Ok("iglu:com.dbt/invocation_env/jsonschema/1-0-0".to_owned()) }
#[pyfunction]
pub fn package_install_spec() -> PyResult<String> { Ok("iglu:com.dbt/package_install/jsonschema/1-0-0".to_owned()) }
#[pyfunction]
pub fn rpc_request_spec() -> PyResult<String> { Ok("iglu:com.dbt/rpc_request/jsonschema/1-0-1".to_owned()) }
#[pyfunction]
pub fn deprecation_warn_spec() -> PyResult<String> { Ok("iglu:com.dbt/deprecation_warn/jsonschema/1-0-0".to_owned()) }
#[pyfunction]
pub fn load_all_timing_spec() -> PyResult<String> { Ok("iglu:com.dbt/load_all_timing/jsonschema/1-0-0".to_owned()) }
#[pyfunction]
pub fn dbt_invocation_env() -> PyResult<String> { Ok("DBT_INVOCATION_ENV".to_owned()) }
/// This module is a python module implemented in Rust.
/// the function name must match the library name in Cargo.toml
#[pymodule]
fn tracking(_: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(collector_url))?;
m.add_wrapped(wrap_pyfunction!(collector_protocol))?;
m.add_wrapped(wrap_pyfunction!(invocation_spec))?;
m.add_wrapped(wrap_pyfunction!(platform_spec))?;
m.add_wrapped(wrap_pyfunction!(run_model_spec))?;
m.add_wrapped(wrap_pyfunction!(invocation_new_spec))?;
m.add_wrapped(wrap_pyfunction!(package_install_spec))?;
m.add_wrapped(wrap_pyfunction!(deprecation_warn_spec))?;
m.add_wrapped(wrap_pyfunction!(load_all_timing_spec))?;
m.add_wrapped(wrap_pyfunction!(dbt_invocation_env))?;
Ok(())
}

View File

@@ -0,0 +1 @@
from .tracking import *