Skip to content

Commit

Permalink
General repository cleanup (#1553)
Browse files Browse the repository at this point in the history
  • Loading branch information
davfsa authored Mar 25, 2023
1 parent cc5d6ea commit 2673726
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 105 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
* text=auto eol=lf

# Language aware diff headers
*.py diff=python
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: CI

on:
push:
branches-ignore:
- "dependabot/**"
pull_request:

concurrency:
Expand Down Expand Up @@ -42,11 +44,11 @@ jobs:
- name: Run tests
shell: bash
run: |
pip install -r dev-requirements/nox.txt
pip install -r dev-requirements.txt
nox -s pytest
nox -s pytest-all-features -- --cov-append
python scripts/normalize_coverage.py
python scripts/ci/normalize_coverage.py
mv .coverage .coverage.${{ matrix.os }}.${{ matrix.python-version }}
- name: Upload coverage
Expand Down Expand Up @@ -105,7 +107,7 @@ jobs:
- name: Check stubs
if: always()
run: |
pip install -r dev-requirements/nox.txt
pip install -r dev-requirements.txt
nox -s generate-stubs
if [ "$(git status --short)" ]; then
echo "Stubs were not updated accordingly to the changes. Please run 'nox -s generate-stubs' and commit the changes to fix this."
Expand Down Expand Up @@ -161,7 +163,7 @@ jobs:

- name: Test twemoji mapping
run: |
pip install -r dev-requirements/nox.txt
pip install -r dev-requirements.txt
nox -s twemoji-test
docs:
Expand All @@ -181,7 +183,7 @@ jobs:

- name: Build documentation
run: |
pip install -r dev-requirements/nox.txt
pip install -r dev-requirements.txt
nox -s sphinx
- name: Upload artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "CodeQL"
name: CodeQL

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Run prepare script
env:
VERSION: ${{ inputs.version }}
run: bash scripts/prepare-release.sh
run: bash scripts/ci/prepare-release.sh

- name: Create pull request
uses: repo-sync/pull-request@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
DEPLOY_WEBHOOK_URL: ${{ secrets.DEPLOY_WEBHOOK_URL }}
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: bash scripts/release.sh
run: bash scripts/ci/release.sh

- name: Re-enable "include administrators" branch protection
uses: benjefferies/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ We have nox to help out with running pipelines locally and provides some helpful

You will need to install `nox` locally before running any pipelines.
```bash
pip install -r dev-requirements/nox.txt
pip install -r dev-requirements.txt
```

Nox is similar to tox, but uses a pure Python configuration instead of an INI based configuration. Nox and tox are
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ In the repository, make a virtual environment (`python -m venv .venv`) and enter
Linux, or for Windows use one of `.venv\Scripts\activate.ps1`, `.venv\Scripts\activate.bat`,
`source .venv/Scripts/activate`).

The first thing you should run is `pip install -r dev-requirements/nox.txt` to install nox.
The first thing you should run is `pip install -r dev-requirements.txt` to install nox.
This handles running predefined tasks and pipelines.

Once this is complete, you can run `nox` without any arguments to ensure everything builds and is correct.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pipelines/codespell.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
]


@nox.session(reuse_venv=True)
@nox.session(default_session=True)
def codespell(session: nox.Session) -> None:
"""Run codespell to check for spelling mistakes."""
session.install(*nox.dev_requirements("codespell"))
Expand Down
4 changes: 2 additions & 2 deletions pipelines/flake8.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
from pipelines import nox


@nox.session(reuse_venv=True)
@nox.session(default_session=True)
def flake8(session: nox.Session) -> None:
"""Run code linting, SAST, and analysis."""
_flake8(session)


@nox.session(reuse_venv=True)
@nox.session()
def flake8_html(session: nox.Session) -> None:
"""Run code linting, SAST, and analysis and generate an HTML report."""
_flake8(session, ("--format=html", f"--htmldir={config.FLAKE8_REPORT}"))
Expand Down
4 changes: 2 additions & 2 deletions pipelines/format.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
GIT = shutil.which("git")


