πŸ› Resolve Windows Docker Bug & 🐍 Upgrade to Python 3.9 (#181)

* Remove unnecessary variables

This variable definition syntax doesn't work on Windows, but those are the defaults anyway, so they aren't necessary

* Clearer documentation of different way of running

* Expose 8081 as 8181 to avoid conflicts on Windows 11

* Update GitHub workflows to Python 3.9

* Upgrade to python 39 and upgrade black

* Upgrade uvicorn

* Revert "Upgrade uvicorn"

This reverts commit 0e70b60be0.

* Pin electionguard to 1.2.3 per Keith

* Revert "Upgrade to python 39 and upgrade black"

This reverts commit c19db4d45b.

* poetry update

* Upgrade python and black (again)

* `poetry add --dev black@21.7b0` PR feedback from Keith

* Downgrade electionguard to 1.2.2 per Steve

* PR Feedback

* Fixed linting errors

* more linting fix
This commit is contained in:
Lee Richardson 2021-12-08 14:58:22 -05:00 ΠΊΠΎΠΌΠΌΠΈΡ‚ ΠΏΡ€ΠΎΠΈΠ·Π²Ρ‘Π» GitHub
Π ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒ 6525173b94
ΠšΠΎΠΌΠΌΠΈΡ‚ 9702fd687d
НС Π½Π°ΠΉΠ΄Π΅Π½ ΠΊΠ»ΡŽΡ‡, ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΉ Π΄Π°Π½Π½ΠΎΠΉ подписи
Π˜Π΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ ΠΊΠ»ΡŽΡ‡Π° GPG: 4AEE18F83AFDEB23
9 ΠΈΠ·ΠΌΠ΅Π½Ρ‘Π½Π½Ρ‹Ρ… Ρ„Π°ΠΉΠ»ΠΎΠ²: 505 Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠΉ ΠΈ 320 ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠΉ

2
.github/workflows/pull_request.yml поставляСмый
ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -8,7 +8,7 @@ on:
types: [pull_request]
env:
PYTHON_VERSION: 3.8
PYTHON_VERSION: 3.9
jobs:
code_analysis:

4
.github/workflows/release.yml поставляСмый
ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -7,7 +7,7 @@ on:
types: [milestone_closed]
env:
PYTHON_VERSION: 3.8
PYTHON_VERSION: 3.9
jobs:
code_analysis:
@ -51,8 +51,6 @@ jobs:
run: make environment
- name: Run Integration Tests
run: make test-integration
# - name: Run Postman Tests
# run: make docker-postman-test
release:
name: Release

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -114,10 +114,10 @@ docker-build:
DOCKER_BUILDKIT=1 docker build -t $(IMAGE_NAME) .
docker-run:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose up --build
docker-compose up --build
docker-dev:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f docker-compose.support.yml -f docker-compose.dev.yml up --build
docker-compose -f docker-compose.support.yml -f docker-compose.dev.yml up --build
docker-postman-test:
@echo πŸ§ͺ RUNNING POSTMAN TESTS IN DOCKER

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -26,8 +26,18 @@ In practice, you will likely need to run at least one instance of each mode. We
- 🐳🐍 [GNU Make](https://www.gnu.org/software/make/manual/make.html) is used to simplify the commands and GitHub Actions. This approach is recommended to simplify the command line experience. This is built in for MacOS and Linux. For Windows, setup is simpler with [Chocolatey](https://chocolatey.org/install) and installing the provided [make package](https://chocolatey.org/packages/make). The other Windows option is [manually installing make](http://gnuwin32.sourceforge.net/packages/make.htm).
- 🐍 [Python 3.8](https://www.python.org/downloads/) is <ins>**required**</ins> to develop this API. If developer uses multiple versions of python, [pyenv](https://github.com/pyenv/pyenv) is suggested to assist version management.
## Running
This codebase can be run one of three different ways:
- Running With Docker
- Developing with Docker
- Developing with Python
## 🐳 Running with Docker
Running with docker runs an official image, it is not for development.
### The official Docker image
We host a Docker image on both [Github Packages](https://github.com/microsoft/electionguard-web-api/packages/397920) and [DockerHub](https://hub.docker.com/r/electionguard/electionguard-web-api).
@ -52,9 +62,9 @@ docker pull electionguard/electionguard-web-api:latest
docker run -d -p 80:8000 --env API_MODE=mediator electionguard/electionguard-web-api:latest
```
### Developing locally with Docker
## 🐳 Developing locally with Docker
If you run Docker and want to run the code locally without Python dependencies, we provide a [Dockerfile](Dockerfile) and [docker-compose.yml](docker-compose.yml).
Developing with Docker is the fastest way to get started, as no dependencies such as Python need to be installed locally. Using this approach uses a [Dockerfile](Dockerfile) and [docker-compose.yml](docker-compose.yml).
Run both APIs at the same time:
@ -70,7 +80,9 @@ make docker-dev
After either command, you will find the `mediator` API running at http://127.0.0.1:8000 and the `guardian` API at http://127.0.0.1:8001
## 🐍 Running with Python
## 🐍 Developing with Python
Developing with Python provides the fastest developer inner loop (speed from code changes to seeing effects of changes), but is more work to set up initially.
### Quick Start
@ -102,7 +114,7 @@ If the code fails to run, [make sure your Python interpreter is set](https://cod
## πŸ§ͺ Testing
End-to-end integration tests can be found in the [`/tests/integration`](/tests/integration) folder. To see them in action, run:
End-to-end integration tests can be found in the [`/tests/integration`](/tests/integration) folder. To see them in action, run:
```bash
make test-integration

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -279,7 +279,7 @@ async def _decrypt_tally(
api_plaintext_tally.state = PlaintextTallyState.COMPLETE
update_plaintext_tally(api_plaintext_tally, settings)
except HTTPException as error:
except HTTPException:
api_plaintext_tally.state = PlaintextTallyState.ERROR
update_plaintext_tally(api_plaintext_tally, settings)
print(sys.exc_info())

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -109,7 +109,9 @@ class LocalRepository(IRepository):
for filename in search_files:
try:
with open(os.path.join(self._storage, filename)) as file, mmap.mmap(
with open(
os.path.join(self._storage, filename), encoding="utf-8"
) as file, mmap.mmap(
file.fileno(), 0, access=mmap.ACCESS_READ
) as search:
if search.find(bytes(query_string, "utf-8")) != -1:
@ -127,7 +129,9 @@ class LocalRepository(IRepository):
raise Exception("Not Implemented")
json_string = json.dumps(dict(value))
filename = hash_elems(json_string).to_hex()
with open(f"{os.path.join(self._storage, filename)}.json", "w") as file:
with open(
f"{os.path.join(self._storage, filename)}.json", "w", encoding="utf-8"
) as file:
file.write(json_string)
return filename

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -31,7 +31,7 @@ services:
image: mongo-express
restart: always
ports:
- 8081:8081
- 8181:8081
environment:
ME_CONFIG_MONGODB_SERVER: electionguard-db
ME_CONFIG_MONGODB_ADMINUSERNAME: root

773
poetry.lock сгСнСрированный

Π Π°Π·Π½ΠΈΡ†Π° ΠΌΠ΅ΠΆΠ΄Ρƒ Ρ„Π°ΠΉΠ»Π°ΠΌΠΈ Π½Π΅ ΠΏΠΎΠΊΠ°Π·Π°Π½Π° ΠΈΠ·-Π·Π° своСго большого Ρ€Π°Π·ΠΌΠ΅Ρ€Π° Π—Π°Π³Ρ€ΡƒΠ·ΠΈΡ‚ΡŒ Ρ€Π°Π·Π½ΠΈΡ†Ρƒ

ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ Ρ„Π°ΠΉΠ»

@ -10,12 +10,12 @@ repository = "https://github.com/microsoft/electionguard-api-python"
documentation = "https://electionguard-api-python.readthedocs.io/"
[tool.poetry.dependencies]
python = "~=3.8"
python = "~=3.9.5"
fastapi = "~0.65"
uvicorn = "~0.11"
pika = "1.2.0"
pymongo = "~3.11.4"
electionguard = "^1.2.2"
electionguard = "1.2.2"
python-jose = "^3.3.0"
passlib = "^1.7.4"
bcrypt = "^3.2.0"
@ -23,7 +23,7 @@ python-multipart = "^0.0.5"
[tool.poetry.dev-dependencies]
black = { version = "20.8b1", allow-prereleases = true }
black = "21.7b0"
mkdocs = "^1"
mypy = "^0.782"
pylint = "^2"
@ -31,7 +31,7 @@ pytest = "^6"
requests = "^2.24.0"
[tool.black]
target-version = ['py38']
target-version = ['py39']
include = '\.pyi?$'
[tool.pylint.'FORMAT']
@ -64,7 +64,7 @@ requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
[mypy]
python_version = 3.8
python_version = 3.9
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true