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

Issue finding executable for datasette on Windows #51

Closed
Poiuy7312 opened this issue Sep 13, 2023 · 2 comments · Fixed by #52 or #118
Closed

Issue finding executable for datasette on Windows #51

Poiuy7312 opened this issue Sep 13, 2023 · 2 comments · Fixed by #52 or #118
Assignees
Labels
bug Something isn't working

Comments

@Poiuy7312
Copy link
Collaborator

chasten datasette-serve C:\Users\Preston\CMPSC-203\ChastenProject\chasten\subject-data\chasten-flattened-csvs-sqlite-db-all-programs-20230905151458-42dbbaac257447cfa602106ce0d5a93d\chasten.db --port 8001

💫 chasten: Analyze the AST of Python Source Code
🔗 GitHub: https://github.com/gkapfham/chasten

✨ Starting a local datasette instance:
   • Database: '...
subject-data\chasten-flattened-csvs-sqlite-db-all-programs-20230905151458-42dbbaac257447cfa602106ce0d5a93d\chasten.db'
   • Metadata: 'None'
   • Port: 8001

✨ Details for datasette startup:
   • Venv: 'C:\Users\Preston\AppData\Local\pypoetry\Cache\virtualenvs\chasten-Ti8Qy4ta-py3.11'
   • Cannot find: 'C:\Users\Preston\AppData\Local\pypoetry\Cache\virtualenvs\chasten-Ti8Qy4ta-py3.11/bin/datasette'

🤷 Was not able to find '{executable_name}'

I got this error when running the above command and found that its searching for the executable in a bin file when they are stored in a file called Scripts on Windows. I fixed this by changing the following code.

executable_name = constants.datasette.Datasette_Executable
    # define the name of the file that contains datasette metadata;
    # note that by default the metadata could be None and thus it
    # will not be passed as a -m argument to the datasette program
    metadata = datasette_metadata
    # identify the location at which the virtual environment exists;
    # note that this is the location where executable dependencies of
    # chasten will exist in a bin directory. For instance, the "datasette"
    # executable that is a dependency of chasten can be found by starting
    # the search from this location for the virtual environment.
    virtual_env_location = sys.prefix
    full_executable_name = virtual_env_location + "/bin/" + executable_name
    (found_executable, executable_path) = filesystem.can_find_executable(
        full_executable_name
    )
    # output diagnostic

To

 executable_name = constants.datasette.Datasette_Executable + ".exe"
    # define the name of the file that contains datasette metadata;
    # note that by default the metadata could be None and thus it
    # will not be passed as a -m argument to the datasette program
    metadata = datasette_metadata
    # identify the location at which the virtual environment exists;
    # note that this is the location where executable dependencies of
    # chasten will exist in a bin directory. For instance, the "datasette"
    # executable that is a dependency of chasten can be found by starting
    # the search from this location for the virtual environment.
    virtual_env_location = sys.prefix
    script = " \Scripts\ "
    scriptst = script.strip()
    full_executable_name = virtual_env_location  + scriptst +  executable_name
    (found_executable, executable_path) = filesystem.can_find_executable(
        full_executable_name
    )

and it ran on windows

💫 chasten: Analyze the AST of Python Source Code
🔗 GitHub: https://github.com/gkapfham/chasten

✨ Starting a local datasette instance:
   • Database: '...
subject-data\chasten-flattened-csvs-sqlite-db-all-programs-20230913151430-90f2041a3273407e963e8b13cb404f5a\chasten.db'
   • Metadata: 'None'
   • Port: 8001

✨ Details for datasette startup:
   • Venv: 'C:\Users\Preston\AppData\Local\pypoetry\Cache\virtualenvs\chasten-Ti8Qy4ta-py3.11'
   • Program: 'C:\Users\Preston\AppData\Local\pypoetry\Cache\virtualenvs\chasten-Ti8Qy4ta-py3.11\Scripts\datasette.exe'

INFO:     Started server process [31096]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8001 (Press CTRL+C to quit)

This is a solution for Windows however it may mean we may need to run different code depending what OS people are using
since executables are stored differently on different OS

@Poiuy7312 Poiuy7312 self-assigned this Sep 13, 2023
@simojo
Copy link
Collaborator

simojo commented Sep 14, 2023

We should rely on Path objects to concatenate paths. This automatically changes between different OSs. Windows uses \path\to\file while linux uses /path/to/file.
Pathlib: https://docs.python.org/3/library/pathlib.html

@simojo simojo added the bug Something isn't working label Sep 14, 2023
@simojo simojo self-assigned this Sep 14, 2023
@gkapfham
Copy link
Collaborator

Hi, I agree with @simojo that this is the general-purpose solution. However, there is one additional challenge faced with this issue. This part of the program needs to run a different executable inside of a virtual environment depending on whether this program is being run on Windows or MacOS/Linux. I've gone through this issue in detail with @Poiuy7312. Can you summarize what we discussed @Poiuy7312 and then say how you are going to push this forward? Thanks everyone for your contributions to this issue and to its ultimate resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants