Skip to content

Commit

Permalink
Sort repos of a given type when adding a repo to that type
Browse files Browse the repository at this point in the history
Also:

- Add pre-commit config and run against all files
  • Loading branch information
daneah committed Nov 14, 2024
1 parent 0696611 commit fcfbf08
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 63 deletions.
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/code-issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
name: Code issue
about: Identify an issue with the source code
title: A concise summary of the issue should go here
labels: ''
assignees: ''

labels: ""
assignees: ""
---

[Line(s) of code in question](<GitHub link to highlighted file lines>)
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
schedule:
- cron: '37 17 * * 0'
- cron: "37 17 * * 0"

jobs:
analyze:
Expand All @@ -20,19 +20,19 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: ["python"]

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
56 changes: 56 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
####################################################
# Checks about the pre-commit configuration itself #
####################################################

repos:
- repo: meta
hooks:
- id: check-hooks-apply # Ensures all defined hooks affect at least one file in the repo
- id: check-useless-excludes # Ensures all defined excludes apply to at least one file in the repo

###########################
# General use / built-ins #
###########################

# Click through to this repository to see what other goodies are available
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-ast # Checks Python code for syntax errors
- id: trailing-whitespace # Removes trailing whitespace from lines in all file types
- id: end-of-file-fixer # Fixes last line of all file types
- id: check-merge-conflict # Checks if you're about to commit a file that hasn't had conflicts resolved
- id: no-commit-to-branch # Checks if you're committing to a disallowed branch (default is master)
- id: check-toml # Checks TOML files for syntax errors
- id: check-yaml # Checks YAML files for syntax errors
args: [--allow-multiple-documents]

##########
# Python #
##########

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
hooks:
- id: ruff

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
additional_dependencies: [typer, types-termcolor]

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py39-plus]

############
# Markdown #
############

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@


https://opensource.org/licenses/MIT

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Move from `setup.cfg` to `pyproject.toml` for package configuration
- Move from `black` to `ruff` for formatting
- Move from `isort` to `ruff` for import sorting
- Sort repos of a given type alphabetically when adding a repo to that type

## [0.0.11] - 2024-10-09

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Use alpha versioning during initial development such that all versions are monot

## Consequences

- Consumers won't know when a change is breaking, and should assume *every* change is breaking
- Consumers won't know when a change is breaking, and should assume _every_ change is breaking
- This decision will need to be amended once the project matures into a stable release pattern
- There is sometimes confusion about versions like `0.0.996` and people try to install `0.99.6` or similar instead
- Every released change during initial development will simply increase the last portion of the version string by one
8 changes: 6 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import datetime
import os
from importlib import metadata
from typing import Any

from sphinx.application import Sphinx

# import sys
# sys.path.insert(0, os.path.abspath('.'))

Expand Down Expand Up @@ -83,7 +87,7 @@
PROJECT_ROOT = Path(__file__).parent.parent
PACKAGE_ROOT = PROJECT_ROOT / "src" / "repo_man"

def run_apidoc(_):
def run_apidoc(_: Any) -> None:
from sphinx.ext import apidoc
apidoc.main([
"--force",
Expand All @@ -97,5 +101,5 @@ def run_apidoc(_):
str(PACKAGE_ROOT / "*.so"),
])

def setup(app):
def setup(app: Sphinx) -> None:
app.connect('builder-inited', run_apidoc)
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ commands = [
]

[tool.tox.env.typecheck]
extras = [
"docs",
]
deps = [
{ replace = "ref", of = ["tool", "tox", "env_run_base", "deps"], extend = true },
"mypy",
"types-termcolor",
]
commands = [
["mypy", { replace = "posargs", default = ["src", "test"], extend = true }],
["mypy", { replace = "posargs", default = ["src", "test", "docs"], extend = true }],
]

[tool.tox.env.format]
Expand All @@ -140,7 +143,7 @@ deps = [
"ruff",
]
commands = [
["ruff", "check", { replace = "posargs", default = ["src", "test"], extend = true }],
["ruff", "check", { replace = "posargs", default = ["src", "test", "docs"], extend = true }],
]

