Skip to content

Commit 0c0bf08

Browse files
authored
Improvements and Docker (#38)
* feat: avoid redirects * feat: add direct Docker support * docs: update readme
1 parent d8844a5 commit 0c0bf08

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Dockerfile
2+
dist
3+
data
4+
_gen

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ __pycache__
3333
pyvenv.cfg
3434
.venv
3535
pip-selfcheck.json
36+
37+
/data
38+
/_gen

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3-alpine
2+
3+
RUN pip install poetry
4+
5+
ADD . /ditto
6+
7+
WORKDIR /ditto
8+
9+
RUN poetry install
10+
CMD poetry run ditto clone --dest-dir ./data && \
11+
poetry run ditto clone --src-url http://localhost/ --dest-dir ./data --select pokemon/129 && \
12+
poetry run ditto analyze --data-dir ./data && \
13+
poetry run ditto transform \
14+
--base-url='https://pokeapi.co' \
15+
--src-dir=./data \
16+
--dest-dir=./_gen

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ This repository contains:
1414
pip install pokeapi-ditto
1515
ditto --help
1616
```
17+
18+
## Docker
19+
20+
You should have a Pokeapi server running on `localhost:80`.
21+
22+
```sh
23+
docker-compose up --build
24+
```

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "2.3"
2+
3+
services:
4+
ditto:
5+
build: .
6+
volumes:
7+
- ./data:/ditto/data
8+
- ./_gen:/ditto/_gen
9+
network_mode: "host"

pokeapi_ditto/commands/clone.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def _do_in_parallel(worker: Callable, data: List, desc: str) -> None:
14-
cpus = os.cpu_count()
14+
cpus = os.cpu_count() - 1
1515
pool = Pool(cpus, initializer=lambda: signal(SIGINT, SIG_IGN))
1616
try:
1717
for _ in tqdm(pool.imap_unordered(worker, data), total=len(data), desc=f"{desc} ({cpus}x)"):
@@ -65,10 +65,10 @@ def _crawl_resource_list(self, url: URL) -> List[URL]:
6565

6666
def clone_single(self, endpoint_and_id: Tuple[str, str]) -> None:
6767
endpoint, id = endpoint_and_id
68-
res_url = self._src_url / "api/v2" / endpoint / id
68+
res_url = URL("{}/api/v2/{}/{}/".format(self._src_url, endpoint, id))
6969
self._crawl(res_url)
7070
if endpoint == "pokemon":
71-
self._crawl(res_url / "encounters")
71+
self._crawl(URL("{}encounters/".format(res_url)))
7272

7373
def clone_endpoint(self, endpoint: str):
7474
res_list_url = self._src_url / "api/v2" / endpoint

0 commit comments

Comments
 (0)