diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d4fffe --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.cache/* +.cache/** +__pycache__/** +.upm +venv/** +**/__pycache__/** \ No newline at end of file diff --git a/.replit b/.replit new file mode 100644 index 0000000..dc97b59 --- /dev/null +++ b/.replit @@ -0,0 +1,94 @@ +run = "python main.py" +entrypoint = "package/src/fpsql/__init__.py" +# A list of globs that specify which files and directories should +# be hidden in the workspace. +hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"] + +# Specifies which nix channel to use when building the environment. +[nix] +channel = "stable-22_11" + +[[hints]] +regex = "stderred: .+GLIBC.+not found" +message = "The command `stderred` is known to cause issues. It's recommended you remove it from your .replit configuration." + +[env] +VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv" +PATH = "${VIRTUAL_ENV}/bin" +PYTHONPATH = "$PYTHONHOME/lib/python3.8:${VIRTUAL_ENV}/lib/python3.8/site-packages" +REPLIT_POETRY_PYPI_REPOSITORY = "https://package-proxy.replit.com/pypi/" +MPLBACKEND = "TkAgg" +POETRY_CACHE_DIR = "${HOME}/${REPL_SLUG}/.cache/pypoetry" + +# Enable unit tests. This is only supported for a few languages. +[unitTest] +language = "python3" + +# Add a debugger! +[debugger] +support = true + + # How to start the debugger. + [debugger.interactive] + transport = "localhost:0" + startCommand = ["dap-python", "main.py"] + + # How to communicate with the debugger. + [debugger.interactive.integratedAdapter] + dapTcpAddress = "localhost:0" + + # How to tell the debugger to start a debugging session. + [debugger.interactive.initializeMessage] + command = "initialize" + type = "request" + + [debugger.interactive.initializeMessage.arguments] + adapterID = "debugpy" + clientID = "replit" + clientName = "replit.com" + columnsStartAt1 = true + linesStartAt1 = true + locale = "en-us" + pathFormat = "path" + supportsInvalidatedEvent = true + supportsProgressReporting = true + supportsRunInTerminalRequest = true + supportsVariablePaging = true + supportsVariableType = true + + # How to tell the debugger to start the debuggee application. + [debugger.interactive.launchMessage] + command = "attach" + type = "request" + + [debugger.interactive.launchMessage.arguments] + logging = {} + +# Configures the packager. +[packager] +language = "python3" +ignoredPackages = ["unit_tests"] + + [packager.features] + enabledForHosting = false + # Enable searching packages from the sidebar. + packageSearch = true + # Enable guessing what packages are needed from the code. + guessImports = true + +# These are the files that need to be preserved when this +# language template is used as the base language template +# for Python repos imported from GitHub +[gitHubImport] +requiredFiles = [".replit", "replit.nix", ".config", "venv"] + +[languages] + +[languages.python3] +pattern = "**/*.py" + +[languages.python3.languageServer] +start = "pylsp" + +[deployment] +run = ["sh", "-c", "python3 main.py"] diff --git a/.replit.backup b/.replit.backup new file mode 100644 index 0000000..6d775d1 --- /dev/null +++ b/.replit.backup @@ -0,0 +1,2 @@ +run = "python main.py" +entrypoint = "package/src/fpsql/__init__.py" \ No newline at end of file diff --git a/askpass.sh b/askpass.sh new file mode 100755 index 0000000..f47ce6e --- /dev/null +++ b/askpass.sh @@ -0,0 +1,5 @@ +#!/bin/bash +case "$1" in + Username*) exec echo "$NAME" ;; + Password*) exec echo "$PASS" ;; +esac \ No newline at end of file diff --git a/fix.sh b/fix.sh new file mode 100755 index 0000000..828a7ca --- /dev/null +++ b/fix.sh @@ -0,0 +1,7 @@ +echo "Fixing poetry..." +pip install --upgrade poetry > /dev/null +echo "Updating/Installing dependencies..." +poetry update > /dev/null +echo "Logging completion..." +touch /tmp/updated.txt +echo "Done!" \ No newline at end of file diff --git a/git_log.txt b/git_log.txt new file mode 100644 index 0000000..6a3b30f --- /dev/null +++ b/git_log.txt @@ -0,0 +1,4 @@ +error: unable to read askpass response from 'replit-git-askpass' +error: unable to read askpass response from 'replit-git-askpass' +remote: Push to create is not enabled for users. +fatal: unable to access 'https://git--firecat650.repl.co/Firepup650/FPSQL.git/': The requested URL returned error: 403 diff --git a/lspfix.sh b/lspfix.sh new file mode 100755 index 0000000..d395be0 --- /dev/null +++ b/lspfix.sh @@ -0,0 +1,4 @@ +unzip pylsp.sh -d venv/lib/python3.8/site-packages +sed -i 6d .config/pip/pip.conf +pip install ujson docstring_to_markdown jedi +mv pylsp venv/bin \ No newline at end of file diff --git a/package/dist/fpsql-1.0.1-py3-none-any.whl b/package/dist/fpsql-1.0.1-py3-none-any.whl new file mode 100644 index 0000000..5d151fd Binary files /dev/null and b/package/dist/fpsql-1.0.1-py3-none-any.whl differ diff --git a/package/dist/fpsql-1.0.1.tar.gz b/package/dist/fpsql-1.0.1.tar.gz new file mode 100644 index 0000000..a14109a Binary files /dev/null and b/package/dist/fpsql-1.0.1.tar.gz differ diff --git a/package/requirements.txt b/package/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/package/setup.py b/package/setup.py new file mode 100644 index 0000000..6068493 --- /dev/null +++ b/package/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup() diff --git a/package/src/fpsql/__init__.py b/package/src/fpsql/__init__.py new file mode 100644 index 0000000..8157e09 --- /dev/null +++ b/package/src/fpsql/__init__.py @@ -0,0 +1,177 @@ +"""Firepup650's SQL Package""" +import sqlite3, ast, pydoc + + +def alias(Function): + def decorator(f): + f.__doc__ = ( + "This method is an alias of the following method:\n\n" + + pydoc.text.document(Function) + ) + return f + + return decorator + + +__VERSION__ = "1.0.26" +__NEW__ = "Adds `remove_prefix` and `remove_suffix`, name mangles internal variables in `sql`, fixes a bug in `console.warn`, adds `__VERSION__`, `__NEW__`, and `__LICENSE__`, adds many aliases for interactive help." +__LICENSE__ = "MIT" + + +class sql: + def addTable(self, tableName: str, mode: int = 0, address: str = "") -> None: + """# Function: sql.addTable + Adds a table to the database + # Inputs: + tableName: str - The name of the table to create + mode: int - Not yet implemented + address: str - Not yet implemented + + # Returns: + None + + # Raises: + None""" + self.__con.execute( + f"""CREATE TABLE IF NOT EXISTS "{tableName}" + (id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + value TEXT NOT NULL)""" + ) + self.__con.commit() + self.__table = tableName + + def __init__(self, filename: str): + """# Function: sql.__init__ + Constructs an SQL instance + # Inputs: + filename: str - The name of the database file to connect to (or `:memory:`) + + # Returns: + None + + # Raises: + None""" + if filename.endswith(".db") or filename == ":memory:": + self.__db = filename + else: + self.__db = filename + ".db" + self.__con = sqlite3.connect(self.__db) + self.addTable("default") + + def setTable(self, tableName: str) -> None: + """# Function: sql.setTable + Sets the currently active table + # Inputs: + tableName: str - The name of the table to use + + # Returns: + None + + # Raises: + None""" + self.__table = tableName + + def get(self, name: str) -> object or None: + """# Function: sql.get + Gets the value of a key + # Inputs: + name: str - The name of the key to retrieve + + # Returns: + object or None - If the key exists, return it's value, otherwise, return `None` + + # Raises: + AttributeError - If the table is unset""" + if not self.__table: + raise AttributeError("Attempted to read from unset table") + cur = self.__con.execute( + f"""SELECT value FROM "{self.__table}" WHERE name = ?""", (name,) + ) + data = cur.fetchone() + if data: + try: + return ast.literal_eval(data[0]) + except: + return data[0] + return None + + def set(self, name: str, value: object) -> int: + """# Function: sql.set + Sets the value of a key + # Inputs: + name: str - The name of the key to set + value: object - The value of the key + + # Returns: + int - `1` if the key was created, `2` if it was updated + + # Raises: + AttributeError - If the table is unset""" + if not self.__table: + raise AttributeError("Attempted to write to unset table") + if self.get(name): + self.__con.execute( + f"""UPDATE "{self.__table}" SET value = ? WHERE name = ?""", + (str(value), name), + ) + self.__con.commit() + return 2 + else: + self.__con.execute( + f"""INSERT INTO "{self.__table}" (name, value) VALUES (?, ?)""", + (name, str(value)), + ) + self.__con.commit() + return 1 + + def delete(self, name: str) -> None: + """# Function: sql.delete + Deletes a key from the table + # Inputs: + name: str - The name of the key to delete + + # Returns: + None + + # Raises: + AttributeError - If the table is unset""" + if not self.__table: + raise AttributeError("Attempted to delete from unset table") + if self.get(name): + self.__con.execute( + f"""DELETE FROM "{self.__table}" WHERE name = ?""", (name,) + ) + self.__con.commit() + + def delete_all(self) -> None: + """# Function: sql.delete_all + Deletes all keys from the table + # Inputs: + None + + # Returns: + None + + # Raises: + AttributeError - If the table is unset""" + if not self.__table: + raise AttributeError("Attempted to delete from unset table") + self.__con.execute(f"""DELETE FROM "{self.__table}" """) + self.__con.commit() + + def close(self) -> None: + """# Function: sql.close + Closes the database connection + # Inputs: + None + + # Returns: + None + + # Raises: + None""" + self.__con.close() + self.__con = None + self.__db = None + self.__table = None diff --git a/package/upload.sh b/package/upload.sh new file mode 100755 index 0000000..40e63dc --- /dev/null +++ b/package/upload.sh @@ -0,0 +1,7 @@ +echo "Formatting..." +black . > /dev/null +echo "Building..." +poetry build > /dev/null +echo "Uploading..." +python3 -m twine upload -r pypi dist/* +echo "Done!" \ No newline at end of file diff --git a/replit.nix b/replit.nix new file mode 100644 index 0000000..58a8fce --- /dev/null +++ b/replit.nix @@ -0,0 +1,22 @@ +{ pkgs }: { + deps = [ + pkgs.man-db + pkgs.less + pkgs.zip + pkgs.unzip + pkgs.python38Full + ]; + env = { + PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ + # Needed for pandas / numpy + pkgs.stdenv.cc.cc.lib + pkgs.zlib + # Needed for pygame + pkgs.glib + # Needed for matplotlib + pkgs.xorg.libX11 + ]; + PYTHONBIN = "${pkgs.python38Full}/bin/python3.8"; + LANG = "en_US.UTF-8"; + }; +} \ No newline at end of file