Skip to content

Commit 10319b2

Browse files
committed
Merge branch 'master' of https://github.com/UnitedIncome/serverless-python-requirements into fix-single-function-deployment
2 parents 6b728f8 + abd6153 commit 10319b2

File tree

20 files changed

+1730
-1286
lines changed

20 files changed

+1730
-1286
lines changed

.circleci/config.yml

-47
This file was deleted.

.github/workflows/lint.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
os: [ubuntu-latest]
12+
node-version: [12]
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Set up Node ${{ matrix.node-version }}
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
21+
- name: Install deps
22+
run: npm install
23+
24+
- name: Lint
25+
run: npm run ci:lint

.github/workflows/publish.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Publish
2+
3+
on: [release]
4+
5+
jobs:
6+
publish-npm:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
- uses: actions/setup-node@v1
11+
with:
12+
version: 12
13+
registry-url: https://registry.npmjs.org/
14+
- run: npm publish
15+
env:
16+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.github/workflows/test.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Test
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
os: [ubuntu-latest, windows-latest, macOS-latest]
12+
python-version: [3.6, 2.7]
13+
node-version: [12]
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v1
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
22+
- name: Set up Node ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
27+
- name: Check python version
28+
run: |
29+
python --version
30+
31+
- name: Install setuptools
32+
run: python -m pip install --force setuptools wheel
33+
34+
- name: Install pipenv / poetry
35+
run: python -m pip install pipenv poetry
36+
37+
- name: Install serverless
38+
run: npm install -g serverless
39+
40+
- name: Install deps
41+
run: npm install
42+
43+
- name: Test
44+
run: npm run test
45+
env:
46+
LC_ALL: C.UTF-8
47+
LANG: C.UTF-8
48+
if: matrix.os != 'macOS-latest'
49+
50+
- name: Test (Mac)
51+
run: npm run test
52+
env:
53+
LC_ALL: en_US.UTF-8
54+
LANG: en_US.UTF-8
55+
if: matrix.os == 'macOS-latest'

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Serverless Python Requirements
22

33
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)
4-
[![CircleCI](https://circleci.com/gh/UnitedIncome/serverless-python-requirements.svg?style=shield)](https://circleci.com/gh/UnitedIncome/serverless-python-requirements)
4+
![Github Actions](https://github.com/UnitedIncome/serverless-python-requirements/workflows/Test/badge.svg)
55
[![npm](https://img.shields.io/npm/v/serverless-python-requirements.svg)](https://www.npmjs.com/package/serverless-python-requirements)
66
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
77

lib/docker.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function findTestFile(servicePath) {
7373
* @return {boolean}
7474
*/
7575
function tryBindPath(serverless, bindPath, testFile) {
76+
const debug = process.env.SLS_DEBUG;
7677
const options = [
7778
'run',
7879
'--rm',
@@ -83,13 +84,12 @@ function tryBindPath(serverless, bindPath, testFile) {
8384
`/test/${testFile}`
8485
];
8586
try {
87+
if (debug) serverless.cli.log(`Trying bindPath ${bindPath} (${options})`);
8688
const ps = dockerCommand(options);
87-
if (process.env.SLS_DEBUG) {
88-
serverless.cli.log(`Trying bindPath ${bindPath} (${options})`);
89-
serverless.cli.log(ps.stdout.trim());
90-
}
89+
if (debug) serverless.cli.log(ps.stdout.trim());
9190
return ps.stdout.trim() === `/test/${testFile}`;
9291
} catch (err) {
92+
if (debug) serverless.cli.log(`Finding bindPath failed with ${err}`);
9393
return false;
9494
}
9595
}

lib/pip.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { spawnSync } = require('child_process');
77
const { quote } = require('shell-quote');
88
const { buildImage, getBindPath, getDockerUid } = require('./docker');
99
const { getStripCommand, getStripMode, deleteFiles } = require('./slim');
10+
const { isPoetryProject } = require('./poetry');
1011
const {
1112
checkForAndDeleteMaxCacheVersions,
1213
sha256Path,
@@ -62,7 +63,8 @@ function generateRequirementsFile(
6263
) {
6364
if (
6465
options.usePoetry &&
65-
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
66+
fse.existsSync(path.join(servicePath, 'pyproject.toml')) &&
67+
isPoetryProject(servicePath)
6668
) {
6769
filterRequirementsFile(
6870
path.join(servicePath, '.serverless/requirements.txt'),
@@ -442,7 +444,8 @@ function copyVendors(vendorFolder, targetFolder, serverless) {
442444
function requirementsFileExists(servicePath, options, fileName) {
443445
if (
444446
options.usePoetry &&
445-
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
447+
fse.existsSync(path.join(servicePath, 'pyproject.toml')) &&
448+
isPoetryProject(servicePath)
446449
) {
447450
return true;
448451
}

lib/poetry.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function pyprojectTomlToRequirements() {
5050

5151
if (requirementsContents.match(editableFlag)) {
5252
this.serverless.cli.log(
53-
'The generated file contains -e lines, removing them...'
53+
'The generated file contains -e flags, removing them...'
5454
);
5555
fse.writeFileSync(
5656
sourceRequirements,
@@ -61,7 +61,8 @@ function pyprojectTomlToRequirements() {
6161
fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
6262
fse.moveSync(
6363
sourceRequirements,
64-
path.join(this.servicePath, '.serverless', 'requirements.txt')
64+
path.join(this.servicePath, '.serverless', 'requirements.txt'),
65+
{ overwrite: true }
6566
);
6667
}
6768

@@ -90,4 +91,4 @@ function isPoetryProject(servicePath) {
9091
return false;
9192
}
9293

93-
module.exports = { pyprojectTomlToRequirements };
94+
module.exports = { pyprojectTomlToRequirements, isPoetryProject };

package.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@
4545
},
4646
"devDependencies": {
4747
"eslint": "^5.16.0",
48-
"prettier": "*",
48+
"prettier": "^1",
4949
"cross-spawn": "*",
50-
"deasync-promise": "*",
51-
"tape": "*"
50+
"tape": "*",
51+
"tape-promise": "*",
52+
"lodash": "^4.16.15"
5253
},
5354
"dependencies": {
5455
"@iarna/toml": "^2.2.3",
@@ -69,8 +70,15 @@
6970
"eslintConfig": {
7071
"extends": "eslint:recommended",
7172
"env": {
73+
"commonjs": true,
7274
"node": true,
7375
"es6": true
76+
},
77+
"parserOptions": {
78+
"ecmaVersion": 2018
79+
},
80+
"rules": {
81+
"no-console": "off"
7482
}
7583
},
7684
"prettier": {

0 commit comments

Comments
 (0)