Skip to content

Commit 3632820

Browse files
authored
Create codeql-analysis.yml (#1127)
* Create codeql-analysis.yml see: - https://github.blog/2022-08-15-the-next-step-for-lgtm-com-github-code-scanning/ - #909 (comment) * Re-implement tempfile.mktemp using NamedTemporaryFile Adds zarr.tests.util.mktemp which can be used from all tests. The NamedTemporaryFile is immediately closed and only the path returned.
1 parent 718ee13 commit 3632820

File tree

7 files changed

+114
-35
lines changed

7 files changed

+114
-35
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ "main" ]
20+
schedule:
21+
- cron: '29 0 * * 1'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'python' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v3
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v2
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
52+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53+
# queries: security-extended,security-and-quality
54+
55+
56+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57+
# If this step fails, then you should remove it and run the build manually (see below)
58+
- name: Autobuild
59+
uses: github/codeql-action/autobuild@v2
60+
61+
# ℹ️ Command-line programs to run using the OS shell.
62+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63+
64+
# If the Autobuild fails above, remove it and uncomment the following three lines.
65+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66+
67+
# - run: |
68+
# echo "Run, Build Application using script"
69+
# ./location_of_script_within_repo/buildscript.sh
70+
71+
- name: Perform CodeQL Analysis
72+
uses: github/codeql-action/analyze@v2

zarr/tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import shutil
66
import unittest
77
from itertools import zip_longest
8-
from tempfile import mkdtemp, mktemp
8+
from tempfile import mkdtemp
99

1010
import numpy as np
1111
import pytest
@@ -53,7 +53,7 @@
5353
StoreV3,
5454
)
5555
from zarr.util import buffer_size
56-
from zarr.tests.util import abs_container, skip_test_env_var, have_fsspec
56+
from zarr.tests.util import abs_container, skip_test_env_var, have_fsspec, mktemp
5757

5858
# noinspection PyMethodMayBeStatic
5959

zarr/tests/test_creation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import atexit
22
import os.path
33
import shutil
4-
import tempfile
54
import warnings
65

76
import numpy as np
@@ -20,6 +19,7 @@
2019
from zarr._storage.store import v3_api_available
2120
from zarr._storage.v3 import DirectoryStoreV3, KVStoreV3
2221
from zarr.sync import ThreadSynchronizer
22+
from zarr.tests.util import mktemp
2323

2424
_VERSIONS = ((None, 2, 3) if v3_api_available else (None, 2))
2525
_VERSIONS2 = ((2, 3) if v3_api_available else (2, ))
@@ -574,7 +574,7 @@ def test_open_like(zarr_version, at_root):
574574
expected_zarr_version = DEFAULT_ZARR_VERSION if zarr_version is None else zarr_version
575575

576576
# zarr array
577-
path = tempfile.mktemp()
577+
path = mktemp()
578578
atexit.register(shutil.rmtree, path)
579579
z = full(100, chunks=10, dtype='f4', compressor=Zlib(5),
580580
fill_value=42, order='F', **kwargs)
@@ -588,7 +588,7 @@ def test_open_like(zarr_version, at_root):
588588
assert (z._store._store_version == z2._store._store_version ==
589589
expected_zarr_version)
590590
# numpy array
591-
path = tempfile.mktemp()
591+
path = mktemp()
592592
atexit.register(shutil.rmtree, path)
593593
a = np.empty(100, dtype='f4')
594594
z3 = open_like(a, path, chunks=10, zarr_version=zarr_version)

zarr/tests/test_hierarchy.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
FSStoreV3, ZipStoreV3, DBMStoreV3, LMDBStoreV3, SQLiteStoreV3,
3333
LRUStoreCacheV3)
3434
from zarr.util import InfoReporter, buffer_size
35-
from zarr.tests.util import skip_test_env_var, have_fsspec, abs_container
35+
from zarr.tests.util import skip_test_env_var, have_fsspec, abs_container, mktemp
3636

3737

3838
_VERSIONS = ((2, 3) if v3_api_available else (2, ))
@@ -1331,7 +1331,7 @@ class TestGroupWithZipStore(TestGroup):
13311331

13321332
@staticmethod
13331333
def create_store():
1334-
path = tempfile.mktemp(suffix='.zip')
1334+
path = mktemp(suffix='.zip')
13351335
atexit.register(os.remove, path)
13361336
store = ZipStore(path)
13371337
return store, None
@@ -1359,7 +1359,7 @@ class TestGroupV3WithZipStore(TestGroupWithZipStore, TestGroupV3):
13591359

