UnboundLocalError: cannot access local variable 'temp_dir' where it is not associated with a value
Yuvalmaster opened this issue Β· comments
Hi,
I'm trying to run the readme-ai on both a github and gitlab repos without any succsess.
I am using python 3.11.4 using conda as venv (tried also with other venvs).
I've installed using pip install readmeai
this is the error I get:
INFO README-AI is now executing.
INFO Repository: https://gitlab.com/corractions/datalake.git
INFO Model: gpt-3.5-turbo
INFO Output: readme-ai.md
ERROR Exception: Error cloning git repository: [WinError 5] Access is denied: 'C:\\Users\\yuval\\AppData\\Local\\Temp\\tmpvmjhqr25\\.git\\objects\\pack\\pack-48b911d1bf9b980873e1d4b0cc2e68b52e19f74b.idx'
ERROR Stacktrace: Traceback (most recent call last):
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\utils\github.py", line 32, in clone_repo_to_temp_dir
shutil.rmtree(git_dir)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 759, in rmtree
return _rmtree_unsafe(path, onerror)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 617, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 617, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 622, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 620, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\yuval\\AppData\\Local\\Temp\\tmpvmjhqr25\\.git\\objects\\pack\\pack-48b911d1bf9b980873e1d4b0cc2e68b52e19f74b.idx'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\main.py", line 66, in md_agent
temp_dir = await asyncio.to_thread(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\asyncio\threads.py", line 25, in to_thread
return await loop.run_in_executor(None, func_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\utils\github.py", line 40, in clone_repo_to_temp_dir
raise ValueError(
ValueError: Error cloning git repository: [WinError 5] Access is denied: 'C:\\Users\\yuval\\AppData\\Local\\Temp\\tmpvmjhqr25\\.git\\objects\\pack\\pack-48b911d1bf9b980873e1d4b0cc2e68b52e19f74b.idx'
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\yuval\anaconda3\Scripts\readmeai.exe\__main__.py", line 7, in <module>
File "C:\Users\yuval\anaconda3\Lib\site-packages\click\core.py", line 1157, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\cli\commands.py", line 37, in commands
main(
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\main.py", line 49, in main
asyncio.run(md_agent(badges, config, config_helper))
File "C:\Users\yuval\anaconda3\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\main.py", line 121, in md_agent
await asyncio.to_thread(shutil.rmtree, temp_dir)
^^^^^^^^
UnboundLocalError: cannot access local variable 'temp_dir' where it is not associated with a value
Hi @Yuvalmaster, is this repository private on both GitHub and GitLab?
The gitlab project is indeed private, but the GitHub project I tried too is not private. I used one of my public repos
Any more details on which GitHub project? I can take a look at the error.
@Yuvalmaster What version are you running? Try running pip install --upgrade readmeai
once more. If that doesn't work I'll do some more debugging. Looks like you're on windows?
Here is the output of your repo from my machine.
Heartbeat-Analysis-Tool---EM
Heartbeat-Analysis-Tool---EM
β¦ Analyzing beats, saving lives.
β¦ Developed with the software and tools below.
π Table of Contents
- π Table of Contents
- π Overview
- π¦ Features
- π Repository Structure
- βοΈ Modules
- π Getting Started
- π£ Roadmap
- π€ Contributing
- π License
- π Acknowledgments
π Overview
The Heartbeat Analysis Tool is a Python project that aims to analyze heart rate data from log files. It provides functionalities for loading CSV files, saving raw data to a PostgreSQL database, and running analysis on the data for all devices. The tool extracts information such as device type, device ID, and date from the log files and performs further analysis based on the provided heart rate parameters. The value proposition of the project lies in its ability to efficiently process and analyze heart rate data, allowing researchers, healthcare professionals, and fitness enthusiasts to gain insights into cardiovascular health.
π¦ Features
Feature | Description | |
---|---|---|
βοΈ | Architecture | The project follows a modular architecture, where different components are organized and separated according to their functionality. It uses the Model-View-Controller (MVC) design pattern. |
π | Documentation | The codebase lacks documentation, making it difficult for new developers to understand its implementation and usage. Additional documentation should be provided to improve comprehension and maintainability of the project. |
π | Dependencies | The project relies on external libraries such as Flask, NumPy, and Pandas. Flask is used for the web framework, while NumPy and Pandas are used for data manipulation and analysis. |
𧩠| Modularity | The codebase is organized into several modules and packages, separating different functionalities. However, there is room for improvement in terms of further breaking down interdependent components into smaller, interchangeable modules. |
π§ͺ | Testing | The codebase currently lacks a comprehensive testing strategy. It would benefit from the implementation of unit tests, integration tests, and automated testing tools like Pytest or Selenium. Proper testing coverage would improve reliability and help catch potential issues or bugs. |
β‘οΈ | Performance | The codebase performance largely depends on the data size and the underlying hardware infrastructure. Proper optimization techniques like caching, efficient algorithms, and database indexing can be applied to enhance the system's speed, efficiency, and resource utilization. |
π | Security | The codebase does not feature explicit security measures, such as input validation, authentication, or authorization mechanisms. Implementing security measures like secure user authentication and secure data handling would enhance the overall security of the system. |
π | Version Control | Version control is implemented using Git, allowing developers to manage and track changes effectively. |
π | Integrations | The project integrates with external services or APIs to collect and analyze heartbeat data. Further integration possibilities include data visualization libraries or tools to enhance data presentation. |
πΆ | Scalability | The system's scalability depends on factors like the underlying infrastructure and the efficiency of the implemented algorithms. To improve scalability, the project could consider techniques like asynchronous programming, horizontal scaling, and distributed storage for handling increased data volume. |
π Repository Structure
βββ Heartbeat-Analysis-Tool---EM/
βββ .gitignore
βββ README.md
βββ config/
β βββ analysis_config.yaml
β βββ db_config_template.yaml
βββ dashboard data/
β βββ EM-HR Monitoring-rev0.3.json
βββ data/
β βββ DAVIDHAMELECH_1111_2023-07-02csv.csv
β βββ HPhire_1111_2023-07-02csv.csv
β βββ HPhire_1111_2023-07-03csv.csv
β βββ HSet_1234_2023-07-01csv.csv
β βββ HSet_1234_2023-07-02.csv
β βββ HSet_1234_2023-07-03csv.csv
β βββ Hi_IwillFail.csv
β βββ Hset_2345_2023-07-02csv.csv
β βββ New Text Document.txt
βββ requirements.txt
βββ run.bat
βββ src/
βββ analysis.py
βββ data_loader.py
βββ database.py
βββ log_parser.py
βββ main.py
βββ setup.py
βοΈ Modules
Root
File | Summary |
---|---|
requirements.txt | The requirements.txt file lists the necessary packages and their versions required for the code to run. It includes numpy, pandas, psycopg2, PyYAML, tqdm, and SQLAlchemy. These packages provide functionalities for data manipulation, SQL database connectivity, and progress tracking. |
run.bat | The code in the run.bat file executes the main.py script using Python, which is located in the src directory. |
Config
File | Summary |
---|---|
db_config_template.yaml | The code defines the configuration for a PostgreSQL database connection, including the host, port, database name, username, password (with a placeholder), schema, and table names. |
analysis_config.yaml | The code reads configuration data from a YAML file. It stores heart rate parameters, start and end codes, measurement code, total beats code, capacity, sample length, and time delta values. These values are used for further analysis or processing. |
Src
File | Summary |
---|---|
analysis.py | HTTPStatus Exception: 400 |
database.py | The code provides a Database class with functionalities for connecting to a PostgreSQL database, saving raw data and analysis data to the database, querying the database, and managing database tables. It also includes utilities for checking file existence, creating tables, and loading data for analysis. |
data_loader.py | The code in data_loader.py is responsible for loading CSV files, saving raw data to a database, and running analysis for each device in the database. It also checks the last primary ID for specified end codes in the log data. |
setup.py | This code is used to check and install all dependencies specified in a requirements file. It utilizes the subprocess module to run the pip install command and handles any errors that may occur during the installation process. |
main.py | The code in the main.py file sets up the project directories, installs required packages, loads raw data to a database, and runs analysis on the data for all devices. Finally, it closes the database connection. |
log_parser.py | This code defines a LogParser class with a static method that loads and extracts information from a log file. It validates the file format, extracts device type, device ID, and date from the file name, reads the file, converts time columns to datetime format, and returns the extracted data as a dictionary. |
π Getting Started
Dependencies
Please ensure you have the following dependencies installed on your system:
- βΉοΈ Dependency 1
- βΉοΈ Dependency 2
- βΉοΈ ...
π§ Installation
- Clone the Heartbeat-Analysis-Tool---EM repository:
git clone https://github.com/Yuvalmaster/Heartbeat-Analysis-Tool---EM
- Change to the project directory:
cd Heartbeat-Analysis-Tool---EM
- Install the dependencies:
pip install -r requirements.txt
π€ Running Heartbeat-Analysis-Tool---EM
python main.py
π§ͺ Tests
pytest
π£ Roadmap
βΉοΈ Task 1: Implement X
βΉοΈ Task 2: Implement Y
βΉοΈ ...
π€ Contributing
Contributions are always welcome! Please follow these steps:
- Fork the project repository. This creates a copy of the project on your account that you can modify without affecting the original project.
- Clone the forked repository to your local machine using a Git client like Git or GitHub Desktop.
- Create a new branch with a descriptive name (e.g.,
new-feature-branch
orbugfix-issue-123
).
git checkout -b new-feature-branch
- Make changes to the project's codebase.
- Commit your changes to your local branch with a clear commit message that explains the changes you've made.
git commit -m 'Implemented new feature.'
- Push your changes to your forked repository on GitHub using the following command
git push origin new-feature-branch
- Create a new pull request to the original project repository. In the pull request, describe the changes you've made and why they're necessary.
The project maintainers will review your changes and provide feedback or merge them into the main branch.
π License
This project is licensed under the βΉοΈ LICENSE-TYPE
License. See the LICENSE-Type file for additional info.
π Acknowledgments
- βΉοΈ List any resources, contributors, inspiration, etc.
I did upgrade but no luck. Still have the same error
readmeai -o readme-ai.md -r https://github.com/Yuvalmaster/Heartbeat-Analysis-Tool---EM
INFO README-AI is now executing.
INFO Repository: https://github.com/Yuvalmaster/Heartbeat-Analysis-Tool---EM
INFO Model: gpt-3.5-turbo
INFO Output: readme-ai.md
ERROR Exception: Error cloning git repository: [WinError 5] Access is denied: 'C:\Users\yuval\AppData\Local\Temp\tmpzi752ypv\.git\objects\pack\pack-e9d9a352ec29916af962d71a15060931963aa8f4.idx'
ERROR Stacktrace: Traceback (most recent call last):
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\utils\github.py", line 32, in clone_repo_to_temp_dir
shutil.rmtree(git_dir)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 759, in rmtree
return _rmtree_unsafe(path, onerror)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 617, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 617, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 622, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 620, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\Users\yuval\AppData\Local\Temp\tmpzi752ypv\.git\objects\pack\pack-e9d9a352ec29916af962d71a15060931963aa8f4.idx'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\main.py", line 66, in md_agent
temp_dir = await asyncio.to_thread(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\asyncio\threads.py", line 25, in to_thread
return await loop.run_in_executor(None, func_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\utils\github.py", line 40, in clone_repo_to_temp_dir
raise ValueError(
ValueError: Error cloning git repository: [WinError 5] Access is denied: 'C:\Users\yuval\AppData\Local\Temp\tmpzi752ypv\.git\objects\pack\pack-e9d9a352ec29916af962d71a15060931963aa8f4.idx'
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\Users\yuval\anaconda3\Scripts\readmeai.exe_main.py", line 7, in
File "C:\Users\yuval\anaconda3\Lib\site-packages\click\core.py", line 1157, in call
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\cli\commands.py", line 37, in commands
main(
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\main.py", line 49, in main
asyncio.run(md_agent(badges, config, config_helper))
File "C:\Users\yuval\anaconda3\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\main.py", line 122, in md_agent
await asyncio.to_thread(shutil.rmtree, temp_dir)
^^^^^^^^
UnboundLocalError: cannot access local variable 'temp_dir' where it is not associated with a value
@Yuvalmaster Just made a small update.
pip install readmeai==0.4.4
Let me know if that changes anything.
readmeai -o readme-ai.md -r https://github.com/Yuvalmaster/Heartbeat-Analysis-Tool---EM
INFO README-AI is now executing.
INFO Repository: https://github.com/Yuvalmaster/Heartbeat-Analysis-Tool---EM
INFO Model: gpt-3.5-turbo
INFO Output: readme-ai.md
ERROR Exception: Error cloning git repository: [WinError 5] Access is denied: 'C:\\Users\\yuval\\AppData\\Local\\Temp\\tmp2sbrd5lh\\.git\\objects\\pack\\pack-e9d9a352ec29916af962d71a15060931963aa8f4.idx'
ERROR Stacktrace: Traceback (most recent call last):
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\utils\github.py", line 32, in clone_repo_to_temp_dir
shutil.rmtree(git_dir)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 759, in rmtree
return _rmtree_unsafe(path, onerror)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 617, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 617, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 622, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\yuval\anaconda3\Lib\shutil.py", line 620, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\yuval\\AppData\\Local\\Temp\\tmp2sbrd5lh\\.git\\objects\\pack\\pack-e9d9a352ec29916af962d71a15060931963aa8f4.idx'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\main.py", line 67, in md_agent
temp_dir = await asyncio.to_thread(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\asyncio\threads.py", line 25, in to_thread
return await loop.run_in_executor(None, func_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\yuval\anaconda3\Lib\site-packages\readmeai\utils\github.py", line 40, in clone_repo_to_temp_dir
raise ValueError(
ValueError: Error cloning git repository: [WinError 5] Access is denied: 'C:\\Users\\yuval\\AppData\\Local\\Temp\\tmp2sbrd5lh\\.git\\objects\\pack\\pack-e9d9a352ec29916af962d71a15060931963aa8f4.idx'
INFO README-AI execution complete.
No luck yet
Hi @Yuvalmaster, can you try once more with
pip install readmeai==0.4.6
If this does not work, I'll boot up a windows machine when I get a chance and do some further debugging.
Theres also a possibility that it could be a permissions issue on your machine. Let me know what happens and we'll go from there.
β οΈ If any other Windows users are experiencing this issue, please comment π
I'm here just to confirm that this issue still exists on my Windows machine, with the latest version installed.
EDIT:
It seems like shutil is having problems deleting stuff in the Temp folder and I had to replace this line:
shutil.rmtree(item) # at line 100 of file `readmeai/services/git.py`
with something else that does the same:
os.system('rmdir /S /Q "{}"'.format(item.absolute()))
Note that it's only a temporary workaround and I hope the creator will fix it someday.
Hello,
Same problem, I am on windows.
Thanks to @minhcrafters the problem is fixed.