Skip to content
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

Fix Python 3.8 and Python 3.9 CI checks #182

Merged
merged 3 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: python -m pip install flake8==3.8.4 nox==2020.12.31 poetry==1.1.4
- run: python -m pip install flake8 nox poetry
- run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- run: python -m nox
45 changes: 10 additions & 35 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import nox
from nox.sessions import Session

package = "hypermodern_python"
nox.options.sessions = "lint", "tests"
nox.options.sessions = ["tests"]
locations = "src", "tests", "noxfile.py", "docs/conf.py"


Expand Down Expand Up @@ -34,41 +33,17 @@ def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> Non
session.install("--constraint=requirements.txt", *args, **kwargs)


@nox.session(python="3.8")
def black(session: Session) -> None:
"""Run black code formatter."""
args = session.posargs or locations
install_with_constraints(session, "black")
session.run("black", *args)


@nox.session(python=["3.8", "3.7"])
def lint(session: Session) -> None:
pass


@nox.session(python=["3.8", "3.7"])
@nox.session
def tests(session: Session) -> None:
"""Run the test suite."""
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(session, "pytest", "pytest-black", "pytest-isort")
session.run("pytest")


@nox.session(python=["3.8", "3.7"])
def typeguard(session: Session) -> None:
"""Runtime type checking using Typeguard."""
args = session.posargs or ["-m", "not e2e"]
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(
session, "pytest", "pytest-mock", "typeguard", "pytest-black", "pytest-isort"
session,
"pytest",
"pytest-black",
"pytest-isort",
"pytest-mypy",
"types-requests",
"types-orjson",
)
session.run("pytest", f"--typeguard-packages={package}", *args)


@nox.session(python="3.8")
def coverage(session: Session) -> None:
"""Upload coverage data."""
install_with_constraints(session, "coverage[toml]", "codecov")
session.run("coverage", "xml", "--fail-under=50")
session.run("codecov", *session.posargs)
session.run("pytest")
107 changes: 106 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ flake8 = "3.8.4"
requests = "^2.26.0"
pytest-black = "^0.3.12"
pytest-isort = "^2.0.0"
pytest-mypy = "^0.8.1"
types-requests = "^2.25.9"
types-orjson = "^3.6.0"

[tool.poetry.extras]
optimize = ["orjson"]
Expand All @@ -42,5 +45,8 @@ use_parentheses = true
ensure_newline_before_comments = true
line_length = 88

[tool.mypy]
ignore_missing_imports = true

[tool.pytest.ini_options]
addopts = "--black --isort"
addopts = "--black --isort --mypy"
4 changes: 2 additions & 2 deletions pywhat/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Filter(Mapping):
* {"Tags": ["Identifiers"], "ExcludeTags": ["Credentials"], "MinRarity": 0.6}
"""

def __init__(self, filters_dict: Optional[Mapping] = None):
def __init__(self, filters_dict=None):
tags = CaseInsensitiveSet(AvailableTags().get_tags())
self._dict = dict()
self._dict = {}
if filters_dict is None:
filters_dict = {}

Expand Down
2 changes: 1 addition & 1 deletion pywhat/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
try:
import orjson as json
except ImportError:
import json
import json # type: ignore


class AvailableTags:
Expand Down
8 changes: 4 additions & 4 deletions pywhat/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(
self,
*,
dist: Optional[Distribution] = None,
key: Callable = Keys.NONE,
key=Keys.NONE,
reverse=False,
boundaryless: Optional[Filter] = None,
):
Expand Down Expand Up @@ -45,7 +45,7 @@ def identify(
if boundaryless is None:
boundaryless = self.boundaryless

identify_obj = {"File Signatures": {}, "Regexes": {}}
identify_obj: dict = {"File Signatures": {}, "Regexes": {}}
search = []

if not only_text and os.path.isdir(text):
Expand All @@ -64,8 +64,8 @@ def identify(
short_name = os.path.basename(string)

magic_numbers = pywhat.magic_numbers.get_magic_nums(string)
with open(string, "r", encoding="utf-8", errors="ignore") as myfile:
contents = [myfile.read()]
with open(string, "r", encoding="utf-8", errors="ignore") as file:
contents = [file.read()]

if include_filenames:
contents.append(os.path.basename(string))
Expand Down
4 changes: 4 additions & 0 deletions pywhat/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def print_raw(self, text: dict, text_input) -> str:
if output_str.strip():
self.console.print(output_str.rstrip())

return output_str

def _check_if_exploit_in_json(self, text: dict) -> bool:
if "File Signatures" in text and text["File Signatures"]:
# loops files
Expand All @@ -190,5 +192,7 @@ def _check_if_exploit_in_json(self, text: dict) -> bool:
if "Exploit" in value["Regex Pattern"].keys():
self.bug_bounty_mode = True

return self.bug_bounty_mode

def _check_if_directory(self, text_input):
return os.path.isdir(text_input)
4 changes: 2 additions & 2 deletions scripts/get_file_sigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def cleanhtml(raw_html):
wt = wtp.parse(r.text)
# prints first 3 items of json, delete [0:3] to print all.

to_iter = {"root": wt.tables[0].data()}
to_iter = to_iter["root"]
sig_dict = {"root": wt.tables[0].data()}
to_iter = sig_dict["root"]
to_dump = []

populars = {"23 21"}
Expand Down
7 changes: 1 addition & 6 deletions tests/test_regex_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def test_instapayment():
_assert_match_first_item("Insta Payment Card Number", res)


def test_instapayment():
def test_stackhawk():
res = r.check(["hawk.wz6bAoFDwcVQFCD9dofE.w2R1PWI8UTvEM4jd56XQ"])
_assert_match_first_item("StackHawk API Key", res)

Expand Down Expand Up @@ -822,11 +822,6 @@ def test_github_refresh_token():
_assert_match_first_item("GitHub Refresh Token", res)


def test_stripe_api_key():
res = r.check(["sk_live_26PHem9AhJZvU623DfE1x4sd"])
_assert_match_first_item("Stripe API Key", res)
SkeletalDemise marked this conversation as resolved.
Show resolved Hide resolved


def test_zapier_webhook():
res = r.check(["https://hooks.zapier.com/hooks/catch/1234567/f8f22dgg/"])
_assert_match_first_item("Zapier Webhook Token", res)
Expand Down