13601360
@staticmethod
13611361
def create_store():
1362-
path = tempfile.mktemp(suffix='.zip')
1362+
path = mktemp(suffix='.zip')
13631363
atexit.register(os.remove, path)
13641364
store = ZipStoreV3(path)
13651365
return store, None
@@ -1369,7 +1369,7 @@ class TestGroupWithDBMStore(TestGroup):
13691369

13701370
@staticmethod
13711371
def create_store():
1372-
path = tempfile.mktemp(suffix='.anydbm')
1372+
path = mktemp(suffix='.anydbm')
13731373
atexit.register(atexit_rmglob, path + '*')
13741374
store = DBMStore(path, flag='n')
13751375
return store, None
@@ -1380,7 +1380,7 @@ class TestGroupV3WithDBMStore(TestGroupWithDBMStore, TestGroupV3):
13801380

13811381
@staticmethod
13821382
def create_store():
1383-
path = tempfile.mktemp(suffix='.anydbm')
1383+
path = mktemp(suffix='.anydbm')
13841384
atexit.register(atexit_rmglob, path + '*')
13851385
store = DBMStoreV3(path, flag='n')
13861386
return store, None
@@ -1391,7 +1391,7 @@ class TestGroupWithDBMStoreBerkeleyDB(TestGroup):
13911391
@staticmethod
13921392
def create_store():
13931393
bsddb3 = pytest.importorskip("bsddb3")
1394-
path = tempfile.mktemp(suffix='.dbm')
1394+
path = mktemp(suffix='.dbm')
13951395
atexit.register(os.remove, path)
13961396
store = DBMStore(path, flag='n', open=bsddb3.btopen)
13971397
return store, None
@@ -1403,7 +1403,7 @@ class TestGroupV3WithDBMStoreBerkeleyDB(TestGroupWithDBMStoreBerkeleyDB, TestGro
14031403
@staticmethod
14041404
def create_store():
14051405
bsddb3 = pytest.importorskip("bsddb3")
1406-
path = tempfile.mktemp(suffix='.dbm')
1406+
path = mktemp(suffix='.dbm')
14071407
atexit.register(os.remove, path)
14081408
store = DBMStoreV3(path, flag='n', open=bsddb3.btopen)
14091409
return store, None
@@ -1414,7 +1414,7 @@ class TestGroupWithLMDBStore(TestGroup):
14141414
@staticmethod
14151415
def create_store():
14161416
pytest.importorskip("lmdb")
1417-
path = tempfile.mktemp(suffix='.lmdb')
1417+
path = mktemp(suffix='.lmdb')
14181418
atexit.register(atexit_rmtree, path)
14191419
store = LMDBStore(path)
14201420
return store, None
@@ -1426,7 +1426,7 @@ class TestGroupV3WithLMDBStore(TestGroupWithLMDBStore, TestGroupV3):
14261426
@staticmethod
14271427
def create_store():
14281428
pytest.importorskip("lmdb")
1429-
path = tempfile.mktemp(suffix='.lmdb')
1429+
path = mktemp(suffix='.lmdb')
14301430
atexit.register(atexit_rmtree, path)
14311431
store = LMDBStoreV3(path)
14321432
return store, None
@@ -1436,7 +1436,7 @@ class TestGroupWithSQLiteStore(TestGroup):
14361436

14371437
def create_store(self):
14381438
pytest.importorskip("sqlite3")
1439-
path = tempfile.mktemp(suffix='.db')
1439+
path = mktemp(suffix='.db')
14401440
atexit.register(atexit_rmtree, path)
14411441
store = SQLiteStore(path)
14421442
return store, None
@@ -1447,7 +1447,7 @@ class TestGroupV3WithSQLiteStore(TestGroupWithSQLiteStore, TestGroupV3):
14471447

14481448
def create_store(self):
14491449
pytest.importorskip("sqlite3")
1450-
path = tempfile.mktemp(suffix='.db')
1450+
path = mktemp(suffix='.db')
14511451
atexit.register(atexit_rmtree, path)
14521452
store = SQLiteStoreV3(path)
14531453
return store, None

zarr/tests/test_storage.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
meta_root, normalize_store_arg)
3737
from zarr.storage import FSStore, rename, listdir
3838
from zarr._storage.v3 import KVStoreV3
39-
from zarr.tests.util import CountingDict, have_fsspec, skip_test_env_var, abs_container
39+
from zarr.tests.util import CountingDict, have_fsspec, skip_test_env_var, abs_container, mktemp
4040
from zarr.util import json_dumps
4141

4242

