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

PEP631/621 Support + Python10 Support + DependABot update #828

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cb8db5f
Inital Work to add in changes for PEP631 complience
jax-b Feb 10, 2024
80a8029
Bumped node version as it was giving sls errors
jax-b Feb 10, 2024
daf4053
Merge branch 'jb-bump-minimum-version' into jb-pyproject-pep631
jax-b Feb 10, 2024
6f7dceb
Bumped Python to 310 to follow ubuntu lts
jax-b Feb 10, 2024
34b4c18
Merge branch 'master' into jb-pyproject-pep631
jax-b Feb 10, 2024
fff51fd
finished up migration to py310 and fixed failing test due to uninstal…
jax-b Feb 10, 2024
4ab6122
Updated python requrements
jax-b Feb 11, 2024
32e61b8
updateded bad hashes
jax-b Feb 11, 2024
b9f5f34
added tests fixed issues with extra self
jax-b Feb 11, 2024
37c5ff6
added fail param to ensure that opt is not included
jax-b Feb 11, 2024
dc12a86
updated variable name and added readme
jax-b Feb 11, 2024
f30ea1f
fixed flask pinned at old version
jax-b Feb 11, 2024
be34587
fixed version not comming in properly
jax-b Feb 24, 2024
9bc910d
fixed wrong tag for group, updated test case with issue i found
jax-b Feb 24, 2024
ce2cc61
fixed issue where a array was added to the array verses it being used…
jax-b Feb 25, 2024
ba19f19
ran prettier and pre-commit
jax-b Feb 25, 2024
8278d42
fixed issue with prettier caused by precommit not reading in the conf…
jax-b Feb 25, 2024
104db3e
seperated out github actions for better clarity
jax-b Feb 25, 2024
460622e
fixed scaleway provider version
jax-b Feb 25, 2024
995dc34
Added install as package configuration
jax-b Feb 25, 2024
5b4ec05
Add custom Python package installation instructions
jax-b Feb 25, 2024
85e8358
fixed issue where test was looking for the wrong package name
jax-b Feb 25, 2024
01a36e7
Merge branch 'install_self' into jb-pyproject-pep631
jax-b Feb 25, 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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.js text eol=lf
*.json text eol=lf
*.json text eol=lf
82 changes: 64 additions & 18 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,67 @@ env:
FORCE_COLOR: 1

jobs:
linuxNode18:
name: '[Linux] Node.js v18: Lint, Eventual Commitlint, Eventual Changelog, Formatting & Unit tests'
code_quality:
name: '[Linux] Node.js v18: Code Quality and formatting checks'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# For commitlint purpose ensure to have complete list of PR commits
# It's loose and imperfect assumption that PR has no more than 30 commits
fetch-depth: 30

- name: Retrieve last master commit (for `git diff` purposes)
run: |
git checkout -b pr
git fetch --prune --depth=30 origin +refs/heads/master:refs/remotes/origin/master
git checkout master
git checkout pr

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v18-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: |
npm-v18-${{ runner.os }}-${{ github.ref }}-
npm-v18-${{ runner.os }}-refs/heads/master-

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 18.x

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save

- name: Validate Prettier formatting
run: npm run prettier-check:updated

- name: Validate ESLint rules
run: npm run lint:updated

- name: Validate commit messages
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
run: npx commitlint -f master

- name: Validate changelog (if new version)
run: |
NEW_VERSION=`git diff -U0 master package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
if [ -n "$NEW_VERSION" ];
then
npx dump-release-notes-from-cc-changelog $NEW_VERSION
fi

unit_tests:
name: '[Linux] Node.js v18: Unit tests'
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -43,10 +102,10 @@ jobs:
npm-v18-${{ runner.os }}-${{ github.ref }}-
npm-v18-${{ runner.os }}-refs/heads/master-

- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: '3.10'

- name: Install Node.js and npm
uses: actions/setup-node@v1
Expand All @@ -71,19 +130,6 @@ jobs:
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Validate Prettier formatting
run: npm run prettier-check:updated
- name: Validate ESLint rules
run: npm run lint:updated
- name: Validate commit messages
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
run: npx commitlint -f master
- name: Validate changelog (if new version)
run: |
NEW_VERSION=`git diff -U0 master package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
if [ -n "$NEW_VERSION" ];
then
npx dump-release-notes-from-cc-changelog $NEW_VERSION
fi

