Skip to content

Commit 3ba2516

Browse files
slovdahlHanfei Shen
andauthored
Replace nix with poetry (#10)
* Remove nix * Introduce poetry to lock dependencies * Update Poetry to 1.1.15 Co-authored-by: Hanfei Shen <[email protected]>
1 parent 9e9cc0c commit 3ba2516

22 files changed

+1458
-1081
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v2
1616
- uses: actions/setup-python@v2
17-
- uses: cachix/install-nix-action@v13
18-
with:
19-
nix_path: nixpkgs=channel:nixos-unstable
2017
- name: Dockerize
2118
run: make dockerize
2219
- name: Deploy to DockerHub

.github/workflows/test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ jobs:
2222
- '3.8'
2323
- '3.9'
2424
- '3.10'
25+
poetry-version:
26+
- '1.1.15'
2527
steps:
2628
- uses: actions/checkout@v3
2729
- uses: actions/setup-python@v4
2830
with:
2931
python-version: ${{ matrix.python-version }}
32+
- name: Install Poetry
33+
run: pip install poetry==${{ matrix.poetry-version }}
3034
- name: Install requirements
31-
run: pip install -r requirements_frozen.txt
35+
run: poetry install
3236
- name: Run tests
33-
run: pytest
37+
run: poetry run pytest

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ ENV/
44
*.egg-info
55
.coverage
66
.pytest_cache
7-
8-
# nix stuff
9-
result
10-
result-*
7+
/MANIFEST
8+
/build/
9+
/dist/
1110

1211
# Editor
1312
*.sw[po]

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM python:3.9-slim AS builder
2+
3+
ARG POETRY_VERSION=1.1.15
4+
RUN pip install poetry==$POETRY_VERSION
5+
6+
WORKDIR /src
7+
8+
COPY pyproject.toml poetry.lock README.md pylintrc ./
9+
COPY marge/ ./marge/
10+
RUN poetry export -o requirements.txt && \
11+
poetry build
12+
13+
14+
FROM python:3.9-slim
15+
16+
RUN apt-get update && apt-get install -y \
17+
git-core \
18+
&& \
19+
rm -rf /var/lib/apt/lists/*
20+
21+
COPY --from=builder /src/requirements.txt /src/dist/marge-*.tar.gz /tmp/
22+
23+
RUN pip install -r /tmp/requirements.txt && \
24+
pip install /tmp/marge-*.tar.gz
25+
26+
ENTRYPOINT ["marge"]

Makefile

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
VERSION?=$$(git rev-parse --abbrev-ref HEAD)
22

33
.PHONY: all
4-
all: requirements_frozen.txt requirements.nix requirements_override.nix marge-bot dockerize
4+
all: dockerize
55

6-
.PHONY: marge-bot
7-
marge-bot:
8-
nix-build --keep-failed --attr marge-bot default.nix
6+
.PHONY: bump
7+
bump: bump-requirements
98

10-
.PHONY: clean
11-
clean:
12-
rm -rf .cache result result-* requirements_frozen.txt
9+
poetry.lock:
10+
poetry install
1311

14-
.PHONY: bump
15-
bump: bump-requirements bump-sources
12+
requirements.txt: poetry.lock
13+
poetry export -o $@
1614

17-
.PHONY: bump-sources
18-
bump-sources:
19-
nix-shell --run niv update
15+
requirements_development.txt: poetry.lock
16+
poetry export --dev -o $@
2017

21-
.PHONY: bump-requirements
22-
bump-requirements: clean requirements_frozen.txt
18+
.PHONY: bump-poetry-lock
19+
bump-poetry-lock:
20+
poetry update
2321

24-
requirements_frozen.txt requirements.nix requirements_override.nix: requirements.txt
25-
pypi2nix -V 3.6 -r $^
22+
.PHONY: clean-requirements
23+
clean-requirements:
24+
rm -rf requirements.txt requirements_development.txt
25+
26+
.PHONY: bump-requirements
27+
bump-requirements: bump-poetry-lock clean-requirements requirements.txt requirements_development.txt
2628

2729
.PHONY: dockerize
2830
dockerize:
29-
docker load --input $$(nix-build --attr docker-image default.nix)
31+
docker build --tag hiboxsystems/marge-bot:$$(cat version) .
3032

3133
.PHONY: docker-push
3234
docker-push:

README.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ optional arguments:
142142
[env var: MARGE_USE_MERGE_COMMIT_BATCHES] (default: False)
143143
--skip-ci-batches Skip CI when updating individual MRs when using batches [env var: MARGE_SKIP_CI_BATCHES] (default: False)
144144
```
145+
145146
Here is a config file example
147+
146148
```yaml
147149
add-part-of: true
148150
add-reviewers: true
@@ -164,8 +166,8 @@ ssh-key-file: token.FILE
164166
# OR use HTTPS instead of SSH
165167
#use-https: true
166168
```
167-
For more information about configuring marge-bot see `--help`
168169
170+
For more information about configuring marge-bot see `--help`
169171
170172
## Running
171173
@@ -280,6 +282,7 @@ docker run --restart=on-failure \ # restart if marge crashes because GitLab is f
280282
HTTPS can be used using any other deployment technique as well.
281283
282284
### Running marge-bot in kubernetes
285+
283286
It's also possible to run marge in kubernetes, e.g. here's how you use a ktmpl
284287
template:
285288
@@ -298,6 +301,7 @@ Once running, the bot will continuously monitor all projects that have its user
298301
will pick up any changes in membership at runtime.
299302
300303
### Running marge-bot in Swarm
304+
301305
Or you can run marge in Docker Swarm, e.g. here's how you use a compose file:
302306
303307
```yaml
@@ -364,46 +368,39 @@ run:
364368
365369
### Running marge-bot as a plain python app
366370
367-
#### Installing marge-bot with nix
368-
369-
Alternatively, if you prefer not to use docker, you can also directly run marge.
370-
If you use [nix](https://nixos.org/nix/) do `nix-env --install -f default.nix`.
371-
372-
The nix install should be fully reproducible on any version of linux (and also
373-
work on OS X, although this is not something we properly test). If you don't
374-
want to use docker we recommend you give nix a try.
375-
376-
#### Installing marge-bot the old-fashioned way
377-
378-
Finally, although this is our least preferred alternative, you can always do
379-
`python3 setup.py install` (note that you will need python3.6).
371+
Install all dependencies with `poetry install` (note that you will need Python 3.6+).
380372
381373
Afterwards, the minimal way to run marge is as follows.
382374
383375
```bash
384-
marge.app --auth-token-file marge-bot.token \
385-
--gitlab-url 'http://your.gitlab.instance.com' \
386-
--ssh-key-file marge-bot-ssh-key
376+
poetry run marge --auth-token-file marge-bot.token \
377+
--gitlab-url 'http://your.gitlab.instance.com' \
378+
--ssh-key-file marge-bot-ssh-key
387379
```
388380
389381
However, we suggest you use a systemd unit file or some other mechanism to
390382
automatically restart marge-bot in case of intermittent GitLab problems.
391383
392-
### Setting up a development environment
384+
## Setting up a development environment
393385
394-
Install `nix` by following https://nix.dev/tutorials/install-nix:
386+
1. Install `poetry` with `pip install poetry`.
387+
2. Check out this repository.
388+
3. Run `poetry install` in the repository root.
389+
390+
### Running linting and tests
395391
396392
```shell
397-
$ sh <(curl -L https://nixos.org/nix/install) --daemon
393+
poetry run pytest
398394
```
399395
400-
After that, a Docker image can be built with:
396+
### Run marge-bot
401397
402398
```shell
403-
$ make dockerize
399+
poetry run marge
404400
```
405401
406402
## Suggested workflow
403+
407404
1. Alice creates a new merge request and assigns Bob and Charlie as reviewers
408405
409406
2. Both review the code and after all issues they raise are resolved by Alice,
@@ -416,7 +413,6 @@ $ make dockerize
416413
the merge request via the GitLab API. It can also add some headers to all
417414
commits in the merge request as described in the next section.
418415
419-
420416
## Adding Reviewed-by:, Tested: and Part-of: to commit messages
421417
422418
Marge-bot supports automated addition of the following
@@ -456,6 +452,7 @@ commits introduced by a single Merge Request when using a fast-forward/rebase
456452
based merge workflow.
457453
458454
## Impersonating approvers
455+
459456
If you want a full audit trail, you will configure GitLab
460457
[require approvals](https://docs.gitlab.com/ee/user/project/merge_requests/merge_request_approvals.html#approvals-required)
461458
for PRs and also turn on
@@ -478,7 +475,6 @@ More than one embargo period can be specified, separated by commas. Any merge
478475
request assigned to her during an embargo period, will be merged in only once all
479476
embargoes are over.
480477
481-
482478
## Batching Merge Requests
483479
484480
The flag `--batch` enables testing and merging merge requests in batches. This can
@@ -600,7 +596,6 @@ This reverts commit 0af5b70a98858c9509c895da2a673ebdb31e20b1.
600596
601597
E.g. `git revert-mr 123`.
602598
603-
604599
## Troubleshooting
605600
606601
Marge-bot continuously logs what she is doing, so this is a good place to look

default.nix

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

dockerize.nix

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

marge.app

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

marge.nix

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

marge/__main__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from marge.app import main
2+
3+
4+
def run():
5+
try:
6+
main()
7+
except Exception as err:
8+
print('Exception occured')
9+
if hasattr(err, 'stdout'):
10+
# pylint: disable=no-member
11+
print(f'stdout was: {err.stdout}')
12+
if hasattr(err, 'stderr'):
13+
# pylint: disable=no-member
14+
print(f'stderr was: {err.stderr}')
15+
raise
16+
17+
18+
if __name__ == '__main__':
19+
run()

nix/sources.json

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

0 commit comments

Comments
 (0)