@@ -1772,7 +1772,7 @@ class TestZipStore(StoreTests):
17721772
ZipStoreClass = ZipStore
17731773

17741774
def create_store(self, **kwargs):
1775-
path = tempfile.mktemp(suffix='.zip')
1775+
path = mktemp(suffix='.zip')
17761776
atexit.register(os.remove, path)
17771777
store = ZipStore(path, mode='w', **kwargs)
17781778
return store
@@ -1853,7 +1853,7 @@ def test_store_and_retrieve_ndarray(self):
18531853
class TestDBMStore(StoreTests):
18541854

18551855
def create_store(self, dimension_separator=None):
1856-
path = tempfile.mktemp(suffix='.anydbm')
1856+
path = mktemp(suffix='.anydbm')
18571857
atexit.register(atexit_rmglob, path + '*')
18581858
# create store using default dbm implementation
18591859
store = DBMStore(path, flag='n', dimension_separator=dimension_separator)
@@ -1869,7 +1869,7 @@ def test_context_manager(self):
18691869
class TestDBMStoreDumb(TestDBMStore):
18701870

18711871
def create_store(self, **kwargs):
1872-
path = tempfile.mktemp(suffix='.dumbdbm')
1872+
path = mktemp(suffix='.dumbdbm')
18731873
atexit.register(atexit_rmglob, path + '*')
18741874

18751875
import dbm.dumb as dumbdbm
@@ -1881,7 +1881,7 @@ class TestDBMStoreGnu(TestDBMStore):
18811881

18821882
def create_store(self, **kwargs):
18831883
gdbm = pytest.importorskip("dbm.gnu")
1884-
path = tempfile.mktemp(suffix=".gdbm") # pragma: no cover
1884+
path = mktemp(suffix=".gdbm") # pragma: no cover
18851885
atexit.register(os.remove, path) # pragma: no cover
18861886
store = DBMStore(
18871887
path, flag="n", open=gdbm.open, write_lock=False, **kwargs
@@ -1893,7 +1893,7 @@ class TestDBMStoreNDBM(TestDBMStore):
18931893

18941894
def create_store(self, **kwargs):
18951895
ndbm = pytest.importorskip("dbm.ndbm")
1896-
path = tempfile.mktemp(suffix=".ndbm") # pragma: no cover
1896+
path = mktemp(suffix=".ndbm") # pragma: no cover
18971897
atexit.register(atexit_rmglob, path + "*") # pragma: no cover
18981898
store = DBMStore(path, flag="n", open=ndbm.open, **kwargs) # pragma: no cover
18991899
return store # pragma: no cover
@@ -1903,7 +1903,7 @@ class TestDBMStoreBerkeleyDB(TestDBMStore):
19031903

19041904
def create_store(self, **kwargs):
19051905
bsddb3 = pytest.importorskip("bsddb3")
1906-
path = tempfile.mktemp(suffix='.dbm')
1906+
path = mktemp(suffix='.dbm')
19071907
atexit.register(os.remove, path)
19081908
store = DBMStore(path, flag='n', open=bsddb3.btopen, write_lock=False, **kwargs)
19091909
return store
@@ -1913,7 +1913,7 @@ class TestLMDBStore(StoreTests):
19131913

19141914
def create_store(self, **kwargs):
19151915
pytest.importorskip("lmdb")
1916-
path = tempfile.mktemp(suffix='.lmdb')
1916+
path = mktemp(suffix='.lmdb')
19171917
atexit.register(atexit_rmtree, path)
19181918
buffers = True
19191919
store = LMDBStore(path, buffers=buffers, **kwargs)
@@ -1930,13 +1930,13 @@ class TestSQLiteStore(StoreTests):
19301930

19311931
def create_store(self, **kwargs):
19321932
pytest.importorskip("sqlite3")
1933-
path = tempfile.mktemp(suffix='.db')
1933+
path = mktemp(suffix='.db')
19341934
atexit.register(atexit_rmtree, path)
19351935
store = SQLiteStore(path, **kwargs)
19361936
return store
19371937

19381938
def test_underscore_in_name(self):
1939-
path = tempfile.mktemp(suffix='.db')
1939+
path = mktemp(suffix='.db')
19401940
atexit.register(atexit_rmtree, path)
19411941
store = SQLiteStore(path)
19421942
store['a'] = b'aaa'

zarr/tests/test_storage_v3.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
LMDBStoreV3, LRUStoreCacheV3, MemoryStoreV3,
1919
MongoDBStoreV3, RedisStoreV3, SQLiteStoreV3, StoreV3,
2020
ZipStoreV3)
21-
from zarr.tests.util import CountingDictV3, have_fsspec, skip_test_env_var
21+
from zarr.tests.util import CountingDictV3, have_fsspec, skip_test_env_var, mktemp
2222

