Skip to content

Commit 68171a4

Browse files
authored
Merge pull request #14 from bugout-dev/internal-improvements
Internal improvements
2 parents 4422329 + edc86e7 commit 68171a4

File tree

9 files changed

+25
-75
lines changed

9 files changed

+25
-75
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
with:
1212
python-version: "3.8"
1313
- name: Install test requirements
14-
run: pip install -r requirements.dev.txt
14+
run: pip install -e .[dev]
1515
- name: Mypy type check
1616
run: mypy bugout/
1717
- name: Black syntax check

.github/workflows/locust.yml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,8 @@ jobs:
2525
run: |
2626
python -m pip install --upgrade pip setuptools
2727
pip install bugout-locust
28-
- name: Generate Locust summary
29-
run: |
30-
COMMENTS_URL=$(python -c 'import json; import os; event = os.environ.get("GITHUB_EVENT_PATH"); raw = open(event); inp_json = json.load(raw); print(inp_json.get("pull_request").get("_links").get("comments").get("href")); raw.close();')
31-
INITIAL_REF=$(locust.github initial)
32-
TERMINAL_REF=$(locust.github terminal)
33-
REPO_URL=$(locust.github repo)
34-
locust --format json $INITIAL_REF $TERMINAL_REF --github $REPO_URL --metadata "{\"comments_url\": \"${COMMENTS_URL}\", \"terminal_hash\": \"$TERMINAL_REF\"}" | tee summary
35-
- name: Cleaning summary
36-
id: clean_summary
37-
run: |
38-
summary=$(cat summary)
39-
summary="${summary//'%'/'%25'}"
40-
summary="${summary//$'\n'/'%0A'}"
41-
summary="${summary//$'\r'/'%0D'}"
42-
echo "::set-output name=summary::$summary"
43-
- name: Upload locust results to Bugout
28+
- name: Generate and send Locust summary
4429
env:
4530
BUGOUT_SECRET: ${{ secrets.BUGOUT_SECRET }}
4631
run: |
47-
curl -k -X POST "https://spire.bugout.dev/github/summary" \
48-
-H "Content-Type: application/json" \
49-
-H "Authorization: Bearer $BUGOUT_SECRET" \
50-
--data '${{ steps.clean_summary.outputs.summary }}'
32+
locust.github publish

bugout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
__email__ = "engineering@bugout.dev"
99
__license__ = "MIT"
10-
__version__ = "0.1.2"
10+
__version__ = "0.1.3"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .group import Group
77
from .journal import Journal
88
from .user import User
9-
from .settings import REQUESTS_TIMEOUT
9+
from .settings import BUGOUT_BROOD_URL, BUGOUT_SPIRE_URL, REQUESTS_TIMEOUT
1010

1111

1212
class InvalidParameters(ValueError):
@@ -17,7 +17,9 @@ class InvalidParameters(ValueError):
1717

1818
class Bugout:
1919
def __init__(
20-
self, brood_api_url: Optional[str] = None, spire_api_url: Optional[str] = None
20+
self,
21+
brood_api_url: str = BUGOUT_BROOD_URL,
22+
spire_api_url: str = BUGOUT_SPIRE_URL,
2123
) -> None:
2224
self.brood_api_url = brood_api_url
2325
self.spire_api_url = spire_api_url
@@ -35,13 +37,9 @@ def spire_url(self):
3537
return self.spire_api_url
3638

3739
def brood_ping(self) -> Dict[str, str]:
38-
if self.brood_api_url is None:
39-
raise InvalidParameters("Brood API url should be provided")
4040
return ping(self.brood_api_url)
4141

4242
def spire_ping(self) -> Dict[str, str]:
43-
if self.spire_api_url is None:
44-
raise InvalidParameters("Spire API url should be provided")
4543
return ping(self.spire_api_url)
4644

4745
# User handlers
@@ -50,15 +48,12 @@ def create_user(
5048
username: str,
5149
email: str,
5250
password: str,
53-
autogenerated_token: str = None,
5451
timeout: float = REQUESTS_TIMEOUT,
52+
**kwargs: Dict[str, Any],
5553
) -> data.BugoutUser:
5654
self.user.timeout = timeout
5755
return self.user.create_user(
58-
username=username,
59-
email=email,
60-
password=password,
61-
autogenerated_token=autogenerated_token,
56+
username=username, email=email, password=password, **kwargs
6257
)
6358

