-
Notifications
You must be signed in to change notification settings - Fork 4
Allow existing code to be used as library #9
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
Open
patcon
wants to merge
4
commits into
eterps:main
Choose a base branch
from
patcon:python-package
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| __pycache__ | ||
| *.egg-info | ||
|
|
||
| # Ignore because we're using this as a library. | ||
| uv.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| install: ## Install as library | ||
| uv sync | ||
| uv pip install -e . | ||
|
|
||
| run: ## Run the example script | ||
| uv run python polislite/polislite.py | ||
|
|
||
|
|
||
| %: | ||
| @true | ||
|
|
||
| .PHONY: help | ||
|
|
||
| help: | ||
| @echo 'Usage: make <command>' | ||
| @echo | ||
| @echo 'where <command> is one of the following:' | ||
| @echo | ||
| @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
|
|
||
| .DEFAULT_GOAL := help |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,156 @@ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "nbformat": 4, | ||||||||||||||||||||||||||||||
| "nbformat_minor": 0, | ||||||||||||||||||||||||||||||
| "metadata": { | ||||||||||||||||||||||||||||||
| "colab": { | ||||||||||||||||||||||||||||||
| "provenance": [], | ||||||||||||||||||||||||||||||
| "authorship_tag": "ABX9TyPLsyDH4WY7BEoL4VGciHd3", | ||||||||||||||||||||||||||||||
| "include_colab_link": true | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| "kernelspec": { | ||||||||||||||||||||||||||||||
| "name": "python3", | ||||||||||||||||||||||||||||||
| "display_name": "Python 3" | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| "language_info": { | ||||||||||||||||||||||||||||||
| "name": "python" | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| "cells": [ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "cell_type": "markdown", | ||||||||||||||||||||||||||||||
| "metadata": { | ||||||||||||||||||||||||||||||
| "id": "view-in-github", | ||||||||||||||||||||||||||||||
| "colab_type": "text" | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| "source": [ | ||||||||||||||||||||||||||||||
| "<a href=\"https://colab.research.google.com/github/patcon/polislite/blob/python-package/polislite_library_usage.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||||||||||||||||||||||||||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "cell_type": "code", | ||||||||||||||||||||||||||||||
| "source": [ | ||||||||||||||||||||||||||||||
| "!pip install git+https://github.com/patcon/polislite.git@python-package" | ||||||||||||||||||||||||||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| "metadata": { | ||||||||||||||||||||||||||||||
| "colab": { | ||||||||||||||||||||||||||||||
| "base_uri": "https://localhost:8080/" | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| "id": "9NebPULW1JTR", | ||||||||||||||||||||||||||||||
| "outputId": "0b95059b-d3b9-4840-8da3-8702b20318d9" | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| "execution_count": 1, | ||||||||||||||||||||||||||||||
| "outputs": [ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "output_type": "stream", | ||||||||||||||||||||||||||||||
| "name": "stdout", | ||||||||||||||||||||||||||||||
| "text": [ | ||||||||||||||||||||||||||||||
| "Collecting git+https://github.com/patcon/polislite.git@python-package\n", | ||||||||||||||||||||||||||||||
| " Cloning https://github.com/patcon/polislite.git (to revision python-package) to /tmp/pip-req-build-b8924s2s\n", | ||||||||||||||||||||||||||||||
| " Running command git clone --filter=blob:none --quiet https://github.com/patcon/polislite.git /tmp/pip-req-build-b8924s2s\n", | ||||||||||||||||||||||||||||||
| " Running command git checkout -b python-package --track origin/python-package\n", | ||||||||||||||||||||||||||||||
| " Switched to a new branch 'python-package'\n", | ||||||||||||||||||||||||||||||
| " Branch 'python-package' set up to track remote branch 'python-package' from 'origin'.\n", | ||||||||||||||||||||||||||||||
| " Resolved https://github.com/patcon/polislite.git to commit 9252f24c4acb6ea38a25c1b51b4546d087e91747\n", | ||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+53
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", | ||||||||||||||||||||||||||||||
| " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", | ||||||||||||||||||||||||||||||
| " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", | ||||||||||||||||||||||||||||||
| "Requirement already satisfied: scikit-learn>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from polislite==0.1.0) (1.6.0)\n", | ||||||||||||||||||||||||||||||
| "Requirement already satisfied: numpy>=1.19.5 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=1.6.0->polislite==0.1.0) (1.26.4)\n", | ||||||||||||||||||||||||||||||
| "Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=1.6.0->polislite==0.1.0) (1.13.1)\n", | ||||||||||||||||||||||||||||||
| "Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=1.6.0->polislite==0.1.0) (1.4.2)\n", | ||||||||||||||||||||||||||||||
| "Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=1.6.0->polislite==0.1.0) (3.5.0)\n", | ||||||||||||||||||||||||||||||
| "Building wheels for collected packages: polislite\n", | ||||||||||||||||||||||||||||||
| " Building wheel for polislite (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", | ||||||||||||||||||||||||||||||
| " Created wheel for polislite: filename=polislite-0.1.0-py3-none-any.whl size=4394 sha256=051e48ee7fc35772739a0611e047949170bec18ff9792890650db6a3faeaef37\n", | ||||||||||||||||||||||||||||||
| " Stored in directory: /tmp/pip-ephem-wheel-cache-3q6whqzs/wheels/0d/d5/a2/fe574e20315f0bdfc7f1d4b81bbf2b2caa4c7a4e2a9ef0511f\n", | ||||||||||||||||||||||||||||||
| "Successfully built polislite\n", | ||||||||||||||||||||||||||||||
| "Installing collected packages: polislite\n", | ||||||||||||||||||||||||||||||
| "Successfully installed polislite-0.1.0\n" | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "cell_type": "code", | ||||||||||||||||||||||||||||||
| "execution_count": 3, | ||||||||||||||||||||||||||||||
| "metadata": { | ||||||||||||||||||||||||||||||
| "colab": { | ||||||||||||||||||||||||||||||
| "base_uri": "https://localhost:8080/" | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| "id": "orSeaE2M1Il7", | ||||||||||||||||||||||||||||||
| "outputId": "ebcf7bef-1486-4379-830f-0e6d6eb3515a" | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| "outputs": [ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "output_type": "stream", | ||||||||||||||||||||||||||||||
| "name": "stdout", | ||||||||||||||||||||||||||||||
| "text": [ | ||||||||||||||||||||||||||||||
| "Consensus Statements:\n", | ||||||||||||||||||||||||||||||
| "- Climate change requires immediate action (strong agreement)\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| "Divisive Statements:\n", | ||||||||||||||||||||||||||||||
| "- Nuclear power is necessary for clean energy\n", | ||||||||||||||||||||||||||||||
| "- Carbon tax should be implemented globally\n", | ||||||||||||||||||||||||||||||
| "- Individual actions matter for sustainability\n", | ||||||||||||||||||||||||||||||
| "- Companies should be held liable for emissions\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| "Group Positions:\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| "Group 1 characteristics:\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Climate change requires immediate action\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Nuclear power is necessary for clean energy\n", | ||||||||||||||||||||||||||||||
| "- strongly disagrees with: Carbon tax should be implemented globally\n", | ||||||||||||||||||||||||||||||
| "- strongly disagrees with: Individual actions matter for sustainability\n", | ||||||||||||||||||||||||||||||
| "- strongly disagrees with: Companies should be held liable for emissions\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| "Group 2 characteristics:\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Climate change requires immediate action\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Nuclear power is necessary for clean energy\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Carbon tax should be implemented globally\n", | ||||||||||||||||||||||||||||||
| "- strongly disagrees with: Individual actions matter for sustainability\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Companies should be held liable for emissions\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| "Group 3 characteristics:\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Climate change requires immediate action\n", | ||||||||||||||||||||||||||||||
| "- strongly disagrees with: Nuclear power is necessary for clean energy\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Carbon tax should be implemented globally\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Individual actions matter for sustainability\n", | ||||||||||||||||||||||||||||||
| "- strongly agrees with: Companies should be held liable for emissions\n" | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| "source": [ | ||||||||||||||||||||||||||||||
| "from polislite.polislite import PolisClusterer\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| "# Example usage\n", | ||||||||||||||||||||||||||||||
| "statements = [\n", | ||||||||||||||||||||||||||||||
| " 'Climate change requires immediate action',\n", | ||||||||||||||||||||||||||||||
| " 'Nuclear power is necessary for clean energy',\n", | ||||||||||||||||||||||||||||||
| " 'Carbon tax should be implemented globally',\n", | ||||||||||||||||||||||||||||||
| " 'Individual actions matter for sustainability',\n", | ||||||||||||||||||||||||||||||
| " 'Companies should be held liable for emissions'\n", | ||||||||||||||||||||||||||||||
| "]\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| "votes = [\n", | ||||||||||||||||||||||||||||||
| " # Group 1: Environmental purists (anti-nuclear)\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'disagree', 'agree', 'agree', 'agree'],\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'disagree', 'agree', 'agree', 'agree'],\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'disagree', 'agree', 'agree', 'agree'],\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| " # Group 2: Tech-focused environmentalists (pro-nuclear)\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'agree', 'agree', 'disagree', 'agree'],\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'agree', 'agree', 'disagree', 'agree'],\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'agree', 'agree', 'disagree', 'agree'],\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| " # Group 3: Business-oriented (anti-regulation)\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'agree', 'disagree', 'disagree', 'disagree'],\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'agree', 'disagree', 'disagree', 'disagree'],\n", | ||||||||||||||||||||||||||||||
| " ['agree', 'agree', 'disagree', 'disagree', 'disagree']\n", | ||||||||||||||||||||||||||||||
| "]\n", | ||||||||||||||||||||||||||||||
| "\n", | ||||||||||||||||||||||||||||||
| "clusterer = PolisClusterer()\n", | ||||||||||||||||||||||||||||||
| "points, clusters = clusterer.analyze_opinions(votes, statements)" | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [project] | ||
| name = "polislite" | ||
| version = "0.1.0" | ||
| description = "A lightweight Polis-like" | ||
| readme = "README.md" | ||
| requires-python = ">=3.10" | ||
| dependencies = [ | ||
| "scikit-learn>=1.6.0", | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.