Skip to content

Commit

Permalink
Upgrade string literals to raw string (#28989)
Browse files Browse the repository at this point in the history
* upgrade comment string to raw string

* fix string in

* fix string with ' '

* revert update on comments

* upgrade only necessary

* fix sample code checker

* fix comments with '''
  • Loading branch information
zhiqiu authored Nov 24, 2020
1 parent 767d0ba commit 3815d7a
Show file tree
Hide file tree
Showing 109 changed files with 586 additions and 449 deletions.
21 changes: 18 additions & 3 deletions paddle/scripts/conda_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/python

# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
import platform
from sys import argv
Expand Down Expand Up @@ -120,7 +135,7 @@ def __init__(self):
self.py_str = ["py27", "py35", "py36", "py37"]
self.pip_end = ".whl --no-deps"
self.pip_prefix_linux = "pip install /package/paddlepaddle"
self.pip_prefix_windows = "pip install C:\package\paddlepaddle"
self.pip_prefix_windows = r"pip install C:\package\paddlepaddle"
self.pip_gpu = "_gpu-"
self.pip_cpu = "-"
self.mac_pip = [
Expand Down Expand Up @@ -216,15 +231,15 @@ def meta_build_windows(var,
- matplotlib"""
if not (cuda_str == None):
meta_str = meta_str + cuda_str

blt_str = var.blt_const + blt_var
if (python_str == var.python27):
blt_str = blt_str + """
pip install C:\package\opencv_python-4.2.0.32-cp27-cp27m-win_amd64.whl"""
else:
meta_str = meta_str + """
- opencv>=3.4.2"""

meta_str = meta_str + var.test + var.about
meta_filename = "meta.yaml"
build_filename = "bld.bat"
Expand Down
10 changes: 5 additions & 5 deletions python/paddle/dataset/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def train(word_idx):
:rtype: callable
"""
return reader_creator(
re.compile("aclImdb/train/pos/.*\.txt$"),
re.compile("aclImdb/train/neg/.*\.txt$"), word_idx)
re.compile(r"aclImdb/train/pos/.*\.txt$"),
re.compile(r"aclImdb/train/neg/.*\.txt$"), word_idx)


@deprecated(
Expand All @@ -137,8 +137,8 @@ def test(word_idx):
:rtype: callable
"""
return reader_creator(
re.compile("aclImdb/test/pos/.*\.txt$"),
re.compile("aclImdb/test/neg/.*\.txt$"), word_idx)
re.compile(r"aclImdb/test/pos/.*\.txt$"),
re.compile(r"aclImdb/test/neg/.*\.txt$"), word_idx)


@deprecated(
Expand All @@ -153,7 +153,7 @@ def word_dict():
:rtype: dict
"""
return build_dict(
re.compile("aclImdb/((train)|(test))/((pos)|(neg))/.*\.txt$"), 150)
re.compile(r"aclImdb/((train)|(test))/((pos)|(neg))/.*\.txt$"), 150)


@deprecated(
Expand Down
12 changes: 6 additions & 6 deletions python/paddle/dataset/tests/imdb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import unittest
import re

TRAIN_POS_PATTERN = re.compile("aclImdb/train/pos/.*\.txt$")
TRAIN_NEG_PATTERN = re.compile("aclImdb/train/neg/.*\.txt$")
TRAIN_PATTERN = re.compile("aclImdb/train/.*\.txt$")
TRAIN_POS_PATTERN = re.compile(r"aclImdb/train/pos/.*\.txt$")
TRAIN_NEG_PATTERN = re.compile(r"aclImdb/train/neg/.*\.txt$")
TRAIN_PATTERN = re.compile(r"aclImdb/train/.*\.txt$")

TEST_POS_PATTERN = re.compile("aclImdb/test/pos/.*\.txt$")
TEST_NEG_PATTERN = re.compile("aclImdb/test/neg/.*\.txt$")
TEST_PATTERN = re.compile("aclImdb/test/.*\.txt$")
TEST_POS_PATTERN = re.compile(r"aclImdb/test/pos/.*\.txt$")
TEST_NEG_PATTERN = re.compile(r"aclImdb/test/neg/.*\.txt$")
TEST_PATTERN = re.compile(r"aclImdb/test/.*\.txt$")


class TestIMDB(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def dgc(self, flag):

@property
def dgc_configs(self):
"""
r"""
Set Deep Gradient Compression training configurations. In general, dgc has serveral configurable
settings that can be configured through a dict.
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/distributed/fleet/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
r"""
fleetrun is a module that spawns multiple distributed
process on each training node for gpu training and cpu training.
Usage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ def get_sys_free_mem():
['vm_stat'], stdout=subprocess.PIPE).communicate()[0]
# Process vm_stat
vmLines = vm.split('\n')
sep = re.compile(':[\s]+')
sep = re.compile(r':[\s]+')
vmStats = {}
for row in range(1, len(vmLines) - 2):
rowText = vmLines[row].strip()
rowElements = sep.split(rowText)
vmStats[(rowElements[0]
)] = int(rowElements[1].strip('\.')) * 4096
)] = int(rowElements[1].strip(r'\.')) * 4096
return vmStats["Pages free"]
elif platform.system() == "Linux":
mems = {}
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/distributed/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
r"""
paddle.distributed.launch is a module that spawns multiple distributed
process on each training node for gpu training.
Usage:
Expand Down
12 changes: 6 additions & 6 deletions python/paddle/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _check_values_dtype_in_probs(self, param, value):


class Uniform(Distribution):
"""Uniform distribution with `low` and `high` parameters.
r"""Uniform distribution with `low` and `high` parameters.
Mathematical Details
Expand Down Expand Up @@ -374,7 +374,7 @@ def probs(self, value):
return elementwise_div((lb * ub), (self.high - self.low), name=name)

def entropy(self):
"""Shannon entropy in nats.
r"""Shannon entropy in nats.
The entropy is
Expand All @@ -391,7 +391,7 @@ def entropy(self):


class Normal(Distribution):
"""The Normal distribution with location `loc` and `scale` parameters.
r"""The Normal distribution with location `loc` and `scale` parameters.
Mathematical details
Expand Down Expand Up @@ -534,7 +534,7 @@ def sample(self, shape, seed=0):
return output

def entropy(self):
"""Shannon entropy in nats.
r"""Shannon entropy in nats.
The entropy is
Expand Down Expand Up @@ -599,7 +599,7 @@ def probs(self, value):
name=name)

def kl_divergence(self, other):
"""The KL-divergence between two normal distributions.
r"""The KL-divergence between two normal distributions.
The probability density function (pdf) is
Expand Down Expand Up @@ -644,7 +644,7 @@ def kl_divergence(self, other):


class Categorical(Distribution):
"""
r"""
Categorical distribution is a discrete probability distribution that
describes the possible results of a random variable that can take on
one of K possible categories, with the probability of each category
Expand Down
6 changes: 3 additions & 3 deletions python/paddle/fluid/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _append_clip_op(self, block, grad_name):


class ErrorClipByValue(BaseErrorClipAttr):
"""
r"""
Clips tensor values to the range [min, max].
Given a tensor ``t`` (see Examples below), this operation clips its value \
Expand Down Expand Up @@ -241,7 +241,7 @@ def _create_operators(self, param, grad):


class ClipGradByNorm(ClipGradBase):
"""
r"""
Limit the l2 norm of multi-dimensional Tensor :math:`X` to ``clip_norm`` .
- If the l2 norm of :math:`X` is greater than ``clip_norm`` , :math:`X` will be compressed by a ratio.
Expand Down Expand Up @@ -343,7 +343,7 @@ def _create_operators(self, param, grad):


class ClipGradByGlobalNorm(ClipGradBase):
"""
r"""
Given a list of Tensor :math:`t\_list` , calculate the global norm for the elements of all tensors in
:math:`t\_list` , and limit it to ``clip_norm`` .
Expand Down
8 changes: 4 additions & 4 deletions python/paddle/fluid/contrib/layers/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def var_conv_2d(input,
act=None,
dtype='float32',
name=None):
"""
r"""
The var_conv_2d layer calculates the output base on the :attr:`input` with variable length,
row, col, input channel, filter size and strides. Both :attr:`input`, :attr:`row`,
and :attr:`col` are 1-level LodTensor. The convolution operation is same as conv2d layer with
Expand Down Expand Up @@ -477,7 +477,7 @@ def fused_embedding_seq_pool(input,
combiner='sum',
param_attr=None,
dtype='float32'):
"""
r"""
**Embedding Sequence pool**
This layer is the fusion of lookup table and sequence_pool.
Expand Down Expand Up @@ -1442,7 +1442,7 @@ def batch_fc(input, param_size, param_attr, bias_size, bias_attr, act=None):


def _pull_box_extended_sparse(input, size, extend_size=64, dtype='float32'):
"""
r"""
**Pull Box Extended Sparse Layer**
This layer is used to lookup embeddings of IDs, provided by :attr:`input`, in
BoxPS lookup table. The result of this lookup is the embedding of each ID in the
Expand Down Expand Up @@ -1640,7 +1640,7 @@ def fused_bn_add_act(x,
moving_variance_name=None,
act=None,
name=None):
"""
r"""
This Op performs batch norm on input x, and adds the result to input y. Then
it performs activation on the sum. The data format of inputs must be NHWC
`[batch, in_height, in_width, in_channels]`.
Expand Down
6 changes: 3 additions & 3 deletions python/paddle/fluid/contrib/layers/rnn_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def basic_gru(input,
activation=None,
dtype='float32',
name='basic_gru'):
"""
r"""
GRU implementation using basic operator, supports multiple layers and bidirectional gru.
.. math::
Expand Down Expand Up @@ -418,7 +418,7 @@ def basic_lstm(input,
forget_bias=1.0,
dtype='float32',
name='basic_lstm'):
"""
r"""
LSTM implementation using basic operators, supports multiple layers and bidirectional LSTM.
.. math::
Expand Down Expand Up @@ -697,7 +697,7 @@ def get_single_direction_output(rnn_input,


class BasicLSTMUnit(Layer):
"""
r"""
****
BasicLSTMUnit class, Using basic operator to build LSTM
The algorithm can be described as the code below.
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/contrib/memory_usage_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


def memory_usage(program, batch_size):
"""
r"""
Get the estimate memory usage of program with input batch size.
Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self,
act_preprocess_layer=None,
weight_quantize_layer=None,
act_quantize_layer=None):
"""
r"""
The constructor for ImperativeQuantAware.
Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


class FakeQuantMovingAverage(layers.Layer):
"""
r"""
FakeQuantMovingAverage layer does the moving_average_abs_max quant and then dequant.
Its computational formula is described as below:
Expand Down Expand Up @@ -128,7 +128,7 @@ def forward(self, input):


class FakeQuantAbsMax(layers.Layer):
"""
r"""
FakeQuantAbsMax layer does the abs_max quant and then dequant.
Its computational formula is described as below:
Expand Down Expand Up @@ -545,7 +545,7 @@ def forward(self, input):

class MovingAverageAbsMaxScale(layers.Layer):
def __init__(self, name=None, moving_rate=0.9, dtype='float32'):
"""
r"""
MovingAverageMaxScale layer is used to calculating the output quantization scale of Layer.
Its computational formula is described as below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class QuantInt8MkldnnPass(object):
"""

def __init__(self, _scope=None, _place=None):
"""
r"""
Args:
scope(fluid.Scope): scope is used to initialize the new parameters.
place(fluid.CPUPlace): place is used to initialize the new parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def __init__(self,
act_preprocess_func=None,
optimizer_func=None,
executor=None):
"""
r"""
Constructor.
Args:
Expand Down
6 changes: 3 additions & 3 deletions python/paddle/fluid/contrib/utils/hdfs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


class HDFSClient(object):
"""
r"""
A tool of HDFS
Args:
Expand Down Expand Up @@ -376,7 +376,7 @@ def ls(self, hdfs_path):
_logger.info("HDFS list path: {} successfully".format(hdfs_path))

ret_lines = []
regex = re.compile('\s+')
regex = re.compile(r'\s+')
out_lines = output.strip().split("\n")
for line in out_lines:
re_line = regex.split(line)
Expand Down Expand Up @@ -418,7 +418,7 @@ def sort_by_time(v1, v2):
_logger.info("HDFS list all files: {} successfully".format(
hdfs_path))
lines = []
regex = re.compile('\s+')
regex = re.compile(r'\s+')
out_lines = output.strip().split("\n")
for line in out_lines:
re_line = regex.split(line)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def less_than_ver(a, b):
import operator

def to_list(s):
s = re.sub('(\.0+)+$', '', s)
s = re.sub(r'(\.0+)+$', '', s)
return [int(x) for x in s.split('.')]

return operator.lt(to_list(a), to_list(b))
Expand Down
Loading

0 comments on commit 3815d7a

Please sign in to comment.