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

feat(code quality): add black and ruff #56

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

zarifpour
Copy link
Contributor

@zarifpour zarifpour commented Jun 1, 2023

I added black and ruff to maintain code quality and implemented a Makefile streamline the execution of common commands.

I also tried to add poetry as the dependency manager, but it was not compatible with the dependency openai-whisper. It seemed to consistently fail on the installation of tritton.

For reference, this is as far as I was able to get:

# pyproject.toml

[tool.poetry]
name = "ecoute"
version = "0.1.0"
description = "Ecoute is a live transcription tool that provides real-time transcripts for both the user's microphone input (You) and the user's speakers output (Speaker) in a textbox. It also generates a suggested response using OpenAI's GPT-3.5 for the user to say based on the live transcription of the conversation."
authors = ["Seva <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.8"
numpy = "==1.24.3"
openai-whisper = "==20230314"
Wave = "==0.0.2"
openai = "==0.27.6"
customtkinter = "==5.1.3"
torch = "==2.0.0"

[tool.poetry.dependencies.PyAudioWPatch]
version = "==0.2.12.5"
platform = "win32"

[tool.poetry.dependencies.pyaudio]
version = "*"
platform = "darwin"

# poetry replacement for: `--extra-index-url https://download.pytorch.org/whl/cu117`
[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cu117"
priority = "supplemental"


[[tool.poetry.source]]
name = "PyPI"
priority = "primary"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

It fails with this error (there was another one for tritton, but I seemed to have lost it somewhere in my console):

Package operations: 6 installs, 1 update, 0 removals

   • Updating torch (2.0.1 -> 2.0.0+cu117): Failed

   RuntimeError

   Unable to find installation candidates for torch (2.0.0+cu117)

   at ~/.pyenv/versions/3.11.1/lib/python3.11/site-packages/poetry/installation/chooser.py:76 in choose_for
        72│ 
        73│             links.append(link)
        74│ 
        75│         if not links:
   →  76│             raise RuntimeError(f"Unable to find installation candidates for {package}")
        77│ 
        78│         # Get the best link
        79│         chosen = max(links, key=lambda link: self._sort_key(package, link))
        80│ 

I noticed another developer had a similar issue: https://github.com/orgs/python-poetry/discussions/7199

@SevaSk SevaSk self-requested a review June 1, 2023 19:16
@SevaSk
Copy link
Owner

SevaSk commented Jun 1, 2023

Thanks for contributing! Could you split the PR between the streamlined installation changes and black and ruff changes? Want to consider those changes separately. Also I think we should ignore linting custom_speech_recognition since its just a copy of the existing SpeechRecognition library with some modifications. Probably a better way to maintain that I haven't considered how.

@zarifpour
Copy link
Contributor Author

Thanks for contributing! Could you split the PR between the streamlined installation changes and black and ruff changes? Want to consider those changes separately. Also I think we should ignore linting custom_speech_recognition since its just a copy of the existing SpeechRecognition library with some modifications. Probably a better way to maintain that I haven't considered how.

I see, I didn't realize it was a copy of an existing SpeechRecognition library. In that case, I will ignore it in regards to linting and formatting. Would it make sense to do something like this - where the library is its own git repo?

Example from: https://github.com/foundry-rs/foundry-rust-template/tree/master/contracts/lib
CleanShot_2023-06-01_16 58 02_Arc_000862@2x

Makefile Outdated
Comment on lines 1 to 21
lint:
@echo
ruff .
@echo
black --check --diff --color .
@echo
pip-audit

format:
ruff --silent --exit-zero --fix .
black .

precommit:
make lint
make format

venv:
python3 -m venv ecout_env

install:
pip install -r requirements.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the streamlined installation changes, let me know if it is necessary to split the PR.

README.md Outdated
Comment on lines 110 to 122

### Installation

1. `make venv`
2. Activate the venv: `ecout_venv`
3. `make install`

### Code quality

Before submitting a pull request run `make precommit` and resolve any issues. Additionally, here are some useful commands:

- `make lint`
- `make format`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the streamlined installation changes, let me know if it is necessary to split the PR.

Copy link
Owner

Choose a reason for hiding this comment

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

Oh Sry! Got confused with the Installation section above.

Makefile Outdated
make format

venv:
python3 -m venv ecout_env
Copy link
Owner

Choose a reason for hiding this comment

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

python or python3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think python3 is preferred since we are working with Python 3.x.x

Copy link
Owner

Choose a reason for hiding this comment

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

Could somehow use either? For me I don't have python3 alias only python in my PATH.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I can change it to python instead of python3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

black .

precommit:
make lint
Copy link
Owner

Choose a reason for hiding this comment

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

Should probably have instructions to install 'make' as well, chocolatey seems easiest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it's built-in on MacOS and Linux, not sure about Windows.

Copy link
Owner

Choose a reason for hiding this comment

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

Windows you have to install it
installing choco with the commad in README and using

choco install make 

would be good enough for instructions

README.md Outdated
### Installation

1. `make venv`
2. Activate the venv: `ecout_venv`
Copy link
Owner

Choose a reason for hiding this comment

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

ecout_env\Scripts\activate ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, I'll add one script for MacOS and one for Windows.

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, sorry. I tried adding a script, but it's not possible to activate the venv with a make command. I'll add both options to the README: for MacOS it's source ecout_env/bin/activate

@SevaSk
Copy link
Owner

SevaSk commented Jun 2, 2023

Not sure why but make lint and make format cant find python files
image

image

@zarifpour
Copy link
Contributor Author

Not sure why but make lint and make format cant find python files

image

image

Hmm, I'm not sure. Maybe the way black behaves is different on windows. Can you try modifying a python file to contain single quotes for a string, instead of double quotes, and see if you get the same message. Perhaps it's behaving normally?

Comment on lines +115 to +139
#### Windows

1. Install make on your Windows machine.

```shell
choco install make
```

2. Create a virtual environment:

```shell
make venv
```

3. Activate the virtual environment:

```shell
.\ecout_venv\Scripts\activate
```

4. Install the required packages:

```shell
make install
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please confirm these steps work.

@zarifpour
Copy link
Contributor Author

I think this is good to go. If you get a chance to review + merge, I would appreciate it. Thanks!

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.

None yet

2 participants