8000 Create PURL CLI tool and library by johnmhoran · Pull Request #267 · aboutcode-org/purldb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Create PURL CLI tool and library #267 8000

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

Merged
merged 15 commits into from
Jan 19, 2024
Merged

Create PURL CLI tool and library #267

merged 15 commits into from
Jan 19, 2024

Conversation

johnmhoran
Copy link
Member

Implements #247.

Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Copy link
Member
@pombredanne pombredanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
I think this only needs a few unit tests and is good to merge, you may want to extract the whole body of validate()m

@johnmhoran
Copy link
Member Author

@pombredanne I just noticed that despite this option we added last week

@click.option(
    "--output",
    type=click.File(mode="w", encoding="utf-8"),
    required=True,
    default="-",
    help="Write validation output as JSON to FILE.",
)

I can successfully run this command without adding --output:

(venv) Wed Jan 03, 2024 03:12 PM  /home/jmh/dev/nexb/purldb jmh (247-create-purl-cli-tool)
$ python purlcli.py validate --purl pkg:blah
[
    {
        "valid": false,
        "exists": null,
        "message": "The provided PackageURL is not valid.",
        "purl": "pkg:blah"
    }
]
(venv) Wed Jan 03, 2024 03:15 PM  /home/jmh/dev/nexb/purldb jmh (247-create-purl-cli-tool)
$

Is that what we want? I thought your point was that you wanted to require the --output flag. The inclusion of default="-", seems to negate that requirement.

Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran
Copy link
Member Author

@pombredanne I've refactored the validate function in purlcli.py and created a new test file, test_purlcli.py, with four tests. Since the function we want to test calls the API, each of those tests also calls the API. Is that what we want? I've checked other test examples but have not identified an alternative approach (though perhaps it's there and I didn't recognize it as such).

Re the additional services we want to add (starting with fetchcode), do we want to merge this current PR (subject to your additional comments) and then create a new PR under the same issue as I add those additional services to the PURL CLI tool/library?

@johnmhoran johnmhoran requested a review from pombredanne January 4, 2024 19:20
Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Reference: #247

Signed-off-by: John M. Horan johnmhoran@gmail.com
Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@JonoYang
Copy link
Member

@johnmhoran We should reorganize the new code and tests that you've created into its own project. For now, I think we should copy the matchcode-toolkit directory and call it purldb-toolkit. You would put your code in the src/purldb_toolkit/ directory and the tests in the tests/ directory. You would then need to update the setup.cfg and other project files, like pyproject.toml, to change references from matchcode-toolkit to purldb-toolkit. We could then move it out into its own repo later, like how we have deltacode.

Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran
Copy link
Member Author

@JonoYang With apologies, I just saw your comment in this PR now -- was busy vetting and refactoring so I could commit and push. Perhaps we could chat briefly at some point before I start the reorg just to make sure I understand. And query whether I should do that before or after I receive some sort of feedback on the PR (definitely including the tests ;-).