- name: Unit tests
run: npm test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ admin.env
#PYTHON STUFF
*.py[co]
__pycache__
.venv

#NODE STUFF
package-lock.json
Expand All @@ -66,6 +67,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
tests/base/.requirements-cache

# Serverless directories
.serverless
Expand Down
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.56.0
hooks:
- id: eslint
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
types_or: [css, javascript, html, json, markdown, yaml]
args: [--semi, --single-quote, --trailing-comma, all]
verbose: true
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9
3.10
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Welcome, and thanks in advance for your help!

Pre-Reqs:

- Python 3.9
- [poetry](https://python-poetry.org/docs/) (if you use multiple versions of Python be sure to install it with python 3.9)
- Python 3.10
- [poetry](https://python-poetry.org/docs/) (if you use multiple versions of Python be sure to install it with python 3.10)
- Perl (used in the tests)
- Node v14 or v16

Expand Down
46 changes: 40 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,53 @@ Instead of:

```toml
[tool.poetry.dependencies]
bottle = {git = "[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
bottle = {git = "[email protected]/bottlepy/bottle.git", tag = "0.12.25"}
```

Use:

```toml
[tool.poetry.dependencies]
bottle = {git = "https://[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
bottle = {git = "https://[email protected]/bottlepy/bottle.git", tag = "0.12.25"}
```

Or, if you have an SSH key configured:

```toml
[tool.poetry.dependencies]
bottle = {git = "ssh://[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
bottle = {git = "ssh://[email protected]/bottlepy/bottle.git", tag = "0.12.25"}
```

## :sparkles::snake::sparkles: PyProject PEP631/621

If you include a `pyproject.toml` and have `dependencies` installed instead of a `requirements.txt` this will
generate a requirements file from it. It is fully compatible with all options such as `zip` and
`dockerizePip`. If you don't want this plugin to generate it for you, set the following option:

```yaml
custom:
pythonRequirements:
usePyProject: false
```

If your PyProject configuration includes custom dependency groups, they will not be installed automatically. To include them in the deployment package, use the `pyprojectWithGroups`.

```yaml
custom:
pythonRequirements:
pyprojectWithGroups:
- internal_dependencies
- lambda_dependencies
```

## :sparkles::snake::sparkles: Custom Python Package installation

If your function rely on your code being installed as a python package use `installFolderAsPackage`. Ensure your code is structured as a python package or otherwise it will not be installed correctly (`pip install .`)

```yaml
custom:
pythonRequirements:
installFolderAsPackage: true
```

## Dealing with Lambda's size limitations
Expand Down Expand Up @@ -285,7 +317,7 @@ custom:
name: ${self:provider.stage}-layerName
description: Python requirements lambda layer
compatibleRuntimes:
- python3.7
- python3.10
licenseInfo: GPLv3
allowedAccounts:
- '*'
Expand Down Expand Up @@ -515,7 +547,7 @@ For usage of `dockerizePip` on Windows do Step 1 only if running serverless on w
Some Python packages require extra OS dependencies to build successfully. To deal with this, replace the default image with a `Dockerfile` like:

```dockerfile
FROM public.ecr.aws/sam/build-python3.9
FROM public.ecr.aws/sam/build-python3.10

# Install your dependencies
RUN yum -y install mysql-devel
Expand Down Expand Up @@ -602,7 +634,7 @@ To handle native dependencies, it's recommended to use the Docker builder with t
custom:
pythonRequirements:
# Can use any Python version supported by Scaleway
dockerImage: rg.fr-par.scw.cloud/scwfunctionsruntimes-public/python-dep:3.11
dockerImage: rg.fr-par.scw.cloud/scwfunctionsruntimes-public/python-dep:3.10
```

## Contributors
Expand Down Expand Up @@ -635,6 +667,8 @@ custom:
- [@drice](https://github.com/drice)
- [@ofercaspi](https://github.com/ofercaspi)
- [@tpansino](https://github.com/tpansino)
- PyProject PEP631/621
- [@jax-b](https://github.com/jax-b)
- [@david-mk-lawrence](https://github.com/david-mk-lawrence) - added Lambda Layer support
- [@bryantbriggs](https://github.com/bryantbiggs) - Fixing CI/CD
- [@jacksgt](https://github.com/jacksgt) - Fixing pip issues
Expand Down
2 changes: 1 addition & 1 deletion example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ service: sls-py-req-test

provider:
name: aws
runtime: python3.9
runtime: python3.10

plugins:
- serverless-python-requirements
Expand Down
2 changes: 1 addition & 1 deletion example_native_deps/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy==1.13.3
scipy==1.0.0
sklearn==0.0
sklearn==0.0
2 changes: 1 addition & 1 deletion example_native_deps/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ service: sls-py-req-test

provider:
name: aws
runtime: python3.9
runtime: python3.10

plugins:
- serverless-python-requirements
Expand Down
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ class ServerlessPythonRequirements {
poetryWithGroups: [],
poetryWithoutGroups: [],
poetryOnlyGroups: [],
usePyProject: true,
pyprojectWithGroups: [],
installFolderAsPackage: false,
},
(this.serverless.service.custom &&
this.serverless.service.custom.pythonRequirements) ||
{}
{},
);
if (
options.pythonBin === this.serverless.service.provider.runtime &&
Expand Down Expand Up @@ -92,19 +95,19 @@ class ServerlessPythonRequirements {
if (!this.warningLogged) {
if (this.log) {
this.log.warning(
'You provided a docker related option but dockerizePip is set to false.'
'You provided a docker related option but dockerizePip is set to false.',
);
} else {
this.serverless.cli.log(
'WARNING: You provided a docker related option but dockerizePip is set to false.'
'WARNING: You provided a docker related option but dockerizePip is set to false.',
);
}
this.warningLogged = true;
}
}
if (options.dockerImage && options.dockerFile) {
throw new Error(
'Python Requirements: you can provide a dockerImage or a dockerFile option, not both.'
'Python Requirements: you can provide a dockerImage or a dockerFile option, not both.',
);
}

Expand Down Expand Up @@ -241,8 +244,8 @@ class ServerlessPythonRequirements {
.then(() =>
injectAllRequirements.bind(this)(
arguments[1].functionObj &&
arguments[1].functionObj.package.artifact
)
arguments[1].functionObj.package.artifact,
),
);
};

Expand Down
6 changes: 3 additions & 3 deletions lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup() {

return BbPromise.all(
artifacts.map((artifact) =>
fse.removeAsync(path.join(this.servicePath, artifact))
)
fse.removeAsync(path.join(this.servicePath, artifact)),
),
);
}

Expand Down Expand Up @@ -58,7 +58,7 @@ function cleanupCache() {
promises.push(fse.removeAsync(file));
});
return BbPromise.all(promises).finally(
() => cleanupProgress && cleanupProgress.remove()
() => cleanupProgress && cleanupProgress.remove(),
);
} else {
if (this.serverless) {
Expand Down
6 changes: 3 additions & 3 deletions lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function dockerCommand(options, pluginInstance) {
) {
throw new pluginInstance.serverless.classes.Error(
'docker not found! Please install it.',
'PYTHON_REQUIREMENTS_DOCKER_NOT_FOUND'
'PYTHON_REQUIREMENTS_DOCKER_NOT_FOUND',
);
}
throw e;
Expand All @@ -42,7 +42,7 @@ async function buildImage(dockerFile, extraArgs, pluginInstance) {
} else {
throw new pluginInstance.serverless.classes.Error(
'dockerRunCmdExtraArgs option must be an array',
'PYTHON_REQUIREMENTS_INVALID_DOCKER_EXTRA_ARGS'
'PYTHON_REQUIREMENTS_INVALID_DOCKER_EXTRA_ARGS',
);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ function findTestFile(servicePath, pluginInstance) {
}
throw new pluginInstance.serverless.classes.Error(
'Unable to find serverless.{yml|yaml|json} or requirements.txt for getBindPath()',
'PYTHON_REQUIREMENTS_MISSING_GET_BIND_PATH_FILE'
'PYTHON_REQUIREMENTS_MISSING_GET_BIND_PATH_FILE',
);
}

Expand Down
Loading
Loading