diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 8b103a8..ad737c9 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -13,7 +13,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: [3.11.4] + python-version: [3.11] steps: - uses: actions/checkout@v3 diff --git a/Installation.md b/Installation.md index 054b207..3b63363 100644 --- a/Installation.md +++ b/Installation.md @@ -31,7 +31,7 @@ or run `setup.ps1` (For Windows User) 2. Run these commands to clone this repository and enter the directory. ```bash git clone https://github.com/Sosokker/ku-polls -cd ku +cd ku-polls ``` 3. (Optional: You can use venv instead)Install virtualenv via pip @@ -41,20 +41,20 @@ python -m pip install --user virtualenv ``` 4. Create virtual environment with `venv` or `virtualenv`. ```bash -python -m virtualenv .venv +python -m virtualenv venv or -python -m venv .venv +python -m venv venv ``` 5. Use `virtual environment` - Windows ```bash -.venv\Scripts\activate +.\venv\Scripts\activate ``` - Linux or MacOS ```bash -source .venv/bin/activate +source venv/bin/activate ``` 6. Install require module. ``` @@ -65,6 +65,10 @@ pip install -r requirements.txt **You can look at `sample.env` for more information and others environment variables to set.** ```bash SECRET_KEY=your_secret_key +DEBUG = False +ALLOWED_HOSTS = *.ku.th, localhost, 127.0.0.1, ::1 +TIME_ZONE = Asia/Bangkok +EMAIL_HOST_PASSWORD = yourpassword ``` You can generate your own `your_secret_key` by this command diff --git a/sample.env b/sample.env index c5af6b1..4c2f812 100644 --- a/sample.env +++ b/sample.env @@ -7,4 +7,8 @@ DEBUG = False # You can use wildcard chars (*) and IP addresses. Use * for any host. ALLOWED_HOSTS = *.ku.th, localhost, 127.0.0.1, ::1 # Your timezone -TIME_ZONE = Asia/Bangkok \ No newline at end of file +TIME_ZONE = Asia/Bangkok +# Password to use for the SMTP server defined in EMAIL_HOST. This setting is used in conjunction +# with EMAIL_HOST_USER when authenticating to the SMTP server. +# If either of these settings is empty, Django won’t attempt authentication. +EMAIL_HOST_PASSWORD=somepassword \ No newline at end of file diff --git a/setup.py b/setup.py index 7b871ff..c9bb97c 100644 --- a/setup.py +++ b/setup.py @@ -20,13 +20,20 @@ def check_python_command(): return None +def install_virtualenv(python_commands): + # Set check=True to throw an error if the return code is non-zero (which is an indication of some error happening). + try: + subprocess.run([python_commands, "-m", "pip", "install", "--user", "virtualenv"], check=True) + except: + print("+++Error Occur when try to install Virtualenv+++") + def create_virtual_environment(env_name, python_command): - subprocess.run([python_command, "-m", "venv", env_name], check=True) + subprocess.run([python_command, "-m", "virtualenv", env_name], check=True) def customize_virtual_environment(): env_name = input("Enter a custom virtual environment name (or press Enter for the default): ").strip() if not env_name: - env_name = ".venv" + env_name = "venv" return env_name def setup_environment_variables(python_command_in_venv): @@ -105,19 +112,21 @@ def main(): setup_venv = input("Do you want to set up a virtual environment? (yes/no): ").lower() if setup_venv == "yes": print("==========================Default Mode==========================") - if not os.path.exists(".venv"): - print("Creating a new virtual environment...") - subprocess.run([python_command, "-m", "venv", ".venv"]) + print("==========================Install Virtualenv==========================") + install_virtualenv(python_command) + if not os.path.exists("venv"): + print("==========================Creating a new virtual environment...==========================") + subprocess.run([python_command, "-m", "virtualenv", "venv"]) else: print("==========================Using an existing virtual environment.==========================") if is_posix: - activate_command = os.path.join(".venv", "bin", "activate") + activate_command = os.path.join("venv", "bin", "activate") elif is_windows: - activate_command = os.path.join(".venv", "Scripts", "activate") + activate_command = os.path.join("venv", "Scripts", "activate") subprocess.run([activate_command], shell=True) - python_command = os.path.join(".venv", "bin", "python") if is_posix else os.path.join(".venv", "Scripts", "python") + python_command = os.path.join("venv", "bin", "python") if is_posix else os.path.join("venv", "Scripts", "python") else: print("Not setting up a virtual environment. Using the global Python interpreter.") @@ -149,6 +158,8 @@ def main(): print("==========================Custom Mode==========================") python_commands = check_python_command() env_name = customize_virtual_environment() + print("==========================Install Virtualenv==========================") + install_virtualenv(python_commands) create_virtual_environment(env_name, python_commands) print(f"Finishing Create Virtual environment {env_name}") python_command_in_venv = os.path.join(env_name, "bin", "python") if is_posix else os.path.join(env_name, "Scripts", "python")