Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From Pipenv to Poetry #1391

Merged
merged 59 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
38e64a4
Add more tomls
SharonHart May 15, 2024
fa35d2f
fix cli versioning
SharonHart May 15, 2024
a58a22b
Drop pipfile
SharonHart May 15, 2024
f990f0a
Drop pipfile
SharonHart May 15, 2024
608972a
Drop pipfile
SharonHart May 15, 2024
882914c
keep pipfile
SharonHart May 15, 2024
f9485c2
keep pipfile
SharonHart May 15, 2024
724cd79
without pipfile
SharonHart May 15, 2024
1276644
typo
SharonHart May 15, 2024
997a9cc
typo
SharonHart May 15, 2024
854490a
typo
SharonHart May 15, 2024
1898eae
typo
SharonHart May 15, 2024
ccfabd1
typo
SharonHart May 15, 2024
60386e4
typo
SharonHart May 15, 2024
138ad28
typo
SharonHart May 15, 2024
54d73a0
typo
SharonHart May 19, 2024
6782447
readmes
SharonHart May 19, 2024
46fa320
drop requires
SharonHart May 19, 2024
1de8117
add requires
SharonHart May 19, 2024
182aa73
w/o readme
SharonHart May 19, 2024
75d75a8
w/o readme
SharonHart May 19, 2024
9787fa3
w/o readme
SharonHart May 19, 2024
39763df
pdm run
SharonHart May 19, 2024
b0a910a
migrate to pdm
SharonHart May 19, 2024
2a9b87e
migrate to pdm
SharonHart May 19, 2024
f0bd249
readme rename
SharonHart May 19, 2024
46e5c62
Fix versioning and docker building
SharonHart May 19, 2024
5c84ac8
Fix versioning and docker building
SharonHart May 19, 2024
a9ea5ac
Fix versioning and docker building
SharonHart May 19, 2024
bc32e74
change build be
SharonHart May 19, 2024
19aed49
change build be
SharonHart May 19, 2024
37a9668
PDM_VENV_WITH_PIP
SharonHart May 19, 2024
ef74488
source-includes
SharonHart May 19, 2024
087d1d4
source-includes
SharonHart May 19, 2024
902364f
source-includes
SharonHart May 19, 2024
7f7b880
compose logs
SharonHart May 20, 2024
7c2700c
compose logs
SharonHart May 20, 2024
83e6c0c
skip hanging
SharonHart May 20, 2024
161270f
skip hanging
SharonHart May 20, 2024
cae9bb6
skip hanging
SharonHart May 20, 2024
eb36956
skip hanging
SharonHart May 20, 2024
78702ad
readd test
SharonHart May 20, 2024
1edf958
fix test
SharonHart May 20, 2024
4eaf471
remove test
SharonHart May 20, 2024
65e32c9
remove test
SharonHart May 20, 2024
acdf983
docs and dockerfiles
SharonHart May 20, 2024
b9580be
Try with poetry
SharonHart May 30, 2024
0cd1095
Try with poetry
SharonHart May 30, 2024
acb3417
Try with poetry
SharonHart May 30, 2024
70465c7
Try with poetry
SharonHart May 30, 2024
5b75c11
drop numpy
SharonHart May 30, 2024
770bb3e
version
SharonHart May 30, 2024
6f35eb3
no-root
SharonHart May 30, 2024
8575d81
fix version extraction
SharonHart Jun 2, 2024
d0ec176
docs and dockerfiles
SharonHart Jun 2, 2024
b34b29f
Merge branch 'main' into shhart/feature/drop-pipfile-poetry
SharonHart Jun 2, 2024
3723009
revert test
SharonHart Jun 2, 2024
a8fa16d
comment hanging test
SharonHart Jun 2, 2024
fba78b5
try clause
SharonHart Jun 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
# Package dependency changes should be approved by a member of 'presidio-administrators' team
*/Pipfile* @microsoft/presidio-administrators

# Version change should be approved by a member of 'presidio-administrators' team
VERSION @microsoft/presidio-administrators
VERSION-IMAGE-REDACTOR @microsoft/presidio-administrators

# Package dependencies and version changes should be approved by a member of 'presidio-administrators' team
**/pyproject.toml @microsoft/presidio-administrators
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ENV/
env.bak/
venv.bak/
*venv/
*Pipfile.lock
poetry.lock

# Spyder project settings
.spyderproject
Expand Down
11 changes: 5 additions & 6 deletions .pipelines/templates/build-analyzer.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
steps:
- task: Bash@3
displayName: 'Setup pipenv'
displayName: 'Setup poetry'
inputs:
targetType: 'inline'
script: |
set -eux # fail on error
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv --python 3
python -m pip install poetry

- task: Bash@3
displayName: 'Install deps'
Expand All @@ -16,9 +15,9 @@ steps:
workingDirectory: 'presidio-analyzer'
script: |
set -eux # fail on error
pipenv install --deploy --dev
pipenv run python -m spacy download en_core_web_lg
pipenv run python -m spacy download en_core_web_sm
poetry install --all-extras
poetry run python -m spacy download en_core_web_lg
poetry run python -m spacy download en_core_web_sm

