Skip to content

Commit

Permalink
Rewrite (#178)
Browse files Browse the repository at this point in the history
* Reinitialize versioning

Signed-off-by: GitHub <[email protected]>

* Reinitialize CI

Signed-off-by: GitHub <[email protected]>

* Reinitialize dependencies

Signed-off-by: GitHub <[email protected]>

* Don't copy in all files to Containerfile

Signed-off-by: GitHub <[email protected]>

* Fix copy paste typo

Signed-off-by: GitHub <[email protected]>

* Fix typo in docs config

Signed-off-by: GitHub <[email protected]>

* Capitalize proper noun

Signed-off-by: GitHub <[email protected]>

* Let Ruff autofix

Signed-off-by: GitHub <[email protected]>

* Remove unused constants

Signed-off-by: GitHub <[email protected]>

* Let Ruff autofix

Signed-off-by: GitHub <[email protected]>

* Add prefix back and wrap async HTTP session in 'with'

Signed-off-by: GitHub <[email protected]>

* Remove pylint ignores

Signed-off-by: GitHub <[email protected]>

* Wrap Dragonfly API access in a class

Signed-off-by: GitHub <[email protected]>

* Remove the pypi command

It will be put back later when actually feasilbe to implement

Signed-off-by: GitHub <[email protected]>

* Remove outdated env sample

Signed-off-by: GitHub <[email protected]>

* Begin working through Ruff lints

Signed-off-by: GitHub <[email protected]>

* Appease the linter

Signed-off-by: GitHub <[email protected]>

---------

Signed-off-by: GitHub <[email protected]>
  • Loading branch information
shenanigansd authored Oct 12, 2023
1 parent d612898 commit 5d3a0a6
Show file tree
Hide file tree
Showing 49 changed files with 805 additions and 770 deletions.
8 changes: 0 additions & 8 deletions .env.sample

This file was deleted.

4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# CI
.github @letsbuilda/devops
# Require DevOps signoff on CI changes
.github @vipyrsec/devops
20 changes: 20 additions & 0 deletions .github/workflows/dependency-review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Dependency Review"

on:
pull_request:

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest

steps:
- name: "Checkout Repository"
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0

- name: "Dependency Review"
uses: actions/dependency-review-action@6c5ccdad469c9f8a2996bfecaec55a631a347034 # v3.1.0
with:
config-file: darbiadev/.github/.github/dependency-review-config.yaml@f185cc076161b47921c6fb6da4c1fd5e40b50bff # v3.0.0
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ permissions:

jobs:
build-push:
uses: darbiadev/.github/.github/workflows/docker-build-push.yaml@068870f051676db9e2651013f7c7196ffdaeadaa # v2.0.0
uses: darbiadev/.github/.github/workflows/docker-build-push.yaml@f185cc076161b47921c6fb6da4c1fd5e40b50bff # v3.0.0
15 changes: 12 additions & 3 deletions .github/workflows/python-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ on:

jobs:
pre-commit:
uses: darbiadev/.github/.github/workflows/generic-precommit.yaml@068870f051676db9e2651013f7c7196ffdaeadaa # v2.0.0
uses: darbiadev/.github/.github/workflows/generic-precommit.yaml@f185cc076161b47921c6fb6da4c1fd5e40b50bff # v3.0.0

lint:
needs: pre-commit
uses: darbiadev/.github/.github/workflows/python-lint.yaml@068870f051676db9e2651013f7c7196ffdaeadaa # v2.0.0
uses: darbiadev/.github/.github/workflows/python-lint.yaml@f185cc076161b47921c6fb6da4c1fd5e40b50bff # v3.0.0

test:
needs: lint
Expand All @@ -21,7 +21,16 @@ jobs:
os: [ ubuntu-latest ]
python-version: [ "3.11" ]

uses: darbiadev/.github/.github/workflows/python-test.yaml@068870f051676db9e2651013f7c7196ffdaeadaa # v2.0.0
uses: darbiadev/.github/.github/workflows/python-test.yaml@f185cc076161b47921c6fb6da4c1fd5e40b50bff # v3.0.0
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}

docs:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

uses: darbiadev/.github/.github/workflows/github-pages-python-sphinx.yaml@f185cc076161b47921c6fb6da4c1fd5e40b50bff # v3.0.0
5 changes: 3 additions & 2 deletions .github/workflows/sentry-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: "Checkout repository"
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0