@nox.session(reuse_venv=True)
@nox.session(default_session=True)
def reformat_code(session: nox.Session) -> None:
"""Remove trailing whitespace in source, run isort, codespell and then run black code formatter."""
session.install(*nox.dev_requirements("formatting"))
Expand All @@ -43,7 +43,7 @@ def reformat_code(session: nox.Session) -> None:
session.run("black", *config.PYTHON_REFORMATTING_PATHS)


@nox.session(reuse_venv=True, venv_backend="none")
@nox.session(default_session=True, venv_backend="none")
def check_trailing_whitespaces(session: nox.Session) -> None:
"""Check for trailing whitespaces in the project."""
remove_trailing_whitespaces(session, check_only=True)
Expand Down
4 changes: 2 additions & 2 deletions pipelines/mypy.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
]


@nox.session(reuse_venv=True)
@nox.session(default_session=True)
def mypy(session: nox.Session) -> None:
"""Perform static type analysis on Python source code using mypy."""
session.install(
Expand All @@ -51,7 +51,7 @@ def mypy(session: nox.Session) -> None:
session.run("mypy", "-p", config.EXAMPLE_SCRIPTS, "--config", config.PYPROJECT_TOML)


@nox.session(reuse_venv=True)
@nox.session()
def generate_stubs(session: nox.Session) -> None:
"""Generate the stubs for the package."""
session.install(*nox.dev_requirements("mypy", "formatting"))
Expand Down
12 changes: 8 additions & 4 deletions pipelines/nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@
from nox import session as _session
from nox.sessions import Session

from pipelines import config
from pipelines import config as _pipelines_config

# Default sessions should be defined here
_options.sessions = ["reformat-code", "pytest", "flake8", "slotscheck", "mypy", "verify-types"]
_options.sessions = []

_NoxCallbackSig = _typing.Callable[[Session], None]


def session(*, reuse_venv: bool = False, **kwargs: _typing.Any) -> _typing.Callable[[_NoxCallbackSig], _NoxCallbackSig]:
def session(**kwargs: _typing.Any) -> _typing.Callable[[_NoxCallbackSig], _NoxCallbackSig]:
def decorator(func: _NoxCallbackSig) -> _NoxCallbackSig:
name = func.__name__.replace("_", "-")
reuse_venv = kwargs.pop("reuse_venv", True)

if kwargs.pop("default_session", False):
_options.sessions.append(name)

return _session(name=name, reuse_venv=reuse_venv, **kwargs)(func)

Expand All @@ -48,6 +52,6 @@ def dev_requirements(*dependencies: str) -> _typing.Sequence[str]:
args = []

for dep in dependencies:
args.extend(("-r", _os.path.join(config.DEV_REQUIREMENTS_DIRECTORY, f"{dep}.txt")))
args.extend(("-r", _os.path.join(_pipelines_config.DEV_REQUIREMENTS_DIRECTORY, f"{dep}.txt")))

return args
2 changes: 1 addition & 1 deletion pipelines/pyright.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def pyright(session: nox.Session) -> None:
session.run("pyright")


@nox.session()
@nox.session(default_session=True)
def verify_types(session: nox.Session) -> None:
"""Verify the "type completeness" of types exported by the library using Pyright."""
session.install(".", *nox.dev_requirements("pyright"))
Expand Down
4 changes: 2 additions & 2 deletions pipelines/pytest.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
]


@nox.session(reuse_venv=True)
@nox.session(default_session=True)
def pytest(session: nox.Session) -> None:
"""Run unit tests and measure code coverage.
Expand All @@ -53,7 +53,7 @@ def pytest(session: nox.Session) -> None:
_pytest(session)


@nox.session(reuse_venv=True)
@nox.session()
def pytest_all_features(session: nox.Session) -> None:
"""Run unit tests and measure code coverage, using speedup modules.
Expand Down
2 changes: 1 addition & 1 deletion pipelines/safety.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pipelines import nox


