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

[WIP] ModuleNotFound Error Fix #115

Merged
merged 9 commits into from
May 28, 2024
Merged

[WIP] ModuleNotFound Error Fix #115

merged 9 commits into from
May 28, 2024

Conversation

ljwoods2
Copy link
Contributor

@ljwoods2 ljwoods2 commented May 24, 2024

Fixes #113

Changes made in this Pull Request:

  • Changed pyproject.toml to use packagename instead of reponame for tests
  • Added setuptools directive to fix installation issue

I used a repo which contains multiple packages as a model for these changes: https://github.com/Gallopsled/pwntools
The idea is that if the repo name differs from the package name, you should be able to do

pip show <repo_name> 

But not be able to import the package using the reponame. You must import using

import <package_name>

However, this leaves the issue of versioning, since the package_name's __init__ method uses (AFAIK) the version is associated with the repo_name. I set the package's version to use the version associated with repo_name by default and the user will have to be responsible for changing this if it doesn't apply (in the case they have two packages in the repo that are both different versions)

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG.md updated?
  • AUTHORS.md updated?
  • Issue raised/referenced?

@ljwoods2 ljwoods2 changed the title [WIP] MDAKit installation [WIP] ModuleNotFound Error Fix May 24, 2024
@pep8speaks
Copy link

pep8speaks commented May 25, 2024

Hello @ljwoods2! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-05-28 01:48:17 UTC

{{cookiecutter.repo_name}}/pyproject.toml Show resolved Hide resolved
Comment on lines 75 to 100
def test_install_and_import(tmpdir):
with tmpdir.as_cwd():
kit = CookiecutterMDAKit(template_analysis_class="MyAnalysisClass")
kit.run()
result = subprocess.run(["python", "-m", "pip", "install",
"-e", "./test-mda-kit"],
capture_output=True, text=True)
if result.returncode != 0:
pytest.fail(f"Failed to install: {result.stderr}")
try:
import test_mdakit_package
except ImportError as e:
pytest.fail(f"Failed to import 'test_mdakit_package': {e}")

def test_gh_actions_debug_python_env(tmpdir):
with tmpdir.as_cwd():

result = subprocess.run(["python", "-m", "pip", "install",
"mdanalysistests"],
capture_output=True, text=True)
if result.returncode != 0:
pytest.fail(f"Failed to install: {result.stderr}")
try:
import MDAnalysisTests
except ImportError as e:
pytest.fail(f"Failed to import 'MDAnalysisTests': {e}")
Copy link
Member

Choose a reason for hiding this comment

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

Thanks so much for opening this PR @ljwoods2! For the cookiecutter repo we have a somewhat complex structure for tests, and in many ways I've found it easier to just run the "cookie" tests as part of a GitHub action (e.g. in #116 I'm currently trying to get the "cookie" tests to fail appropriately, as part of the cookie testing is importing the package). This also avoids complicated actions like installing a Python package into the active environment while Python is running, which can also potentially complicate other tests in the same environment. I'd be keen to err on the side of keeping this kind of importing test to within the cookie infrastructure as much as possible, as it also replicates the user experience more (at least when the tests work...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see, thank you for explaining, I thought the issue was that the install wasn't being tested, not that the test was failing out before it installed and imported the package. I will remove this

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @ljwoods2! This is looking great -- CI is failing for codecov reasons that should be fixed in #111, so I'll merge that first and then this should be good to go!

@@ -6,7 +6,7 @@ requires = [
build-backend = "setuptools.build_meta"

[project]
name = "{{cookiecutter.repo_name}}"
name = "{{cookiecutter.package_name}}"
Copy link
Member

@lilyminium lilyminium May 25, 2024

Choose a reason for hiding this comment

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

Hmm -- the docs reckon this name should be what you want the package to be called on PyPI, and allow things like hyphens here. Should this remain just the package name? @orbeckst any opinions here -- what did you have in mind for mdgeomkit?

Edit: sorry I see you reverted this later!

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if my input is still needed but for completeness: I just tried a different name for the project_name (the PyPi install name, the one that can have hyphens) from the Python package/module "import" name package_name to see if anything would break... and it did:

project_name [ProjectName]: mdgeomkit
repo_name [mdgeomkit]: mdgeomkit
package_name [mdgeomkit]: mdgeom

@lilyminium lilyminium mentioned this pull request May 27, 2024
5 tasks
Copy link
Member

@lilyminium lilyminium left a comment

Choose a reason for hiding this comment

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

LGTM and now fixing the broken CI in main -- thank you @ljwoods2! Just one final nitpick and please add yourself to AUTHORS: https://github.com/MDAnalysis/cookiecutter-mdakit/blob/main/AUTHORS.md

Comment on lines 4 to 5
import subprocess
import sys
Copy link
Member

Choose a reason for hiding this comment

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

I think these imports now aren't used?

@lilyminium
Copy link
Member

Thank you @ljwoods2 for fixing this issue!

@lilyminium lilyminium merged commit 11fdc10 into MDAnalysis:main May 28, 2024
12 checks passed
@orbeckst
Copy link
Member

Many thanks @ljwoods2 and @lilyminium !

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.

module not found after pip install
4 participants