Skip to content

Commit

Permalink
Create sample python package (#801)
Browse files Browse the repository at this point in the history
* Start creating sample python package with https post request

Signed-off-by: Elaine Chien <[email protected]>

* decode output

Signed-off-by: Elaine Chien <[email protected]>

* Revise README and Makefile

Signed-off-by: Elaine Chien <[email protected]>

* spelling

Signed-off-by: Elaine Chien <[email protected]>

* Add https post request call to install and import phases

Signed-off-by: Elaine Chien <[email protected]>

* Remove requirements.txt

* Change function names to use underscores

Signed-off-by: Elaine Chien <[email protected]>

* Add newline

Signed-off-by: Elaine Chien <[email protected]>

* Remove license and just defer to main package analysis license

Signed-off-by: Elaine Chien <[email protected]>

---------

Signed-off-by: Elaine Chien <[email protected]>
Co-authored-by: Elaine Chien <[email protected]>
Co-authored-by: Caleb Brown <[email protected]>
  • Loading branch information
3 people authored Aug 9, 2023
1 parent 5e36625 commit 93adcac
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sample_packages/sample_python_package/README.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions sample_packages/sample_python_package/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>" },
]
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",
]
12 changes: 12 additions & 0 deletions sample_packages/sample_python_package/setup.py
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions sample_packages/sample_python_package/src/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
19 changes: 19 additions & 0 deletions sample_packages/sample_python_package/src/example.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 93adcac

Please sign in to comment.