@nox.session(reuse_venv=True)
@nox.session(default_session=True)
def safety(session: nox.Session) -> None:
"""Perform dependency scanning."""
session.install("-r", "requirements.txt", *nox.dev_requirements("safety"))
Expand Down
2 changes: 1 addition & 1 deletion pipelines/slotscheck.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pipelines import nox


@nox.session()
@nox.session(default_session=True)
def slotscheck(session: nox.Session) -> None:
"""Check for common slotting mistakes."""
session.install(".", *nox.dev_requirements("slotscheck"))
Expand Down
4 changes: 2 additions & 2 deletions pipelines/sphinx.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from pipelines import nox


@nox.session(reuse_venv=True)
@nox.session()
def sphinx(session: nox.Session):
"""Generate docs using sphinx."""
if "--no-refs" in session.posargs:
Expand Down Expand Up @@ -85,7 +85,7 @@ def close(self) -> None:
self.server.shutdown()


@nox.session(reuse_venv=True, venv_backend="none")
@nox.session(venv_backend="none")
def view_docs(_: nox.Session) -> None:
"""Start an HTTP server for any generated pages in `/public/docs/dirhtml`."""
with contextlib.closing(HTTPServerThread()) as thread:
Expand Down
4 changes: 2 additions & 2 deletions pipelines/twemoji.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from pipelines import nox


@nox.session(reuse_venv=True)
@nox.session()
def twemoji_test(session: nox.Session):
"""Brute-force test all possible Twemoji mappings for Discord unicode emojis."""
session.install("-e", ".")
session.run("python", "scripts/test_twemoji_mapping.py")
session.run("python", "scripts/ci/test_twemoji_mapping.py", session.create_tmp())
2 changes: 1 addition & 1 deletion pipelines/utils.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
]


@nox.session(reuse_venv=False, venv_backend="none")
@nox.session(venv_backend="none")
def purge(session: nox.Session) -> None:
"""Delete any nox-generated files."""
for func, trash_list in TO_DELETE:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ posix_read "Twine username" TWINE_USERNAME
posix_read "Twine password" TWINE_PASSWORD
posix_read "Discord deployment webhook URL" DEPLOY_WEBHOOK_URL

bash scripts/release.sh
bash scripts/ci/release.sh
23 changes: 20 additions & 3 deletions scripts/release.sh → scripts/ci/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ else
fi

echo "===== INSTALLING DEPENDENCIES ====="
pip install -r requirements.txt -r dev-requirements/release.txt -r dev-requirements/nox.txt
pip install -r requirements.txt -r dev-requirements/release.txt -r dev-requirements.txt

export REF=$(git rev-parse HEAD)

Expand All @@ -74,10 +74,27 @@ echo "-- Uploading to PyPI --"
python -m twine upload --disable-progress-bar --skip-existing dist/* --non-interactive --repository-url https://upload.pypi.org/legacy/

echo "===== SENDING WEBHOOK ====="
bash scripts/release-webhook.sh
curl \
-X POST \
-H "Content-Type: application/json" \
"${DEPLOY_WEBHOOK_URL}" \
-d '{
"username": "Github Actions",
"embeds": [
{
"title": "'"${VERSION} has been deployed to PyPI"'",
"color": 6697881,
"description": "'"Install it now by executing: \`\`\`pip install hikari==${VERSION}\`\`\`\\nDocumentation can be found at https://docs.hikari-py.dev/en/${VERSION}"'",
"footer": {
"text": "'"SHA: ${REF}"'"
}
}
]
}'


echo "===== UPDATING VERSION IN REPOSITORY ====="
NEW_VERSION=$(python scripts/increase_version_number.py "${VERSION}")
NEW_VERSION=$(python scripts/ci/increase_version_number.py "${VERSION}")

echo "-- Setting up git --"
git fetch origin
Expand Down
Loading

0 comments on commit 2673726

Please sign in to comment.