Skip to content

Commit

Permalink
Migrated package manager from pipenv to poetry (#26)
Browse files Browse the repository at this point in the history
Migrated package manager from pipenv to poetry
  • Loading branch information
ysavary authored Jan 7, 2022
1 parent 926b5ec commit ebaefc7
Show file tree
Hide file tree
Showing 14 changed files with 1,228 additions and 909 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.git
dist
.pytest_cache
volumes
.env*
2 changes: 1 addition & 1 deletion .env.localhost.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# COMMONS
MONGODB_URL=mongodb://localhost:27017/winds_mobi
MONGODB_URL=mongodb://localhost:27017/winds
REDIS_URL=redis://localhost:6380/0
GOOGLE_API_KEY=

Expand Down
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# COMMONS
MONGODB_URL=mongodb://mongodb:27017/winds_mobi
MONGODB_URL=mongodb://mongodb:27017/winds
REDIS_URL=redis://host.docker.internal:6380/0
GOOGLE_API_KEY=

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install python dependencies with pipenv
- name: Install python dependencies with poetry
run: |
pip install pipenv
pipenv install --deploy --dev
pip install poetry
poetry install
- name: Check python code format
run: pipenv run black --check .
run: poetry run black --check .

- name: Run python linter
run: pipenv run flake8 .
run: poetry run flake8 .

- name: Run python tests
run: pipenv run pytest
run: poetry run pytest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.pyc
dist/
.pytest_cache
.idea/
/volumes/
.env
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ FROM base AS python

RUN apt update; \
apt --yes --no-install-recommends install build-essential libpq-dev libmariadb-dev
RUN pip install pipenv
RUN pip install poetry

COPY . .
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
RUN POETRY_VIRTUALENVS_IN_PROJECT=true poetry install --no-dev

FROM base AS runtime

Expand Down
41 changes: 0 additions & 41 deletions Pipfile

This file was deleted.

851 changes: 0 additions & 851 deletions Pipfile.lock

This file was deleted.

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Google Cloud API results are cached with redis.

### Requirements

- python 3.9
- python 3.9 and poetry
- mongodb 4.4
- redis
- Google Cloud API key
Expand All @@ -25,6 +25,9 @@ See [settings.py](https://github.com/winds-mobi/winds-mobi-providers/blob/master

#### macOS 11

- `brew install openssl`
- `export LDFLAGS=-L/usr/local/opt/openssl/lib`

- `brew install mysql-client`
- `export PATH=/usr/local/opt/mysql-client/bin:$PATH`

Expand All @@ -36,8 +39,8 @@ See [settings.py](https://github.com/winds-mobi/winds-mobi-providers/blob/master

### Python environment

- `pipenv install`
- `pipenv shell`
- `poetry install`
- `poetry shell`

### Run the project with docker compose

Expand Down
3 changes: 2 additions & 1 deletion admin_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from winds_mobi_provider.logging import configure_logging

configure_logging()
log = logging.getLogger(__file__)
log = logging.getLogger(__name__)


def save_clusters(nb_clusters):
Expand Down Expand Up @@ -68,6 +68,7 @@ def save_clusters(nb_clusters):
mongo_bulk.find({"_id": ids[index]}).update({"$addToSet": {"clusters": int(n_clusters)}})

mongo_bulk.execute()
log.info(f"Done, created {nb_clusters} clusters")
except Exception as e:
log.exception(f"Error while creating clusters: {e}")

Expand Down
5 changes: 4 additions & 1 deletion admin_stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from winds_mobi_provider.logging import configure_logging

configure_logging()
log = logging.getLogger(__file__)
log = logging.getLogger(__name__)


def delete_stations(days: int, provider: Optional[str]):
Expand All @@ -20,13 +20,16 @@ def delete_stations(days: int, provider: Optional[str]):
query = {"seen": {"$lt": now - days * 3600 * 24}}
if provider:
query["pv-code"] = provider
nb = 0
for station in mongo_db.stations.find(query):
seen = arrow.Arrow.fromtimestamp(station["seen"])
log.info(
f"Deleting {station['_id']} ['{station['short']}'], last seen at {seen.format('YYYY-MM-DD HH:mm:ssZZ')}"
)
mongo_db[station["_id"]].drop()
mongo_db.stations.remove({"_id": station["_id"]})
nb += 1
log.info(f"Done, deleted {nb} stations")


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit ebaefc7

Please sign in to comment.