Skip to content

Commit

Permalink
style!: enable clippy upper-case-acronyms-aggressive (#1345)
Browse files Browse the repository at this point in the history
* rename `GCP` -> `Gcp`, `NodeID` -> `NodeId`
* update CI `cargo-generate` template testing to use PR's branch instead
of whatever `main` happens to be
  • Loading branch information
MingweiSamuel committed Jul 16, 2024
1 parent bbef070 commit 12b8ba5
Show file tree
Hide file tree
Showing 34 changed files with 118 additions and 2,172 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
rustflags = [
"-Zproc-macro-backtrace",
"-Wunused_qualifications",
"-Wclippy::upper_case_acronyms",
# Flag to make build.rs scripts generate docs. Should only be used in this repository
# internally, not by dependants.
'--cfg=HYDROFLOW_GENERATE_DOCS',
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ jobs:
components: rustfmt, clippy

- name: Action cargo-generate
uses: cargo-generate/cargo-generate-action@v0.17.5
uses: cargo-generate/cargo-generate-action@v0.20.0
with:
name: generated
template: template/hydroflow
arguments: "-d hydroflow_git=${{ github.event.pull_request.head.repo.clone_url }} -d hydroflow_branch=${{ github.event.pull_request.head.ref }}"
- name: Move generated project
run: |
mv generated ${{ runner.temp }}/
Expand Down Expand Up @@ -113,10 +114,11 @@ jobs:
components: rustfmt, clippy

- name: Action cargo-generate
uses: cargo-generate/cargo-generate-action@v0.17.5
uses: cargo-generate/cargo-generate-action@v0.20.0
with:
name: generated
template: template/hydroflow_plus
arguments: "-d hydroflow_git=${{ github.event.pull_request.head.repo.clone_url }} -d hydroflow_branch=${{ github.event.pull_request.head.ref }}"
- name: Move generated project
run: |
mv generated ${{ runner.temp }}/
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
upper-case-acronyms-aggressive = true
6 changes: 3 additions & 3 deletions design_docs/2023-02_hydro_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ module main(
Assume we also have a `src/echo_client.hf` file that periodically sends `EchoMsg`s to an `outbound` channel and logs echos from the `inbound` channel. We can deploy this program to a cloud machine using the following `echo.hydro.py` config file:
```python
from hydro import Deployment
from hydro.gcp import GCPMachine # keys are automatically loaded from somewhere
from hydro.gcp import GcpMachine # keys are automatically loaded from somewhere

async def main():
deployment = Deployment()

# Specify the GCP instances we want to deploy to
server_machine = deployment.GCPMachine(
server_machine = deployment.GcpMachine(
project="hydro-1234",
zone="us-west1-a",
type="e2-micro",
)

client_machine = deployment.GCPMachine(
client_machine = deployment.GcpMachine(
project="hydro-1234",
zone="us-west1-a",
type="e2-micro",
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/deploy/deployments-hosts-and-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ Hydro Deploy also supports deploying to cloud VMs, currently supporting Google C
### Google Cloud Platform
To deploy to Google Cloud Platform, you will need to install Terraform and the Google Cloud SDK (see [install](./install)). You will also need to create a Google Cloud project.

The first step is to create a VPC, which will enable network connections for our services. We can do this by creating a `hydro.GCPNetwork` object:
The first step is to create a VPC, which will enable network connections for our services. We can do this by creating a `hydro.GcpNetwork` object:
```python
network = deployment.GCPNetwork(
network = deployment.GcpNetwork(
project="my-project"
)
```

Then, we can launch a VM on this network using `hydro.GCPComputeEngineHost`:
Then, we can launch a VM on this network using `hydro.GcpComputeEngineHost`:
```python
host = deployment.GCPComputeEngineHost(
host = deployment.GcpComputeEngineHost(
name="my-host",
network=network,
machine_type="e2-micro",
Expand Down
12 changes: 6 additions & 6 deletions hydro_deploy/core/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use anyhow::Result;
use futures::{StreamExt, TryStreamExt};
use tokio::sync::RwLock;

use super::gcp::GCPNetwork;
use super::gcp::GcpNetwork;
use super::{
progress, CustomService, GCPComputeEngineHost, Host, LocalhostHost, ResourcePool,
progress, CustomService, GcpComputeEngineHost, Host, LocalhostHost, ResourcePool,
ResourceResult, Service,
};
use crate::ServiceBuilder;
Expand All @@ -32,17 +32,17 @@ impl Deployment {
}

#[allow(non_snake_case)]
pub fn GCPComputeEngineHost(
pub fn GcpComputeEngineHost(
&mut self,
project: impl Into<String>,
machine_type: impl Into<String>,
image: impl Into<String>,
region: impl Into<String>,
network: Arc<RwLock<GCPNetwork>>,
network: Arc<RwLock<GcpNetwork>>,
user: Option<String>,
) -> Arc<RwLock<GCPComputeEngineHost>> {
) -> Arc<RwLock<GcpComputeEngineHost>> {
self.add_host(|id| {
GCPComputeEngineHost::new(id, project, machine_type, image, region, network, user)
GcpComputeEngineHost::new(id, project, machine_type, image, region, network, user)
})
}

Expand Down
18 changes: 9 additions & 9 deletions hydro_deploy/core/src/gcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ impl LaunchedSshHost for LaunchedComputeEngine {
}

#[derive(Debug)]
pub struct GCPNetwork {
pub struct GcpNetwork {
pub project: String,
pub existing_vpc: Option<String>,
id: String,
}

impl GCPNetwork {
impl GcpNetwork {
pub fn new(project: impl Into<String>, existing_vpc: Option<String>) -> Self {
Self {
project: project.into(),
Expand Down Expand Up @@ -167,26 +167,26 @@ impl GCPNetwork {
}
}

pub struct GCPComputeEngineHost {
pub struct GcpComputeEngineHost {
pub id: usize,
pub project: String,
pub machine_type: String,
pub image: String,
pub region: String,
pub network: Arc<RwLock<GCPNetwork>>,
pub network: Arc<RwLock<GcpNetwork>>,
pub user: Option<String>,
pub launched: Option<Arc<LaunchedComputeEngine>>,
external_ports: Vec<u16>,
}

impl GCPComputeEngineHost {
impl GcpComputeEngineHost {
pub fn new(
id: usize,
project: impl Into<String>,
machine_type: impl Into<String>,
image: impl Into<String>,
region: impl Into<String>,
network: Arc<RwLock<GCPNetwork>>,
network: Arc<RwLock<GcpNetwork>>,
user: Option<String>,
) -> Self {
Self {
Expand All @@ -204,7 +204,7 @@ impl GCPComputeEngineHost {
}

#[async_trait]
impl Host for GCPComputeEngineHost {
impl Host for GcpComputeEngineHost {
fn target_type(&self) -> HostTargetType {
HostTargetType::Linux
}
Expand Down Expand Up @@ -483,7 +483,7 @@ impl Host for GCPComputeEngineHost {
Ok((
ClientStrategy::ForwardedTcpPort(self),
Box::new(|me| {
me.downcast_mut::<GCPComputeEngineHost>()
me.downcast_mut::<GcpComputeEngineHost>()
.unwrap()
.request_port(&ServerStrategy::ExternalTcpPort(22)); // needed to forward
ServerStrategy::InternalTcpPort
Expand All @@ -510,7 +510,7 @@ impl Host for GCPComputeEngineHost {
}
ClientStrategy::InternalTcpPort(target_host) => {
if let Some(gcp_target) =
target_host.as_any().downcast_ref::<GCPComputeEngineHost>()
target_host.as_any().downcast_ref::<GcpComputeEngineHost>()
{
self.project == gcp_target.project
} else {
Expand Down
2 changes: 1 addition & 1 deletion hydro_deploy/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use localhost::LocalhostHost;
pub mod ssh;

pub mod gcp;
pub use gcp::GCPComputeEngineHost;
pub use gcp::GcpComputeEngineHost;

pub mod azure;
pub use azure::AzureHost;
Expand Down
6 changes: 3 additions & 3 deletions hydro_deploy/hydro_cli/hydro/_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Deployment(object):

def Localhost(self) -> "LocalhostHost": ...

def GCPComputeEngineHost(self, project: str, machine_type: str, image: str, region: str, network: "GCPNetwork", user: Optional[str] = None) -> "GCPComputeEngineHost": ...
def GcpComputeEngineHost(self, project: str, machine_type: str, image: str, region: str, network: "GcpNetwork", user: Optional[str] = None) -> "GcpComputeEngineHost": ...

def CustomService(self, on: "Host", external_ports: List[int]) -> "CustomService": ...

Expand All @@ -32,10 +32,10 @@ class Host(object):
class LocalhostHost(Host):
def client_only() -> "LocalhostHost": ...

class GCPNetwork(object):
class GcpNetwork(object):
def __init__(self, project: str, existing: Optional[str] = None) -> None: ...

class GCPComputeEngineHost(Host):
class GcpComputeEngineHost(Host):
internal_ip: str
external_ip: Optional[str]
ssh_key_path: str
Expand Down
28 changes: 14 additions & 14 deletions hydro_deploy/hydro_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,18 @@ impl Deployment {
}

#[allow(non_snake_case, clippy::too_many_arguments)]
fn GCPComputeEngineHost(
fn GcpComputeEngineHost(
&self,
py: Python<'_>,
project: String,
machine_type: String,
image: String,
region: String,
network: GCPNetwork,
network: GcpNetwork,
user: Option<String>,
) -> PyResult<Py<PyAny>> {
let arc = self.underlying.blocking_write().add_host(|id| {
core::GCPComputeEngineHost::new(
core::GcpComputeEngineHost::new(
id,
project,
machine_type,
Expand All @@ -203,7 +203,7 @@ impl Deployment {
PyClassInitializer::from(Host {
underlying: arc.clone(),
})
.add_subclass(GCPComputeEngineHost { underlying: arc }),
.add_subclass(GcpComputeEngineHost { underlying: arc }),
)?
.into_py(py))
}
Expand Down Expand Up @@ -357,27 +357,27 @@ impl LocalhostHost {

#[pyclass]
#[derive(Clone)]
struct GCPNetwork {
underlying: Arc<RwLock<core::gcp::GCPNetwork>>,
struct GcpNetwork {
underlying: Arc<RwLock<core::gcp::GcpNetwork>>,
}

#[pymethods]
impl GCPNetwork {
impl GcpNetwork {
#[new]
fn new(project: String, existing: Option<String>) -> Self {
GCPNetwork {
underlying: Arc::new(RwLock::new(core::gcp::GCPNetwork::new(project, existing))),
GcpNetwork {
underlying: Arc::new(RwLock::new(core::gcp::GcpNetwork::new(project, existing))),
}
}
}

#[pyclass(extends=Host, subclass)]
struct GCPComputeEngineHost {
underlying: Arc<RwLock<core::GCPComputeEngineHost>>,
struct GcpComputeEngineHost {
underlying: Arc<RwLock<core::GcpComputeEngineHost>>,
}

#[pymethods]
impl GCPComputeEngineHost {
impl GcpComputeEngineHost {
#[getter]
fn internal_ip(&self) -> String {
self.underlying
Expand Down Expand Up @@ -876,8 +876,8 @@ async def coroutine_to_safely_cancellable(c, cancel_token):
module.add_class::<Host>()?;
module.add_class::<LocalhostHost>()?;

module.add_class::<GCPNetwork>()?;
module.add_class::<GCPComputeEngineHost>()?;
module.add_class::<GcpNetwork>()?;
module.add_class::<GcpComputeEngineHost>()?;

module.add_class::<Service>()?;
module.add_class::<CustomService>()?;
Expand Down
4 changes: 2 additions & 2 deletions hydro_deploy/hydro_cli_examples/2pc.hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ async def main(args):
deployment = hydro.Deployment()
localhost_machine = deployment.Localhost()

machine1 = deployment.GCPComputeEngineHost(
machine1 = deployment.GcpComputeEngineHost(
project="autocompartmentalization",
machine_type="e2-micro",
image="debian-cloud/debian-11",
region="us-west1-a"
) if machine_1_gcp else localhost_machine

machine2 = deployment.GCPComputeEngineHost(
machine2 = deployment.GcpComputeEngineHost(
project="autocompartmentalization",
machine_type="e2-micro",
image="debian-cloud/debian-11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ async def main(args):
deployment = hydro.Deployment()
localhost_machine = deployment.Localhost()

gcp_vpc = hydro.GCPNetwork(
gcp_vpc = hydro.GcpNetwork(
project="autocompartmentalization",
)

machine2 = deployment.GCPComputeEngineHost(
machine2 = deployment.GcpComputeEngineHost(
project="autocompartmentalization",
machine_type="e2-micro",
image="debian-cloud/debian-11",
Expand Down
4 changes: 2 additions & 2 deletions hydro_deploy/hydro_cli_examples/hydro_python_sender.hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ async def main(args):
deployment = hydro.Deployment()
localhost_machine = deployment.Localhost()

gcp_vpc = hydro.GCPNetwork(
gcp_vpc = hydro.GcpNetwork(
project="autocompartmentalization",
)

machine2 = deployment.GCPComputeEngineHost(
machine2 = deployment.GcpComputeEngineHost(
project="autocompartmentalization",
machine_type="e2-micro",
image="debian-cloud/debian-11",
Expand Down
4 changes: 2 additions & 2 deletions hydro_deploy/hydro_cli_examples/pn_counter.hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ async def main(args):
on=localhost_machine,
)

gcp_vpc = hydro.GCPNetwork(
gcp_vpc = hydro.GcpNetwork(
project="hydro-chrisdouglas",
)

def create_machine():
if args[0] == "gcp":
return deployment.GCPComputeEngineHost(
return deployment.GcpComputeEngineHost(
project="hydro-chrisdouglas",
machine_type="e2-micro",
image="debian-cloud/debian-11",
Expand Down
6 changes: 3 additions & 3 deletions hydro_deploy/hydro_cli_examples/simple_dedalus.hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ async def main(args):
deployment = hydro.Deployment()
localhost_machine = deployment.Localhost()

gcp_vpc = hydro.GCPNetwork(
gcp_vpc = hydro.GcpNetwork(
project="autocompartmentalization",
)

machine1 = deployment.GCPComputeEngineHost(
machine1 = deployment.GcpComputeEngineHost(
project="autocompartmentalization",
machine_type="e2-micro",
image="debian-cloud/debian-11",
region="us-west1-a",
network=gcp_vpc
) if machine_1_gcp else localhost_machine

machine2 = deployment.GCPComputeEngineHost(
machine2 = deployment.GcpComputeEngineHost(
project="autocompartmentalization",
machine_type="e2-micro",
image="debian-cloud/debian-11",
Expand Down
4 changes: 2 additions & 2 deletions hydro_deploy/hydro_cli_examples/tagged_python_sender.hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ async def main(args):
deployment = hydro.Deployment()
localhost_machine = deployment.Localhost()

gcp_vpc = hydro.GCPNetwork(
gcp_vpc = hydro.GcpNetwork(
project="autocompartmentalization",
)

machine2 = deployment.GCPComputeEngineHost(
machine2 = deployment.GcpComputeEngineHost(
project="autocompartmentalization",
machine_type="e2-micro",
image="debian-cloud/debian-11",
Expand Down
Loading

0 comments on commit 12b8ba5

Please sign in to comment.