From 2321d912de138663c0e55b078716b09da801add8 Mon Sep 17 00:00:00 2001 From: Rishabh <53911515+Rishabh672003@users.noreply.github.com> Date: Sun, 30 Jun 2024 23:23:40 +0530 Subject: [PATCH 1/5] feat: configured CI/CD pipeline (#1) * test: ci/cd * fix: fixed the ci/cd * fix: add ruff installation through pip --- .github/workflows/python-app.yml | 27 +++++++++++++++++++++++++++ pdm.lock | 31 +++++++++++++++++++++++++++++-- pyproject.toml | 5 +++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..ee5402e --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,27 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: ["main", "github-action"] + pull_request: + branches: ["main"] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup PDM + uses: pdm-project/setup-pdm@v4 + - name: Install dependencies + run: pdm install && pip install ruff + - name: Lint with ruff + run: | + ruff check . diff --git a/pdm.lock b/pdm.lock index c75609a..539cb10 100644 --- a/pdm.lock +++ b/pdm.lock @@ -2,10 +2,10 @@ # It is not intended for manual editing. [metadata] -groups = ["default"] +groups = ["default", "lint"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:8370645052d0df22651203276f05313a3e76c93e8e202993007ffacd5e8657cb" +content_hash = "sha256:b880d031d567b4325c4c64519cb30e3b49a4e523741866b363f6c6fbf235cbff" [[package]] name = "click" @@ -53,6 +53,33 @@ files = [ {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"}, ] +[[package]] +name = "ruff" +version = "0.5.0" +requires_python = ">=3.7" +summary = "An extremely fast Python linter and code formatter, written in Rust." +groups = ["lint"] +files = [ + {file = "ruff-0.5.0-py3-none-linux_armv6l.whl", hash = "sha256:ee770ea8ab38918f34e7560a597cc0a8c9a193aaa01bfbd879ef43cb06bd9c4c"}, + {file = "ruff-0.5.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:38f3b8327b3cb43474559d435f5fa65dacf723351c159ed0dc567f7ab735d1b6"}, + {file = "ruff-0.5.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:7594f8df5404a5c5c8f64b8311169879f6cf42142da644c7e0ba3c3f14130370"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:adc7012d6ec85032bc4e9065110df205752d64010bed5f958d25dbee9ce35de3"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d505fb93b0fabef974b168d9b27c3960714d2ecda24b6ffa6a87ac432905ea38"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9dc5cfd3558f14513ed0d5b70ce531e28ea81a8a3b1b07f0f48421a3d9e7d80a"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:db3ca35265de239a1176d56a464b51557fce41095c37d6c406e658cf80bbb362"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b1a321c4f68809fddd9b282fab6a8d8db796b270fff44722589a8b946925a2a8"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2c4dfcd8d34b143916994b3876b63d53f56724c03f8c1a33a253b7b1e6bf2a7d"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:81e5facfc9f4a674c6a78c64d38becfbd5e4f739c31fcd9ce44c849f1fad9e4c"}, + {file = "ruff-0.5.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:e589e27971c2a3efff3fadafb16e5aef7ff93250f0134ec4b52052b673cf988d"}, + {file = "ruff-0.5.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d2ffbc3715a52b037bcb0f6ff524a9367f642cdc5817944f6af5479bbb2eb50e"}, + {file = "ruff-0.5.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:cd096e23c6a4f9c819525a437fa0a99d1c67a1b6bb30948d46f33afbc53596cf"}, + {file = "ruff-0.5.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:46e193b36f2255729ad34a49c9a997d506e58f08555366b2108783b3064a0e1e"}, + {file = "ruff-0.5.0-py3-none-win32.whl", hash = "sha256:49141d267100f5ceff541b4e06552e98527870eafa1acc9dec9139c9ec5af64c"}, + {file = "ruff-0.5.0-py3-none-win_amd64.whl", hash = "sha256:e9118f60091047444c1b90952736ee7b1792910cab56e9b9a9ac20af94cd0440"}, + {file = "ruff-0.5.0-py3-none-win_arm64.whl", hash = "sha256:ed5c4df5c1fb4518abcb57725b576659542bdbe93366f4f329e8f398c4b71178"}, + {file = "ruff-0.5.0.tar.gz", hash = "sha256:eb641b5873492cf9bd45bc9c5ae5320648218e04386a5f0c264ad6ccce8226a1"}, +] + [[package]] name = "xdg-base-dirs" version = "6.0.1" diff --git a/pyproject.toml b/pyproject.toml index e49e15f..6b03c3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,5 +20,10 @@ build-backend = "pdm.backend" [tool.pdm] distribution = true +[tool.pdm.dev-dependencies] +lint = [ + "ruff>=0.5.0", +] + [project.scripts] pyfix-imports = "pyfix_imports.commandline.cli:cli" From e35ebb1208c3e12598743611685e083f9eaf9b6e Mon Sep 17 00:00:00 2001 From: Rishabh <53911515+Rishabh672003@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:38:38 +0530 Subject: [PATCH 2/5] updated ci/cd (#2) * test: ci/cd * fix: fixed the ci/cd * fix: add ruff installation through pip * feat: added test and updated the workflow * feat: updated the install command --- .github/workflows/python-app.yml | 19 ++++++++--- pdm.lock | 58 +++++++++++++++++++++++++++++--- pyproject.toml | 7 ++-- tests/mod_test.py | 15 +++++++++ tests/test.py | 32 ++++++++++++++++++ 5 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 tests/mod_test.py create mode 100644 tests/test.py diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index ee5402e..96371ea 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -13,15 +13,26 @@ permissions: contents: read jobs: - build: - runs-on: ubuntu-latest + Testing: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: [3.8, 3.9,"3.10", "3.11", "3.12"] + os: [ubuntu-latest, macOS-latest, windows-latest] steps: - uses: actions/checkout@v4 - - name: Setup PDM + - name: Set up PDM uses: pdm-project/setup-pdm@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies - run: pdm install && pip install ruff + run: | + pdm install ; pip install ruff pytest + - name: Run Tests + run: | + pdm run -v pytest tests - name: Lint with ruff run: | ruff check . diff --git a/pdm.lock b/pdm.lock index 539cb10..cd42d2d 100644 --- a/pdm.lock +++ b/pdm.lock @@ -2,10 +2,10 @@ # It is not intended for manual editing. [metadata] -groups = ["default", "lint"] +groups = ["default", "lint", "tests"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:b880d031d567b4325c4c64519cb30e3b49a4e523741866b363f6c6fbf235cbff" +content_hash = "sha256:e285b71f523631af7620de1aaae03e845bc1d812c8a1956924c697d7597951de" [[package]] name = "click" @@ -26,8 +26,8 @@ name = "colorama" version = "0.4.6" requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" summary = "Cross-platform colored terminal text." -groups = ["default"] -marker = "platform_system == \"Windows\"" +groups = ["default", "tests"] +marker = "platform_system == \"Windows\" or sys_platform == \"win32\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -42,6 +42,39 @@ files = [ {file = "importlib-1.0.4.zip", hash = "sha256:b6ee7066fea66e35f8d0acee24d98006de1a0a8a94a8ce6efe73a9a23c8d9826"}, ] +[[package]] +name = "iniconfig" +version = "2.0.0" +requires_python = ">=3.7" +summary = "brain-dead simple config-ini parsing" +groups = ["tests"] +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] +name = "packaging" +version = "24.1" +requires_python = ">=3.8" +summary = "Core utilities for Python packages" +groups = ["tests"] +files = [ + {file = "packaging-24.1-py3-none-any.whl", hash = "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"}, + {file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"}, +] + +[[package]] +name = "pluggy" +version = "1.5.0" +requires_python = ">=3.8" +summary = "plugin and hook calling mechanisms for python" +groups = ["tests"] +files = [ + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, +] + [[package]] name = "pyflakes" version = "3.2.0" @@ -53,6 +86,23 @@ files = [ {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"}, ] +[[package]] +name = "pytest" +version = "8.2.2" +requires_python = ">=3.8" +summary = "pytest: simple powerful testing with Python" +groups = ["tests"] +dependencies = [ + "colorama; sys_platform == \"win32\"", + "iniconfig", + "packaging", + "pluggy<2.0,>=1.5", +] +files = [ + {file = "pytest-8.2.2-py3-none-any.whl", hash = "sha256:c434598117762e2bd304e526244f67bf66bbd7b5d6cf22138be51ff661980343"}, + {file = "pytest-8.2.2.tar.gz", hash = "sha256:de4bb8104e201939ccdc688b27a89a7be2079b22e2bd2b07f806b6ba71117977"}, +] + [[package]] name = "ruff" version = "0.5.0" diff --git a/pyproject.toml b/pyproject.toml index 6b03c3a..3d1aceb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,9 +21,8 @@ build-backend = "pdm.backend" distribution = true [tool.pdm.dev-dependencies] -lint = [ - "ruff>=0.5.0", -] +lint = ["ruff>=0.5.0"] +tests = ["pytest>=8.2.2"] [project.scripts] -pyfix-imports = "pyfix_imports.commandline.cli:cli" +pyfix-imports = "pyfix_imports.commandline.cli:cli" \ No newline at end of file diff --git a/tests/mod_test.py b/tests/mod_test.py new file mode 100644 index 0000000..89c3301 --- /dev/null +++ b/tests/mod_test.py @@ -0,0 +1,15 @@ +from pyfix_imports.pyflake import pyflake +from tests.test import test_code + +def check_code(output): + mod_list = pyflake(output) + + if mod_list: + return mod_list + else: + return {} + + +def test_code_output(): + assert check_code(test_code) == {'defaultdict', 'Tuple', 'List', 'mp', 'Optional', 'time', 'np', 'deque', 'os', 'itertools', 'Dict', 'dedent', 'collections', 'random'} + diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..28b4f63 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,32 @@ +test_code = """ +start = time.time() +a = np.array([1, 2, 3, 4]) +b = os.getcwd() + + +c = random.randint(1, 3) + +deq = deque() +a = dedent("121") +d = defaultdict(str) + +a = mp.sqrt_mod(12, 2) + +itt = itertools.accumulate([1, 2, 3, 4]) + +print(list(itt)) + +assert list(itt) == [1, 3, 6, 10] + +Points = collections.namedtuple("Point", ["x", "y"]) + + +def fname(a: Dict[int, List], b: Tuple[int], c: Optional[List]): + pass + + +z = os.getcwd() + +end = time.time() +print(end - start) +""" From 23ddd304182bca3000057a9a3b1a678d06c399e1 Mon Sep 17 00:00:00 2001 From: Rishabh <53911515+Rishabh672003@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:41:51 +0530 Subject: [PATCH 3/5] updated the python version checked in the ci/cd --- .github/workflows/python-app.yml | 2 +- pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 96371ea..bd7842a 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -17,7 +17,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: [3.8, 3.9,"3.10", "3.11", "3.12"] + python-version: ["3.11", "3.12"] os: [ubuntu-latest, macOS-latest, windows-latest] steps: diff --git a/pyproject.toml b/pyproject.toml index 3d1aceb..ed413d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ dependencies = [ "importlib>=1.0.4", "xdg-base-dirs>=6.0.1", ] -requires-python = ">=3.12" +requires-python = ">=3.11" readme = "README.md" license = { text = "GPL-3.0-only" } @@ -25,4 +25,4 @@ lint = ["ruff>=0.5.0"] tests = ["pytest>=8.2.2"] [project.scripts] -pyfix-imports = "pyfix_imports.commandline.cli:cli" \ No newline at end of file +pyfix-imports = "pyfix_imports.commandline.cli:cli" From 69ffc0d62d0930d00a9db21ee65f7ce2c222dcba Mon Sep 17 00:00:00 2001 From: Rishabh <53911515+Rishabh672003@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:44:57 +0530 Subject: [PATCH 4/5] final change update it to 3.10 --- .github/workflows/python-app.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index bd7842a..be771be 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -17,7 +17,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.11", "3.12"] + python-version: ["3.10","3.11", "3.12"] os: [ubuntu-latest, macOS-latest, windows-latest] steps: diff --git a/pyproject.toml b/pyproject.toml index ed413d4..95e6984 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ dependencies = [ "importlib>=1.0.4", "xdg-base-dirs>=6.0.1", ] -requires-python = ">=3.11" +requires-python = ">=3.10" readme = "README.md" license = { text = "GPL-3.0-only" } From 0dccd86983bffb028adecde63d3b60974fd85c70 Mon Sep 17 00:00:00 2001 From: Rishabh <53911515+Rishabh672003@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:56:28 +0530 Subject: [PATCH 5/5] fix: try to fix the failing tests --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index be771be..a5640f3 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -32,7 +32,7 @@ jobs: pdm install ; pip install ruff pytest - name: Run Tests run: | - pdm run -v pytest tests + pdm run -v pytest - name: Lint with ruff run: | ruff check .