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

Use int-parameters for random.randrange() #3177

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion luigi/contrib/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def fs(self):
@contextmanager
def temporary_path(self):
tmp_dir = tempfile.mkdtemp()
num = random.randrange(0, 1e10)
num = random.randrange(0, 10_000_000_000)
temp_path = '{}{}luigi-tmp-{:010}{}'.format(
tmp_dir, os.sep,
num, ntpath.basename(self.path))
Expand Down
8 changes: 4 additions & 4 deletions luigi/contrib/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _sftp_put(self, local_path, path, atomic):
self.conn.makedirs(directory)

if atomic:
tmp_path = os.path.join(directory, 'luigi-tmp-{:09d}'.format(random.randrange(0, 1e10)))
tmp_path = os.path.join(directory, 'luigi-tmp-{:09d}'.format(random.randrange(0, 10_000_000_000)))
else:
tmp_path = normpath

Expand All @@ -279,7 +279,7 @@ def _ftp_put(self, local_path, path, atomic):

# random file name
if atomic:
tmp_path = folder + os.sep + 'luigi-tmp-%09d' % random.randrange(0, 1e10)
tmp_path = folder + os.sep + 'luigi-tmp-%09d' % random.randrange(0, 10_000_000_000)
else:
tmp_path = normpath

Expand All @@ -297,7 +297,7 @@ def get(self, path, local_path):
if folder and not os.path.exists(folder):
os.makedirs(folder)

tmp_local_path = local_path + '-luigi-tmp-%09d' % random.randrange(0, 1e10)
tmp_local_path = local_path + '-luigi-tmp-%09d' % random.randrange(0, 10_000_000_000)

# download file
self._connect()
Expand Down Expand Up @@ -409,7 +409,7 @@ def open(self, mode):

elif mode == 'r':
temppath = '{}-luigi-tmp-{:09d}'.format(
self.path.lstrip('/'), random.randrange(0, 1e10)
self.path.lstrip('/'), random.randrange(0, 10_000_000_000)
)
try:
# store reference to the TemporaryDirectory because it will be removed on GC
Expand Down
2 changes: 1 addition & 1 deletion luigi/contrib/hadoop_jar.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def fix_paths(job):
args.append(x.path)
else: # output
x_path_no_slash = x.path[:-1] if x.path[-1] == '/' else x.path
y = luigi.contrib.hdfs.HdfsTarget(x_path_no_slash + '-luigi-tmp-%09d' % random.randrange(0, 1e10))
y = luigi.contrib.hdfs.HdfsTarget(x_path_no_slash + '-luigi-tmp-%09d' % random.randrange(0, 10_000_000_000))
tmp_files.append((y, x_path_no_slash))
logger.info('Using temp path: %s for path %s', y.path, x.path)
args.append(y.path)
Expand Down
2 changes: 1 addition & 1 deletion luigi/contrib/hdfs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def tmppath(path=None, include_unix_username=True):
Note that include_unix_username might work on windows too.
"""
addon = "luigitemp-%08d" % random.randrange(1e9)
addon = "luigitemp-%09d" % random.randrange(0, 10_000_000_000)
temp_dir = '/tmp' # default tmp dir if none is specified in config

# 1. Figure out to which temporary directory to place
Expand Down
2 changes: 1 addition & 1 deletion luigi/contrib/hdfs/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def is_writable(self):
return False

def _is_writable(self, path):
test_path = path + '.test_write_access-%09d' % random.randrange(1e10)
test_path = path + '.test_write_access-%09d' % random.randrange(10_000_000_000)
try:
self.fs.touchz(test_path)
self.fs.remove(test_path, recursive=False)
Expand Down
6 changes: 3 additions & 3 deletions luigi/contrib/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def put(self, local_path, path):
if folder and not self.exists(folder):
self.remote_context.check_output(['mkdir', '-p', folder])

tmp_path = path + '-luigi-tmp-%09d' % random.randrange(0, 1e10)
tmp_path = path + '-luigi-tmp-%09d' % random.randrange(0, 10_000_000_000)
self._scp(local_path, "%s:%s" % (self.remote_context._host_ref(), tmp_path))
self.remote_context.check_output(['mv', tmp_path, path])

Expand All @@ -268,7 +268,7 @@ def get(self, path, local_path):
except OSError:
pass

tmp_local_path = local_path + '-luigi-tmp-%09d' % random.randrange(0, 1e10)
tmp_local_path = local_path + '-luigi-tmp-%09d' % random.randrange(0, 10_000_000_000)
self._scp("%s:%s" % (self.remote_context._host_ref(), path), tmp_local_path)
os.rename(tmp_local_path, local_path)

Expand All @@ -285,7 +285,7 @@ def __init__(self, fs, path):
if folder:
self.fs.mkdir(folder)

self.__tmp_path = self.path + '-luigi-tmp-%09d' % random.randrange(0, 1e10)
self.__tmp_path = self.path + '-luigi-tmp-%09d' % random.randrange(0, 10_000_000_000)
super(AtomicRemoteFileWriter, self).__init__(
self.fs.remote_context._prepare_cmd(['cat', '>', self.__tmp_path]))

Expand Down
2 changes: 1 addition & 1 deletion luigi/local_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def move_to_final_destination(self):
os.rename(self.tmp_path, self.path)

def generate_tmp_path(self, path):
return path + '-luigi-tmp-%09d' % random.randrange(0, 1e10)
return path + '-luigi-tmp-%09d' % random.randrange(0, 10_000_000_000)


class LocalFileSystem(FileSystem):
Expand Down
4 changes: 2 additions & 2 deletions luigi/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def run(self):
with self.output().temporary_path() as self.temp_output_path:
run_some_external_command(output_path=self.temp_output_path)
"""
num = random.randrange(0, 10000000000)
num = random.randrange(0, 10_000_000_000)
slashless_path = self.path.rstrip('/').rstrip("\\")
_temp_path = '{}-luigi-tmp-{:010}{}'.format(
slashless_path,
Expand Down Expand Up @@ -328,7 +328,7 @@ def close(self):
self.move_to_final_destination()

def generate_tmp_path(self, path):
return os.path.join(tempfile.gettempdir(), 'luigi-s3-tmp-%09d' % random.randrange(0, 10000000000))
return os.path.join(tempfile.gettempdir(), 'luigi-s3-tmp-%09d' % random.randrange(0, 10_000_000_000))

def move_to_final_destination(self):
raise NotImplementedError()
Expand Down
2 changes: 1 addition & 1 deletion luigi/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def __exit__(self, type, value, traceback):
def _generate_worker_info(self):
# Generate as much info as possible about the worker
# Some of these calls might not be available on all OS's
args = [('salt', '%09d' % random.randrange(0, 999999999)),
args = [('salt', '%09d' % random.randrange(0, 10_000_000_000)),
('workers', self.worker_processes)]
try:
args += [('host', socket.gethostname())]
Expand Down