- template: ./build-python.yml
parameters:
Expand Down
7 changes: 3 additions & 4 deletions .pipelines/templates/build-anonymizer.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
steps:
- task: Bash@3
displayName: 'Setup pipenv'
displayName: 'Setup poetry'
inputs:
targetType: 'inline'
script: |
set -eux # fail on error
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv --python 3
python -m pip install poetry

- task: Bash@3
displayName: 'Install deps: Anonymizer'
Expand All @@ -16,7 +15,7 @@ steps:
workingDirectory: 'presidio-anonymizer'
script: |
set -eux # fail on error
pipenv install --deploy --dev
poetry install

- template: ./build-python.yml
parameters:
Expand Down
10 changes: 5 additions & 5 deletions .pipelines/templates/build-cli.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
steps:
- task: Bash@3
displayName: 'Setup pipenv'
displayName: 'Setup poetry'
inputs:
targetType: 'inline'
script: |
set -eux # fail on error
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv --python 3
python -m pip install poetry

- task: Bash@3
displayName: 'Install deps'
inputs:
targetType: 'inline'
workingDirectory: 'presidio-cli'
script: |
set -eux # fail on error
pipenv install --deploy --dev
pipenv run python -m spacy download en_core_web_lg
poetry install
poetry run python -m spacy download en_core_web_lg
- template: ./build-python.yml
parameters:
SERVICE: 'Cli'
Expand Down
12 changes: 6 additions & 6 deletions .pipelines/templates/build-image-redactor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ steps:
sudo apt show tesseract-ocr
sudo tesseract -v
- task: Bash@3
displayName: 'Setup pipenv'
displayName: 'Setup poetry'
inputs:
targetType: 'inline'
script: |
set -eux # fail on error
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv --python 3
python -m pip install poetry

- task: Bash@3
displayName: 'Install deps'
inputs:
targetType: 'inline'
workingDirectory: 'presidio-image-redactor'
script: |
set -eux # fail on error
pipenv install --deploy --dev
pipenv run python -m spacy download en_core_web_lg
pipenv run pip install -e ../presidio-analyzer/.
poetry install
poetry run python -m spacy download en_core_web_lg
poetry run pip install -e ../presidio-analyzer/.
- template: ./build-python.yml
parameters:
SERVICE: 'Image-Redactor'
Expand Down
4 changes: 2 additions & 2 deletions .pipelines/templates/build-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ steps:
script: |
set -eux # fail on error
# Install pytest and run tests
pipenv run pip install pytest pytest-azurepipelines
pipenv run pytest -vv
poetry run pip install pytest pytest-azurepipelines
poetry run pytest -vv

- task: Bash@3
displayName: 'Package Wheel: ${{ parameters.SERVICE }}'
Expand Down
11 changes: 5 additions & 6 deletions .pipelines/templates/build-structured.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
steps:
- task: Bash@3
displayName: 'Setup pipenv'
displayName: 'Setup poetry'
inputs:
targetType: 'inline'
script: |
set -eux # fail on error
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv --python 3
python -m pip install poetry

- task: Bash@3
displayName: 'Install deps'
Expand All @@ -16,9 +15,9 @@ steps:
workingDirectory: 'presidio-structured'
script: |
set -eux # fail on error
pipenv install --deploy --dev
pipenv run pip install -e ../presidio-analyzer/. # Use the existing analyzer and not the one in PyPI
pipenv run pip install -e ../presidio-anonymizer/. # Use the existing analyzer and not the one in PyPI
poetry install
poetry run pip install -e ../presidio-analyzer/. # Use the existing analyzer and not the one in PyPI
poetry run pip install -e ../presidio-anonymizer/. # Use the existing analyzer and not the one in PyPI

