Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sample python package #801

Merged
merged 12 commits into from
Aug 9, 2023
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/
elainechien marked this conversation as resolved.
Show resolved Hide resolved
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]
elainechien marked this conversation as resolved.
Show resolved Hide resolved
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()