class TestPURLCLI_validate(object):
@pytest.mark.parametrize(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pombredanne How do you feel about using the pytest.mark.parametrize to hold the test input and expected results?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works. If the list is small you can use it like there:

(For very large test suites, the toolkit approach using YAML test data files for license and copyright can work too, but is much more work and I would likely rewrite this using pytest.mark.parametrize today though the bulk would stay the same: data files for expectations, test files for data and objects to read these )

@JonoYang
Copy link
Member

@JonoYang With apologies, I just saw your comment in this PR now -- was busy vetting and refactoring so I could commit and push. Perhaps we could chat briefly at some point before I start the reorg just to make sure I understand. And query whether I should do that before or after I receive some sort of feedback on the PR (definitely including the tests ;-).

We can have a call about this

@johnmhoran
Copy link
Member Author

@JonoYang Re the restructuring, I've added several files in the new project folder, including setup.cfg, which is based on that file in the matchcode-toolkit folder. The last section of the matchcode-toolkit file is

[options.entry_points]
scancode_post_scan =
    fingerprint = matchcode_toolkit.plugin_fingerprint:Fingerprint

This does not appear relevant to our new purldb-toolkit project and I plan to remove -- is that correct?

@johnmhoran
Copy link
Member Author

@JonoYang I've added the new structure and basic files but cannot import purlcli.py -- do I need to run pip install -e . first?

@johnmhoran
Copy link
Member Author

@JonoYang I ran pip install -e . but still cannot access my new project and import purlcli in my test file.

image

@johnmhoran
Copy link
Member Author

@JonoYang I've added purldb-toolkit >= 0.0.1 to the install_requires field of the parent setup.cfg (I already added and edited pyproject.toml, setup.cfg and setup.py for the new purldb-toolkit project) and reran pip install -e . but get this:

(venv) Thu Jan 18, 2024 09:51 AM  /home/jmh/dev/nexb/purldb jmh (247-create-purl-cli-tool)
$ pip install -e .
Obtaining file:///home/jmh/dev/nexb/purldb
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: jawa==2.2.0 in ./venv/lib/python3.8/site-packages (from purldb==3.0.1.dev47+gddd9eea.d20240118) (2.2.0)
Requirement already satisfied: scancode-toolkit[full]==32.0.8 in ./venv/lib/python3.8/site-packages (from purldb==3.0.1.dev47+gddd9eea.d20240118) (32.0.8)
Requirement already satisfied: reppy2==0.3.6 in ./venv/lib/python3.8/site-packages (from purldb==3.0.1.dev47+gddd9eea.d20240118) (0.3.6)
ERROR: Could not find a version that satisfies the requirement purldb-toolkit>=0.0.1 (from purldb) (from versions: none)
ERROR: No matching distribution found for purldb-toolkit>=0.0.1

[notice] A new release of pip available: 22.2.2 -> 23.3.2
[notice] To update, run: pip install --upgrade pip

(venv) Thu Jan 18, 2024 10:05 AM  /home/jmh/dev/nexb/purldb jmh (247-create-purl-cli-tool)
$

@JonoYang
Copy link
Member

@johnmhoran

@JonoYang I ran pip install -e . but still cannot access my new project and import purlcli in my test file.

You would need to install your new purldb-toolkit by going to the purldb-toolkit directory and running pip install -e . while you're in the venv that you want to be in.

I would add --editable purldb-toolkit to lines 33-35, right after matchcode-toolkit: https://github.com/nexB/purldb/blob/main/configure#L33

This will ensure that we install purldb-toolkit to the venv when we run ./configure

@JonoYang I've added purldb-toolkit >= 0.0.1 to the install_requires field of the parent setup.cfg (I already added and edited pyproject.toml, setup.cfg and setup.py for the new purldb-toolkit project) and reran pip install -e . but get this:

I would not put purldb-toolkit as a dependency of purldb since purldb does not use code from purldb-toolkit.

@johnmhoran
Copy link
Member Author

@JonoYang I've followed your guidance and get this error when running pip install -e . from the purldb-toolkit directory:

(venv) Thu Jan 18, 2024 10:34 AM  /home/jmh/dev/nexb/purldb/purldb-toolkit jmh (247-create-purl-cli-tool)
$ pip install -e .
Obtaining file:///home/jmh/dev/nexb/purldb/purldb-toolkit
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "/home/jmh/dev/nexb/purldb/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/home/jmh/dev/nexb/purldb/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/jmh/dev/nexb/purldb/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 191, in prepare_metadata_for_build_editable
          return hook(metadata_directory, config_settings)
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 446, in prepare_metadata_for_build_editable
          return self.prepare_metadata_for_build_wheel(
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 366, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 6, in <module>
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 147, in setup
          _setup_distribution = dist = klass(attrs)
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 314, in __init__
          self.metadata.version = self._normalize_version(self.metadata.version)
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 350, in _normalize_version
          normalized = str(Version(version))
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/_vendor/packaging/version.py", line 198, in __init__
          raise InvalidVersion(f"Invalid version: '{version}'")
      setuptools.extern.packaging.version.InvalidVersion: Invalid version: '9999.$Format:%h-%cs$'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

[notice] A new release of pip available: 22.2.2 -> 23.3.2
[notice] To update, run: pip install --upgrade pip

(venv) Thu Jan 18, 2024 10:34 AM  /home/jmh/dev/nexb/purldb/purldb-toolkit jmh (247-create-purl-cli-tool)
$

@JonoYang
Copy link
Member

@JonoYang I've followed your guidance and get this error when running pip install -e . from the purldb-toolkit directory:

(venv) Thu Jan 18, 2024 10:34 AM  /home/jmh/dev/nexb/purldb/purldb-toolkit jmh (247-create-purl-cli-tool)
$ pip install -e .
Obtaining file:///home/jmh/dev/nexb/purldb/purldb-toolkit
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "/home/jmh/dev/nexb/purldb/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/home/jmh/dev/nexb/purldb/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/jmh/dev/nexb/purldb/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 191, in prepare_metadata_for_build_editable
          return hook(metadata_directory, config_settings)
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 446, in prepare_metadata_for_build_editable
          return self.prepare_metadata_for_build_wheel(
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 366, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 6, in <module>
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 147, in setup
          _setup_distribution = dist = klass(attrs)
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 314, in __init__
          self.metadata.version = self._normalize_version(self.metadata.version)
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 350, in _normalize_version
          normalized = str(Version(version))
        File "/tmp/pip-build-env-z_ob221w/overlay/lib/python3.8/site-packages/setuptools/_vendor/packaging/version.py", line 198, in __init__
          raise InvalidVersion(f"Invalid version: '{version}'")
      setuptools.extern.packaging.version.InvalidVersion: Invalid version: '9999.$Format:%h-%cs$'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

[notice] A new release of pip available: 22.2.2 -> 23.3.2
[notice] To update, run: pip install --upgrade pip

(venv) Thu Jan 18, 2024 10:34 AM  /home/jmh/dev/nexb/purldb/purldb-toolkit jmh (247-create-purl-cli-tool)
$

Hmm, I think you may have to state a version in the pyproject.toml, at the top of the file, it should look something like this:

[project]
name = "purldb-toolkit"
version = "0.0.1"

@johnmhoran
Copy link
Member Author

🙂 It already looks like this:

image

purlcli.py Outdated
"bitbucket",
"rubygems",
]
purl_type = purl.split(":")[1].split("/")[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create a PackageURL object from purl string, and then access the type field of that object

Suggested change
purl_type = purl.split(":")[1].split("/")[0]
purl = PackageURL.from_string(purl)
if purl.type not in SUPPORTED_ECOSYSTEMS:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonoYang Talk about over-engineering. I was so proud of devising purl.split(":")[1].split("/")[0], and overlooked the straightforward approach that you identified and that I've now incorporated. Thank you. ;-) Reran my purlcli tests, all 42 passed.

Reran make test and ... error -- not sure what this is telling me to do:

. . .

_________________________________________________________________________________________________ ERROR collecting purldb-toolkit/setup.py _________________________________________________________________________________________________
import file mismatch:
imported module 'setup' has this __file__ attribute:
  /home/jmh/dev/nexb/purldb/setup.py
which is not the same as the test file we want to collect:
  /home/jmh/dev/nexb/purldb/purldb-toolkit/setup.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
========================================================================================================= short test summary info ==========================================================================================================
ERROR purldb-toolkit/setup.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================= 1 error in 3.11s =============================================================================================================
make: *** [Makefile:110: test] Error 2

(venv) Thu Jan 18, 2024 12:27 PM  /home/jmh/dev/nexb/purldb jmh (247-create-purl-cli-tool)
$

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmhoran

The test setup is a bit convoluted. Pytest didn't play nice with the directory layout I created, where we have modules like matchcode-toolkit and purldb-toolkit. To stop that error, I had to tell pytest to ignore those directories, then I added in extra commands to pytest to just test those specific directories.

We want to update this line: https://github.com/nexB/purldb/blob/247-create-purl-cli-tool/Makefile#L110

to ${ACTIVATE} DJANGO_SETTINGS_MODULE=purldb_project.settings ${PYTHON_EXE} -m pytest -vvs --ignore matchcode-toolkit --ignore purldb-toolkit --ignore packagedb/tests/test_throttling.py

and then add another line to test the purldb-toolkit specifically
${ACTIVATE} ${PYTHON_EXE} -m pytest -vvs purldb-toolkit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonoYang

Did the pytest fine-tuning, reran 'make test'. Only failures were the same 2 as the other day, which we expect atm.

FAILED minecode/tests/test_maven.py::MavenEnd2EndTest::test_visit_and_map_with_index - AssertionError: Lists differ: [{'ur[31 chars]ven2/cnuernber/dtype-next/0.4.2/dtype-next-0.4[49087 chars]one}] != [{'ur[31 chars]ven2/.index/nexus-mav
en-repository-index.532.g[49087 chars]one}]
FAILED minecode/tests/test_ls.py::ParseDirectoryListingTest::test_parse_listing_from_lslr - AssertionError: Lists differ: [{'pa[1527 chars] '2023-01', 'target': None}, {'path': 'dists/e[974 chars]one}] != [{'pa[1527 chars] '2024-01', 't
arget': None}, {'path': 'dists/e[974 chars]one}]

. . .

2 failed, 583 passed, 2 skipped, 30 xfailed, 71 warnings in 81.68s (0:01:21)

. . .

and all 42 of my purlcli tests pass. Ready to commit and push.

@JonoYang
Copy link
Member

🙂 It already looks like this:

image

Try replacing line 6 with requires = ["setuptools == 68.2.2", "wheel", "setuptools_scm[toml] >= 6"]

From https://stackoverflow.com/a/77527178, looks like something changed in setuptools.

@johnmhoran
Copy link
Member Author

Thanks @JonoYang . ;-) I'll make your suggested change, but first I see the last line of the error message is

setuptools.extern.packaging.version.InvalidVersion: Invalid version: '9999.$Format:%h-%cs$'

which seems to refer to line 12 of pyproject.toml

fallback_version = "9999.$Format:%h-%cs$"

which is identical to line 12 of the matchcode-toolkit pyproject.toml. FWIW. Making your change now, will then rerun pip install -e .

@johnmhoran
Copy link
Member Author

@JonoYang Made your change and the pip install succeeded.

Using matchcode-toolkit as a model, in nexb/purldb/matchcode-toolkit/tests/test_fingerprinting.py I see, e.g., from matchcode_toolkit.fingerprinting import split_fingerprint.

But in nexb/purldb/purldb-toolkit/tests/test_purlcli.py I cannot use the equivalent from purldb_toolkit import purlcli -- VSCode says this cannot be resolved. However, I seem to be able to use this w/o any error messages: from src.purldb_toolkit import purlcli. That is inconsistent with matchcode-toolkit, which has the same structure, and seems wrong but I'll give it a try anyway. Does that seem odd to you?

@johnmhoran
Copy link
Member Author

@JonoYang Now I'm getting weird errors from my pytest commands -- seems related to src.

int: make sure your test modules/packages have valid Python names.
Traceback:
venv/lib/python3.8/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
venv/lib/python3.8/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
    ???
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
venv/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
purldb-toolkit/tests/test_purlcli.py:10: in <module>
    from src.purldb_toolkit import purlcli
E   ModuleNotFoundError: No module named 'src'
========================================================================================================= short test summary info ==========================================================================================================
ERROR purldb-toolkit/tests/test_purlcli.py - ModuleNotFoundError: No module named 'src'

@JonoYang
Copy link
Member

@JonoYang Made your change and the pip install succeeded.

Using matchcode-toolkit as a model, in nexb/purldb/matchcode-toolkit/tests/test_fingerprinting.py I see, e.g., from matchcode_toolkit.fingerprinting import split_fingerprint.

But in nexb/purldb/purldb-toolkit/tests/test_purlcli.py I cannot use the equivalent from purldb_toolkit import purlcli -- VSCode says this cannot be resolved. However, I seem to be able to use this w/o any error messages: from src.purldb_toolkit import purlcli. That is inconsistent with matchcode-toolkit, which has the same structure, and seems wrong but I'll give it a try anyway. Does that seem odd to you?

I'm encountering the same problems you are when I try installing the matchcode-toolkit directory. Maybe more things changed with setuptools. I will see if using an earlier version of setuptools will help.

@johnmhoran
Copy link
Member Author

Thanks @JonoYang ! 🤞

@JonoYang
Copy link
Member

@JonoYang Now I'm getting weird errors from my pytest commands -- seems related to src.

int: make sure your test modules/packages have valid Python names.
Traceback:
venv/lib/python3.8/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
venv/lib/python3.8/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
    ???
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
venv/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
purldb-toolkit/tests/test_purlcli.py:10: in <module>
    from src.purldb_toolkit import purlcli
E   ModuleNotFoundError: No module named 'src'
========================================================================================================= short test summary info ==========================================================================================================
ERROR purldb-toolkit/tests/test_purlcli.py - ModuleNotFoundError: No module named 'src'

On line 10 in purldb-toolkit/tests/test_purlcli.py, try using from purldb_toolkit import purlcli instead of from src.purldb_toolkit import purlcli

@johnmhoran
Copy link
Member Author

That was something I tried more than an hour ago and got the same VSCode warning I'm getting now:

image

I guess I'll ignore the VSCode warning and rerun pip install -e . as if VSCode is wrong and see what happens.

@johnmhoran
Copy link
Member Author

@JonoYang

I realize rerunning pip again was unnecessary but I did it before I realized -- and #$@%^$ VSCode's warning is plain wrong -- running my revised command -- DJANGO_SETTINGS_MODULE=purldb_project.settings pytest -vvs purldb-toolkit/tests/test_purlcli.py -- all 42 (many parametrized) tests passed.

…#247

Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran
Copy link
Member Author

@JonoYang We have 4 failed tests among the GH tests, e.g., https://github.com/nexB/purldb/actions/runs/7576042489/job/20633970493?pr=267

===== 1 failed, 584 passed, 2 skipped, 30 xfailed, 156 warnings in 46.90s ======
make: *** [Makefile:110: test] Error 1
Error: Process completed with exit code 2.

That was one of the makefile lines I just edited. But I think the actual failure data starts on line 1490:

FAILED minecode/tests/test_ls.py::ParseDirectoryListingTest::test_parse_listing_from_lslr - AssertionError: Lists differ: [{'pa[1527 chars] '2023-01', 'target': None}, {'path': 'dists/e[974 chars]one}] != [{'pa[1527 chars] '2024-01', 'target': None}, {'path': 'dists/e[974 chars]one}]

First differing element 14:
{'pat[36 chars]'type': 'f', 'size': 187349, 'date': '2023-01', 'target': None}
{'pat[36 chars]'type': 'f', 'size': 187349, 'date': '2024-01', 'target': None}

Diff is 3157 characters long. Set self.maxDiff to None to see it.

Not related to my purlcli work.

@JonoYang
Copy link
Member

@JonoYang We have 4 failed tests among the GH tests, e.g., https://github.com/nexB/purldb/actions/runs/7576042489/job/20633970493?pr=267

===== 1 failed, 584 passed, 2 skipped, 30 xfailed, 156 warnings in 46.90s ======
make: *** [Makefile:110: test] Error 1
Error: Process completed with exit code 2.

That was one of the makefile lines I just edited. But I think the actual failure data starts on line 1490:

FAILED minecode/tests/test_ls.py::ParseDirectoryListingTest::test_parse_listing_from_lslr - AssertionError: Lists differ: [{'pa[1527 chars] '2023-01', 'target': None}, {'path': 'dists/e[974 chars]one}] != [{'pa[1527 chars] '2024-01', 'target': None}, {'path': 'dists/e[974 chars]one}]

First differing element 14:
{'pat[36 chars]'type': 'f', 'size': 187349, 'date': '2023-01', 'target': None}
{'pat[36 chars]'type': 'f', 'size': 187349, 'date': '2024-01', 'target': None}

Diff is 3157 characters long. Set self.maxDiff to None to see it.

Not related to my purlcli work.

I would update the expected test results for this test:

On line https://github.com/nexB/purldb/blob/main/minecode/tests/test_ls.py#L60, change regen=False to regen=True, and then run that specific test using python manage.py test minecode.tests.test_ls.ParseDirectoryListingTest.test_parse_listing_from_lslr, revert regen=True to regen=False, and then commit the updated test results.

Copy link
Member
@JonoYang JonoYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmhoran I've suggested some variable name changes and to add docstrings for some functions. Other than that, I think the PR is looking good.

Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran
Copy link
Member Author

Expected test results have been updated and committed.

@johnmhoran
Copy link
Member Author

@JonoYang I believe I've addressed all of your comments. Thank you for taking the time to provide very helpful feedback. Will commit and push shortly.

Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran
Copy link
Member Author

@JonoYang All 42 tests in test_purlcli.py passed, and make test had just 1 failure -- an expected failure. Committed and pushed.

BUT: 2 failed tests in GH, both referring to test_purlcli.py:

ERROR purldb-toolkit/tests/test_purlcli.py - django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
ERROR purldb-toolkit/tests/test_purlcli.py - django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Haven't seen this before -- a result of the directory restructuring?

@JonoYang
Copy link
Member

@JonoYang All 42 tests in test_purlcli.py passed, and make test had just 1 failure -- an expected failure. Committed and pushed.

BUT: 2 failed tests in GH, both referring to test_purlcli.py:

ERROR purldb-toolkit/tests/test_purlcli.py - django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
ERROR purldb-toolkit/tests/test_purlcli.py - django.core.exceptions.ImproperlyConfigured: Requested setting REST_FRAMEWORK, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Haven't seen this before -- a result of the directory restructuring?

This is because you have this import statement here is usually used in the context of a django project test: https://github.com/nexB/purldb/blob/3ceace31dad0adf3650027aa4147baf2dfe404fd/purldb-toolkit/tests/test_purlcli.py#L10

This line should be removed.

Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran
Copy link
Member Author

@JonoYang Fixed as requested, committed and pushed, but again:

=========================== short test summary info ============================
ERROR purldb-toolkit/tests/test_purlcli.py - django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
ERROR purldb-toolkit/tests/test_purlcli.py - django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!
============================== 2 errors in 1.20s ===============================
make: *** [Makefile:113: test] Error 2
Error: Process completed with exit code 2.

and the culprit this time:

purldb-toolkit/tests/test_purlcli.py:11: in <module>
    from packagedb.models import Package

I suspect these errors are triggered by unused imports, which describes the last and this error. There's a group of other unused imports, remnants of the multiple stages of testing. I'm breaking for dinner now but will attend to this after dinner -- plan to remove all unused imports, which I should always do in any event, and will keep you posted. Thanks mucho for all of your help @JonoYang

Reference: #247

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran
Copy link
Member Author

@JonoYang Removed the remaining no-longer-used imports from test_purlcli.py, all local tests passed except the 1 expected failure, committed, pushed, all GH checks passed.

Signed-off-by: Jono Yang <jyang@nexb.com>
@JonoYang
Copy link
Member

@johnmhoran Thanks for the changes! I've updated purldb-toolkit/setup.cfg install_requires, but everything looks good. Merging

@JonoYang JonoYang merged commit 86bce5f into main Jan 19, 2024
@JonoYang JonoYang deleted the 247-create-purl-cli-tool branch January 19, 2024 18:15
JonoYang added a commit that referenced this pull request Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0