Repository: CIME-Software/perplexipy (language: python)

Issue:
Initial repository setup
Initial repository setup


Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d352f02
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,154 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+*.egg
+*.egg-info/
+.Python
+.eggs/
+.installed.cfg
+MANIFEST
+bin/*
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+lib/
+lib64/
+parts/
+pip-wheel-metadata/
+sdist/
+share/python-wheels/
+var/
+wheels/
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.python-version
+
+# pipenv
+#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+#   However, in case of collaboration, if having platform-specific dependencies or dependencies
+#   having no cross-platform support, pipenv may install dependencies that don't work, or not
+#   install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+
+
+
+# perplexipy
+
+**.NERD*
+**.bash_*
+**.config
+**.gitconfig
+**.jupyter
+**.local
+**.ssh/
+**/*psd
+**/.conda/*
+**/.cufflinks*
+**/.npm/*
+**/.theano
+**/.vim/*
+**/pyvenv.cfg
+**crypt-password*
+**devpi-hostname*
+**devpi-password*
+**devpi-user*
+**dummy.py
+**dummy.txt
+**pip.conf
+**test.txt
+*swp
+
+
+# pycharm
+**.idea
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..885b884
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,113 @@
+# See:  https://raw.githubusercontent.com/pr3d4t0r/m0toko/master/LICENSE.txt
+
+
+SHELL=/bin/bash
+
+BUILD=./build
+DEVPI_HOST=$(shell cat devpi-hostname.txt)
+DEVPI_PASSWORD=$(shell cat ./devpi-password.txt)
+DEVPI_USER=$(shell cat ./devpi-user.txt)
+DIST=./dist
+MANPAGES=./manpages
+PACKAGE=$(shell cat package.txt)
+REQUIREMENTS=requirements.txt
+VERSION=$(shell echo "from $(PACKAGE) import __VERSION__; print(__VERSION__)" | python)
+
+
+# Targets:
+
+all: ALWAYS
+	make test
+	make manpage
+	make package
+
+
+clean:
+	rm -Rf $(BUILD)/*
+	rm -Rf $(DIST)/*
+	rm -Rf $(MANPAGES)/*
+	rm -Rfv $$(find $(PACKAGE)/ | awk '/__pycache__$$/')
+	rm -Rfv $$(find tests | awk '/__pycache__$$/')
+	rm -Rfv $$(find . | awk '/.ipynb_checkpoints/')
+	rm -Rfv ./.pytest_cache
+	mkdir -p ./dist
+	pushd ./dist ; pip uninstall -y $(PACKAGE)==$(VERSION) || true ; popd
+
+
+devpi:
+	devpi use $(DEVPI_HOST)
+	@devpi login $(DEVPI_USER) --password="$(DEVPI_PASSWORD)"
+	devpi use $(DEVPI_USER)/dev
+	devpi -v use --set-cfg $(DEVPI_USER)/dev
+	@[[ -e "pip.conf-bak" ]] && rm -f "pip.conf-bak"
+
+
+install:
+	pip install -U $(PACKAGE)==$(VERSION)
+	pip list | awk 'NR < 3 { print; } /$(PACKAGE)/'
+
+
+libupdate:
+	pip install -U pip
+	pip install -Ur $(REQUIREMENTS)
+
+
+local:
+	pip install --no-dependencies -e .
+
+
+manpage:
+	mkdir -p $(MANPAGES)
+	t=$$(mktemp) && awk -v "v=$(VERSION)" '/^%/ { $$4 = v; print; next; } { print; }' README.md > "$$t" && cat "$$t" > README.md && rm -f "$$t"
+	pandoc --standalone --to man README.md -o $(MANPAGES)/$(PACKAGE).1
+
+
+nuke: ALWAYS
+	make clean
+
+
+package:
+	pip install -r $(REQUIREMENTS)
+	python -m build -wn
+
+
+# The publish: target is for PyPI, not for the devpi server.
+publish:
+	twine --no-color check $(DIST)/*
+	twine --no-color upload --verbose $(DIST)/*
+
+
+refresh: ALWAYS
+	pip install -U -r requirements.txt
+
+
+# Delete the Python virtual environment - necessary when updating the
+# host's actual Python, e.g. upgrade from 3.7.5 to 3.7.6.
+resetpy: ALWAYS
+	rm -Rfv ./.Python ./bin ./build ./dist ./include ./lib
+
+
+targets:
+	@printf "Makefile targets:\n\n"
+	@cat Makefile| awk '/:/ && !/^#/ && !/targets/ && !/Makefile/ { gsub("ALWAYS", ""); gsub(":", ""); print; } /^ALWAYS/ { next; }'
+
+
+test: ALWAYS
+	@echo "Version = $(VERSION)"
+	@make local
+	pytest -v ./tests/$(PACKAGE)-test.py
+	pip uninstall -y $(PACKAGE)==$(VERSION) || true
+	rm -Rfv $$(find $(PACKAGE)/ | awk '/__pycache__$$/')
+	rm -Rfv $$(find tests | awk '/__pycache__$$/')
+
+
+tools:
+	pip install -Ur dev-tools.txt
+
+
+upload:
+	devpi upload dist/*whl
+
+
+ALWAYS:
+
diff --git a/dev-tools.txt b/dev-tools.txt
new file mode 100644
index 0000000..060dd41
--- /dev/null
+++ b/dev-tools.txt
@@ -0,0 +1,4 @@
+devpi-client
+ptpython
+pudb
+pytest
diff --git a/package.txt b/package.txt
new file mode 100644
index 0000000..b2b4170
--- /dev/null
+++ b/package.txt
@@ -0,0 +1,1 @@
+perplexipy
diff --git a/perplexipy/__init__.py b/perplexipy/__init__.py
new file mode 100644
index 0000000..ea017f6
--- /dev/null
+++ b/perplexipy/__init__.py
@@ -0,0 +1,27 @@
+# See: https://github.com/CIME-Software/perplexipy/blob/master/LICENSE.txt
+
+
+__VERSION__ = '0.0.1'
+
+
+import requests
+
+
+PERPLEXITY_API_URL = 'https://api.perplexity.ai'
+
+
+class PerplexityClientError(Exception):
+    def __init__(self, errorMessage):
+        super().__init__(errorMessage)
+
+
+class PerplexityClient:
+    def __init__(self, key, endpoint = PERPLEXITY_API_URL):
+        if not key:
+            raise PerplexityClientError('Provide a valid key argument during instantiation')
+        if not 'pplx-' in key:
+            raise PerplexityClientError('The key %s i missing the pplx- prefix - invalid API key')
+
+        self._key = key
+        self._endpoint = endpoint
+
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..77f1374
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,58 @@
+# See: https://github.com/CIME-Software/perplexipy/blob/master/LICENSE.txt
+
+[build-system]
+requires = [ 'setuptools' ]
+build-backend = 'setuptools.build_meta'
+
+
+[metadata]
+url = 'https://github.com/CIME-Software/perplexipy'
+
+
+[project]
+authors = [
+    { name = 'CIME Software Ltd', email = 'perplexipy@cime.net' }
+]
+classifiers = [
+    'Development Status :: 4 - Beta',
+    'Intended Audience :: Developers',
+    'License :: OSI Approved :: BSD License',
+    'Operating System :: OS Independent',
+    'Programming Language :: Python :: 3',
+    'Programming Language :: Python :: 3.9',
+    'Topic :: Scientific/Engineering :: Artificial Intelligence',
+    'Topic :: Software Development :: Libraries :: Python Modules',
+]
+description = 'perplexipy - A robust Perplexity AI API client'
+dynamic = [
+    'dependencies',
+    'version',
+]
+name = 'perplexipy'
+readme = 'README.md'
+requires-python = '>=3.9'
+
+
+# [project.scripts]
+# perplexipy = 'perplexipy:main'
+
+
+[tool.pytest.ini_options]
+addopts = '-sv'
+testpaths = [
+    'tests'
+]
+
+
+[tool.setuptools]
+include-package-data = true
+packages = [
+    'perplexipy',
+    # 'tests', # because test modules import objects from other test modules
+]
+
+
+[tool.setuptools.dynamic]
+dependencies = { file = 'requirements.txt' }
+version = { attr = 'perplexipy.__VERSION__' }
+
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..f229360
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,1 @@
+requests


Test patch:
diff --git a/tests/perplexipy-test.py b/tests/perplexipy-test.py
new file mode 100644
index 0000000..e916012
--- /dev/null
+++ b/tests/perplexipy-test.py
@@ -0,0 +1,18 @@
+# See: https://github.com/CIME-Software/perplexipy/blob/master/LICENSE.txt
+
+from perplexipy import PerplexityClient
+from perplexipy import PerplexityClientError
+
+import pytest
+
+
+def test_PerplexityClient():
+    with pytest.raises(PerplexityClientError):
+        PerplexityClient(None)
+    with pytest.raises(PerplexityClientError):
+        PerplexityClient('')
+    with pytest.raises(PerplexityClientError):
+        PerplexityClient('xxxx')
+
+
+