Skip to content

Commit

Permalink
Upgrade project structure so a package can be build (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
javierdelapuente authored Apr 10, 2024
1 parent 6eeab02 commit ec4c1b1
Show file tree
Hide file tree
Showing 74 changed files with 260 additions and 236 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
!/main.py
!/requirements.txt
!/src
!/pyproject.toml
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Project prepared to be installed with `pip install`, so it can be reused in
the repository https://github.com/canonical/gatekeeper-repo-test

## [v0.9.0] - 2024-04-04

### Added
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ RUN apt-get update && \

RUN mkdir /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app
RUN pip install --no-cache-dir -r requirements.txt

COPY . /usr/src/app
RUN pip install --no-cache-dir /usr/src/app

ENV PYTHONPATH /usr/src/app
CMD ["/usr/src/app/main.py"]
2 changes: 1 addition & 1 deletion generate-src-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# See LICENSE file for licensing details.

rm -rf src-docs
lazydocs --no-watermark --output-path src-docs src/*.py
lazydocs --no-watermark --output-path src-docs src/gatekeeper/*.py
15 changes: 11 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@
from functools import partial
from pathlib import Path

from src import GETTING_STARTED, exceptions, pre_flight_checks, run_migrate, run_reconcile, types_
from src.clients import get_clients
from src.constants import DEFAULT_BRANCH
from src.types_ import ActionResult, PullRequestAction
from gatekeeper import (
GETTING_STARTED,
exceptions,
pre_flight_checks,
run_migrate,
run_reconcile,
types_,
)
from gatekeeper.clients import get_clients
from gatekeeper.constants import DEFAULT_BRANCH
from gatekeeper.types_ import ActionResult, PullRequestAction

GITHUB_HEAD_REF_ENV_NAME = "GITHUB_HEAD_REF"
GITHUB_OUTPUT_ENV_NAME = "GITHUB_OUTPUT"
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

[project]
name = "discourse-gatekeeper"
version = "0.9.0"
dynamic = ["dependencies"]

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

[tool.bandit]
exclude_dirs = ["/venv/", ".tox"]
[tool.bandit.assert_used]
Expand Down
8 changes: 4 additions & 4 deletions src-docs/__init__.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

<a href="../src/__init__.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/__init__.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `__init__.py`
Library for uploading docs to charmhub.
Expand All @@ -15,7 +15,7 @@ Library for uploading docs to charmhub.

---

<a href="../src/__init__.py#L75"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/__init__.py#L75"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `run_reconcile`

Expand Down Expand Up @@ -50,7 +50,7 @@ Upload the documentation to charmhub.

---

<a href="../src/__init__.py#L191"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/__init__.py#L191"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `run_migrate`

Expand All @@ -75,7 +75,7 @@ Migrate existing docs from charmhub to local repository.

---

<a href="../src/__init__.py#L255"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/__init__.py#L255"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `pre_flight_checks`

Expand Down
4 changes: 2 additions & 2 deletions src-docs/action.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

<a href="../src/action.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/action.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `action.py`
Module for taking the required actions to match the server state with the local state.
Expand All @@ -15,7 +15,7 @@ Module for taking the required actions to match the server state with the local

---

<a href="../src/action.py#L444"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/action.py#L444"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `run_all`

Expand Down
8 changes: 4 additions & 4 deletions src-docs/check.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

<a href="../src/check.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/check.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `check.py`
Module for running checks.
Expand All @@ -11,7 +11,7 @@ Module for running checks.

---

<a href="../src/check.py#L53"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/check.py#L53"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `get_path_with_diffs`

Expand All @@ -37,7 +37,7 @@ Generate the paths that have either local or server content changes.

---

<a href="../src/check.py#L159"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/check.py#L159"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `conflicts`

Expand Down Expand Up @@ -67,7 +67,7 @@ The second type of conflict is a logical conflict which arises out of that there

---

<a href="../src/check.py#L259"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/check.py#L259"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `external_refs`

Expand Down
4 changes: 2 additions & 2 deletions src-docs/clients.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

<a href="../src/clients.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/clients.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `clients.py`
Module for Client class.


---

<a href="../src/clients.py#L27"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/clients.py#L27"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `get_clients`

Expand Down
4 changes: 2 additions & 2 deletions src-docs/commit.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

<a href="../src/commit.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/commit.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `commit.py`
Module for handling interactions with git commit.


---

<a href="../src/commit.py#L44"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/commit.py#L44"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `parse_git_show`

Expand Down
2 changes: 1 addition & 1 deletion src-docs/constants.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

<a href="../src/constants.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/constants.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `constants.py`
Shared constants.
Expand Down
8 changes: 4 additions & 4 deletions src-docs/content.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

<a href="../src/content.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/content.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `content.py`
Module for checking conflicts using 3-way merge and create content based on a 3 way merge.


---

<a href="../src/content.py#L20"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/content.py#L20"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `conflicts`

Expand All @@ -34,7 +34,7 @@ Check for merge conflicts based on the git merge algorithm.

---

<a href="../src/content.py#L38"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/content.py#L38"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `merge`

Expand Down Expand Up @@ -66,7 +66,7 @@ Create the merged content based on the git merge algorithm.

---

<a href="../src/content.py#L100"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/content.py#L100"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `diff`

Expand Down
22 changes: 11 additions & 11 deletions src-docs/discourse.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

<a href="../src/discourse.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `discourse.py`
Interface for Discourse interactions.


---

<a href="../src/discourse.py#L498"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L498"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `create_discourse`

Expand Down Expand Up @@ -50,7 +50,7 @@ Interact with a discourse server.

Attrs: host: The host of the discourse server.

<a href="../src/discourse.py#L77"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L77"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

Expand Down Expand Up @@ -80,7 +80,7 @@ The HTTP protocol and hostname for discourse (e.g., https://discourse).

---

<a href="../src/discourse.py#L290"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L290"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `absolute_url`

Expand All @@ -103,7 +103,7 @@ Get the URL including base path for a topic.

---

<a href="../src/discourse.py#L316"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L316"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `check_topic_read_permission`

Expand All @@ -128,7 +128,7 @@ Uses whether retrieve topic succeeds as indication whether the read permission i

---

<a href="../src/discourse.py#L302"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L302"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `check_topic_write_permission`

Expand All @@ -151,7 +151,7 @@ Check whether the credentials have write permission on a topic.

---

<a href="../src/discourse.py#L409"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L409"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `create_topic`

Expand Down Expand Up @@ -181,7 +181,7 @@ Create a new topic.

---

<a href="../src/discourse.py#L439"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L439"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `delete_topic`

Expand Down Expand Up @@ -210,7 +210,7 @@ Delete a topic.

---

<a href="../src/discourse.py#L372"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L372"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `retrieve_topic`

Expand Down Expand Up @@ -239,7 +239,7 @@ Retrieve the topic content.

---

<a href="../src/discourse.py#L133"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L133"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `topic_url_valid`

Expand All @@ -264,7 +264,7 @@ Validations: 1. The URL must start with the base path configured during constru

---

<a href="../src/discourse.py#L462"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/discourse.py#L462"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `update_topic`

Expand Down
8 changes: 4 additions & 4 deletions src-docs/docs_directory.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

<a href="../src/docs_directory.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/docs_directory.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `docs_directory.py`
Class for reading the docs directory.
Expand All @@ -11,7 +11,7 @@ Class for reading the docs directory.

---

<a href="../src/docs_directory.py#L46"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/docs_directory.py#L46"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `calculate_table_path`

Expand All @@ -35,7 +35,7 @@ Calculate the table path of a path.

---

<a href="../src/docs_directory.py#L128"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/docs_directory.py#L128"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `read`

Expand All @@ -61,7 +61,7 @@ Algorithm: 1. Get a list of all sub directories and .md files in the docs fold

---

<a href="../src/docs_directory.py#L155"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/docs_directory.py#L155"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `has_docs_directory`

Expand Down
4 changes: 2 additions & 2 deletions src-docs/download.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

<a href="../src/download.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/download.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `download.py`
Library for downloading docs folder from charmhub.


---

<a href="../src/download.py#L38"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/download.py#L38"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `recreate_docs`

Expand Down
2 changes: 1 addition & 1 deletion src-docs/exceptions.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

<a href="../src/exceptions.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/exceptions.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `exceptions.py`
Exceptions for uploading docs to charmhub.
Expand Down
Loading

0 comments on commit ec4c1b1

Please sign in to comment.