Skip to content

Commit 5e3c3a5

Browse files
wj-Mcatsijunhe
andauthored
[New features] complete auto-deploy (#4175)
* complete auto-deploy * update manual deploy for paddlenlp * fix typo * Update paddlenlp/version.py Co-authored-by: Sijun He <[email protected]> * update auto-deploy Co-authored-by: Sijun He <[email protected]>
1 parent 9ef9a8d commit 5e3c3a5

File tree

7 files changed

+108
-129
lines changed

7 files changed

+108
-129
lines changed

.flake8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[flake8]
22
ignore = E203, E501, E741, W503, W605
33
max-line-length = 119
4+
5+
# E402: module level import not at top of file
46
per-file-ignores =
5-
__init__.py:F401,F403
7+
__init__.py:F401,F403,E402

.github/workflows/pypi.yml

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,20 @@
11
name: PyPI
22

3-
on: [push, pull_request]
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
package:
7+
description: 'Package to be deployed'
8+
required: true
9+
default: 'paddlenlp'
10+
type: choice
11+
options:
12+
- paddlenlp
13+
- paddle-pipelines
14+
- ppdiffusers
415

516
jobs:
6-
build:
7-
name: Build
8-
runs-on: ubuntu-20.04
9-
steps:
10-
- uses: actions/checkout@v2
11-
- uses: actions/setup-python@v1
12-
with:
13-
python-version: 3.8
14-
- name: Install dependencies
15-
run: |
16-
python -m pip install --upgrade pip
17-
make install
18-
19-
ppdiffusers:
20-
name: Pack
21-
needs: build
22-
runs-on: ubuntu-20.04
23-
steps:
24-
- uses: actions/checkout@v2
25-
- uses: actions/setup-python@v1
26-
with:
27-
python-version: 3.8
28-
- name: Install dependencies
29-
run: |
30-
python -m pip install --upgrade pip
31-
pip install setuptools wheel twine
32-
make install-ppdiffusers
33-
34-
- name: Should Deploy to Pypi Server
35-
id: should-deploy
36-
run: python scripts/should_deploy.py --name ppdiffusers >> $GITHUB_OUTPUT
37-
- name: Check Branch
38-
id: check-branch
39-
run: |
40-
if [[ ${{ github.ref }} =~ ^refs/heads/(develop)$ ]]; then
41-
echo "match=true" >> $GITHUB_OUTPUT
42-
fi # See: https://stackoverflow.com/a/58869470/1123955
43-
44-
- name: Is A Publish Branch
45-
if: steps.check-branch.outputs.match == 'true' && steps.should-deploy.outputs.should_deploy == 'true'
46-
env:
47-
TWINE_USERNAME: paddle-dev
48-
TWINE_PASSWORD: ${{ secrets.paddlenlp }}
49-
run: |
50-
make deploy-ppdiffusers
51-
52-
- name: Should Not Deploy To Pypi Server
53-
if: steps.should-deploy.outputs.should_deploy != 'true'
54-
run: echo 'should not deploy pypi server'
55-
56-
- name: Is Not A Publish Branch
57-
if: steps.check-branch.outputs.match != 'true'
58-
run: echo 'Not A Publish Branch'
59-
60-
paddle_pipelines:
17+
Deployment:
6118
name: Pack
6219
needs: build
6320
runs-on: ubuntu-20.04
@@ -70,11 +27,12 @@ jobs:
7027
run: |
7128
python -m pip install --upgrade pip
7229
pip install setuptools wheel twine
73-
make install-paddle-pipelines
30+
- name: Deploy Package
31+
id: deploy-package
32+
env:
33+
PACKAGE: ${{ inputs.package }}
34+
run: python scripts/should_deploy.py --name $PACKAGE >> $GITHUB_OUTPUT
7435

75-
- name: Should Deploy to Pypi Server
76-
id: should-deploy
77-
run: python scripts/should_deploy.py --name paddle-pipelines >> $GITHUB_OUTPUT
7836
- name: Check Branch
7937
id: check-branch
8038
run: |
@@ -87,8 +45,9 @@ jobs:
8745
env:
8846
TWINE_USERNAME: paddle-dev
8947
TWINE_PASSWORD: ${{ secrets.paddlenlp }}
48+
PACKAGE: ${{ inputs.package }}
9049
run: |
91-
make deploy-paddle-pipelines
50+
make deploy-$PACKAGE
9251
9352
- name: Should Not Deploy To Pypi Server
9453
if: steps.should-deploy.outputs.should_deploy != 'true'

Makefile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@ install:
5050

5151
.PHONY: deploy-ppdiffusers
5252
deploy-ppdiffusers:
53-
cd ppdiffusers && make
54-
55-
.PHONY: install-ppdiffusers
56-
install-ppdiffusers:
57-
cd ppdiffusers && make install
53+
cd ppdiffusers && make install && make
5854

5955
.PHONY: deploy-paddle-pipelines
6056
deploy-paddle-pipelines:
61-
cd pipelines && make
62-
63-
.PHONY: install-paddle-pipelines
64-
install-paddle-pipelines:
65-
cd pipelines && make install
66-
57+
cd pipelines && make install && make
58+
59+
.PHONY: deploy-paddlenlp
60+
deploy-paddlenlp:
61+
# install related package
62+
make install
63+
# deploy version
64+
echo "VERSION = '$$(cat VERSION)'" > paddlenlp/version.py
65+
# build
66+
python3 setup.py sdist bdist_wheel
67+
# upload
68+
twine upload --skip-existing dist/*

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.2.3
1+
2.4.5

paddlenlp/__init__.py

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "2.4.0.dev" # Maybe dev is better
15+
from .version import VERSION
16+
17+
__version__ = VERSION # Maybe dev is better
1618
import sys
1719

1820
if "datasets" in sys.modules.keys():
@@ -23,47 +25,50 @@
2325
"This may cause PaddleNLP datasets to be unavalible in intranet. "
2426
"Please import paddlenlp before datasets module to avoid download issues"
2527
)
26-
from . import data
27-
from . import datasets
28-
from . import embeddings
29-
from . import ops
30-
from . import layers
31-
from . import metrics
32-
from . import seq2vec
33-
from . import transformers
34-
from . import utils
35-
from . import losses
36-
from . import experimental
37-
from .taskflow import Taskflow
38-
from .server import SimpleServer
39-
from . import trainer
40-
from . import prompt
41-
from . import dataaug
4228
import paddle
4329

30+
from . import (
31+
data,
32+
dataaug,
33+
datasets,
34+
embeddings,
35+
experimental,
36+
layers,
37+
losses,
38+
metrics,
39+
ops,
40+
prompt,
41+
seq2vec,
42+
trainer,
43+
transformers,
44+
utils,
45+
)
46+
from .server import SimpleServer
47+
from .taskflow import Taskflow
48+
4449
paddle.disable_signal_handler()
4550

51+
import sys
52+
import warnings
53+
54+
# BatchSampler use `_non_static_mode` which is not included in version <= 2.3,
55+
# thus use `in_dynamic_mode` instead.
56+
from paddle import in_dynamic_mode
57+
4658
# Patches for DataLoader/BatchSamper to allow using other than paddle.io.Dataset
4759
# in Paddle version lower than 2.3
4860
from paddle.fluid.reader import (
49-
_current_expected_place,
50-
_get_paddle_place_list,
51-
_get_paddle_place,
52-
_convert_places,
61+
BatchSampler,
5362
IterableDataset,
63+
_convert_places,
64+
_current_expected_place,
5465
_DatasetKind,
66+
_get_paddle_place,
67+
_get_paddle_place_list,
5568
_InfiniteIterableSampler,
56-
BatchSampler,
5769
use_pinned_memory,
5870
)
5971

60-
# BatchSampler use `_non_static_mode` which is not included in version <= 2.3,
61-
# thus use `in_dynamic_mode` instead.
62-
from paddle import in_dynamic_mode
63-
64-
import warnings
65-
import sys
66-
6772

6873
def _patch_data_loader_init(
6974
self,
@@ -157,7 +162,11 @@ def _patch_data_loader_init(
157162
self._iterator = None
158163

159164

160-
from paddle.fluid.dataloader.batch_sampler import Sampler, RandomSampler, SequenceSampler
165+
from paddle.fluid.dataloader.batch_sampler import (
166+
RandomSampler,
167+
Sampler,
168+
SequenceSampler,
169+
)
161170

162171

163172
def _patch_batch_sampler_init(self, dataset=None, sampler=None, shuffle=False, batch_size=1, drop_last=False):

paddlenlp/version.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This file is generated automatically by Github Actions
16+
# DO NOT MODIFY MANUALLY
17+
VERSION = "0.0.0"

scripts/should_deploy.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import subprocess
1919
import sys
2020

21+
from packaging import version
22+
2123
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2224

2325

@@ -57,35 +59,23 @@ def read_version_of_local_package(version_file_path: str) -> str:
5759
return version
5860

5961

60-
def should_ppdiffusers_deploy():
61-
"""print the result to terminal"""
62-
local_version_file = os.path.join(PROJECT_ROOT, "ppdiffusers/VERSION")
63-
remote_version = read_version_of_remote_package("ppdiffusers")
64-
local_version = read_version_of_local_package(local_version_file)
65-
66-
should_deploy = str(remote_version != local_version).lower()
67-
print(f"should_deploy={should_deploy}")
68-
69-
70-
def should_paddle_pipelines_deploy():
71-
"""print the result to terminal"""
72-
local_version_file = os.path.join(PROJECT_ROOT, "pipelines/VERSION")
73-
remote_version = read_version_of_remote_package("pipelines")
74-
local_version = read_version_of_local_package(local_version_file)
75-
76-
should_deploy = str(remote_version != local_version).lower()
77-
print(f"should_deploy={should_deploy}")
78-
79-
8062
if __name__ == "__main__":
8163
parser = argparse.ArgumentParser()
8264
parser.add_argument("--name", required=True)
8365

8466
args = parser.parse_args()
8567

86-
if args.name == "ppdiffusers":
87-
should_ppdiffusers_deploy()
88-
elif args.name == "paddle-pipelines":
89-
should_paddle_pipelines_deploy()
90-
else:
68+
version_file_map = {
69+
"paddlenlp": "VERSION",
70+
"ppdiffusers": "ppdiffusers/VERSION",
71+
"paddle-pipelines": "pipelines/VERSION",
72+
}
73+
if args.name not in version_file_map:
9174
raise ValueError(f"package<{args.name}> not supported")
75+
76+
local_version_file = os.path.join(PROJECT_ROOT, version_file_map[args.name])
77+
remote_version = read_version_of_remote_package(args.name)
78+
local_version = read_version_of_local_package(local_version_file)
79+
80+
should_deploy = str(version.parse(remote_version) < version.parse(local_version)).lower()
81+
print(f"should_deploy={should_deploy}")

0 commit comments

Comments
 (0)