From 93adcac50a4f591e4a83c958695ad22747a24c57 Mon Sep 17 00:00:00 2001 From: Elaine Chien Date: Wed, 9 Aug 2023 00:16:39 +0000 Subject: [PATCH] Create sample python package (#801) * Start creating sample python package with https post request Signed-off-by: Elaine Chien * decode output Signed-off-by: Elaine Chien * Revise README and Makefile Signed-off-by: Elaine Chien * spelling Signed-off-by: Elaine Chien * Add https post request call to install and import phases Signed-off-by: Elaine Chien * Remove requirements.txt * Change function names to use underscores Signed-off-by: Elaine Chien * Add newline Signed-off-by: Elaine Chien * Remove license and just defer to main package analysis license Signed-off-by: Elaine Chien --------- Signed-off-by: Elaine Chien Co-authored-by: Elaine Chien Co-authored-by: Caleb Brown --- .../sample_python_package/README.md | 9 +++++++++ .../sample_python_package/pyproject.toml | 18 ++++++++++++++++++ .../sample_python_package/setup.py | 12 ++++++++++++ .../sample_python_package/src/__init__.py | 8 ++++++++ .../sample_python_package/src/example.py | 19 +++++++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 sample_packages/sample_python_package/README.md create mode 100644 sample_packages/sample_python_package/pyproject.toml create mode 100644 sample_packages/sample_python_package/setup.py create mode 100644 sample_packages/sample_python_package/src/__init__.py create mode 100755 sample_packages/sample_python_package/src/example.py diff --git a/sample_packages/sample_python_package/README.md b/sample_packages/sample_python_package/README.md new file mode 100644 index 00000000..eadd5e6c --- /dev/null +++ b/sample_packages/sample_python_package/README.md @@ -0,0 +1,9 @@ +## Sample Python package + +This package will simulate different scenarios to test package analysis on. + +To use this package for local analysis, build this package by running +`python3 -m build` in this directory. The package will be located in the dist/ +folder. + +The same license for the rest of the package analysis project applies to this package. diff --git a/sample_packages/sample_python_package/pyproject.toml b/sample_packages/sample_python_package/pyproject.toml new file mode 100644 index 00000000..dee0cf46 --- /dev/null +++ b/sample_packages/sample_python_package/pyproject.toml @@ -0,0 +1,18 @@ +[build-system] +requires = ["setuptools", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[project] +name = "sample_python_package" +version = "0.0.1" +authors = [ + { name="OpenSSF " }, +] +description = "A small example package" +readme = "README.md" +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", +] diff --git a/sample_packages/sample_python_package/setup.py b/sample_packages/sample_python_package/setup.py new file mode 100644 index 00000000..9790d468 --- /dev/null +++ b/sample_packages/sample_python_package/setup.py @@ -0,0 +1,12 @@ +import sys +import os +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(SCRIPT_DIR) + +from setuptools import setup, find_packages +from src.example import * + +setup(name="sample_python_package", + packages=find_packages(),) + +send_https_post_request("setup.py") diff --git a/sample_packages/sample_python_package/src/__init__.py b/sample_packages/sample_python_package/src/__init__.py new file mode 100644 index 00000000..0fcc0e72 --- /dev/null +++ b/sample_packages/sample_python_package/src/__init__.py @@ -0,0 +1,8 @@ +import sys +import os +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(SCRIPT_DIR) + +from example import * + +send_https_post_request("__init__.py") diff --git a/sample_packages/sample_python_package/src/example.py b/sample_packages/sample_python_package/src/example.py new file mode 100755 index 00000000..8c59e892 --- /dev/null +++ b/sample_packages/sample_python_package/src/example.py @@ -0,0 +1,19 @@ +import http.client +import json + +# Sends an HTTPS post request and prints out the response. +def send_https_post_request(location: str) -> None: + host = "www.httpbin.org" + conn = http.client.HTTPSConnection(host) + data = {'text': 'Sending data through HTTPS from: ' + location} + json_data = json.dumps(data) + conn.request("POST", "/post", json_data, headers={"Host": host}) + response = conn.getresponse() + print(response.read().decode()) + +def main(): + send_https_post_request("main function") + + +if __name__ == "__main__": + main()