[tool.tox.env.docs]
Expand Down
3 changes: 2 additions & 1 deletion src/repo_man/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def add(
config.add_section(repo_type)

if "known" not in config[repo_type] or str(repo) not in config[repo_type]["known"].split("\n"):
config.set(repo_type, "known", f"{original_config}\n{repo}")
ordered_repos = sorted(original_config.split("\n") + [str(repo)])
config.set(repo_type, "known", "\n".join(ordered_repos))

with open(REPO_TYPES_CFG, "w") as config_file:
config.write(config_file)
30 changes: 15 additions & 15 deletions test/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from pathlib import Path
from typing import Callable

import typer
from typer.testing import CliRunner

from repo_man.cli import cli


def test_add_clean_confirm(
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
runner: CliRunner, get_config: Callable[[], configparser.ConfigParser]
) -> None:
with runner.isolated_filesystem():
(Path(".") / "some-repo").mkdir()
Expand All @@ -30,15 +30,15 @@ def test_add_clean_confirm(
assert (
config_file.read()
== """[some-type]
known =
known =
some-repo
"""
)


def test_add_clean_no_confirm_new_file(
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
runner: CliRunner, get_config: Callable[[], configparser.ConfigParser]
) -> None:
with runner.isolated_filesystem():
(Path(".") / "some-repo").mkdir()
Expand All @@ -47,14 +47,14 @@ def test_add_clean_no_confirm_new_file(
assert result.exit_code == 1
assert (
result.output
== """No repo-man.cfg file found. Do you want to continue? [y/N]:
== """No repo-man.cfg file found. Do you want to continue? [y/N]:
Aborted.
"""
)


def test_add_with_existing_file(
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
runner: CliRunner, get_config: Callable[[], configparser.ConfigParser]
) -> None:
with runner.isolated_filesystem():
with open("repo-man.cfg", "w") as config_file:
Expand Down Expand Up @@ -83,19 +83,19 @@ def test_add_with_existing_file(
assert (
config_file.read()
== """[foo]
known =
known =
bar
[some-type]
known =
known =
some-repo
"""
)


def test_add_with_existing_file_and_type(
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
runner: CliRunner, get_config: Callable[[], configparser.ConfigParser]
) -> None:
with runner.isolated_filesystem():
with open("repo-man.cfg", "w") as config_file:
Expand All @@ -116,7 +116,7 @@ def test_add_with_existing_file_and_type(
assert (
config_file.read()
== """[some-type]
known =
known =
bar
some-repo
Expand All @@ -125,7 +125,7 @@ def test_add_with_existing_file_and_type(


def test_add_multiple_types(
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
runner: CliRunner, get_config: Callable[[], configparser.ConfigParser]
) -> None:
with runner.isolated_filesystem():
with open("repo-man.cfg", "w") as config_file:
Expand Down Expand Up @@ -156,20 +156,20 @@ def test_add_multiple_types(
assert (
config_file.read()
== """[some-type]
known =
known =
bar
some-repo
[some-other-type]
known =
known =
some-repo
"""
)


def test_add_no_action_needed(
runner: typer.testing.CliRunner, get_config: Callable[[], configparser.ConfigParser]
runner: CliRunner, get_config: Callable[[], configparser.ConfigParser]
) -> None:
with runner.isolated_filesystem():
with open("repo-man.cfg", "w") as config_file:
Expand All @@ -190,7 +190,7 @@ def test_add_no_action_needed(
assert (
config_file.read()
== """[some-type]
known =
known =
some-repo
"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_implode.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_implode_when_config_present_no_confirm(runner: typer.testing.CliRunner)
assert result.exit_code == 1
assert (
result.output
== """Are you sure you want to do this? [y/N]:
== """Are you sure you want to do this? [y/N]:
Aborted.
"""
)
Expand Down
12 changes: 6 additions & 6 deletions test/test_list_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_list_repos_with_matches(
with open("repo-man.cfg", "w") as config_file:
config_file.write(
"""[foo]
known =
known =
some-repo
some-other-repo
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_list_repos_when_long(
with open("repo-man.cfg", "w") as config_file:
config_file.write(
f"""[foo]
known =
known =
{config_list}
"""
Expand All @@ -96,11 +96,11 @@ def test_list_repos_for_multiple_tags(
with open("repo-man.cfg", "w") as config_file:
config_file.write(
"""[foo]
known =
known =
some-repo
[bar]
known =
known =
some-other-repo
"""
Expand All @@ -124,11 +124,11 @@ def test_list_repos_when_invalid_type(
with open("repo-man.cfg", "w") as config_file:
config_file.write(
"""[foo]
known =
known =
some-repo
[bar]
known =
known =
some-other-repo
"""
Expand Down
Loading

0 comments on commit fcfbf08

Please sign in to comment.