Π·Π΅ΡΠΊΠ°Π»ΠΎ ΠΈΠ· https://github.com/microsoft/electionguard-api-python.git
π 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 commit0e70b60be0
. * Pin electionguard to 1.2.3 per Keith * Revert "Upgrade to python 39 and upgrade black" This reverts commitc19db4d45b
. * 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:
Π ΠΎΠ΄ΠΈΡΠ΅Π»Ρ
6525173b94
ΠΠΎΠΌΠΌΠΈΡ
9702fd687d
|
@ -8,7 +8,7 @@ on:
|
|||
types: [pull_request]
|
||||
|
||||
env:
|
||||
PYTHON_VERSION: 3.8
|
||||
PYTHON_VERSION: 3.9
|
||||
|
||||
jobs:
|
||||
code_analysis:
|
||||
|
|
|
@ -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
|
||||
|
|
4
Makefile
4
Makefile
|
@ -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
|
||||
|
|
20
README.md
20
README.md
|
@ -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
|
||||
|
|
Π Π°Π·Π½ΠΈΡΠ° ΠΌΠ΅ΠΆΠ΄Ρ ΡΠ°ΠΉΠ»Π°ΠΌΠΈ Π½Π΅ ΠΏΠΎΠΊΠ°Π·Π°Π½Π° ΠΈΠ·-Π·Π° ΡΠ²ΠΎΠ΅Π³ΠΎ Π±ΠΎΠ»ΡΡΠΎΠ³ΠΎ ΡΠ°Π·ΠΌΠ΅ΡΠ°
ΠΠ°Π³ΡΡΠ·ΠΈΡΡ ΡΠ°Π·Π½ΠΈΡΡ
|
@ -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
|
||||
|
|
ΠΠ°Π³ΡΡΠ·ΠΊΠ°β¦
Π‘ΡΡΠ»ΠΊΠ° Π² Π½ΠΎΠ²ΠΎΠΉ Π·Π°Π΄Π°ΡΠ΅