6459
def get_user(
@@ -80,13 +75,11 @@ def find_user(
8075
self,
8176
username: str,
8277
token: Union[str, uuid.UUID] = None,
83-
installation_token: str = None,
8478
timeout: float = REQUESTS_TIMEOUT,
79+
**kwargs: Dict[str, Any],
8580
) -> data.BugoutUser:
8681
self.user.timeout = timeout
87-
return self.user.find_user(
88-
username=username, token=token, installation_token=installation_token
89-
)
82+
return self.user.find_user(username=username, token=token, **kwargs)
9083

9184
def confirm_email(
9285
self,
@@ -533,7 +526,7 @@ def search(
533526
token: Union[str, uuid.UUID],
534527
journal_id: Union[str, uuid.UUID],
535528
timeout: float = REQUESTS_TIMEOUT,
536-
**queries: Dict[str, Any]
529+
**queries: Dict[str, Any],
537530
) -> data.BugoutSearchResults:
538531
self.journal.timeout = timeout
539532
return self.journal.search(token=token, journal_id=journal_id, **queries)

bugout/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import os
22

3+
BUGOUT_BROOD_URL = "https://auth.bugout.dev"
4+
BUGOUT_SPIRE_URL = "https://spire.bugout.dev"
5+
36
REQUESTS_TIMEOUT = 5
47
REQUESTS_TIMEOUT_RAW = os.environ.get("BUGOUT_TIMEOUT_SECONDS")
58
try:

bugout/user.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,17 @@ def create_user(
3737
username: str,
3838
email: str,
3939
password: str,
40-
autogenerated_token: Optional[str] = None,
40+
**kwargs: Dict[str, Any],
4141
) -> BugoutUser:
4242
create_user_path = "user"
4343
data = {
4444
"username": username,
4545
"email": email,
4646
"password": password,
4747
}
48-
headers = None
49-
if autogenerated_token is not None:
50-
headers = {
51-
"x-bugout-installation-token": autogenerated_token,
52-
}
48+
headers = {}
49+
if "headers" in kwargs.keys():
50+
headers.update(kwargs["headers"])
5351
result = self._call(
5452
method=Method.post, path=create_user_path, headers=headers, data=data
5553
)
@@ -79,14 +77,14 @@ def find_user(
7977
self,
8078
username: str,
8179
token: Union[str, uuid.UUID] = None,
82-
installation_token: str = None,
80+
**kwargs: Dict[str, Any],
8381
) -> BugoutUser:
8482
find_user_path = f"user/find?username={username}"
8583
headers = {}
8684
if token is not None:
8785
headers.update({"Authorization": f"Bearer {token}"})
88-
if installation_token is not None:
89-
headers.update({"x-bugout-installation-token": installation_token})
86+
if "headers" in kwargs.keys():
87+
headers.update(kwargs["headers"])
9088
result = self._call(method=Method.get, path=find_user_path, headers=headers)
9189
return BugoutUser(**result)
9290

requirements.dev.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

requirements.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

setup.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313
with open("README.md") as ifp:
1414
long_description = ifp.read()
1515

16-
17-
def load_requirements(fname: str) -> list:
18-
requirements = []
19-
with open(fname, "r") as fp:
20-
for req in parse_requirements(fp.read()):
21-
extras = "[{}]".format(",".join(req.extras)) if req.extras else ""
22-
requirements.append("{}{}{}".format(req.name, extras, req.specifier))
23-
return requirements
24-
25-
2616
setup(
2717
name=MODULE_NAME,
2818
version=module.__version__,
@@ -49,7 +39,7 @@ def load_requirements(fname: str) -> list:
4939
packages=find_packages(),
5040
package_data={"bugout": ["py.typed"]},
5141
zip_safe=False,
52-
install_requires=load_requirements("requirements.txt"),
53-
extras_require={"dev": load_requirements("requirements.dev.txt")},
42+
install_requires=["pydantic", "requests"],
43+
extras_require={"dev": ["black", "mypy"]},
5444
entry_points={"console_scripts": ["{0} = {0}.__main__:main".format(MODULE_NAME)]},
5545
)

0 commit comments

Comments
 (0)