diff --git a/luigi/contrib/dropbox.py b/luigi/contrib/dropbox.py index 9a8f4d7dfb..aaa77953b2 100644 --- a/luigi/contrib/dropbox.py +++ b/luigi/contrib/dropbox.py @@ -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)) diff --git a/luigi/contrib/ftp.py b/luigi/contrib/ftp.py index 91c766729f..d155e8ef8b 100644 --- a/luigi/contrib/ftp.py +++ b/luigi/contrib/ftp.py @@ -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 @@ -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 @@ -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() @@ -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 diff --git a/luigi/contrib/hadoop_jar.py b/luigi/contrib/hadoop_jar.py index 095fac4c4f..2635aeca5e 100644 --- a/luigi/contrib/hadoop_jar.py +++ b/luigi/contrib/hadoop_jar.py @@ -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) diff --git a/luigi/contrib/hdfs/config.py b/luigi/contrib/hdfs/config.py index e80ca12fa9..abafcdfb87 100644 --- a/luigi/contrib/hdfs/config.py +++ b/luigi/contrib/hdfs/config.py @@ -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 diff --git a/luigi/contrib/hdfs/target.py b/luigi/contrib/hdfs/target.py index 182c275aa1..8617fde26a 100644 --- a/luigi/contrib/hdfs/target.py +++ b/luigi/contrib/hdfs/target.py @@ -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) diff --git a/luigi/contrib/ssh.py b/luigi/contrib/ssh.py index 3119a94117..beda1c9e23 100644 --- a/luigi/contrib/ssh.py +++ b/luigi/contrib/ssh.py @@ -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]) @@ -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) @@ -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])) diff --git a/luigi/local_target.py b/luigi/local_target.py index 2fd718bcb9..5cdade2ec7 100644 --- a/luigi/local_target.py +++ b/luigi/local_target.py @@ -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): diff --git a/luigi/target.py b/luigi/target.py index 86cac9dbad..973a129109 100644 --- a/luigi/target.py +++ b/luigi/target.py @@ -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, @@ -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() diff --git a/luigi/worker.py b/luigi/worker.py index 84359e4740..f065208be8 100644 --- a/luigi/worker.py +++ b/luigi/worker.py @@ -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())]