2323
# pytest will fail to run if the following fixtures aren't imported here
2424
from .test_storage import StoreTests as _StoreTests
@@ -330,7 +330,7 @@ class TestZipStoreV3(_TestZipStore, StoreV3Tests):
330330
ZipStoreClass = ZipStoreV3
331331

332332
def create_store(self, **kwargs):
333-
path = tempfile.mktemp(suffix='.zip')
333+
path = mktemp(suffix='.zip')
334334
atexit.register(os.remove, path)
335335
store = ZipStoreV3(path, mode='w', **kwargs)
336336
return store
@@ -339,7 +339,7 @@ def create_store(self, **kwargs):
339339
class TestDBMStoreV3(_TestDBMStore, StoreV3Tests):
340340

341341
def create_store(self, dimension_separator=None):
342-
path = tempfile.mktemp(suffix='.anydbm')
342+
path = mktemp(suffix='.anydbm')
343343
atexit.register(atexit_rmglob, path + '*')
344344
# create store using default dbm implementation
345345
store = DBMStoreV3(path, flag='n', dimension_separator=dimension_separator)
@@ -349,7 +349,7 @@ def create_store(self, dimension_separator=None):
349349
class TestDBMStoreV3Dumb(_TestDBMStoreDumb, StoreV3Tests):
350350

351351
def create_store(self, **kwargs):
352-
path = tempfile.mktemp(suffix='.dumbdbm')
352+
path = mktemp(suffix='.dumbdbm')
353353
atexit.register(atexit_rmglob, path + '*')
354354

355355
import dbm.dumb as dumbdbm
@@ -361,7 +361,7 @@ class TestDBMStoreV3Gnu(_TestDBMStoreGnu, StoreV3Tests):
361361

362362
def create_store(self, **kwargs):
363363
gdbm = pytest.importorskip("dbm.gnu")
364-
path = tempfile.mktemp(suffix=".gdbm") # pragma: no cover
364+
path = mktemp(suffix=".gdbm") # pragma: no cover
365365
atexit.register(os.remove, path) # pragma: no cover
366366
store = DBMStoreV3(
367367
path, flag="n", open=gdbm.open, write_lock=False, **kwargs
@@ -373,7 +373,7 @@ class TestDBMStoreV3NDBM(_TestDBMStoreNDBM, StoreV3Tests):
373373

374374
def create_store(self, **kwargs):
375375
ndbm = pytest.importorskip("dbm.ndbm")
376-
path = tempfile.mktemp(suffix=".ndbm") # pragma: no cover
376+
path = mktemp(suffix=".ndbm") # pragma: no cover
377377
atexit.register(atexit_rmglob, path + "*") # pragma: no cover
378378
store = DBMStoreV3(path, flag="n", open=ndbm.open, **kwargs) # pragma: no cover
379379
return store # pragma: no cover
@@ -383,7 +383,7 @@ class TestDBMStoreV3BerkeleyDB(_TestDBMStoreBerkeleyDB, StoreV3Tests):
383383

384384
def create_store(self, **kwargs):
385385
bsddb3 = pytest.importorskip("bsddb3")
386-
path = tempfile.mktemp(suffix='.dbm')
386+
path = mktemp(suffix='.dbm')
387387
atexit.register(os.remove, path)
388388
store = DBMStoreV3(path, flag='n', open=bsddb3.btopen, write_lock=False, **kwargs)
389389
return store
@@ -393,7 +393,7 @@ class TestLMDBStoreV3(_TestLMDBStore, StoreV3Tests):
393393

394394
def create_store(self, **kwargs):
395395
pytest.importorskip("lmdb")
396-
path = tempfile.mktemp(suffix='.lmdb')
396+
path = mktemp(suffix='.lmdb')
397397
atexit.register(atexit_rmtree, path)
398398
buffers = True
399399
store = LMDBStoreV3(path, buffers=buffers, **kwargs)
@@ -404,7 +404,7 @@ class TestSQLiteStoreV3(_TestSQLiteStore, StoreV3Tests):
404404

405405
def create_store(self, **kwargs):
406406
pytest.importorskip("sqlite3")
407-
path = tempfile.mktemp(suffix='.db')
407+
path = mktemp(suffix='.db')
408408
atexit.register(atexit_rmtree, path)
409409
store = SQLiteStoreV3(path, **kwargs)
410410
return store

0 commit comments

Comments
 (0)