Skip to content

Commit

Permalink
Switch to pipenv/Pipfile
Browse files Browse the repository at this point in the history
  • Loading branch information
audiodude committed Nov 11, 2023
1 parent 952e46f commit 81edbe0
Show file tree
Hide file tree
Showing 7 changed files with 923 additions and 25 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python 3.9.4
38 changes: 38 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
fakeredis = "==2.4.0"
flask = "==2.3.2"
flask-session2 = "==1.3.1"
flask-cors = "*"
flask-gzip = "*"
gunicorn = "*"
kiwixstorage = "==0.8"
mwclient = "==0.9.3"
mwoauth = "==0.3.8"
mwparserfromhell = "==0.5.2"
oauthlib = "==2.1.0"
pyjwt = "==2.4.0"
pymysql = "==0.9.3"
pyparsing = "==3.0.9"
pytz = "==2022.7.1"
pyyaml = "==6.0.1"
redis = "==4.4.4"
requests = "==2.31.0"
rdflib = "~=6.0"
rq = "==1.13.0"
rq-scheduler = "==0.13.0"
validators = "*"
attrs = "==18.2.0"

[dev-packages]
pre-commit = "==2.21.0"
pytest = "~=6.0"
yapf = "==0.28.0"
yoyo-migrations = "==7.3.2"

[requires]
python_version = "3.9.4"
851 changes: 851 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,30 @@ interfaces with. They are used for unit testing.

This code is targeted to and tested on Python 3.9.4.

### Creating your virtualenv
### Installing dependencies

As of Python 3.3, creating a virtualenv is a single easy command. It is
recommmended that you run this command in the top level directory:
WP1 uses [Pipenv](https://pipenv.pypa.io/en/latest/) to managed dependencies.
A `Pipfile` and `Pipfile.lock` are provided. You should have the pipenv tool
installed in your global Python install (not in a virtualenv):

```bash
python3 -m venv venv
pip3 install pipenv
```

### Activating your virtualenv

To activate your virtualenv, run:
Then you can use:

```bash
source venv/bin/activate
pipenv install --dev
```

You should see your prompt change, with a `(venv)` appended to the front.

### Installing requirements

To install the requirements, make sure you are in your virtualenv as
explained above, then use the following command:

```bash
pip3 install -r requirements.txt
```
Which will install the dependencies at the precise versions specified in the
`Pipfile.lock` file. Behind the scenes, Pipenv creates a virtualenv for you
automatically, which it keeps up to date when you run Pipenv commands. You
can use the `pipenv shell` command to start a shell using the environment,
which is similar to "activating" a virtualenv. You can also use `pipenv run`
to run arbitrary individual shell commands within that environment. In many
cases, it will be more convenient to use commands like `pipenv run pytest`
then actually spawning a subshell.

### Installing frontend requirements

Expand Down Expand Up @@ -146,7 +143,7 @@ in `docker-compose-test.yml` you can copy these directly from the example
file. However, you are free to provide your own test database that will
be destroyed after every test run. See the section "Running the tests".

### Running the backend (Python/nose) tests
### Running the backend (Python/pytest) tests

The backend/python tests require a MariaDB or MySQL instance to connect to in
order to verify various statements and logic. This database does not need to be
Expand All @@ -161,7 +158,7 @@ you should be able to simply run the following command from this
directory to run the tests:

```bash
nosetests
pipenv run pytest
```

### Running the frontend (Cypress) integration tests
Expand All @@ -178,6 +175,8 @@ cd wp1-frontend
$(yarn bin)/cypress run
```

Then follow the GUI prompts to run "Electron E2E tests".

# Development

For development, you will need to have Docker installed as explained above.
Expand Down
7 changes: 5 additions & 2 deletions docker/dev-workers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ LABEL maintainer="kiwix"
# Python app
WORKDIR /usr/src
RUN mkdir app
COPY requirements.txt app/requirements.txt
RUN pip3 install --no-cache-dir -r app/requirements.txt
RUN pip3 install --upgrade pip && pip3 install --no-cache-dir pipenv

Check warning on line 9 in docker/dev-workers/Dockerfile

View check run for this annotation

codefactor.io / CodeFactor

docker/dev-workers/Dockerfile#L9

Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>` (DL3042)
COPY ./Pipfile app/Pipfile
COPY ./Pipfile.lock app/Pipfile.lock
WORKDIR /usr/src/app
RUN pipenv install --system --deploy --ignore-pipfile
COPY . app

# Start
Expand Down
5 changes: 4 additions & 1 deletion docker/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ LABEL maintainer="kiwix"
# Python app
WORKDIR /usr/src
COPY . app
RUN pip3 install --no-cache-dir -r app/requirements.txt

RUN pip3 install --upgrade pip && pip3 install --no-cache-dir pipenv

Check warning on line 10 in docker/web/Dockerfile

View check run for this annotation

codefactor.io / CodeFactor

docker/web/Dockerfile#L10

Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>` (DL3042)
WORKDIR /usr/src/app
RUN pipenv install --system --deploy --ignore-pipfile

# Start
COPY docker/web/start.sh /usr/local/bin/start.sh
Expand Down
7 changes: 5 additions & 2 deletions docker/workers/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12
FROM python:3.9

# Meta
LABEL maintainer="kiwix"
Expand All @@ -10,7 +10,10 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends cron && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install --no-cache-dir -r app/requirements.txt

RUN pip3 install --upgrade pip && pip3 install --no-cache-dir pipenv

Check warning on line 14 in docker/workers/Dockerfile

View check run for this annotation

codefactor.io / CodeFactor

docker/workers/Dockerfile#L14

Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>` (DL3042)
WORKDIR /usr/src/app
RUN pipenv install --system --deploy --ignore-pipfile

RUN chmod -R a+x /usr/src/app/cron/

Expand Down

0 comments on commit 81edbe0

Please sign in to comment.