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

move src/examples to examples #70

Merged
merged 3 commits into from
Mar 19, 2024
Merged

Conversation

aconchillo
Copy link
Contributor

I believe this will capture users' attention better. People just click at examples, plus I believe it is more common to have them in the root directory.

@aconchillo
Copy link
Contributor Author

Oh... I think this is more tricky (since the examples depends on the examples package). I'll mark it as a draft.

@aconchillo aconchillo marked this pull request as draft March 18, 2024 19:09
@aconchillo aconchillo marked this pull request as ready for review March 18, 2024 20:26
'..',
'..',))
sys.path.append(project_root)

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems, to me, like a lot of boilerplate to need to add to every sample. Is this normal in Python repos?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added a comment about this. The other option is for the user to set PYTHONPATH.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I actually prefer the PYTHONPATH approach, but for some reason I went with the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add a line to the README. Something like:

To run the example you need to set PYTHONPATH.

export  PYTHONPATH=`pwd`
....
....

@aconchillo
Copy link
Contributor Author

@Moishe @chadbailey59 With these changes we don't make examples part of the dailyai distribution any more. Today, if you do pip install dailyai it will also install the examples. I believe the examples should just be in the repo and keep the distribution small.

To do that, since the examples fodler is also a python package (because of examples/support/runner.py) there are 2 options:

  • User needs to specify PYTHONPATH. For example: PYTHONPATH=. python/examples/foundational/02....
  • Each example file adds the repos root folder to the python search path. Which is what I've done here.

WDYT?

@aconchillo aconchillo force-pushed the move-src-example-to-examples branch from 323560a to b033808 Compare March 18, 2024 21:05
@aconchillo
Copy link
Contributor Author

I've updated the PR with the PYTHONPATH approach.

@Moishe
Copy link
Contributor

Moishe commented Mar 18, 2024

I don't love setting PYTHONPATH either, because it's gonna require extra setup steps to run the examples inside VSCode (or whatever other IDE).

What if we just put a copy of the runner.py file in foundational and starter-apps (and removed the support directory entirely)? In this case I think a little duplicated code in favor of ease of running the examples might be better.

(I tried using relative imports with no luck, maybe because it would also require a PYTHONPATH, just a different one)

@aconchillo
Copy link
Contributor Author

I don't love setting PYTHONPATH either, because it's gonna require extra setup steps to run the examples inside VSCode (or whatever other IDE).

What if we just put a copy of the runner.py file in foundational and starter-apps (and removed the support directory entirely)? In this case I think a little duplicated code in favor of ease of running the examples might be better.

That works for me! I was also thinking of adding runner.py into the dailyai package inside a util/daily subpackage or something. But I like this idea better for now.

(I tried using relative imports with no luck, maybe because it would also require a PYTHONPATH, just a different one)

Yes, I tried that as well without luck.

@aconchillo
Copy link
Contributor Author

I don't love setting PYTHONPATH either, because it's gonna require extra setup steps to run the examples inside VSCode (or whatever other IDE).
What if we just put a copy of the runner.py file in foundational and starter-apps (and removed the support directory entirely)? In this case I think a little duplicated code in favor of ease of running the examples might be better.

That works for me! I was also thinking of adding runner.py into the dailyai package inside a util/daily subpackage or something. But I like this idea better for now.

Actually, this has the same problem as the relative import as you would do:

from .runner import configure

But since we don't have a package....

@aconchillo aconchillo force-pushed the move-src-example-to-examples branch from b033808 to a970595 Compare March 18, 2024 22:14
@aconchillo
Copy link
Contributor Author

Alright, I have moved auth.py and runner.py into dailyai.examples packages. This of course works well. Now you have to do:

from dailyai.examples.runner import configure

@aconchillo
Copy link
Contributor Author

I have also added these lines:

from dotenv import load_dotenv
load_dotenv()

to each script, since this is specific to the application itself, not the library.

@Moishe
Copy link
Contributor

Moishe commented Mar 18, 2024

I copied runner.py into the examples directory and changed the import to:

from runner import configure

and then, from the examples directory,

(env) ➜  examples git:(move-src-example-to-examples) ✗ python foundational/01-say-one-thing.py -u https://moishe.daily.co/sample-testing
Using cache found in /Users/moishe/.cache/torch/hub/snakers4_silero-vad_master
20 2024-03-18 19:45:44,831 🎬 Starting frame consumer thread

that seems to work fine without adding any example-specific code to the package. Does that work for you?

@aconchillo aconchillo force-pushed the move-src-example-to-examples branch from a970595 to a573277 Compare March 19, 2024 00:10
@aconchillo
Copy link
Contributor Author

I copied runner.py into the examples directory and changed the import to:

from runner import configure

and then, from the examples directory,

(env) ➜  examples git:(move-src-example-to-examples) ✗ python foundational/01-say-one-thing.py -u https://moishe.daily.co/sample-testing
Using cache found in /Users/moishe/.cache/torch/hub/snakers4_silero-vad_master
20 2024-03-18 19:45:44,831 🎬 Starting frame consumer thread

that seems to work fine without adding any example-specific code to the package. Does that work for you?

Duh! Of course it works. PR updated.

@aconchillo
Copy link
Contributor Author

I kept load_dotenv() in each script though instead of inside runner.py.

@aconchillo aconchillo requested a review from Moishe March 19, 2024 15:00
@aconchillo aconchillo merged commit 4286597 into main Mar 19, 2024
1 check passed
@aconchillo aconchillo deleted the move-src-example-to-examples branch October 23, 2024 20:53
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.

2 participants