Skip to content

Commit

Permalink
cleaned up code , replaced simplejson with orjson for better performa…
Browse files Browse the repository at this point in the history
…nce , got rid of jsonobjects and replaced with dataclasses
  • Loading branch information
1YiB committed Feb 4, 2023
1 parent ed78b64 commit 90cd7a3
Show file tree
Hide file tree
Showing 22 changed files with 398 additions and 423 deletions.
170 changes: 170 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# personal files
**/trash
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# 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/
cover/

# 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
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .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

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml


# End of https://www.toptal.com/developers/gitignore/api/python
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "run vs_api",
"type": "shell",
"command": "cd ${cwd}/src/;conda activate vs-api;python main.py"
}
]
}
4 changes: 1 addition & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ dependencies:
- pip
- pip:
- httpx
- simplejson
- ndicts
- jsonobject
- orjson
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
httpx
simplejson
ndicts
jsonobject
orjson
8 changes: 0 additions & 8 deletions src/main.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/vs_api/ovsx/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .info import info
from .namespace import namespace
from .publisher import publisher
from .reviews import reviews
from .search import search

__all__ = ["info","namespace","reviews","search"]
__all__ = ["info","publisher","reviews","search"]
15 changes: 4 additions & 11 deletions src/vs_api/ovsx/api/info.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from typing import Any
import httpx
import orjson as json

def info(uid: str, client: httpx.Client) -> tuple[bytes, int]:
"""
returns info on extension

Args:
id (str): unique identifier of extension
client (httpx.Client): httpx http client
Returns:
tuple[bytes, int]: tuple('api response','api status code')
"""
def info(uid: str, client: httpx.Client) -> tuple[Any, int]:

endpoint = uid
r = client.get(url=endpoint)
return (r.content, r.status_code)
return (json.loads(r.content), r.status_code)
18 changes: 0 additions & 18 deletions src/vs_api/ovsx/api/namespace.py

This file was deleted.

10 changes: 10 additions & 0 deletions src/vs_api/ovsx/api/publisher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Any
import httpx
import orjson as json


def publisher(namespace:str,client:httpx.Client) -> tuple[Any, int]:

endpoint = f"/{namespace}"
r = client.get(url=endpoint)
return (json.loads(r.content),r.status_code)
15 changes: 4 additions & 11 deletions src/vs_api/ovsx/api/reviews.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from typing import Any
import httpx
import orjson as json

def reviews(uid:str,client:httpx.Client) -> tuple[bytes, int]:
"""
returns all reviews of an extension

Args:
uid (str): extension unique identifier
client (httpx.Client): httpx http client
Returns:
tuple[bytes, int]: tuple('api response','api status code')
"""
def reviews(uid:str,client:httpx.Client) -> tuple[Any, int]:

endpoint = f"{uid}/reviews"
r = client.get(url=endpoint)
return (r.content,r.status_code)
return (json.loads(r.content),r.status_code)
20 changes: 6 additions & 14 deletions src/vs_api/ovsx/api/search.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
from typing import Any
import httpx
import orjson as json

def search(query:str,size:int,category:str,sortBy: str,sortOrder:str,client:httpx.Client) -> tuple[bytes, int]:
"""
returns info on extensions that match the query

Args:
query (str): search by name,desc or keywords
size (int): no.of results to fetch
category (str): category of extension to display
sortBy (str): sorting of extensions
sortOrder (str): sorting in ascending or descending
client (httpx.Client): httpx http client

Returns:
tuple[bytes, int]: tuple('api response','api status code')
"""
def search(query:str,size:int,category:str,sortBy: str,sortOrder:str,client:httpx.Client) -> tuple[Any, int]:


endpoint = f"/-/search?query={query}&size={size}&category={category}&sortBy={sortBy}&sortOrder={sortOrder}"
r = client.get(url=endpoint)
return (r.content,r.status_code)
return (json.loads(r.content),r.status_code)
6 changes: 3 additions & 3 deletions src/vs_api/ovsx/errors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .ExtensionNotFound import ExtensionNotFound
from .PublisherNotFound import PublisherNotFound
from .extension_not_found import ExtensionNotFound
from .publisher_not_found import PublisherNotFound

__all__ = ["ExtensionNotFound","PublisherNotFound"]
__all__ = ["extension_not_found","publisher_not_found"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ def __init__(self, uid: str, message: Optional[str]) -> None:
self.uid = uid
self.message = f"Extension not found: {self.uid}" or message
super().__init__(self.message)

File renamed without changes.
9 changes: 8 additions & 1 deletion src/vs_api/ovsx/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
from . import info, namespace, reviews, search

from .publisher import publisher
from .info import info
from .search import search
from .reviews import reviews


__all__ = ["publisher","info","search","reviews"]
Loading

0 comments on commit 90cd7a3

Please sign in to comment.