Skip to content

Commit

Permalink
Merge pull request #11 from ersul4ik/fix-tests-circle
Browse files Browse the repository at this point in the history
Fix tests circle
  • Loading branch information
Erik Sultanaliev authored Nov 28, 2018
2 parents 47a36d9 + cb8ee09 commit 090e45a
Show file tree
Hide file tree
Showing 23 changed files with 507 additions and 156 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- checkout
- run:
name: Tests runner
working_directory: swcregistrypython/
working_directory: swc_registry/
command: |
pip install -r ../requirements.txt
python test.py
pytest ../tests/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ requests.egg-info/
*.egg
env/
dist
swcregistrypython.egg-info/
*.egg-info/
.eggs/
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include swcregistrypython/swc-definition.json
include swc_registry/swc-definition.json
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SWC-registry-python

[![CircleCI](https://circleci.com/gh/SmartContractSecurity/SWC-registry-python.svg?style=svg)](https://circleci.com/gh/SmartContractSecurity/SWC-registry-python)

## Description
Python library for accessing SWC-registry content.

## Installation

```console
$ pip install -U swc-registry
```

## Usage
```python
from swc_registry import SWC

swc = SWC('SWC-100')
swc.title
```

## Contribution
1 change: 0 additions & 1 deletion README.rst

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests==2.20.1
pytest==4.0.1
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==4.0.0
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[aliases]
test=pytest
60 changes: 46 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
import setuptools
setuptools.setup(
name="swcregistrypython",
version="1.0",

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:copyright: (c) 2017 by Lev Lazinskiy
:license: MIT, see LICENSE for more details.
"""
import os
import sys

from setuptools import setup
from setuptools.command.install import install

# circleci.py version
VERSION = "1.1.1"

class VerifyVersionCommand(install):
"""Custom command to verify that the git tag matches our version"""
description = 'verify that the git tag matches our version'

def run(self):
tag = os.getenv('CIRCLE_TAG')

if tag != VERSION:
info = "Git tag: {0} does not match the version of this app: {1}".format(
tag, VERSION
)
sys.exit(info)

setup(
name="swc-registry",
version=VERSION,
url="https://github.com/SmartContractSecurity/SWC-registry-python",
author="SmartContractSecurity",
author_email="[email protected]",
description="An package to get the required swc definition fields.",
long_description=open('README.rst').read(),
packages=['swcregistrypython'],
include_package_data = True,
install_requires=[
'requests==2.20.1',
],
description="Python library for accessing SWC-registry content.",
long_description=open("README.md").read(),
packages=["swc_registry"],
include_package_data=True,
install_requires=["requests==2.20.1"],
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4'
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
],
setup_requires=["pytest-runner"],
tests_require=["pytest"],
cmdclass={
'verify': VerifyVersionCommand,
}
)
5 changes: 5 additions & 0 deletions swc_registry/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from swc_registry.get_entry_info import SWC

__version__ = "0.0.3"
__author__ = "SmartContractSecurity"
__all__ = []
111 changes: 111 additions & 0 deletions swc_registry/get_entry_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import os
import requests
import json


class SWCException(Exception):
pass


class Singleton(type):
_instances = {}

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]


class SWCRegistry(object, metaclass=Singleton):
"""
Registry class takes care of loading and downloading the swc registry
"""

def __init__(self):
self._content = None

@staticmethod
def _get_latest_version():
try:
url = (
"https://raw.githubusercontent.com/SmartContractSecurity/SWC-registry/master/export/swc-definition"
".json"
)
response = requests.get(url).json()
return response
except requests.exceptions.RequestException:
return None

def _load_from_file(self):
path_file_content = os.path.join(
os.path.dirname(__file__), "swc-definition.json"
)
with open(path_file_content, "r") as f:
self._content = json.load(f)

def update(self):
self._content = SWCRegistry._get_latest_version()

@property
def content(self):
if self._content is None:
self._load_from_file()
return self._content

def __repr__(self):
return "<SWCRegistry with {} entries>".format(len(self.content.keys()))


class SWC:
"""
SWC class contains information on an SWC entry
Example usage:
swc = SWC('SWC-100')
print(swc.title)
"""

def __init__(self, swc_id, get_last=False):
self.swc_id = swc_id
if get_last:
SWCRegistry().update()

@property
def _swc_content(self):
return SWCRegistry().content

@property
def _content(self):
entries = self._swc_content
current_entry = entries.get(self.swc_id)
if not current_entry:
raise SWCException("SWC with ID {} does not exist".format(self.swc_id))
content = current_entry.get("content", {})
return content

@property
def title(self) -> str:
content = self._content
title = content.get("Title", "")
return title

@property
def relationships(self) -> str:
content = self._content
relationships = content.get("Relationships", "")
return relationships

@property
def description(self) -> str:
content = self._content
description = content.get("Description", "")
return description

@property
def remediation(self) -> str:
content = self._content
remediation = content.get("Remediation", "")
return remediation

def __repr__(self):
return "<SWC swc_id={0.swc_id} title={0.title}>".format(self)
Loading

0 comments on commit 090e45a

Please sign in to comment.