- name: Create Sentry release
- name: "Create Sentry release"
uses: getsentry/action-release@4744f6a65149f441c5f396d5b0877307c0db52c7 # v1.4.1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ repos:
args: [ --fix=lf ]
- id: end-of-file-fixer
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.280"
rev: "v0.0.292"
hooks:
- id: ruff
17 changes: 8 additions & 9 deletions Dockerfile → Containerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
FROM python:3.11-slim@sha256:edaf703dce209d774af3ff768fc92b1e3b60261e7602126276f9ceb0e3a96874

RUN adduser --disabled-password bot
USER bot

# Define Git SHA build argument for sentry
# Define Git SHA build argument for Sentry
ARG git_sha="development"
ENV GIT_SHA=$git_sha

WORKDIR /home/bot

COPY requirements.txt .
COPY requirements/requirements.txt .
RUN python -m pip install --requirement requirements.txt

COPY --chown=bot:bot . .
COPY pyproject.toml pyproject.toml
COPY src/ src/
RUN python -m pip install .

CMD ["python", "-m", "bot"]
RUN adduser --disabled-password bot
USER bot

CMD [ "python", "-m", "bot" ]
9 changes: 6 additions & 3 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
.. See docs for details on formatting your entries
https://releases.readthedocs.io/en/latest/concepts.html
Changelog
=========

- :release:`4.0.0 <4th October 2023>`
- :feature:`-` Reinitialize versioning
- :feature:`-` Reinitialize CI
- :feature:`-` Reinitialize dependencies
- :feature:`-` Don't copy in all files to Containerfile

- :release:`2.3.2 <15th May 2023>`
- :feature:`62` Add slash command to bring up package modal on demand

Expand Down
26 changes: 12 additions & 14 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from importlib.metadata import metadata

project_metadata = metadata("dragonfly-bot")
project_metadata = metadata("bot")
project: str = project_metadata["Name"]
release: str = project_metadata["Version"]
REPO_LINK: str = project_metadata["Project-URL"].replace("repository, ", "")
Expand Down Expand Up @@ -53,16 +53,16 @@
releases_release_uri = f"{REPO_LINK}/releases/tag/v%s"


def linkcode_resolve(domain, info):
"""linkcode_resolve"""
def linkcode_resolve(domain: str, info: dict) -> str:
"""linkcode_resolve."""
if domain != "py":
return None
if not info["module"]:
return None

import importlib # pylint: disable=import-outside-toplevel
import inspect # pylint: disable=import-outside-toplevel
import types # pylint: disable=import-outside-toplevel
import importlib
import inspect
import types

mod = importlib.import_module(info["module"])

Expand All @@ -76,14 +76,12 @@ def linkcode_resolve(domain, info):

if isinstance(
val,
(
types.ModuleType,
types.MethodType,
types.FunctionType,
types.TracebackType,
types.FrameType,
types.CodeType,
),
types.ModuleType
| types.MethodType
| types.FunctionType
| types.TracebackType
| types.FrameType
| types.CodeType,
):
try:
lines, first = inspect.getsourcelines(val)
Expand Down
29 changes: 14 additions & 15 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ COMMANDS
install-dev install local package in editable mode
update-deps update the dependencies
upgrade-deps upgrade the dependencies
lint run `isort` and `black`
pylint run `pylint`
lint run `pre-commit` and `black` and `ruff`
test run `pytest`
build-dist run `python -m build`
clean delete generated content
help, -? show this help message
#>
param(
[Parameter(Position = 0)]
[ValidateSet("init", "install-dev", "update-deps", "upgrade-deps", "lint", "pylint", "test", "build-dist", "clean", "help")]
[ValidateSet("init", "install-dev", "update-deps", "upgrade-deps", "lint", "test", "build-dist", "clean", "help")]
[string]$Command
)

Expand All @@ -41,25 +40,28 @@ function Invoke-Install-Dev

function Invoke-Update-Deps
{
pip-compile --output-file requirements.txt requirements.in
python -m pip install --upgrade pip-tools
pip-compile --resolver=backtracking requirements/requirements.in --output-file requirements/requirements.txt
pip-compile --resolver=backtracking requirements/requirements-dev.in --output-file requirements/requirements-dev.txt
pip-compile --resolver=backtracking requirements/requirements-tests.in --output-file requirements/requirements-tests.txt
pip-compile --resolver=backtracking requirements/requirements-docs.in --output-file requirements/requirements-docs.txt
}

