Bug description
When using PriceCollector.collect(), an AttributeError: module 'utils' has no attribute 'collect_vendors' can occur if the user's project also contains a file named utils.py in the root directory (i.e., the current working directory when running a script or notebook).
This happens because chemprice/chemprice.py (and potentially other internal modules) uses an absolute import import utils. This can cause Python to import the user's utils.py instead of the chemprice package's own chemprice/utils.py file, which contains the collect_vendors function.
To Reproduce
Steps to reproduce the behavior:
- Create a Python project.
- Install
chemprice.
- Create a file named
utils.py in the root of the project (it can be empty or contain any code).
- In a script or notebook in the project root, try to use
PriceCollector().collect(["CCO"]).
- See error:
AttributeError: module 'utils' has no attribute 'collect_vendors'
Expected behavior
chemprice should always use its internal utils.py module, regardless of whether a utils.py file exists in the user's project directory.
Suggested Solution
Modify the import statement in chemprice/chemprice.py (and any other internal modules that import utils) from:
import utils
to a relative import:
from . import utils
This will ensure that the chemprice package always loads its own utils module.
Environment (example):
- Python version: 3.11
- chemprice version: 1.1.0
- OS: macOS
Bug description
When using
PriceCollector.collect(), anAttributeError: module 'utils' has no attribute 'collect_vendors'can occur if the user's project also contains a file namedutils.pyin the root directory (i.e., the current working directory when running a script or notebook).This happens because
chemprice/chemprice.py(and potentially other internal modules) uses an absolute importimport utils. This can cause Python to import the user'sutils.pyinstead of thechempricepackage's ownchemprice/utils.pyfile, which contains thecollect_vendorsfunction.To Reproduce
Steps to reproduce the behavior:
chemprice.utils.pyin the root of the project (it can be empty or contain any code).PriceCollector().collect(["CCO"]).AttributeError: module 'utils' has no attribute 'collect_vendors'Expected behavior
chempriceshould always use its internalutils.pymodule, regardless of whether autils.pyfile exists in the user's project directory.Suggested Solution
Modify the import statement in
chemprice/chemprice.py(and any other internal modules that importutils) from:import utilsto a relative import:
from . import utilsThis will ensure that the
chempricepackage always loads its ownutilsmodule.Environment (example):