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

UnboundLocalError: cannot access local variable 'temp_dir' where it is not associated with a value #59

Open
Yuvalmaster opened this issue Oct 1, 2023 · 11 comments

Comments

@Yuvalmaster
Copy link

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
@eli64s
Copy link
Owner

eli64s commented Oct 1, 2023

Hi @Yuvalmaster, is this repository private on both GitHub and GitLab?

@Yuvalmaster
Copy link
Author

The gitlab project is indeed private, but the GitHub project I tried too is not private. I used one of my public repos

@eli64s
Copy link
Owner

eli64s commented Oct 1, 2023

Any more details on which GitHub project? I can take a look at the error.

@Yuvalmaster
Copy link
Author

@eli64s
Copy link
Owner

eli64s commented Oct 1, 2023

@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.

tqdm Python pandas NumPy Markdown JSON

GitHub license git-last-commit GitHub commit activity GitHub top language

📖 Table of Contents


📍 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

  1. Clone the Heartbeat-Analysis-Tool---EM repository:
git clone https://github.com/Yuvalmaster/Heartbeat-Analysis-Tool---EM
  1. Change to the project directory:
cd Heartbeat-Analysis-Tool---EM
  1. 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:

  1. Fork the project repository. This creates a copy of the project on your account that you can modify without affecting the original project.
  2. Clone the forked repository to your local machine using a Git client like Git or GitHub Desktop.
  3. Create a new branch with a descriptive name (e.g., new-feature-branch or bugfix-issue-123).
git checkout -b new-feature-branch
  1. Make changes to the project's codebase.
  2. 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.'
  1. Push your changes to your forked repository on GitHub using the following command
git push origin new-feature-branch
  1. 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.

↑ Return


@Yuvalmaster
Copy link
Author

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

@eli64s
Copy link
Owner

eli64s commented Oct 1, 2023

@Yuvalmaster Just made a small update.

pip install readmeai==0.4.4

Let me know if that changes anything.

@Yuvalmaster
Copy link
Author

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

@eli64s
Copy link
Owner

eli64s commented Oct 6, 2023

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 🙂

@minhcrafters
Copy link

minhcrafters commented Mar 10, 2024

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.

@ludofigueiredo
Copy link

Hello,
Same problem, I am on windows.

Thanks to @minhcrafters the problem is fixed.

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

No branches or pull requests

4 participants