function Invoke-Upgrade-Deps
{
python -m pip install --upgrade pip-tools pre-commit
pre-commit autoupdate
pip-compile --output-file requirements.txt --upgrade requirements.in
pip-compile --resolver=backtracking --upgrade requirements/requirements.in --output-file requirements/requirements.txt
pip-compile --resolver=backtracking --upgrade requirements/requirements-dev.in --output-file requirements/requirements-dev.txt
pip-compile --resolver=backtracking --upgrade requirements/requirements-tests.in --output-file requirements/requirements-tests.txt
pip-compile --resolver=backtracking --upgrade requirements/requirements-docs.in --output-file requirements/requirements-docs.txt
}

function Invoke-Lint
{
pre-commit run --all-files
python -m isort src/
python -m black src/
}

function Invoke-Pylint
{
python -m pylint src/
python -m black .
python -m ruff --fix .
}

function Invoke-Test
Expand Down Expand Up @@ -104,9 +106,6 @@ switch ($Command)
"upgrade-deps" {
Invoke-Upgrade-Deps
}
"pylint" {
Invoke-Pylint
}
"test" {
Invoke-Test
}
Expand Down
49 changes: 26 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
[project]
name = "bot"
version = "3.0.0"
dynamic = ["dependencies"]
version = "4.0.0"
dynamic = ["dependencies", "optional-dependencies"]

[project.urls]
repository = "https://github.com/vipyrsec/bot/"
documentation = "https://docs.vipyrsec.com/bot/"

[project.optional-dependencies]
dev = [
"pip-tools",
"pre-commit",
"black",
"ruff",
]
tests = [
"pytest",
]
docs = [
"sphinx",
"furo",
"sphinx-autoapi",
"toml",
"releases",
]

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic.dependencies]
file = ["requirements.txt"]
file = ["requirements/requirements.txt"]

[tool.setuptools.dynamic.optional-dependencies]
dev = { file = ["requirements/requirements-dev.txt"] }
tests = { file = ["requirements/requirements-tests.txt"] }
docs = { file = ["requirements/requirements-docs.txt"] }

[tool.black]
target-version = ["py311"]
line-length = 120

[tool.ruff]
target-version = "py311"
line-length = 120
select = ["ALL"]
ignore = [
"G004", # (Logging statement uses f-string) - Developer UX
"S101", # (Use of `assert` detected) - This should probably be changed
]

[tool.ruff.extend-per-file-ignores]
"docs/*" = [
"INP001", # (File `tests/*.py` is part of an implicit namespace package. Add an `__init__.py`.) - Docs are not modules
]
"tests/*" = [
"INP001", # (File `tests/*.py` is part of an implicit namespace package. Add an `__init__.py`.) - Tests are not modules
"S101", # (Use of `assert` detected) - Yes, that's the point
]

[tool.pytest.ini_options]
addopts = "tests -r a -v --doctest-modules src"
[tool.ruff.pydocstyle]
convention = "numpy"
7 changes: 7 additions & 0 deletions requirements/requirements-dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Constrain versions installed to be compatible with core dependencies
--constraint requirements.txt

pip-tools
pre-commit
black
ruff
56 changes: 56 additions & 0 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --output-file=requirements/requirements-dev.txt requirements/requirements-dev.in
#
black==23.9.1
# via -r requirements/requirements-dev.in
build==1.0.3
# via pip-tools
cfgv==3.4.0
# via pre-commit
click==8.1.7
# via
# black
# pip-tools
distlib==0.3.7
# via virtualenv
filelock==3.12.4
# via
# -c requirements/requirements.txt
# virtualenv
identify==2.5.30
# via pre-commit
mypy-extensions==1.0.0
# via black
nodeenv==1.8.0
# via pre-commit
packaging==23.2
# via
# black
# build
pathspec==0.11.2
# via black
pip-tools==7.3.0
# via -r requirements/requirements-dev.in
platformdirs==3.11.0
# via
# black
# virtualenv
pre-commit==3.4.0
# via -r requirements/requirements-dev.in
pyproject-hooks==1.0.0
# via build
pyyaml==6.0.1
# via pre-commit
ruff==0.0.292
# via -r requirements/requirements-dev.in
virtualenv==20.24.5
# via pre-commit
wheel==0.41.2
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
Loading

0 comments on commit 5d3a0a6

Please sign in to comment.