- template: ./build-python.yml
parameters:
Expand Down
7 changes: 7 additions & 0 deletions .pipelines/templates/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ steps:
ANONYMIZER_BASE_URL: ${{ parameters.anonymizer_base_url }}
TEST_SUITE: ${{ parameters.test_suite }}
displayName: Run tests
- task: DockerCompose@0
displayName: Docker Logs
inputs:
dockerComposeCommand: logs
dockerComposeFile: docker-compose.yml
buildImages: false
condition: always()
4 changes: 2 additions & 2 deletions .pipelines/templates/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ stages:
steps:
- bash: |
set -eu # exit on error
ver=$(cat VERSION)
ver=$(grep -m 1 version presidio-analyzer/pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
echo $ver
echo "##vso[task.setvariable variable=version;isOutput=true]$ver"
displayName: Set Version
Expand All @@ -25,7 +25,7 @@ stages:
steps:
- bash: |
set -eu # exit on error
imageVer=$(cat VERSION-IMAGE-REDACTOR)
imageVer=$(grep -m 1 version presidio-image-redactor/pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
echo $imageVer
echo "##vso[task.setvariable variable=imageVersion;isOutput=true]$imageVer"
displayName: Set Image Version
Expand Down
52 changes: 0 additions & 52 deletions .pipelines/templates/validate-version.yml

This file was deleted.

1 change: 0 additions & 1 deletion VERSION

This file was deleted.

1 change: 0 additions & 1 deletion VERSION-IMAGE-REDACTOR

This file was deleted.

1 change: 0 additions & 1 deletion VERSION-PRESIDIO-STRUCTURED

This file was deleted.

56 changes: 21 additions & 35 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,52 @@ The project is structured so that:
- In the project root directory, you will find common code for using, serving and testing Presidio
as a cluster of services, as well as CI/CD pipelines codebase and documentation.

### Setting up Pipenv
### Setting up Poetry

[Pipenv](https://pipenv.pypa.io/en/latest/) is a Python workflow manager, handling
dependencies and environment for Python packages. It is used by each Presidio service
as the dependencies manager, to be aligned with the specific requirements versions.
Follow these steps when starting to work on a Presidio service with Pipenv:
[Poetry](https://python-poetry.org/) is Python package manager. It is used to manage dependencies and virtual
environments for Presidio services.
Follow these steps when starting to work on a Presidio service with poetry:

1. Install Pipenv
1. Install poetry

- Using Pip

```sh
pip install --user pipenv
pip install poetry
```

- Using Homebrew (in MacOS)

```
brew install pipenv
brew install poetry
```

Additional installation instructions for Pipenv: <https://pipenv.readthedocs.io/en/latest/install/#installing-pipenv>
Additional installation instructions for poetry: <https://python-poetry.org/docs/#installation>

2. Have Pipenv create a virtualenv for the project and install all requirements in the Pipfile,
2. Have poetry create a virtualenv for the project and install all requirements in the pyproject.toml,
including dev requirements.

For example, in the `presidio-analyzer` folder, run:

```
pipenv install --dev --skip-lock
poetry install --all-extras
```

3. Run all tests:

```
pipenv run pytest
poetry run pytest
```

4. To run arbitrary scripts within the virtual env, start the command with
`pipenv run`. For example:
1. `pipenv run ruff check`
2. `pipenv run pip freeze`
3. `pipenv run python -m spacy download en_core_web_lg`
`poetry run`. For example:
1. `poetry run ruff check`
2. `poetry run pip freeze`
3. `poetry run python -m spacy download en_core_web_lg`

Command 3 downloads the default spacy model needed for Presidio Analyzer.`

#### Alternatively, activate the virtual environment and use the commands by starting a pipenv shell

1. Start shell:

```
pipenv shell
```

2. Run commands in the shell

```
pytest
pip freeze
```
#### Alternatively, activate the virtual environment and use the commands using [this method](https://python-poetry.org/docs/basic-usage/#activating-the-virtual-environment).

### Development guidelines

Expand Down Expand Up @@ -107,9 +93,9 @@ use docker-compose ps:
```bash
>docker-compose ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d5a258d19c2 presidio-anonymizer "/bin/sh -c 'pipenv …" 6 minutes ago Up 6 minutes 0.0.0.0:5001->5001/tcp presidio_presidio-anonymizer_1
9aad2b68f93c presidio-analyzer "/bin/sh -c 'pipenv …" 2 days ago Up 6 minutes 0.0.0.0:5002->5001/tcp presidio_presidio-analyzer_1
1448dfb3ec2b presidio-image-redactor "/bin/sh -c 'pipenv …" 2 seconds ago Up 2 seconds 0.0.0.0:5003->5001/tcp presidio_presidio-image-redactor_1
6d5a258d19c2 presidio-anonymizer "/bin/sh -c 'poetry …" 6 minutes ago Up 6 minutes 0.0.0.0:5001->5001/tcp presidio_presidio-anonymizer_1
9aad2b68f93c presidio-analyzer "/bin/sh -c 'poetry …" 2 days ago Up 6 minutes 0.0.0.0:5002->5001/tcp presidio_presidio-analyzer_1
1448dfb3ec2b presidio-image-redactor "/bin/sh -c 'poetry …" 2 seconds ago Up 2 seconds 0.0.0.0:5003->5001/tcp presidio_presidio-image-redactor_1
```

Edit docker-compose.yml configuration file to change the default ports.
Expand Down Expand Up @@ -152,7 +138,7 @@ Running the tests locally can be done in two ways:
1. Using cli, from each service directory, run:

```sh
pipenv run pytest
poetry run pytest
```

2. Using your IDE.
Expand Down Expand Up @@ -235,7 +221,7 @@ run.bat

Presidio services are PEP8 compliant and continuously enforced on style guide issues during the build process using `ruff`, in turn running `flake8` and other linters.

Running ruff locally, using `pipenv run ruff check`, you can check for those issues prior to committing a change.
Running ruff locally, using `poetry run ruff check`, you can check for those issues prior to committing a change.

Ruff runs linters in addition to the basic `flake8` functionality, Presidio uses linters as part as ruff such as:

Expand Down
Loading
Loading